Skip to content

Commit 15c8ae5

Browse files
Jian WengXingyu Zhou
authored andcommitted
imp module is deprecated (apache#4275)
1 parent 3cd73de commit 15c8ae5

11 files changed

Lines changed: 171 additions & 29 deletions

File tree

python/tvm/hybrid/module.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"""
2323

2424
import ast
25-
import imp
2625

2726
from ..contrib import util
2827
from .util import _internal_assert
@@ -112,5 +111,9 @@ def visit_FunctionDef(self, node):
112111
if self.name is None:
113112
self.name = finder.name
114113
self.root_ = finder.root
115-
py_module = imp.load_source(self.name, path)
116-
self.func_ = getattr(py_module, self.name)
114+
115+
_, local_ = {}, {}
116+
exec(self.src_, _, local_) #pylint: disable=exec-used
117+
local_.pop('tvm')
118+
assert len(local_) == 1
119+
self.func_ = list(local_.values())[0]

topi/python/topi/cpp/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""FFI for C++ TOPI ops and schedules"""
2+
from .impl import * #pylint: disable=wildcard-import
3+
from . import cuda
4+
from . import nn
5+
from . import vision
6+
from . import x86
7+
from . import generic
8+
from . import rocm
9+
from . import image

topi/python/topi/cpp/cuda.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
"""FFI for CUDA TOPI ops and schedules"""
18+
19+
from tvm._ffi.function import _init_api_prefix
20+
21+
_init_api_prefix("topi.cpp.cuda", "topi.cuda")

topi/python/topi/cpp/generic.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
"""FFI for generic TOPI ops and schedules"""
18+
19+
from tvm._ffi.function import _init_api_prefix
20+
21+
_init_api_prefix("topi.cpp.generic", "topi.generic")

topi/python/topi/cpp/image.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
"""FFI for image TOPI ops and schedules"""
18+
19+
from tvm._ffi.function import _init_api_prefix
20+
21+
_init_api_prefix("topi.cpp.image", "topi.image")
Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
# KIND, either express or implied. See the License for the
1515
# specific language governing permissions and limitations
1616
# under the License.
17-
"""FFI for C++ TOPI ops and schedules"""
17+
"""Load Lib for C++ TOPI ops and schedules"""
1818
import sys
1919
import os
2020
import ctypes
21-
from imp import new_module as _new_module
21+
2222
from tvm._ffi.function import _init_api_prefix
2323
from tvm._ffi import libinfo
2424

@@ -42,27 +42,3 @@ def _load_lib():
4242
_LIB, _LIB_NAME = _load_lib()
4343

4444
_init_api_prefix("topi.cpp", "topi")
45-
46-
def _create_module(name):
47-
fullname = __name__ + "." + name
48-
mod = _new_module(fullname)
49-
sys.modules[fullname] = mod
50-
return mod
51-
52-
# pylint: disable-msg=C0103
53-
nn = _create_module("nn")
54-
_init_api_prefix("topi.cpp.nn", "topi.nn")
55-
generic = _create_module("generic")
56-
_init_api_prefix("topi.cpp.generic", "topi.generic")
57-
cuda = _create_module("cuda")
58-
_init_api_prefix("topi.cpp.cuda", "topi.cuda")
59-
rocm = _create_module("rocm")
60-
_init_api_prefix("topi.cpp.rocm", "topi.rocm")
61-
x86 = _create_module("x86")
62-
_init_api_prefix("topi.cpp.x86", "topi.x86")
63-
vision = _create_module("vision")
64-
_init_api_prefix("topi.cpp.vision", "topi.vision")
65-
yolo = _create_module("vision.yolo")
66-
_init_api_prefix("topi.cpp.vision.yolo", "topi.vision.yolo")
67-
image = _create_module("image")
68-
_init_api_prefix("topi.cpp.image", "topi.image")

topi/python/topi/cpp/nn.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
"""FFI for NN TOPI ops and schedules"""
18+
19+
from tvm._ffi.function import _init_api_prefix
20+
21+
_init_api_prefix("topi.cpp.nn", "topi.nn")

topi/python/topi/cpp/rocm.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
"""FFI for Rocm TOPI ops and schedules"""
18+
19+
from tvm._ffi.function import _init_api_prefix
20+
21+
_init_api_prefix("topi.cpp.rocm", "topi.rocm")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""FFI for vision TOPI ops and schedules"""
2+
3+
from tvm._ffi.function import _init_api_prefix
4+
5+
from . import yolo
6+
7+
_init_api_prefix("topi.cpp.vision", "topi.vision")
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
"""FFI for Yolo TOPI ops and schedules"""
18+
19+
from tvm._ffi.function import _init_api_prefix
20+
21+
_init_api_prefix("topi.cpp.vision.yolo", "topi.vision.yolo")

0 commit comments

Comments
 (0)