From 67744744e142c8a9044e4967c8871431d6d4f4dd Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 7 May 2020 06:37:14 +0000 Subject: [PATCH 01/12] fix the error message of reshape() --- python/mxnet/numpy/multiarray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/mxnet/numpy/multiarray.py b/python/mxnet/numpy/multiarray.py index f8cf69aaa1c4..be34554dae93 100644 --- a/python/mxnet/numpy/multiarray.py +++ b/python/mxnet/numpy/multiarray.py @@ -1436,7 +1436,7 @@ def reshape(self, *args, **kwargs): # pylint: disable=arguments-differ if len(kwargs) == 1: if 'order' not in kwargs: raise TypeError('{} is an invalid keyword argument for this function' - .format(kwargs.keys()[0])) + .format(list(kwargs.keys())[0])) # python3.6 - TypeError: 'dict_keys' object does not support indexing order = kwargs.pop('order', 'C') if order != 'C': raise NotImplementedError('only supports C-order,' From 29ddefecb6246357d1f5eedcbba6282cf781a493 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 7 May 2020 10:31:12 +0000 Subject: [PATCH 02/12] Fixing issue #16655 reshape() error message --- python/mxnet/numpy/multiarray.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/mxnet/numpy/multiarray.py b/python/mxnet/numpy/multiarray.py index be34554dae93..6eb474ee2a64 100644 --- a/python/mxnet/numpy/multiarray.py +++ b/python/mxnet/numpy/multiarray.py @@ -1435,8 +1435,8 @@ def reshape(self, *args, **kwargs): # pylint: disable=arguments-differ raise TypeError('function takes at most 1 keyword argument') if len(kwargs) == 1: if 'order' not in kwargs: - raise TypeError('{} is an invalid keyword argument for this function' - .format(list(kwargs.keys())[0])) # python3.6 - TypeError: 'dict_keys' object does not support indexing + raise TypeError("'{}' is an invalid keyword argument for this function" + .format(list(kwargs.keys())[0])) order = kwargs.pop('order', 'C') if order != 'C': raise NotImplementedError('only supports C-order,' From 7627eaaa9189061937ba0a1c9872b38a025e6806 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 9 Jun 2020 05:40:22 +0000 Subject: [PATCH 03/12] test pr --- python/mxnet/ndarray/ndarray.py | 2 ++ src/c_api/c_api.cc | 7 ++++++- src/operator/tvmop/op_module.cc | 6 ++++++ src/operator/tvmop/op_module.h | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/python/mxnet/ndarray/ndarray.py b/python/mxnet/ndarray/ndarray.py index 49a4406aa0ff..6d042bbca3f9 100644 --- a/python/mxnet/ndarray/ndarray.py +++ b/python/mxnet/ndarray/ndarray.py @@ -2560,10 +2560,12 @@ def asnumpy(self): [1, 1, 1]], dtype=int32) """ data = np.empty(self.shape, dtype=self.dtype) + ''' check_call(_LIB.MXNDArraySyncCopyToCPU( self.handle, data.ctypes.data_as(ctypes.c_void_p), ctypes.c_size_t(data.size))) + ''' return data def asscalar(self): diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index 82f3b71be1b8..c5caf31faa1a 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -1363,7 +1363,12 @@ int MXGetVersion(int *out) { #if MXNET_USE_TVM_OP int MXLoadTVMOp(const char *libpath) { API_BEGIN(); - tvm::runtime::TVMOpModule::Get()->Load(libpath); + tvm::runtime::TVMOpModule *libpath_module = tvm::runtime::TVMOpModule::Get(); + libpath_module->Load(libpath); + tvm::runtime::TVMOpModule *cubin_module = tvm::runtime::TVMOpModule::Get(); + cubin_module->Load("/home/ubuntu/Documents/mxnet/build/libtvmop.cubin"); + libpath_module->Import(*cubin_module); + std::cout << "_________ MXLoadTVMOp succeed __________" << std::endl; API_END(); } diff --git a/src/operator/tvmop/op_module.cc b/src/operator/tvmop/op_module.cc index c75e5a990086..d833ae0585c2 100644 --- a/src/operator/tvmop/op_module.cc +++ b/src/operator/tvmop/op_module.cc @@ -46,6 +46,12 @@ void TVMOpModule::Load(const std::string &filepath) { *module_ptr_ = module; } +void TVMOpModule::Import(const TVMOpModule& module) { + CHECK(module_ptr_ != nullptr) << "module_ptr_ is not initialized."; + std::lock_guard lock(mutex_); + module_ptr_->Import(*(module.module_ptr_)); +} + PackedFunc GetFunction(const std::shared_ptr &module, const std::string &op_name, const std::vector &args) { diff --git a/src/operator/tvmop/op_module.h b/src/operator/tvmop/op_module.h index 269a0aa50c11..8a25b3b9951e 100644 --- a/src/operator/tvmop/op_module.h +++ b/src/operator/tvmop/op_module.h @@ -44,6 +44,8 @@ class TVMOpModule { // Load TVM operators binary void Load(const std::string& filepath); + void Import(const TVMOpModule& module); + void Call(const std::string& func_name, const mxnet::OpContext& ctx, const std::vector& args) const; From 087a1007d72806936b22fa8cfd36f96ae9cc4d68 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 9 Jun 2020 08:25:41 +0000 Subject: [PATCH 04/12] fixing #17840 --- contrib/tvmop/compile.py | 6 ++++++ src/c_api/c_api.cc | 7 +++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/contrib/tvmop/compile.py b/contrib/tvmop/compile.py index 6341e70fe766..dadd941ec84a 100644 --- a/contrib/tvmop/compile.py +++ b/contrib/tvmop/compile.py @@ -152,6 +152,12 @@ def get_cuda_arch(arch): # we create libtvmop.o first, which gives us chance to link tvm_runtime together with the libtvmop # to allow mxnet find external helper functions in libtvm_runtime func_binary.save(arguments.target_path + "/libtvmop.o") + func_binary.imported_modules[0].save(arguments.target_path + "/libtvmop.cubin") + # dev_module = func_binary.imported_modules[0] + # print("-----GPU code-----") + # print(dev_module.get_source()) + # print("-----GPU code END-----") + ld_path = arguments.target_path if arguments.ld_path is None else arguments.ld_path create_shared(arguments.target_path + "/libtvmop.so", arguments.target_path + "/libtvmop.o", diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index c5caf31faa1a..05ff8eaf8a68 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -1365,10 +1365,9 @@ int MXLoadTVMOp(const char *libpath) { API_BEGIN(); tvm::runtime::TVMOpModule *libpath_module = tvm::runtime::TVMOpModule::Get(); libpath_module->Load(libpath); - tvm::runtime::TVMOpModule *cubin_module = tvm::runtime::TVMOpModule::Get(); - cubin_module->Load("/home/ubuntu/Documents/mxnet/build/libtvmop.cubin"); - libpath_module->Import(*cubin_module); - std::cout << "_________ MXLoadTVMOp succeed __________" << std::endl; + tvm::runtime::TVMOpModule cubin_module; + cubin_module.Load("/home/ubuntu/Documents/mxnet/build/libtvmop.cubin"); + libpath_module->Import(cubin_module); API_END(); } From 75f975b20278bd99f135fad720ed8826d8d726ec Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Tue, 9 Jun 2020 09:44:02 +0000 Subject: [PATCH 05/12] fixing issue #17840 --- contrib/tvmop/compile.py | 5 ----- python/mxnet/ndarray/ndarray.py | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/contrib/tvmop/compile.py b/contrib/tvmop/compile.py index dadd941ec84a..1ffbdbb5d57a 100644 --- a/contrib/tvmop/compile.py +++ b/contrib/tvmop/compile.py @@ -153,11 +153,6 @@ def get_cuda_arch(arch): # to allow mxnet find external helper functions in libtvm_runtime func_binary.save(arguments.target_path + "/libtvmop.o") func_binary.imported_modules[0].save(arguments.target_path + "/libtvmop.cubin") - # dev_module = func_binary.imported_modules[0] - # print("-----GPU code-----") - # print(dev_module.get_source()) - # print("-----GPU code END-----") - ld_path = arguments.target_path if arguments.ld_path is None else arguments.ld_path create_shared(arguments.target_path + "/libtvmop.so", arguments.target_path + "/libtvmop.o", diff --git a/python/mxnet/ndarray/ndarray.py b/python/mxnet/ndarray/ndarray.py index 6d042bbca3f9..e992f2e3705a 100644 --- a/python/mxnet/ndarray/ndarray.py +++ b/python/mxnet/ndarray/ndarray.py @@ -2560,12 +2560,12 @@ def asnumpy(self): [1, 1, 1]], dtype=int32) """ data = np.empty(self.shape, dtype=self.dtype) - ''' + check_call(_LIB.MXNDArraySyncCopyToCPU( self.handle, data.ctypes.data_as(ctypes.c_void_p), ctypes.c_size_t(data.size))) - ''' + return data def asscalar(self): From e7935f12e2a8f7880a95f10ade6ed60448011c47 Mon Sep 17 00:00:00 2001 From: Jinbo Ci <32102965+jinboci@users.noreply.github.com> Date: Wed, 8 Jul 2020 18:27:50 +0800 Subject: [PATCH 06/12] Update compile.py --- contrib/tvmop/compile.py | 1 - 1 file changed, 1 deletion(-) diff --git a/contrib/tvmop/compile.py b/contrib/tvmop/compile.py index 1ffbdbb5d57a..6341e70fe766 100644 --- a/contrib/tvmop/compile.py +++ b/contrib/tvmop/compile.py @@ -152,7 +152,6 @@ def get_cuda_arch(arch): # we create libtvmop.o first, which gives us chance to link tvm_runtime together with the libtvmop # to allow mxnet find external helper functions in libtvm_runtime func_binary.save(arguments.target_path + "/libtvmop.o") - func_binary.imported_modules[0].save(arguments.target_path + "/libtvmop.cubin") ld_path = arguments.target_path if arguments.ld_path is None else arguments.ld_path create_shared(arguments.target_path + "/libtvmop.so", arguments.target_path + "/libtvmop.o", From 25274a2bf5f56323b5694645d6aa639aa8870dee Mon Sep 17 00:00:00 2001 From: Jinbo Ci <32102965+jinboci@users.noreply.github.com> Date: Wed, 8 Jul 2020 18:30:16 +0800 Subject: [PATCH 07/12] Update ndarray.py --- python/mxnet/ndarray/ndarray.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/python/mxnet/ndarray/ndarray.py b/python/mxnet/ndarray/ndarray.py index 93e7007a3d97..9cc8b8942c1d 100644 --- a/python/mxnet/ndarray/ndarray.py +++ b/python/mxnet/ndarray/ndarray.py @@ -2564,12 +2564,10 @@ def asnumpy(self): [1, 1, 1]], dtype=int32) """ data = np.empty(self.shape, dtype=self.dtype) - check_call(_LIB.MXNDArraySyncCopyToCPU( self.handle, data.ctypes.data_as(ctypes.c_void_p), ctypes.c_size_t(data.size))) - return data def asscalar(self): From cc709ec7efcf1c1e3b3c4c6af38c449ee1f89b98 Mon Sep 17 00:00:00 2001 From: Jinbo Ci <32102965+jinboci@users.noreply.github.com> Date: Wed, 8 Jul 2020 18:32:00 +0800 Subject: [PATCH 08/12] Update c_api.cc --- src/c_api/c_api.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/c_api/c_api.cc b/src/c_api/c_api.cc index 1c9d7b87536d..ea39d9ac6e5b 100644 --- a/src/c_api/c_api.cc +++ b/src/c_api/c_api.cc @@ -1363,11 +1363,7 @@ int MXGetVersion(int *out) { #if MXNET_USE_TVM_OP int MXLoadTVMOp(const char *libpath) { API_BEGIN(); - tvm::runtime::TVMOpModule *libpath_module = tvm::runtime::TVMOpModule::Get(); - libpath_module->Load(libpath); - tvm::runtime::TVMOpModule cubin_module; - cubin_module.Load("/home/ubuntu/Documents/mxnet/build/libtvmop.cubin"); - libpath_module->Import(cubin_module); + tvm::runtime::TVMOpModule::Get()->Load(libpath); API_END(); } From 9ae7772d8b7b1098f82a74ca175a1473c7493556 Mon Sep 17 00:00:00 2001 From: Jinbo Ci <32102965+jinboci@users.noreply.github.com> Date: Wed, 8 Jul 2020 18:32:39 +0800 Subject: [PATCH 09/12] Update op_module.cc --- src/operator/tvmop/op_module.cc | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/operator/tvmop/op_module.cc b/src/operator/tvmop/op_module.cc index d833ae0585c2..c75e5a990086 100644 --- a/src/operator/tvmop/op_module.cc +++ b/src/operator/tvmop/op_module.cc @@ -46,12 +46,6 @@ void TVMOpModule::Load(const std::string &filepath) { *module_ptr_ = module; } -void TVMOpModule::Import(const TVMOpModule& module) { - CHECK(module_ptr_ != nullptr) << "module_ptr_ is not initialized."; - std::lock_guard lock(mutex_); - module_ptr_->Import(*(module.module_ptr_)); -} - PackedFunc GetFunction(const std::shared_ptr &module, const std::string &op_name, const std::vector &args) { From aa7038b65562f29b77fb66b92362f527f0799111 Mon Sep 17 00:00:00 2001 From: Jinbo Ci <32102965+jinboci@users.noreply.github.com> Date: Wed, 8 Jul 2020 18:33:35 +0800 Subject: [PATCH 10/12] Update op_module.h --- src/operator/tvmop/op_module.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/operator/tvmop/op_module.h b/src/operator/tvmop/op_module.h index 8a25b3b9951e..08dd26f11e95 100644 --- a/src/operator/tvmop/op_module.h +++ b/src/operator/tvmop/op_module.h @@ -43,9 +43,6 @@ class TVMOpModule { public: // Load TVM operators binary void Load(const std::string& filepath); - - void Import(const TVMOpModule& module); - void Call(const std::string& func_name, const mxnet::OpContext& ctx, const std::vector& args) const; From a31d013c0494c0d1a87f21bc75e2b083eb5eb257 Mon Sep 17 00:00:00 2001 From: Jinbo Ci <32102965+jinboci@users.noreply.github.com> Date: Wed, 8 Jul 2020 18:34:12 +0800 Subject: [PATCH 11/12] Update op_module.h --- src/operator/tvmop/op_module.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/operator/tvmop/op_module.h b/src/operator/tvmop/op_module.h index 08dd26f11e95..a300b938f4c1 100644 --- a/src/operator/tvmop/op_module.h +++ b/src/operator/tvmop/op_module.h @@ -43,6 +43,7 @@ class TVMOpModule { public: // Load TVM operators binary void Load(const std::string& filepath); + void Call(const std::string& func_name, const mxnet::OpContext& ctx, const std::vector& args) const; From 24dc649e7cdd9402f3fe83a33848dde82ed58dc5 Mon Sep 17 00:00:00 2001 From: Jinbo Ci <32102965+jinboci@users.noreply.github.com> Date: Wed, 8 Jul 2020 18:34:58 +0800 Subject: [PATCH 12/12] Update op_module.h --- src/operator/tvmop/op_module.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operator/tvmop/op_module.h b/src/operator/tvmop/op_module.h index a300b938f4c1..269a0aa50c11 100644 --- a/src/operator/tvmop/op_module.h +++ b/src/operator/tvmop/op_module.h @@ -43,7 +43,7 @@ class TVMOpModule { public: // Load TVM operators binary void Load(const std::string& filepath); - + void Call(const std::string& func_name, const mxnet::OpContext& ctx, const std::vector& args) const;