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

Commit c7e273c

Browse files
committed
Fix
1 parent a23e659 commit c7e273c

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ mxnet_option(USE_GPROF "Compile with gprof (profiling) flag" OFF)
4343
mxnet_option(USE_CXX14_IF_AVAILABLE "Build with C++14 if the compiler supports it" OFF)
4444
mxnet_option(USE_VTUNE "Enable use of Intel Amplifier XE (VTune)" OFF) # one could set VTUNE_ROOT for search path
4545
mxnet_option(USE_TVM_OP "Enable use of TVM operator build system." OFF)
46-
mxnet_option(USE_TVM_OP_CUDA_ARCH "Specify the CUDA ARCH for which TVM-generated kernels are compiled." none)
4746
mxnet_option(ENABLE_CUDA_RTC "Build with CUDA runtime compilation support" ON)
4847
mxnet_option(BUILD_CPP_EXAMPLES "Build cpp examples" ON)
4948
mxnet_option(INSTALL_EXAMPLES "Install the example source files." OFF)
@@ -758,8 +757,8 @@ if(USE_TVM_OP)
758757
endif()
759758

760759
set(TVM_OP_COMPILE_OPTIONS "-o${CMAKE_CURRENT_BINARY_DIR}/libtvmop.so")
761-
if(NOT USE_TVM_OP_CUDA_ARCH STREQUAL "none")
762-
set(TVM_OP_COMPILE_OPTIONS "${TVM_OP_COMPILE_OPTIONS} --cuda-arch ${USE_TVM_OP_CUDA_ARCH}")
760+
if(CUDA_ARCH_BIN)
761+
set(TVM_OP_COMPILE_OPTIONS "${TVM_OP_COMPILE_OPTIONS} --cuda-arch ${CUDA_ARCH_BIN}")
763762
endif()
764763
add_custom_command(TARGET mxnet POST_BUILD
765764
COMMAND ${CMAKE_COMMAND} -E env

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,13 +473,11 @@ CFLAGS += -I$(TVM_PATH)/include -DMXNET_USE_TVM_OP=1
473473
LDFLAGS += -L$(ROOTDIR)/lib -ltvm_runtime -Wl,-rpath,'$${ORIGIN}'
474474

475475
TVM_USE_CUDA := OFF
476-
TVM_OP_CUDA_ARCH := NONE
477476
ifeq ($(USE_CUDA), 1)
478477
TVM_USE_CUDA := ON
479478
ifneq ($(USE_CUDA_PATH), NONE)
480479
TVM_USE_CUDA := $(USE_CUDA_PATH)
481480
endif
482-
TVM_OP_CUDA_ARCH = $(USE_TVM_OP_CUDA_ARCH)
483481
endif
484482
endif
485483

@@ -633,8 +631,8 @@ lib/libtvm_runtime.so:
633631
cd $(ROOTDIR)
634632

635633
TVM_OP_COMPILE_OPTIONS = -o $(ROOTDIR)/lib/libtvmop.so
636-
ifneq ($(TVM_OP_CUDA_ARCH), NONE)
637-
TVM_OP_COMPILE_OPTIONS += --cuda-arch $(TVM_OP_CUDA_ARCH)
634+
ifneq ($(CUDA_ARCH),)
635+
TVM_OP_COMPILE_OPTIONS += --cuda-arch "$(CUDA_ARCH)"
638636
endif
639637
lib/libtvmop.so: lib/libtvm_runtime.so $(wildcard contrib/tvmop/*/*.py contrib/tvmop/*.py)
640638
echo "Compile TVM operators"

ci/docker/runtime_functions.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ NOSE_COVERAGE_ARGUMENTS="--with-coverage --cover-inclusive --cover-xml --cover-b
2626
NOSE_TIMER_ARGUMENTS="--with-timer --timer-ok 1 --timer-warning 15 --timer-filter warning,error"
2727
CI_CUDA_COMPUTE_CAPABILITIES="-gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_70,code=sm_70"
2828
CI_CMAKE_CUDA_ARCH_BIN="52,70"
29-
CI_CUDA_ARCH="sm_70"
3029

3130
clean_repo() {
3231
set -ex
@@ -753,7 +752,6 @@ build_ubuntu_gpu_mkldnn() {
753752
USE_TVM_OP=1 \
754753
CUDA_ARCH="$CI_CUDA_COMPUTE_CAPABILITIES" \
755754
USE_SIGNAL_HANDLER=1 \
756-
USE_TVM_OP_CUDA_ARCH="$CI_CUDA_ARCH" \
757755
-j$(nproc)
758756
}
759757

@@ -771,7 +769,6 @@ build_ubuntu_gpu_mkldnn_nocudnn() {
771769
USE_TVM_OP=1 \
772770
CUDA_ARCH="$CI_CUDA_COMPUTE_CAPABILITIES" \
773771
USE_SIGNAL_HANDLER=1 \
774-
USE_TVM_OP_CUDA_ARCH="$CI_CUDA_ARCH" \
775772
-j$(nproc)
776773
}
777774

@@ -790,7 +787,6 @@ build_ubuntu_gpu_cuda101_cudnn7() {
790787
USE_DIST_KVSTORE=1 \
791788
CUDA_ARCH="$CI_CUDA_COMPUTE_CAPABILITIES" \
792789
USE_SIGNAL_HANDLER=1 \
793-
USE_TVM_OP_CUDA_ARCH="$CI_CUDA_ARCH" \
794790
-j$(nproc)
795791

796792
make cython PYTHON=python2
@@ -828,7 +824,6 @@ build_ubuntu_gpu_cmake_mkldnn() {
828824
-DUSE_CUDA=1 \
829825
-DUSE_CUDNN=1 \
830826
-DUSE_TVM_OP=1 \
831-
-DUSE_TVM_OP_CUDA_ARCH=$CI_CUDA_ARCH \
832827
-DPython3_EXECUTABLE=/usr/bin/python3 \
833828
-DUSE_MKLML_MKL=1 \
834829
-DCMAKE_BUILD_TYPE=Release \
@@ -855,7 +850,6 @@ build_ubuntu_gpu_cmake() {
855850
-DUSE_CUDA=ON \
856851
-DUSE_CUDNN=ON \
857852
-DUSE_TVM_OP=ON \
858-
-DUSE_TVM_OP_CUDA_ARCH=$CI_CUDA_ARCH \
859853
-DPython3_EXECUTABLE=/usr/bin/python3 \
860854
-DUSE_MKL_IF_AVAILABLE=OFF \
861855
-DUSE_MKLML_MKL=OFF \
@@ -903,7 +897,6 @@ build_ubuntu_gpu_large_tensor() {
903897
-DUSE_CUDA=ON \
904898
-DUSE_CUDNN=ON \
905899
-DUSE_TVM_OP=ON \
906-
-DUSE_TVM_OP_CUDA_ARCH=$CI_CUDA_ARCH \
907900
-DPython3_EXECUTABLE=/usr/bin/python3 \
908901
-DUSE_MKL_IF_AVAILABLE=OFF \
909902
-DUSE_MKLML_MKL=OFF \

contrib/tvmop/compile.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121

2222
import os
2323
import argparse
24+
import re
25+
import logging
2426
from tvmop.opdef import __OP_DEF__
2527
from tvm.autotvm.measure.measure_methods import set_cuda_target_arch
2628

29+
logging.basicConfig(level=logging.INFO)
30+
2731

2832
def get_target(device):
2933
if device == "cpu":
@@ -33,6 +37,31 @@ def get_target(device):
3337
assert False, "Unknown device " + device
3438

3539

40+
def get_cuda_arch(arch):
41+
if arch is None:
42+
return None
43+
44+
if not isinstance(arch, str):
45+
raise TypeError('Expecting parameter arch as a str, while got a {}'.format(str(type(arch))))
46+
47+
if len(arch) == 0:
48+
return None
49+
50+
# the arch string contains '-arch=sm_xx'
51+
flags = arch.split()
52+
for flag in flags:
53+
if flag.startswith('-arch='):
54+
return flag[len('-arch='):]
55+
56+
# find the highest compute capability
57+
comp_caps = re.findall(r'\d+', arch)
58+
if len(comp_caps) == 0:
59+
return None
60+
61+
comp_caps = [int(c) for c in comp_caps]
62+
return 'sm_' + str(max(comp_caps))
63+
64+
3665
if __name__ == "__main__":
3766
import sys
3867
sys.path.append(os.path.dirname(sys.path[0]))
@@ -59,6 +88,11 @@ def get_target(device):
5988
lowered_funcs = {get_target("cpu"): func_list_llvm}
6089
if len(func_list_cuda) > 0:
6190
lowered_funcs[get_target("cuda")] = func_list_cuda
62-
set_cuda_target_arch(arguments.cuda_arch)
91+
cuda_arch = get_cuda_arch(arguments.cuda_arch)
92+
if cuda_arch is None:
93+
logging.info('No cuda arch specified. TVM will try to detect it from the build platform.')
94+
else:
95+
logging.info('Cuda arch {} set for compiling TVM operator kernels.'.format(cuda_arch))
96+
set_cuda_target_arch(cuda_arch)
6397
func_binary = tvm.build(lowered_funcs, name="tvmop")
6498
func_binary.export_library(arguments.target_path)

0 commit comments

Comments
 (0)