MCPcopy
hub / github.com/apache/tvm / test_example_npu_runtime_execution

Function test_example_npu_runtime_execution

tests/python/contrib/test_example_npu.py:225–260  ·  view source on GitHub ↗

Test end-to-end execution with the example NPU runtime

()

Source from the content-addressed store, hash-verified

223
224@example_npu_enabled
225def test_example_npu_runtime_execution():
226 """Test end-to-end execution with the example NPU runtime"""
227 import tvm.relax.backend.contrib.example_npu
228
229 # Create simple test inputs
230 np.random.seed(42)
231 x_np = np.random.randn(2, 4).astype("float32")
232 w_np = np.random.randn(4, 8).astype("float32")
233
234 # Expected output (computed with NumPy)
235 expected = np.maximum(0, np.matmul(x_np, w_np))
236
237 # Build and run with example NPU backend
238 mod = MatmulReLU
239 patterns = get_patterns_with_prefix("example_npu")
240
241 # Apply transformations
242 mod = FuseOpsByPattern(patterns, bind_constants=False, annotate_codegen=True)(mod)
243 mod = MergeCompositeFunctions()(mod)
244 mod = RunCodegen()(mod)
245
246 # Build the module
247 target = tvm.target.Target("llvm")
248 with tvm.transform.PassContext(opt_level=3):
249 built = relax.build(mod, target)
250
251 # Create VM and run
252 vm = relax.VirtualMachine(built, tvm.cpu())
253
254 x_tvm = tvm.runtime.tensor(x_np, tvm.cpu())
255 w_tvm = tvm.runtime.tensor(w_np, tvm.cpu())
256
257 result = vm["main"](x_tvm, w_tvm)
258
259 # Verify the result shape is correct (the runtime is a stub and does not compute numerically)
260 assert result.numpy().shape == expected.shape
261
262
263if __name__ == "__main__":

Callers 1

Calls 11

get_patterns_with_prefixFunction · 0.90
FuseOpsByPatternFunction · 0.90
MergeCompositeFunctionsFunction · 0.90
RunCodegenFunction · 0.90
seedMethod · 0.80
numpyMethod · 0.80
astypeMethod · 0.45
maximumMethod · 0.45
matmulMethod · 0.45
buildMethod · 0.45
cpuMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…