Skip to content

Commit

Permalink
[Lang] Raise errors when using the packed switch (#7125)
Browse files Browse the repository at this point in the history
### Brief Summary

The `packed` switch of `ti.init()` should be removed according to the
[deprecation
notice](https://github.com/taichi-dev/taichi/releases/tag/v1.3.0).
However, to avoid a large changeset immediately before release (#7104),
let's raise errors first and get that in later.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and lin-hitonami committed Jan 12, 2023
1 parent 580dcab commit ba26c34
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 143 deletions.
1 change: 0 additions & 1 deletion docs/lang/articles/contribution/write_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,5 +283,4 @@ Now, Taichi supports the following extensions:
| bls | Block-local storage |
| assertion | Run-time asserts in Taichi kernels |
| extfunc | Support inserting external function calls or backend source |
| packed | Packed mode: shapes will not be padded to powers of two |
| dynamic_index | Dynamic index support for tensors |
14 changes: 3 additions & 11 deletions python/taichi/lang/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from taichi._lib import core as _ti_core
from taichi._lib.utils import locale_encode
from taichi.lang import impl
from taichi.lang.exception import TaichiRuntimeError
from taichi.lang.expr import Expr
from taichi.lang.impl import axes, get_runtime
from taichi.profiler.kernel_profiler import get_default_kernel_profiler
Expand Down Expand Up @@ -184,7 +185,7 @@
The list of currently available extensions is ['sparse', 'quant', \
'mesh', 'quant_basic', 'data64', 'adstack', 'bls', 'assertion', \
'extfunc', 'packed', 'dynamic_index'].
'extfunc', 'dynamic_index'].
"""


Expand Down Expand Up @@ -346,7 +347,6 @@ def init(arch=None,
* ``cpu_max_num_threads`` (int): Sets the number of threads used by the CPU thread pool.
* ``debug`` (bool): Enables the debug mode, under which Taichi does a few more things like boundary checks.
* ``print_ir`` (bool): Prints the CHI IR of the Taichi kernels.
* ``packed`` (bool): Enables the packed memory layout. See https://docs.taichi-lang.org/docs/layout.
*``offline_cache`` (bool): Enables offline cache of the compiled kernels. Default to True. When this is enabled Taichi will cache compiled kernel on your local disk to accelerate future calls.
*``random_seed`` (int): Sets the seed of the random generator. The default is 0.
"""
Expand All @@ -362,15 +362,7 @@ def init(arch=None,
check_require_version(require_version)

if "packed" in kwargs:
if kwargs["packed"] is True:
warnings.warn(
"Currently packed=True is the default setting and the switch will be removed in v1.4.0.",
DeprecationWarning)
else:
warnings.warn(
"The automatic padding mode (packed=False) will no longer exist in v1.4.0. The switch will "
"also be removed then. Make sure your code doesn't rely on it.",
DeprecationWarning)
raise TaichiRuntimeError("The 'packed' switch has been removed.")

if "dynamic_index" in kwargs:
warnings.warn(
Expand Down
26 changes: 4 additions & 22 deletions tests/python/test_bitmasked.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from tests import test_utils


def _test_basic():
@test_utils.test(require=ti.extension.sparse)
def test_basic():
x = ti.field(ti.i32)
c = ti.field(ti.i32)
s = ti.field(ti.i32)
Expand Down Expand Up @@ -30,16 +31,6 @@ def sum():
assert s[None] == 42


@test_utils.test(require=ti.extension.sparse)
def test_basic():
_test_basic()


@test_utils.test(require=ti.extension.sparse, packed=True)
def test_basic_packed():
_test_basic()


@test_utils.test(require=ti.extension.sparse)
def test_bitmasked_then_dense():
x = ti.field(ti.f32)
Expand Down Expand Up @@ -177,7 +168,8 @@ def deactivate():
assert c[None] == 0


def _test_sparsity_changes():
@test_utils.test(require=ti.extension.sparse)
def test_sparsity_changes():
x = ti.field(ti.i32)
c = ti.field(ti.i32)
s = ti.field(ti.i32)
Expand Down Expand Up @@ -210,16 +202,6 @@ def run():
assert s[None] == 42


@test_utils.test(require=ti.extension.sparse)
def test_sparsity_changes():
_test_sparsity_changes()


@test_utils.test(require=ti.extension.sparse, packed=True)
def test_sparsity_changes_packed():
_test_sparsity_changes()


@test_utils.test(require=ti.extension.sparse)
def test_bitmasked_offset_child():
x = ti.field(ti.i32)
Expand Down
22 changes: 6 additions & 16 deletions tests/python/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,12 @@ def test_deprecate_metal_sparse():
ti.root.dynamic(ti.i, 10)


def test_deprecated_packed_true():
with pytest.warns(
DeprecationWarning,
match=
"Currently packed=True is the default setting and the switch will be removed in v1.4.0."
):
ti.init(packed=True)


def test_deprecated_packed_false():
with pytest.warns(
DeprecationWarning,
match=
r"The automatic padding mode \(packed=False\) will no longer exist in v1.4.0. The switch will "
"also be removed then. Make sure your code doesn't rely on it."):
ti.init(packed=False)
# Remove this before v1.5.0
@pytest.mark.parametrize("value", [True, False])
def test_removed_packed(value):
with pytest.raises(ti.TaichiRuntimeError,
match="The 'packed' switch has been removed."):
ti.init(packed=value)


@test_utils.test(arch=ti.vulkan)
Expand Down
22 changes: 0 additions & 22 deletions tests/python/test_indices_assert.py

This file was deleted.

11 changes: 0 additions & 11 deletions tests/python/test_mpm_particle_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,3 @@ def test_mpm_particle_list_no_leakage():
# By default Taichi will allocate 0.5 GB for testing.
mpm = MPMSolver(res=(128, 128))
mpm.step()


@pytest.mark.run_in_serial
@test_utils.test(require=ti.extension.sparse,
exclude=[ti.metal],
device_memory_GB=1.0,
packed=True)
def test_mpm_particle_list_no_leakage_packed():
# By default Taichi will allocate 0.5 GB for testing.
mpm = MPMSolver(res=(128, 128))
mpm.step()
2 changes: 1 addition & 1 deletion tests/python/test_packed_size.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(arch=[ti.cpu, ti.cuda], packed=True)
@test_utils.test(arch=[ti.cpu, ti.cuda])
def test_packed_size():
x = ti.field(ti.i32)
ti.root.dense(ti.l, 3).dense(ti.ijk, 129).place(x)
Expand Down
13 changes: 2 additions & 11 deletions tests/python/test_sparse_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ def func():
assert s[None] == 3


def _test_pointer2():
@test_utils.test(require=ti.extension.sparse)
def test_pointer2():
x = ti.field(ti.f32)
s = ti.field(ti.i32)

Expand Down Expand Up @@ -103,16 +104,6 @@ def func():
assert s[None] == 5 * n


@test_utils.test(require=ti.extension.sparse)
def test_pointer2():
_test_pointer2()


@test_utils.test(require=ti.extension.sparse, packed=True)
def test_pointer2_packed():
_test_pointer2()


@pytest.mark.skip(reason='https://github.com/taichi-dev/taichi/issues/2520')
@test_utils.test(require=ti.extension.sparse)
def test_pointer_direct_place():
Expand Down
18 changes: 2 additions & 16 deletions tests/python/test_struct_for_intermediate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,11 @@ def iterate():
assert x[i * n, j * m] == 1, (i, j)


@test_utils.test(require=ti.extension.sparse,
demote_dense_struct_fors=False,
packed=False)
@test_utils.test(require=ti.extension.sparse, demote_dense_struct_fors=False)
def test_nested():
_test_nested()


@test_utils.test(demote_dense_struct_fors=True, packed=False)
@test_utils.test(demote_dense_struct_fors=True)
def test_nested_demote():
_test_nested()


@test_utils.test(require=ti.extension.sparse,
demote_dense_struct_fors=False,
packed=True)
def test_nested_packed():
_test_nested()


@test_utils.test(demote_dense_struct_fors=True, packed=True)
def test_nested_demote_packed():
_test_nested()
37 changes: 5 additions & 32 deletions tests/python/test_struct_for_non_pot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
from tests import test_utils


def _test_1d():
@test_utils.test()
def test_1d():
x = ti.field(ti.i32)
sum = ti.field(ti.i32)

Expand All @@ -23,16 +24,7 @@ def accumulate():


@test_utils.test()
def test_1d():
_test_1d()


@test_utils.test(packed=True)
def test_1d_packed():
_test_1d()


def _test_2d():
def test_2d():
x = ti.field(ti.i32)
sum = ti.field(ti.i32)

Expand All @@ -58,17 +50,8 @@ def accumulate():
assert sum[None] == gt


@test_utils.test()
def test_2d():
_test_2d()


@test_utils.test(packed=True)
def test_2d_packed():
_test_2d()


def _test_2d_pointer():
@test_utils.test(require=ti.extension.sparse)
def test_2d_pointer():
block_size, leaf_size = 3, 8
x = ti.field(ti.i32)
block = ti.root.pointer(ti.ij, (block_size, block_size))
Expand All @@ -93,13 +76,3 @@ def test() -> ti.i32:
ans += i + j * 2

assert ans == test()


@test_utils.test(require=ti.extension.sparse, packed=False)
def test_2d_pointer():
_test_2d_pointer()


@test_utils.test(require=ti.extension.sparse, packed=True)
def test_2d_pointer_packed():
_test_2d_pointer()

0 comments on commit ba26c34

Please sign in to comment.