diff --git a/HalideIR b/HalideIR index 87b089a0ba20f2e8257038ee9211d6816088ce95..e20e5e9abb3aa43147a90a4ffb3e190f62862970 160000 --- a/HalideIR +++ b/HalideIR @@ -1 +1 @@ -Subproject commit 87b089a0ba20f2e8257038ee9211d6816088ce95 +Subproject commit e20e5e9abb3aa43147a90a4ffb3e190f62862970 diff --git a/Jenkinsfile b/Jenkinsfile index 4fc2285f507c9bd86ca209265d71eaf472dfe467..d74a207168292b1c1c9e8b036226bb5abe57fcb2 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -107,6 +107,7 @@ stage('Build') { sh """ echo USE_ROCM=1 >> config.mk echo ROCM_PATH=/opt/rocm >> config.mk + echo USE_VULKAN=1 >> config.mk """ make('gpu', '-j2') } diff --git a/src/codegen/llvm/intrin_rule_llvm.cc b/src/codegen/llvm/intrin_rule_llvm.cc index 0338f007cac66ba7668bff718c88d6c5c58e067a..2e6bf061eb5e5884d4f92d87b97ee2e7c39a9af4 100644 --- a/src/codegen/llvm/intrin_rule_llvm.cc +++ b/src/codegen/llvm/intrin_rule_llvm.cc @@ -25,6 +25,27 @@ TVM_REGISTER_GLOBAL("tvm.intrin.rule.llvm.log") TVM_REGISTER_GLOBAL("tvm.intrin.rule.llvm.sqrt") .set_body(DispatchLLVMPureIntrin<::llvm::Intrinsic::sqrt, 1>); +TVM_REGISTER_GLOBAL("tvm.intrin.rule.llvm.tanh") +.set_body([](const TVMArgs& targs, TVMRetValue* rv) { + Expr e = targs[0]; + const ir::Call* call = e.as<ir::Call>(); + CHECK(call != nullptr); + const Expr& x = call->args[0]; + Expr one = make_const(x.type(), 1); + Expr two = make_const(x.type(), 2); + Expr neg_two = make_const(x.type(), -2); + + Expr exp_neg2x = ir::Call::make( + x.type(), "exp", {neg_two * x}, ir::Call::PureIntrinsic); + Expr exp_pos2x = ir::Call::make( + x.type(), "exp", {two * x}, ir::Call::PureIntrinsic); + + Expr tanh_pos = (one - exp_neg2x) / (one + exp_neg2x); + Expr tanh_neg = (exp_pos2x - one) / (exp_pos2x + one); + *rv = ir::Select::make( + x >= make_zero(x.type()), tanh_pos, tanh_neg); +}); + TVM_REGISTER_GLOBAL("tvm.intrin.rule.llvm.pow") .set_body(DispatchLLVMPureIntrin<::llvm::Intrinsic::pow, 1>); diff --git a/src/codegen/spirv/ir_builder.cc b/src/codegen/spirv/ir_builder.cc index 26f851031e5a5a68f1e86eb7a1c33509dd4c98da..500c88ae832de8e981d92ed8200288ec31c6d7d4 100644 --- a/src/codegen/spirv/ir_builder.cc +++ b/src/codegen/spirv/ir_builder.cc @@ -311,8 +311,8 @@ Value IRBuilder::GetConst_(const SType& dtype, const uint64_t* pvalue) { } CHECK_LE(dtype.type.bits(), 64); Value ret = NewValue(dtype, kConstant); - if (1 == dtype.type.bits() && dtype.is_uint()) { - // Boolean types. + if (dtype.type == UInt(1)) { + // bool types. if (*pvalue) { ib_.Begin(spv::OpConstantTrue).AddSeq(ret); } else { diff --git a/tests/ci_build/Dockerfile.gpu b/tests/ci_build/Dockerfile.gpu index b71b4cb118ec0099866489033933cd11c9e0d512..e49e498b8d406a26031a47e46f317cd8f4a6b334 100644 --- a/tests/ci_build/Dockerfile.gpu +++ b/tests/ci_build/Dockerfile.gpu @@ -43,6 +43,11 @@ RUN bash /install/ubuntu_install_opengl.sh # Enable doxygen for c++ doc build RUN apt-get install -y doxygen graphviz +# Install vulkan +COPY install/ubuntu_install_vulkan.sh /install/ubuntu_install_vulkan.sh +RUN bash /install/ubuntu_install_vulkan.sh + + # Environment variables ENV PATH=/node_modules/.bin:${PATH} ENV PATH=/usr/local/nvidia/bin:${PATH} @@ -53,3 +58,10 @@ ENV C_INCLUDE_PATH=/usr/local/cuda/include:${C_INCLUDE_PATH} ENV LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/nvidia/lib64:${LIBRARY_PATH} ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:/usr/local/nvidia/lib64:${LD_LIBRARY_PATH} ENV LD_LIBRARY_PATH=/opt/rocm/lib:${LD_LIBRARY_PATH} + +ENV PATH=/node_modules/.bin:${PATH} + +ENV VULKAN_SDK=/usr/local/VulkanSDK/1.0.65.0/x86_64 +ENV PATH=${PATH}:${VULKAN_SDK}/bin +ENV LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${VULKAN_SDK}/lib +ENV VK_LAYER_PATH=${VULKAN_SDK}/etc/explicit_layer.d diff --git a/tests/ci_build/install/ubuntu_install_vulkan.sh b/tests/ci_build/install/ubuntu_install_vulkan.sh new file mode 100644 index 0000000000000000000000000000000000000000..a4155da496518af14e305ad5ddaf2f081c4ec46d --- /dev/null +++ b/tests/ci_build/install/ubuntu_install_vulkan.sh @@ -0,0 +1,9 @@ +#/bin/bash + +wget https://sdk.lunarg.com/sdk/download/1.0.65.0/linux/vulkansdk-linux-x86_64-1.0.65.0.run + +bash vulkansdk-linux-x86_64-1.0.65.0.run +mv VulkanSDK /usr/local/VulkanSDK +cd /usr/local/VulkanSDK/1.0.65.0 +./build_tools.sh +./build_samples.sh diff --git a/topi/tests/python/test_topi_math.py b/topi/tests/python/test_topi_math.py index 937639785b0b5b80fe6717f35be8ebbde0bcdc88..b1b989179f08c6314fe6b63815c0729db9177cfa 100644 --- a/topi/tests/python/test_topi_math.py +++ b/topi/tests/python/test_topi_math.py @@ -15,16 +15,38 @@ def test_ewise(): l = tvm.var('l') A = tvm.placeholder((m, l), name='A') - def test_apply(func, name): + shape = (20, 3) + + def test_apply(func, name, f_numpy): B = func(A) assert tuple(B.shape) == tuple(A.shape) assert B.op.body[0].name == name + a_np = np.random.uniform(size=shape).astype(A.dtype) + a_np = np.abs(a_np) + b_np = f_numpy(a_np) + + def check_device(device): + ctx = tvm.context(device, 0) + if not ctx.exist: + print("Skip because %s is not enabled" % device) + return + print("Running on target: %s" % device) + with tvm.target.create(device): + s = topi.generic.schedule_injective(B) + a = tvm.nd.array(a_np, ctx) + b = tvm.nd.array(np.zeros_like(b_np), ctx) + foo = tvm.build(s, [A, B], device, name=name) + foo(a, b) + np.testing.assert_allclose(b.asnumpy(), b_np, rtol=1e-5) + + for device in ['cuda', 'opencl', 'metal', 'rocm', 'vulkan', 'llvm']: + check_device(device) - test_apply(topi.exp, "exp") - test_apply(topi.tanh, "tanh") - test_apply(topi.sigmoid, "sigmoid") - test_apply(topi.log, "log") - test_apply(topi.sqrt, "sqrt") + test_apply(topi.exp, "exp", np.exp) + test_apply(topi.tanh, "tanh", np.tanh) + test_apply(topi.sigmoid, "sigmoid", lambda x:1/(1+np.exp(-x))) + test_apply(topi.log, "log", np.log) + test_apply(topi.sqrt, "sqrt", np.sqrt) if __name__ == "__main__": test_util()