Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Error] Better error message when creating sparse snodes on backends that do not support sparse #7191

Merged
merged 1 commit into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions python/taichi/_snode/fields_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,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:
if not _ti_core.is_extension_supported(impl.current_cfg().arch,
_ti_core.Extension.sparse):
raise TaichiRuntimeError(
"Pointer SNode on metal backend is deprecated and removed.")
"Pointer SNode is not supported on this backend.")
self._check_not_finalized()
self.empty = False
return self.root.pointer(indices, dimensions)
Expand All @@ -90,19 +91,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:
if not _ti_core.is_extension_supported(impl.current_cfg().arch,
_ti_core.Extension.sparse):
raise TaichiRuntimeError(
"Dynamic SNode on metal backend is deprecated and removed.")
"Dynamic SNode is not supported on this backend.")
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:
if not _ti_core.is_extension_supported(impl.current_cfg().arch,
_ti_core.Extension.sparse):
raise TaichiRuntimeError(
"Bitmasked SNode on metal backend is deprecated and removed.")
"Bitmasked SNode is not supported on this backend.")
self._check_not_finalized()
self.empty = False
return self.root.bitmasked(indices, dimensions)
Expand Down
15 changes: 9 additions & 6 deletions python/taichi/lang/snode.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ def pointer(self, axes, dimensions):
Returns:
The added :class:`~taichi.lang.SNode` instance.
"""
if impl.current_cfg().arch == _ti_core.metal:
if not _ti_core.is_extension_supported(impl.current_cfg().arch,
_ti_core.Extension.sparse):
raise TaichiRuntimeError(
"Pointer SNode on metal backend is deprecated and removed.")
"Pointer SNode is not supported on this backend.")
if isinstance(dimensions, numbers.Number):
dimensions = [dimensions] * len(axes)
return SNode(self.ptr.pointer(axes, dimensions, get_traceback()))
Expand All @@ -73,9 +74,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:
if not _ti_core.is_extension_supported(impl.current_cfg().arch,
_ti_core.Extension.sparse):
raise TaichiRuntimeError(
"Dynamic SNode on metal backend is deprecated and removed.")
"Dynamic SNode is not supported on this backend.")
assert len(axis) == 1
if chunk_size is None:
chunk_size = dimension
Expand All @@ -92,9 +94,10 @@ def bitmasked(self, axes, dimensions):
Returns:
The added :class:`~taichi.lang.SNode` instance.
"""
if impl.current_cfg().arch == _ti_core.metal:
if not _ti_core.is_extension_supported(impl.current_cfg().arch,
_ti_core.Extension.sparse):
raise TaichiRuntimeError(
"Bitmasked SNode on metal backend is deprecated and removed.")
"Bitmasked SNode is not supported on this backend.")
if isinstance(dimensions, numbers.Number):
dimensions = [dimensions] * len(axes)
return SNode(self.ptr.bitmasked(axes, dimensions, get_traceback()))
Expand Down
18 changes: 0 additions & 18 deletions tests/python/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,6 @@ def test_deprecate_element_shape_ndarray_arg():
element_shape=(1, ))


# Remove this before v1.5.0
@test_utils.test(arch=ti.metal)
def test_deprecate_metal_sparse():
with pytest.raises(
ti.TaichiRuntimeError,
match="Pointer SNode on metal backend is deprecated and removed."):
ti.root.pointer(ti.i, 10)
with pytest.raises(
ti.TaichiRuntimeError,
match="Bitmasked SNode on metal backend is deprecated and removed."
):
ti.root.bitmasked(ti.j, 10)
with pytest.raises(
ti.TaichiRuntimeError,
match="Dynamic SNode on metal backend is deprecated and removed."):
ti.root.dynamic(ti.i, 10)


@test_utils.test(arch=ti.vulkan)
def test_deprecated_rwtexture_type():
n = 128
Expand Down
36 changes: 36 additions & 0 deletions tests/python/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,39 @@ def foo():
b = a * x

foo()


@test_utils.test(exclude=[ti.x64, ti.arm64, ti.cuda])
def test_sparse_not_supported():
with pytest.raises(
ti.TaichiRuntimeError,
match="Pointer SNode is not supported on this backend."):
ti.root.pointer(ti.i, 10)

with pytest.raises(
ti.TaichiRuntimeError,
match="Pointer SNode is not supported on this backend."):
a = ti.root.dense(ti.i, 10)
a.pointer(ti.j, 10)

with pytest.raises(
ti.TaichiRuntimeError,
match="Dynamic SNode is not supported on this backend."):
ti.root.dynamic(ti.i, 10)

with pytest.raises(
ti.TaichiRuntimeError,
match="Dynamic SNode is not supported on this backend."):
a = ti.root.dense(ti.i, 10)
a.dynamic(ti.j, 10)

with pytest.raises(
ti.TaichiRuntimeError,
match="Bitmasked SNode is not supported on this backend."):
ti.root.bitmasked(ti.i, 10)

with pytest.raises(
ti.TaichiRuntimeError,
match="Bitmasked SNode is not supported on this backend."):
a = ti.root.dense(ti.i, 10)
a.bitmasked(ti.j, 10)