Commit 0ba579f5 by Tianqi Chen Committed by GitHub

Fix Vulkan Build, add tanh to llvm instrinsic, fix halideIR (#868)

* Fix Vulkan Build, add tanh to llvm instrinsic, fix halideIR

* fix llvm tanh
parent 116b5a5a
Subproject commit 87b089a0ba20f2e8257038ee9211d6816088ce95
Subproject commit e20e5e9abb3aa43147a90a4ffb3e190f62862970
......@@ -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')
}
......
......@@ -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>);
......
......@@ -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 {
......
......@@ -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
#/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
......@@ -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()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment