Browse Source

!733 fix bug of import _akg failed

Merge pull request !733 from zyli2020/master
tags/v0.3.0-alpha
mindspore-ci-bot Gitee 5 years ago
parent
commit
353fa8d763
2 changed files with 62 additions and 46 deletions
  1. +1
    -46
      mindspore/_akg/__init__.py
  2. +61
    -0
      mindspore/_akg/add_path.py

+ 1
- 46
mindspore/_akg/__init__.py View File

@@ -13,51 +13,6 @@
# limitations under the License.

"""__init__"""
from __future__ import absolute_import as _abs
import sys
import os
from . import add_path
from .op_build import op_build
from .message import compilewithjson


def AKGAddPath():
"""_akg add path."""
pwd = os.path.dirname(os.path.realpath(__file__))
tvm_path = os.path.realpath(pwd)
if tvm_path not in sys.path:
sys.path.insert(0, tvm_path)
else:
sys.path.remove(tvm_path)
sys.path.insert(0, tvm_path)


class AKGMetaPathFinder:
"""class AKGMetaPath finder."""

def find_module(self, fullname, path=None):
"""method _akg find module."""
if fullname.startswith("_akg.tvm"):
rname = fullname[5:]
return AKGMetaPathLoader(rname)
if fullname.startswith("_akg.topi"):
rname = fullname[5:]
return AKGMetaPathLoader(rname)
return None


class AKGMetaPathLoader:
"""class AKGMetaPathLoader loader."""
def __init__(self, rname):
self.__rname = rname

def load_module(self, fullname):
if self.__rname in sys.modules:
sys.modules.pop(self.__rname)
AKGAddPath()
__import__(self.__rname, globals(), locals())
self.__target_module = sys.modules[self.__rname]
sys.modules[fullname] = self.__target_module
return self.__target_module


sys.meta_path.insert(0, AKGMetaPathFinder())

+ 61
- 0
mindspore/_akg/add_path.py View File

@@ -0,0 +1,61 @@
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed 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.

"""add tvm path"""
import sys
import os


def AKGAddPath():
"""_akg add path."""
pwd = os.path.dirname(os.path.realpath(__file__))
tvm_path = os.path.realpath(pwd)
if tvm_path not in sys.path:
sys.path.insert(0, tvm_path)
else:
sys.path.remove(tvm_path)
sys.path.insert(0, tvm_path)


class AKGMetaPathFinder:
"""class AKGMetaPath finder."""

def find_module(self, fullname, path=None):
"""method _akg find module."""
if fullname.startswith("_akg.tvm"):
rname = fullname[5:]
return AKGMetaPathLoader(rname)
if fullname.startswith("_akg.topi"):
rname = fullname[5:]
return AKGMetaPathLoader(rname)
return None


class AKGMetaPathLoader:
"""class AKGMetaPathLoader loader."""

def __init__(self, rname):
self.__rname = rname

def load_module(self, fullname):
if self.__rname in sys.modules:
sys.modules.pop(self.__rname)
AKGAddPath()
__import__(self.__rname, globals(), locals())
self.__target_module = sys.modules[self.__rname]
sys.modules[fullname] = self.__target_module
return self.__target_module


sys.meta_path.insert(0, AKGMetaPathFinder())

Loading…
Cancel
Save