MCPcopy Index your code
hub / github.com/apache/tvm / test_executable_export_library

Function test_executable_export_library

tests/python/runtime/test_executable.py:102–134  ·  view source on GitHub ↗

Test export_library method.

()

Source from the content-addressed store, hash-verified

100
101
102def test_executable_export_library():
103 """Test export_library method."""
104 lib = tvm.tirx.build(MyModule, target="llvm")
105 executable = Executable(lib)
106
107 # Create a temporary directory for the library
108 temp_dir = tempfile.mkdtemp()
109 try:
110 lib_path = os.path.join(temp_dir, "test_lib.so")
111 executable.export_library(lib_path)
112
113 # Verify the library was created
114 assert os.path.exists(lib_path)
115
116 # Load the library back
117 loaded_mod = tvm.runtime.load_module(lib_path)
118 assert loaded_mod is not None
119
120 # Test the loaded module
121 a = tvm.runtime.tensor(np.array([1.0] * 10, dtype="float32"))
122 b = tvm.runtime.tensor(np.array([2.0] * 10, dtype="float32"))
123 c = tvm.runtime.tensor(np.array([0.0] * 10, dtype="float32"))
124
125 loaded_mod["add"](a, b, c)
126
127 # Check results
128 tvm.testing.assert_allclose(c.numpy(), np.array([3.0] * 10, dtype="float32"))
129 finally:
130 # Clean up
131 if os.path.exists(temp_dir):
132 import shutil
133
134 shutil.rmtree(temp_dir)
135
136
137def test_executable_export_library_with_workspace():

Callers

nothing calls this directly

Calls 6

export_libraryMethod · 0.95
ExecutableClass · 0.90
numpyMethod · 0.80
buildMethod · 0.45
joinMethod · 0.45
load_moduleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…