Integration test for Executable with a simple TVM module.
()
| 173 | |
| 174 | |
| 175 | def test_executable_integration(): |
| 176 | """Integration test for Executable with a simple TVM module.""" |
| 177 | # Create target and build |
| 178 | target = tvm.target.Target("llvm") |
| 179 | lib = tvm.tirx.build(MyModule, target=target) |
| 180 | |
| 181 | # Create an executable |
| 182 | executable = Executable(lib) |
| 183 | |
| 184 | # Test jit |
| 185 | jitted_mod = executable.jit() |
| 186 | assert jitted_mod is not None |
| 187 | |
| 188 | # Test __getitem__ |
| 189 | add_func = executable["add"] |
| 190 | assert add_func is not None |
| 191 | |
| 192 | # Test the function works |
| 193 | a = tvm.runtime.tensor(np.array([1.0] * 10, dtype="float32")) |
| 194 | b = tvm.runtime.tensor(np.array([2.0] * 10, dtype="float32")) |
| 195 | c = tvm.runtime.tensor(np.array([0.0] * 10, dtype="float32")) |
| 196 | |
| 197 | add_func(a, b, c) |
| 198 | |
| 199 | # Check results |
| 200 | tvm.testing.assert_allclose(c.numpy(), np.array([3.0] * 10, dtype="float32")) |
| 201 | |
| 202 | # Test export_library |
| 203 | temp_dir = tempfile.mkdtemp() |
| 204 | try: |
| 205 | lib_path = os.path.join(temp_dir, "test_lib.so") |
| 206 | executable.export_library(lib_path) |
| 207 | |
| 208 | # Verify the library was created |
| 209 | assert os.path.exists(lib_path) |
| 210 | |
| 211 | # Load the library back |
| 212 | loaded_mod = tvm.runtime.load_module(lib_path) |
| 213 | assert loaded_mod is not None |
| 214 | |
| 215 | # Test the loaded module |
| 216 | loaded_add = loaded_mod["add"] |
| 217 | c_loaded = tvm.runtime.tensor(np.array([0.0] * 10, dtype="float32")) |
| 218 | loaded_add(a, b, c_loaded) |
| 219 | |
| 220 | # Check results |
| 221 | tvm.testing.assert_allclose(c_loaded.numpy(), np.array([3.0] * 10, dtype="float32")) |
| 222 | |
| 223 | finally: |
| 224 | # Clean up |
| 225 | if os.path.exists(temp_dir): |
| 226 | import shutil |
| 227 | |
| 228 | shutil.rmtree(temp_dir) |
| 229 | |
| 230 | |
| 231 | def test_executable_jit_force_recompile(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…