Skip to content
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
2 changes: 1 addition & 1 deletion python/unittest_py/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ xdoctest==1.3.0
ubelt==1.4.0 # just for xdoctest
mypy==1.19.1
soundfile
apache-tvm-ffi==0.1.5
apache-tvm-ffi==0.1.10
graphviz
nvidia-ml-py3 ; platform_system != "Darwin"
35 changes: 28 additions & 7 deletions test/legacy_test/test_tvm_ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ def test_c_dlpack_exchange_api_cpu(self):
"""

mod: Module = tvm_ffi.cpp.load_inline(
name='mod', cpp_sources=cpp_source, functions='add_one_cpu'
name='mod',
cpp_sources=cpp_source,
functions='add_one_cpu',
keep_module_alive=False,
)

x = paddle.full((3,), 1.0, dtype='float32').cpu()
Expand Down Expand Up @@ -141,11 +144,23 @@ def test_c_dlpack_exchange_api_alloc_tensor(self):
}
"""
mod: Module = tvm_ffi.cpp.load_inline(
name='mod', cpp_sources=cpp_source, functions=['add_one_cpu']
name='mod',
cpp_sources=cpp_source,
functions=['add_one_cpu'],
keep_module_alive=False,
)
x = paddle.full((3,), 1.0, dtype='float32').cpu()
y = mod.add_one_cpu(x)
np.testing.assert_allclose(y.numpy(), [2.0, 2.0, 2.0])

def run_check():
"""Must run in a separate function to ensure deletion happens before mod unloads.

When a module returns an object, the object deleter address is part of the
loaded library. We need to keep the module loaded until the object is deleted.
"""
x = paddle.full((3,), 1.0, dtype='float32').cpu()
y = mod.add_one_cpu(x)
np.testing.assert_allclose(y.numpy(), [2.0, 2.0, 2.0])

run_check()


class TestDLPackDataType(unittest.TestCase):
Expand Down Expand Up @@ -191,7 +206,10 @@ def test_data_type_as_input(self):
}
"""
mod: Module = tvm_ffi.cpp.load_inline(
name='mod', cpp_sources=cpp_source, functions='check_dtype'
name='mod',
cpp_sources=cpp_source,
functions='check_dtype',
keep_module_alive=False,
)
for dtype in [
paddle.bool,
Expand Down Expand Up @@ -251,7 +269,10 @@ def test_dlpack_device_type_as_input(self):
}
"""
mod: Module = tvm_ffi.cpp.load_inline(
name='mod', cpp_sources=cpp_source, functions='check_device'
name='mod',
cpp_sources=cpp_source,
functions='check_device',
keep_module_alive=False,
)

x_cpu = paddle.zeros((10,), dtype='float32').cpu()
Expand Down
Loading