This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Testcases and CI to include TVM as dependency
- Loading branch information
Showing
5 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
|
||
|
||
echo deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main\ | ||
>> /etc/apt/sources.list.d/llvm.list | ||
echo deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-5.0 main\ | ||
>> /etc/apt/sources.list.d/llvm.list | ||
|
||
wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - | ||
apt-get update && apt-get install -y --force-yes llvm-5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
# Build and install TVM | ||
cd /tmp | ||
git clone https://github.com/dmlc/tvm/ --recursive | ||
cd tvm | ||
cp make/config.mk | ||
echo USE_CUDA=1 >> config.mk | ||
echo LLVM_CONFIG=llvm-config-5.0 >> config.mk | ||
echo USE_RPC=1 >> config.mk | ||
echo USE_GRAPH_RUNTIME=1 >> config.mk | ||
echo CUDA_PATH=/usr/local/cuda >> config.mk | ||
make -j10 | ||
|
||
cd python | ||
python setup.py install | ||
cd - | ||
|
||
cd topi/python | ||
python setup.py install | ||
cd - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
"""Test TVM bridge, only enable this when TVM is available""" | ||
import mxnet as mx | ||
import numpy as np | ||
|
||
def test_tvm_bridge(): | ||
# only enable test if TVM is available | ||
try: | ||
import tvm | ||
import tvm.contrib.mxnet | ||
import topi | ||
except ImportError: | ||
return | ||
|
||
shape = (20,) | ||
scale = tvm.var("scale", dtype="float32") | ||
x = tvm.placeholder(shape) | ||
y = tvm.placeholder(shape) | ||
z = tvm.compute(shape, lambda i: x[i] + y[i]) | ||
zz = tvm.compute(shape, lambda *i: z(*i) * scale) | ||
|
||
target = tvm.target.cuda() | ||
# build the function | ||
with target: | ||
s = topi.generic.schedule_injective(zz) | ||
f = tvm.build(s, [x, y, zz, scale]) | ||
|
||
# get a mxnet version | ||
mxf = tvm.contrib.mxnet.to_mxnet_func(f, const_loc=[0, 1]) | ||
ctx = mx.gpu(0) | ||
xx = mx.nd.uniform(shape=shape, ctx=ctx) | ||
yy = mx.nd.uniform(shape=shape, ctx=ctx) | ||
zz = mx.nd.empty(shape=shape, ctx=ctx) | ||
# invoke myf: this runs in mxnet engine | ||
mxf(xx, yy, zz, 10.0) | ||
np.testing.assert_allclose( | ||
zz.asnumpy(), (xx.asnumpy() + yy.asnumpy()) * 10) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_tvm_bridge() |