Skip to content

Commit

Permalink
[aot] Deprecate filename arg in ti.aot.Module.save() (taichi-dev#6554)
Browse files Browse the repository at this point in the history
Issue: #

### Brief Summary
`filename` argument in `ti.aot.Module.save()` has been no-op for a long
time. This PR deprecates it and annouce that it'll be removed in v1.4.0
release.

Also added a test file called `test_deprecation.py` which is designed to
be the place to check all DeprecationWarnings so that before every
release we can just check here to see if we can safely remove any
deprecated apis.
  • Loading branch information
ailzhang authored Nov 9, 2022
1 parent 81ce4de commit 957d424
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
9 changes: 7 additions & 2 deletions python/taichi/aot/module.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from contextlib import contextmanager
from glob import glob
from pathlib import Path, PurePosixPath
Expand Down Expand Up @@ -199,14 +200,18 @@ def add_kernel_template(self, kernel_fn):
kt = KernelTemplate(kernel_fn, self)
yield kt

def save(self, filepath, filename):
def save(self, filepath, filename=None):
"""
Args:
filepath (str): path to a folder to store aot files.
filename (str): filename prefix for stored aot files.
"""
if filename is not None:
warnings.warn(
"Specifying filename is no-op and will be removed in release v1.4.0",
DeprecationWarning)
filepath = str(PurePosixPath(Path(filepath)))
self._aot_builder.dump(filepath, filename)
self._aot_builder.dump(filepath, "")

def archive(self, filepath: str):
"""
Expand Down
18 changes: 9 additions & 9 deletions tests/python/test_aot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def init():
m = ti.aot.Module(ti.opengl)
m.add_field('density', density)
m.add_kernel(init)
m.save(tmpdir, '')
m.save(tmpdir)
with open(os.path.join(tmpdir, 'metadata.json')) as json_file:
res = json.load(json_file)
range_hint = res['aot_data']['kernels']['init']['tasks'][0][
Expand All @@ -70,7 +70,7 @@ def init(x: ti.f32, density1: ti.types.ndarray(field_dim=2)):
with tempfile.TemporaryDirectory() as tmpdir:
m = ti.aot.Module(ti.lang.impl.current_cfg().arch)
m.add_kernel(init, {'density1': density1})
m.save(tmpdir, '')
m.save(tmpdir)
with open(os.path.join(tmpdir, 'metadata.json')) as json_file:
res = json.load(json_file)
buffer_binds = res['aot_data']['kernels']['init']['tasks'][0][
Expand All @@ -96,7 +96,7 @@ def init():
m = ti.aot.Module(ti.lang.impl.current_cfg().arch)
m.add_field('density', density)
m.add_kernel(init)
m.save(tmpdir, '')
m.save(tmpdir)
with open(os.path.join(tmpdir, 'metadata.json')) as json_file:
json.load(json_file)

Expand All @@ -117,7 +117,7 @@ def foo(n: ti.template()):
with m.add_kernel_template(foo) as kt:
kt.instantiate(n=6)
kt.instantiate(n=8)
m.save(tmpdir, '')
m.save(tmpdir)
with open(os.path.join(tmpdir, 'metadata.json')) as json_file:
json.load(json_file)

Expand Down Expand Up @@ -228,7 +228,7 @@ def init():
m.add_field("grid_m", grid_m)
m.add_kernel(substep)
m.add_kernel(init)
m.save(tmpdir, '')
m.save(tmpdir)
with open(os.path.join(tmpdir, 'metadata.json')) as json_file:
json.load(json_file)

Expand Down Expand Up @@ -409,7 +409,7 @@ def initialize():
m.add_kernel(initialize)
m.add_kernel(substep)

m.save(tmpdir, '')
m.save(tmpdir)
with open(os.path.join(tmpdir, 'metadata.json')) as json_file:
json.load(json_file)

Expand Down Expand Up @@ -503,7 +503,7 @@ def substep(x: ti.types.ndarray(element_dim=1),
}
m.add_kernel(substep, template_args=template_args)

m.save(tmpdir, '')
m.save(tmpdir)
with open(os.path.join(tmpdir, 'metadata.json')) as json_file:
json.load(json_file)

Expand Down Expand Up @@ -570,7 +570,7 @@ def init_data(test_vec: ivec3):
# note ti.aot.Module(ti.opengl) is no-op according to its docstring.
m = ti.aot.Module(ti.lang.impl.current_cfg().arch)
m.add_graph("g_init", g_init)
m.save(tmpdir, '')
m.save(tmpdir)
with open(os.path.join(tmpdir, 'metadata.json'), "r") as json_file:
json.load(json_file)

Expand All @@ -596,4 +596,4 @@ def test(a: ti.types.ndarray(), c: ti.u8):
m = ti.aot.Module(ti.lang.impl.current_cfg().arch, caps=['spirv_has_int8'])
m.add_graph('g_init', g)
with tempfile.TemporaryDirectory() as tmpdir:
m.save(tmpdir, '')
m.save(tmpdir)
21 changes: 21 additions & 0 deletions tests/python/test_deprecation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import tempfile

import pytest

import taichi as ti
from tests import test_utils


@test_utils.test(arch=[ti.vulkan, ti.opengl, ti.cuda, ti.cpu])
def test_deprecated_aot_save_filename():
density = ti.field(float, shape=(4, 4))

with tempfile.TemporaryDirectory() as tmpdir:
m = ti.aot.Module(ti.lang.impl.current_cfg().arch)
m.add_field('density', density)
with pytest.warns(
DeprecationWarning,
match=
r'Specifying filename is no-op and will be removed in release v1.4.0'
):
m.save(tmpdir, 'filename')

0 comments on commit 957d424

Please sign in to comment.