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

Function test_llvm_add_pipeline

tests/python/codegen/test_target_codegen_cross_llvm.py:54–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52
53@pytest.mark.skipif(not env.has_llvm(), reason="need llvm")
54def test_llvm_add_pipeline():
55 nn = 1024
56
57 def verify_elf(path, e_machine):
58 with open(path, "rb") as fi:
59 arr = fi.read(20)
60 assert struct.unpack("ccc", arr[1:4]) == (b"E", b"L", b"F")
61 endian = struct.unpack("b", arr[0x5:0x6])[0]
62 endian = "<" if endian == 1 else ">"
63 assert struct.unpack(endian + "h", arr[0x12:0x14])[0] == e_machine
64
65 def build_arm():
66 target = {"kind": "llvm", "mtriple": "armv7-none-linux-gnueabihf"}
67 if not tvm.runtime.enabled("llvm"):
68 print(f"Skip because {target} is not enabled..")
69 return
70 temp = utils.tempdir()
71 f = tvm.tirx.build(AddModule, target=target)
72 path = temp.relpath("myadd.o")
73 f.write_to_file(path)
74 verify_elf(path, 0x28)
75 asm_path = temp.relpath("myadd.asm")
76 f.write_to_file(asm_path)
77 # Do a RPC verification, launch kernel on Arm Board if available.
78 host = os.environ.get("TVM_RPC_ARM_HOST", None)
79 remote = None
80 if host:
81 port = int(os.environ["TVM_RPC_ARM_PORT"])
82 try:
83 remote = rpc.connect(host, port)
84 except RuntimeError as e:
85 pass
86
87 if remote:
88 remote.upload(path)
89 farm = remote.load_module("myadd.o")
90 dev = remote.cpu(0)
91 n = nn
92 a = tvm.runtime.tensor(np.random.uniform(size=n).astype("float32"), dev)
93 b = tvm.runtime.tensor(np.random.uniform(size=n).astype("float32"), dev)
94 c = tvm.runtime.tensor(np.zeros(n, dtype="float32"), dev)
95 farm(a, b, c)
96 tvm.testing.assert_allclose(c.numpy(), a.numpy() + b.numpy())
97 print("Verification finish on remote..")
98
99 build_arm()
100
101
102if __name__ == "__main__":

Calls 1

build_armFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…