Skip to content

Commit

Permalink
[Lang] Add deprecation warning for the removal of the packed switch (t…
Browse files Browse the repository at this point in the history
…aichi-dev#6753)

Issue: taichi-dev#6660

### Brief Summary

Apart from the deprecated warning, the previously added limitation that
"non-first division on an axis must be a power of two" is now made
purely a warning because it can already let users learn the best
practice.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
2 people authored and quadpixels committed May 13, 2023
1 parent ce4b704 commit 534bfe0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
11 changes: 11 additions & 0 deletions python/taichi/lang/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,17 @@ def init(arch=None,
if require_version is not 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)

if "default_up" in kwargs:
raise KeyError(
"'default_up' is always the unsigned type of 'default_ip'. Please set 'default_ip' instead."
Expand Down
8 changes: 3 additions & 5 deletions taichi/ir/snode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ SNode &SNode::create_node(std::vector<Axis> axes,
} else {
TI_WARN_IF(
packed && !bit::is_power_of_two(sizes[i]),
"Non-first division of an axis on a SNodeTree path should be a power "
"of two to achieve best performance:\n{} We plan to turn this "
"warning into an error at v1.4.0. If you do have a use case that "
"needs to violate this rule, please submit an issue to notify us.",
tb);
"Shape {} is detected on non-first division of axis {}:\n{} For "
"best performance, we recommend that you set it to a power of two.",
sizes[i], char('i' + ind), tb);
}
new_node.extractors[ind].activate(
bit::log2int(bit::least_pot_bound(sizes[i])));
Expand Down
18 changes: 18 additions & 0 deletions tests/python/test_deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,21 @@ def test_deprecate_metal_sparse():
"Dynamic SNode on metal backend is deprecated and removed in this release."
):
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)

0 comments on commit 534bfe0

Please sign in to comment.