def check_llvm(use_file):
     if not clang.find_clang(required=False):
         print("skip because clang is not available")
         return
     temp = utils.tempdir()
     ll_path = temp.relpath("temp.ll")
     ll_code = clang.create_llvm(cc_code, output=ll_path)
     s = te.create_schedule(B.op)
     if use_file:
         s[B].pragma(s[B].op.axis[0], "import_llvm", ll_path)
     else:
         s[B].pragma(s[B].op.axis[0], "import_llvm", ll_code)
     # BUILD and invoke the kernel.
     f = tvm.build(s, [A, B], "llvm")
     dev = tvm.cpu(0)
     # launch the kernel.
     a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), dev)
     b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), dev)
     f(a, b)
     tvm.testing.assert_allclose(b.asnumpy(), a.asnumpy() + 1.0)
Exemple #2
0
 def check_llvm(use_file):
     if not tvm.module.enabled("llvm"):
         return
     if not clang.find_clang(required=False):
         print("skip because clang is not available")
         return
     temp = util.tempdir()
     ll_path = temp.relpath("temp.ll")
     ll_code = clang.create_llvm(cc_code, output=ll_path)
     s = tvm.create_schedule(B.op)
     if use_file:
         s[B].pragma(s[B].op.axis[0], "import_llvm", ll_path)
     else:
         s[B].pragma(s[B].op.axis[0], "import_llvm", ll_code)
     # BUILD and invoke the kernel.
     f = tvm.build(s, [A, B], "llvm")
     ctx = tvm.cpu(0)
     # launch the kernel.
     a = tvm.nd.array(np.random.uniform(size=n).astype(A.dtype), ctx)
     b = tvm.nd.array(np.random.uniform(size=n).astype(B.dtype), ctx)
     f(a, b)
     tvm.testing.assert_allclose(
         b.asnumpy(), a.asnumpy() + 1.0)