imp module is deprecated (#4275)
authorJian Weng <jian.weng@ucla.edu>
Fri, 15 Nov 2019 17:13:04 +0000 (09:13 -0800)
committerTianqi Chen <tqchen@users.noreply.github.com>
Fri, 15 Nov 2019 17:13:04 +0000 (09:13 -0800)
python/tvm/hybrid/module.py
topi/python/topi/cpp/__init__.py [new file with mode: 0644]
topi/python/topi/cpp/cuda.py [new file with mode: 0644]
topi/python/topi/cpp/generic.py [new file with mode: 0644]
topi/python/topi/cpp/image.py [new file with mode: 0644]
topi/python/topi/cpp/impl.py [moved from topi/python/topi/cpp.py with 64% similarity]
topi/python/topi/cpp/nn.py [new file with mode: 0644]
topi/python/topi/cpp/rocm.py [new file with mode: 0644]
topi/python/topi/cpp/vision/__init__.py [new file with mode: 0644]
topi/python/topi/cpp/vision/yolo.py [new file with mode: 0644]
topi/python/topi/cpp/x86.py [new file with mode: 0644]

index 13e45a7..9811ae1 100644 (file)
@@ -22,7 +22,6 @@ To enable this feature, you need to build with -DUSE_HYBRID_DUMP=ON.
 """
 
 import ast
-import imp
 
 from ..contrib import util
 from .util import _internal_assert
@@ -112,5 +111,9 @@ class HybridModule(object):
         if self.name is None:
             self.name = finder.name
         self.root_ = finder.root
-        py_module = imp.load_source(self.name, path)
-        self.func_ = getattr(py_module, self.name)
+
+        _, local_ = {}, {}
+        exec(self.src_, _, local_) #pylint: disable=exec-used
+        local_.pop('tvm')
+        assert len(local_) == 1
+        self.func_ = list(local_.values())[0]
diff --git a/topi/python/topi/cpp/__init__.py b/topi/python/topi/cpp/__init__.py
new file mode 100644 (file)
index 0000000..c52a819
--- /dev/null
@@ -0,0 +1,9 @@
+"""FFI for C++ TOPI ops and schedules"""
+from .impl import * #pylint: disable=wildcard-import
+from . import cuda
+from . import nn
+from . import vision
+from . import x86
+from . import generic
+from . import rocm
+from . import image
diff --git a/topi/python/topi/cpp/cuda.py b/topi/python/topi/cpp/cuda.py
new file mode 100644 (file)
index 0000000..920b271
--- /dev/null
@@ -0,0 +1,21 @@
+# 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.
+"""FFI for CUDA TOPI ops and schedules"""
+
+from tvm._ffi.function import _init_api_prefix
+
+_init_api_prefix("topi.cpp.cuda", "topi.cuda")
diff --git a/topi/python/topi/cpp/generic.py b/topi/python/topi/cpp/generic.py
new file mode 100644 (file)
index 0000000..a8a7165
--- /dev/null
@@ -0,0 +1,21 @@
+# 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.
+"""FFI for generic TOPI ops and schedules"""
+
+from tvm._ffi.function import _init_api_prefix
+
+_init_api_prefix("topi.cpp.generic", "topi.generic")
diff --git a/topi/python/topi/cpp/image.py b/topi/python/topi/cpp/image.py
new file mode 100644 (file)
index 0000000..c6a8f2c
--- /dev/null
@@ -0,0 +1,21 @@
+# 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.
+"""FFI for image TOPI ops and schedules"""
+
+from tvm._ffi.function import _init_api_prefix
+
+_init_api_prefix("topi.cpp.image", "topi.image")
similarity index 64%
rename from topi/python/topi/cpp.py
rename to topi/python/topi/cpp/impl.py
index a1c1c8e..5eff604 100644 (file)
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-"""FFI for C++ TOPI ops and schedules"""
+"""Load Lib for C++ TOPI ops and schedules"""
 import sys
 import os
 import ctypes
-from imp import new_module as _new_module
+
 from tvm._ffi.function import _init_api_prefix
 from tvm._ffi import libinfo
 
@@ -42,27 +42,3 @@ def _load_lib():
 _LIB, _LIB_NAME = _load_lib()
 
 _init_api_prefix("topi.cpp", "topi")
-
-def _create_module(name):
-    fullname = __name__ + "." + name
-    mod = _new_module(fullname)
-    sys.modules[fullname] = mod
-    return mod
-
-# pylint: disable-msg=C0103
-nn = _create_module("nn")
-_init_api_prefix("topi.cpp.nn", "topi.nn")
-generic = _create_module("generic")
-_init_api_prefix("topi.cpp.generic", "topi.generic")
-cuda = _create_module("cuda")
-_init_api_prefix("topi.cpp.cuda", "topi.cuda")
-rocm = _create_module("rocm")
-_init_api_prefix("topi.cpp.rocm", "topi.rocm")
-x86 = _create_module("x86")
-_init_api_prefix("topi.cpp.x86", "topi.x86")
-vision = _create_module("vision")
-_init_api_prefix("topi.cpp.vision", "topi.vision")
-yolo = _create_module("vision.yolo")
-_init_api_prefix("topi.cpp.vision.yolo", "topi.vision.yolo")
-image = _create_module("image")
-_init_api_prefix("topi.cpp.image", "topi.image")
diff --git a/topi/python/topi/cpp/nn.py b/topi/python/topi/cpp/nn.py
new file mode 100644 (file)
index 0000000..59bf147
--- /dev/null
@@ -0,0 +1,21 @@
+# 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.
+"""FFI for NN TOPI ops and schedules"""
+
+from tvm._ffi.function import _init_api_prefix
+
+_init_api_prefix("topi.cpp.nn", "topi.nn")
diff --git a/topi/python/topi/cpp/rocm.py b/topi/python/topi/cpp/rocm.py
new file mode 100644 (file)
index 0000000..d57ce3e
--- /dev/null
@@ -0,0 +1,21 @@
+# 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.
+"""FFI for Rocm TOPI ops and schedules"""
+
+from tvm._ffi.function import _init_api_prefix
+
+_init_api_prefix("topi.cpp.rocm", "topi.rocm")
diff --git a/topi/python/topi/cpp/vision/__init__.py b/topi/python/topi/cpp/vision/__init__.py
new file mode 100644 (file)
index 0000000..b965a03
--- /dev/null
@@ -0,0 +1,7 @@
+"""FFI for vision TOPI ops and schedules"""
+
+from tvm._ffi.function import _init_api_prefix
+
+from . import yolo
+
+_init_api_prefix("topi.cpp.vision", "topi.vision")
diff --git a/topi/python/topi/cpp/vision/yolo.py b/topi/python/topi/cpp/vision/yolo.py
new file mode 100644 (file)
index 0000000..072ab29
--- /dev/null
@@ -0,0 +1,21 @@
+# 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.
+"""FFI for Yolo TOPI ops and schedules"""
+
+from tvm._ffi.function import _init_api_prefix
+
+_init_api_prefix("topi.cpp.vision.yolo", "topi.vision.yolo")
diff --git a/topi/python/topi/cpp/x86.py b/topi/python/topi/cpp/x86.py
new file mode 100644 (file)
index 0000000..a6db26e
--- /dev/null
@@ -0,0 +1,21 @@
+# 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.
+"""FFI for x86 TOPI ops and schedules"""
+
+from tvm._ffi.function import _init_api_prefix
+
+_init_api_prefix("topi.cpp.x86", "topi.x86")