Skip to content

Commit

Permalink
[Metal] [error] Raise deprecate warning and error when using sparse s…
Browse files Browse the repository at this point in the history
…nodes on metal (#6739)

Issue: #6358

### Brief Summary

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
lin-hitonami and pre-commit-ci[bot] authored Nov 28, 2022
1 parent 13ce3f0 commit 8ee95c9
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 7 deletions.
13 changes: 13 additions & 0 deletions python/taichi/_snode/fields_builder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from typing import Any, Optional, Sequence, Union

from taichi._lib import core as _ti_core
Expand Down Expand Up @@ -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)
Expand All @@ -87,13 +92,21 @@ 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)

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)
Expand Down
13 changes: 13 additions & 0 deletions python/taichi/lang/snode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numbers
import warnings

from taichi._lib import core as _ti_core
from taichi.lang import expr, impl, matrix
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions tests/python/test_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 8 additions & 2 deletions tests/python/test_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
23 changes: 23 additions & 0 deletions tests/python/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion tests/python/test_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/python/test_no_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 8ee95c9

Please sign in to comment.