Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit 5aa96c4

Browse files
committed
Testcases and CI to include TVM as dependency
1 parent 46504e5 commit 5aa96c4

File tree

5 files changed

+130
-1
lines changed

5 files changed

+130
-1
lines changed

nnvm

Submodule nnvm updated 1 file

tests/ci_build/Dockerfile.gpu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ COPY install/ubuntu_install_r.sh /install/
1212
RUN /install/ubuntu_install_r.sh
1313
COPY install/ubuntu_install_perl.sh /install/
1414
RUN /install/ubuntu_install_perl.sh
15+
16+
COPY install/ubuntu_install_llvm.sh /install/
17+
RUN /install/ubuntu_install_llvm.sh
18+
19+
COPY install/ubuntu_install_tvm.sh /install/
20+
RUN /install/ubuntu_install_tvm.sh
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
21+
22+
echo deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main\
23+
>> /etc/apt/sources.list.d/llvm.list
24+
echo deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main\
25+
>> /etc/apt/sources.list.d/llvm.list
26+
27+
wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
28+
apt-get update && apt-get install -y --force-yes llvm-5.0
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
# Build and install TVM
21+
cd /tmp
22+
git clone https://github.com/dmlc/tvm/ --recursive
23+
cd tvm
24+
cp make/config.mk
25+
echo USE_CUDA=1 >> config.mk
26+
echo LLVM_CONFIG=llvm-config-5.0 >> config.mk
27+
echo USE_RPC=1 >> config.mk
28+
echo USE_GRAPH_RUNTIME=1 >> config.mk
29+
echo CUDA_PATH=/usr/local/cuda >> config.mk
30+
make -j10
31+
32+
cd python
33+
python setup.py install
34+
cd -
35+
36+
cd topi/python
37+
python setup.py install
38+
cd -

tests/python/gpu/test_tvm_bridge.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
"""Test TVM bridge, only enable this when TVM is available"""
19+
import mxnet as mx
20+
import numpy as np
21+
22+
def test_tvm_bridge():
23+
# only enable test if TVM is available
24+
try:
25+
import tvm
26+
import tvm.contrib.mxnet
27+
import topi
28+
except ImportError:
29+
return
30+
31+
shape = (20,)
32+
scale = tvm.var("scale", dtype="float32")
33+
x = tvm.placeholder(shape)
34+
y = tvm.placeholder(shape)
35+
z = tvm.compute(shape, lambda i: x[i] + y[i])
36+
zz = tvm.compute(shape, lambda *i: z(*i) * scale)
37+
38+
target = tvm.target.cuda()
39+
# build the function
40+
with target:
41+
s = topi.generic.schedule_injective(zz)
42+
f = tvm.build(s, [x, y, zz, scale])
43+
44+
# get a mxnet version
45+
mxf = tvm.contrib.mxnet.to_mxnet_func(f, const_loc=[0, 1])
46+
ctx = mx.gpu(0)
47+
xx = mx.nd.uniform(shape=shape, ctx=ctx)
48+
yy = mx.nd.uniform(shape=shape, ctx=ctx)
49+
zz = mx.nd.empty(shape=shape, ctx=ctx)
50+
# invoke myf: this runs in mxnet engine
51+
mxf(xx, yy, zz, 10.0)
52+
np.testing.assert_allclose(
53+
zz.asnumpy(), (xx.asnumpy() + yy.asnumpy()) * 10)
54+
55+
56+
if __name__ == "__main__":
57+
test_tvm_bridge()

0 commit comments

Comments
 (0)