From 9890c29b1dfeb29cbe85436633b3b17c51906f2f Mon Sep 17 00:00:00 2001 From: looop5 Date: Thu, 16 Jul 2020 15:06:31 +0800 Subject: [PATCH] add macro in CMakeLists.txt to differ backend d and gpu, add modification statement --- CMakeLists.txt | 3 ++ .../src/pass/split_host_device.cc | 41 +++++++++---------- .../patch/incubator-tvm/incubator-tvm.patch | 40 ++++++++++++++---- 3 files changed, 55 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b19926e..6808d0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,9 @@ add_definitions(-DDMLC_LOG_CUSTOMIZE=1) if(USE_AKG_LOG) add_definitions(-DUSE_AKG_LOG=1) endif() +if(NOT USE_CUDA) + add_definitions("-DBACKEND_D") +endif() # Generic compilation options include(CheckCXXCompilerFlag) diff --git a/third_party/incubator-tvm/src/pass/split_host_device.cc b/third_party/incubator-tvm/src/pass/split_host_device.cc index d1e32f5..4f62c7c 100644 --- a/third_party/incubator-tvm/src/pass/split_host_device.cc +++ b/third_party/incubator-tvm/src/pass/split_host_device.cc @@ -234,33 +234,32 @@ class HostDeviceSplitter : public IRMutator { } } - const char* mode = getenv("RUNTIME_MODE"); - if (mode) { - std::shared_ptr na = std::make_shared(); - for (unsigned i = 0; i < (unsigned)args_real.size(); i++) { - bool match = false; - for (unsigned j = 0; j < (unsigned)n->args.size(); j++) { - if (strcmp(args_real[i].get()->name_hint.c_str(), n->args[j].get()->name_hint.c_str()) == 0) { - na->args.push_back(n->args[j]); - match = true; - break; - } else { - continue; - } +#ifdef BACKEND_D + std::shared_ptr na = std::make_shared(); + for (unsigned i = 0; i < (unsigned)args_real.size(); i++) { + bool match = false; + for (unsigned j = 0; j < (unsigned)n->args.size(); j++) { + if (strcmp(args_real[i].get()->name_hint.c_str(), n->args[j].get()->name_hint.c_str()) == 0) { + na->args.push_back(n->args[j]); + match = true; + break; + } else { + continue; } + } - if (!match) { - na->args.push_back(args_real[i]); - // mark handle data type. - for (auto kv : handle_data_type_) { - if (strcmp(args_real[i].get()->name_hint.c_str(), kv.first->name_hint.c_str()) == 0) { - n->handle_data_type.Set(args_real[i], kv.second); - } + if (!match) { + na->args.push_back(args_real[i]); + // mark handle data type. + for (auto kv : handle_data_type_) { + if (strcmp(args_real[i].get()->name_hint.c_str(), kv.first->name_hint.c_str()) == 0) { + n->handle_data_type.Set(args_real[i], kv.second); } } } - n->args = na->args; } + n->args = na->args; +#endif LoweredFunc f_device(n); Array call_args; diff --git a/third_party/patch/incubator-tvm/incubator-tvm.patch b/third_party/patch/incubator-tvm/incubator-tvm.patch index 6a66763..20142d6 100644 --- a/third_party/patch/incubator-tvm/incubator-tvm.patch +++ b/third_party/patch/incubator-tvm/incubator-tvm.patch @@ -1,7 +1,19 @@ -diff -uprN tvm_orig/python/tvm/_ffi/base.py tvm/python/tvm/_ffi/base.py ---- tvm_orig/python/tvm/_ffi/base.py 2020-04-13 20:18:09.519984547 +0800 -+++ tvm/python/tvm/_ffi/base.py 2020-04-13 20:14:21.510253128 +0800 -@@ -48,7 +48,18 @@ else: +diff -Npur tvm_orig/python/tvm/_ffi/base.py tvm/python/tvm/_ffi/base.py +--- tvm_orig/python/tvm/_ffi/base.py 2020-07-16 14:39:28.859033775 +0800 ++++ tvm/python/tvm/_ffi/base.py 2020-07-16 14:42:26.594223690 +0800 +@@ -16,6 +16,11 @@ + # under the License. + # coding: utf-8 + # pylint: disable=invalid-name ++ ++# ++# 2020.7.16 - Modify _load_lib function to find the correct library. ++# ++ + """Base library for TVM FFI.""" + from __future__ import absolute_import + +@@ -48,7 +53,18 @@ else: def _load_lib(): """Load libary by searching possible path.""" @@ -21,10 +33,22 @@ diff -uprN tvm_orig/python/tvm/_ffi/base.py tvm/python/tvm/_ffi/base.py lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_GLOBAL) # DMatrix functions lib.TVMGetLastError.restype = ctypes.c_char_p -diff -uprN tvm_orig/topi/python/topi/cpp/impl.py tvm/topi/python/topi/cpp/impl.py ---- tvm_orig/topi/python/topi/cpp/impl.py 2020-04-13 20:18:09.535984509 +0800 -+++ tvm/topi/python/topi/cpp/impl.py 2020-04-13 20:16:41.784427200 +0800 -@@ -31,11 +31,18 @@ def _get_lib_names(): +diff -Npur tvm_orig/topi/python/topi/cpp/impl.py tvm/topi/python/topi/cpp/impl.py +--- tvm_orig/topi/python/topi/cpp/impl.py 2020-07-16 14:40:07.754722324 +0800 ++++ tvm/topi/python/topi/cpp/impl.py 2020-07-16 14:42:56.638225874 +0800 +@@ -14,6 +14,11 @@ + # KIND, either express or implied. See the License for the + # specific language governing permissions and limitations + # under the License. ++ ++# ++# 2020.7.16 - Modify _load_lib function to find the correct library. ++# ++ + """Load Lib for C++ TOPI ops and schedules""" + import sys + import os +@@ -31,11 +36,18 @@ def _get_lib_names(): def _load_lib(): """Load libary by searching possible path.""" -- GitLab