From 8ee95c9be0c26bc0bccc15f4662ed758877b7b89 Mon Sep 17 00:00:00 2001 From: Lin Jiang Date: Mon, 28 Nov 2022 14:42:34 +0800 Subject: [PATCH] [Metal] [error] Raise deprecate warning and error when using sparse snodes on metal (#6739) Issue: https://github.com/taichi-dev/taichi/discussions/6358 ### Brief Summary Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- python/taichi/_snode/fields_builder.py | 13 +++++++++++++ python/taichi/lang/snode.py | 13 +++++++++++++ tests/python/test_compare.py | 6 +++--- tests/python/test_debug.py | 10 ++++++++-- tests/python/test_deprecation.py | 23 +++++++++++++++++++++++ tests/python/test_gc.py | 2 +- tests/python/test_no_activate.py | 2 +- 7 files changed, 62 insertions(+), 7 deletions(-) diff --git a/python/taichi/_snode/fields_builder.py b/python/taichi/_snode/fields_builder.py index b4c22c0cadf11..191ffdb45ca52 100644 --- a/python/taichi/_snode/fields_builder.py +++ b/python/taichi/_snode/fields_builder.py @@ -1,3 +1,4 @@ +import warnings from typing import Any, Optional, Sequence, Union from taichi._lib import core as _ti_core @@ -74,6 +75,10 @@ def dense(self, indices: Union[Sequence[_Axis], _Axis], def pointer(self, indices: Union[Sequence[_Axis], _Axis], dimensions: Union[Sequence[int], int]): """Same as :func:`taichi.lang.snode.SNode.pointer`""" + if impl.current_cfg().arch == _ti_core.metal: + warnings.warn( + "Pointer SNode on metal backend is deprecated, and it will be removed in v1.4.0.", + DeprecationWarning) self._check_not_finalized() self.empty = False return self.root.pointer(indices, dimensions) @@ -87,6 +92,10 @@ def dynamic(self, dimension: Union[Sequence[int], int], chunk_size: Optional[int] = None): """Same as :func:`taichi.lang.snode.SNode.dynamic`""" + if impl.current_cfg().arch == _ti_core.metal: + raise TaichiRuntimeError( + "Dynamic SNode on metal backend is deprecated and removed in this release." + ) self._check_not_finalized() self.empty = False return self.root.dynamic(index, dimension, chunk_size) @@ -94,6 +103,10 @@ def dynamic(self, def bitmasked(self, indices: Union[Sequence[_Axis], _Axis], dimensions: Union[Sequence[int], int]): """Same as :func:`taichi.lang.snode.SNode.bitmasked`""" + if impl.current_cfg().arch == _ti_core.metal: + warnings.warn( + "Bitmasked SNode on metal backend is deprecated, and it will be removed in v1.4.0.", + DeprecationWarning) self._check_not_finalized() self.empty = False return self.root.bitmasked(indices, dimensions) diff --git a/python/taichi/lang/snode.py b/python/taichi/lang/snode.py index 3d96752356a3a..f31f2cfcdedc2 100644 --- a/python/taichi/lang/snode.py +++ b/python/taichi/lang/snode.py @@ -1,4 +1,5 @@ import numbers +import warnings from taichi._lib import core as _ti_core from taichi.lang import expr, impl, matrix @@ -47,6 +48,10 @@ def pointer(self, axes, dimensions): Returns: The added :class:`~taichi.lang.SNode` instance. """ + if impl.current_cfg().arch == _ti_core.metal: + warnings.warn( + "Pointer SNode on metal backend is deprecated, and it will be removed in v1.4.0.", + DeprecationWarning) if isinstance(dimensions, numbers.Number): dimensions = [dimensions] * len(axes) return SNode( @@ -74,6 +79,10 @@ def dynamic(self, axis, dimension, chunk_size=None): Returns: The added :class:`~taichi.lang.SNode` instance. """ + if impl.current_cfg().arch == _ti_core.metal: + raise TaichiCompilationError( + "Dynamic SNode on metal backend is deprecated and removed in this release." + ) assert len(axis) == 1 if chunk_size is None: chunk_size = dimension @@ -91,6 +100,10 @@ def bitmasked(self, axes, dimensions): Returns: The added :class:`~taichi.lang.SNode` instance. """ + if impl.current_cfg().arch == _ti_core.metal: + warnings.warn( + "Bitmasked SNode on metal backend is deprecated, and it will be removed in v1.4.0.", + DeprecationWarning) if isinstance(dimensions, numbers.Number): dimensions = [dimensions] * len(axes) return SNode( diff --git a/tests/python/test_compare.py b/tests/python/test_compare.py index c5a178b683512..64f0caa8ddfea 100644 --- a/tests/python/test_compare.py +++ b/tests/python/test_compare.py @@ -5,7 +5,7 @@ from tests import test_utils -@test_utils.test(require=ti.extension.sparse) +@test_utils.test(require=ti.extension.sparse, exclude=ti.metal) def test_compare_basics(): a = ti.field(ti.i32) ti.root.dynamic(ti.i, 256).place(a) @@ -44,7 +44,7 @@ def func(): assert a[11] -@test_utils.test(require=ti.extension.sparse) +@test_utils.test(require=ti.extension.sparse, exclude=ti.metal) def test_compare_equality(): a = ti.field(ti.i32) ti.root.dynamic(ti.i, 256).place(a) @@ -120,7 +120,7 @@ def func(): assert b[None] == 2 -@test_utils.test(require=ti.extension.sparse) +@test_utils.test(require=ti.extension.sparse, exclude=ti.metal) def test_chain_compare(): a = ti.field(ti.i32) ti.root.dynamic(ti.i, 256).place(a) diff --git a/tests/python/test_debug.py b/tests/python/test_debug.py index 4274964acb542..763be5c9c49fc 100644 --- a/tests/python/test_debug.py +++ b/tests/python/test_debug.py @@ -66,7 +66,10 @@ def func(): func() -@test_utils.test(require=ti.extension.assertion, debug=True, gdb_trigger=False) +@test_utils.test(require=ti.extension.assertion, + debug=True, + gdb_trigger=False, + exclude=ti.metal) def test_out_of_bound_dynamic(): x = ti.field(ti.i32) @@ -80,7 +83,10 @@ def func(): func() -@test_utils.test(require=ti.extension.assertion, debug=True, gdb_trigger=False) +@test_utils.test(require=ti.extension.assertion, + debug=True, + gdb_trigger=False, + exclude=ti.metal) def test_not_out_of_bound_dynamic(): x = ti.field(ti.i32) diff --git a/tests/python/test_deprecation.py b/tests/python/test_deprecation.py index a8c3c59451fd3..3aaaf477d6813 100644 --- a/tests/python/test_deprecation.py +++ b/tests/python/test_deprecation.py @@ -69,3 +69,26 @@ def test_deprecate_field_dim_ndarray_annotation(): @ti.kernel def func(x: ti.types.ndarray(field_dim=(16, 16))): pass + + +@test_utils.test(arch=ti.metal) +def test_deprecate_metal_sparse(): + with pytest.warns( + DeprecationWarning, + match= + "Pointer SNode on metal backend is deprecated, and it will be removed in v1.4.0." + ): + a = ti.root.pointer(ti.i, 10) + with pytest.warns( + DeprecationWarning, + match= + "Bitmasked SNode on metal backend is deprecated, and it will be removed in v1.4.0." + ): + b = a.bitmasked(ti.j, 10) + + with pytest.raises( + ti.TaichiRuntimeError, + match= + "Dynamic SNode on metal backend is deprecated and removed in this release." + ): + ti.root.dynamic(ti.i, 10) diff --git a/tests/python/test_gc.py b/tests/python/test_gc.py index 4028c249b82ea..a4276eec7c8f5 100644 --- a/tests/python/test_gc.py +++ b/tests/python/test_gc.py @@ -59,7 +59,7 @@ def test_block(): _test_block_gc() -@test_utils.test(require=ti.extension.sparse) +@test_utils.test(require=ti.extension.sparse, exclude=ti.metal) def test_dynamic_gc(): x = ti.field(dtype=ti.i32) diff --git a/tests/python/test_no_activate.py b/tests/python/test_no_activate.py index 43311f2c1dec1..5221c7bf60a5b 100644 --- a/tests/python/test_no_activate.py +++ b/tests/python/test_no_activate.py @@ -2,7 +2,7 @@ from tests import test_utils -@test_utils.test(require=ti.extension.sparse) +@test_utils.test(require=ti.extension.sparse, exclude=ti.metal) def test_no_activate(): x = ti.field(ti.f32)