Skip to content

Commit

Permalink
runtime version
Browse files Browse the repository at this point in the history
  • Loading branch information
Hideousmon committed Oct 28, 2023
1 parent a489f81 commit 6beb4e6
Show file tree
Hide file tree
Showing 12 changed files with 278 additions and 705 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@
[submodule "python/pybind11"]
path = python/pybind11
url = https://github.com/pybind/pybind11.git
[submodule "tools/pnnx/python/pybind11"]
path = tools/pnnx/python/pybind11
url = https://github.com/pybind/pybind11.git
12 changes: 1 addition & 11 deletions tools/pnnx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.15")
cmake_policy(SET CMP0091 NEW)
endif()

set(PNNX_VERSION_MAJOR 1)
set(PNNX_VERSION_MINOR 0)

project(pnnx)
cmake_minimum_required(VERSION 3.12)

Expand All @@ -33,8 +30,6 @@ set(CMAKE_CXX_STANDARD 14)
#set(CMAKE_BUILD_TYPE release)

option(PNNX_COVERAGE "build for coverage" OFF)
option(PNNX_LIB "build static library" OFF)
option(PNNX_PYTHON "build python api" OFF)

#set(Torch_INSTALL_DIR "/home/nihui/.local/lib/python3.9/site-packages/torch" CACHE STRING "")
#set(Torch_INSTALL_DIR "/home/nihui/osd/pnnx/pytorch-v1.10.0/build/install" CACHE STRING "")
Expand Down Expand Up @@ -62,7 +57,6 @@ endif()
find_package(Python3 COMPONENTS Interpreter Development)

PNNXProbeForPyTorchInstall()

find_package(Torch REQUIRED)

find_package(TorchVision QUIET)
Expand Down Expand Up @@ -93,8 +87,4 @@ include_directories(${TORCH_INCLUDE_DIRS})
add_subdirectory(src)

enable_testing()
add_subdirectory(tests)

if(PNNX_PYTHON)
add_subdirectory(python)
endif()
add_subdirectory(tests)
48 changes: 0 additions & 48 deletions tools/pnnx/python/CMakeLists.txt

This file was deleted.

18 changes: 14 additions & 4 deletions tools/pnnx/python/pnnx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

from .pnnx import *
import os
import platform
EXEC_DIR_PATH = os.path.dirname(os.path.abspath(__file__))
if platform.system() == 'Linux' or platform.system() == "Darwin":
EXEC_PATH = EXEC_DIR_PATH + "/pnnx"
elif platform.system() == "Windows":
EXEC_PATH = EXEC_DIR_PATH + "/pnnx.exe"
else:
raise Exception("Unsupported platform for pnnx.")

from .utils.export import export
from .utils.convert import convert

import os
os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"
try:
import importlib.metadata
__version__ = importlib.metadata.version("pnnx")
except:
pass

__version__ = pnnx.__version__
4 changes: 2 additions & 2 deletions tools/pnnx/python/pnnx/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

from .export import *
from .convert import *
from .export import export
from .convert import convert
86 changes: 44 additions & 42 deletions tools/pnnx/python/pnnx/utils/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,14 @@
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.

import torch
import os
import pnnx


def check_type(data, dataname, types, typesname):
if not(data is None):
if (type(data) in types):
return True
else:
raise Exception(dataname + " should be "+ typesname + ".")
else:
return True
from .utils import check_type, generate_inputs_arg, str_in_list_to_str
import subprocess
from .. import EXEC_PATH

def convert(ptpath, input_shapes, input_types, input_shapes2 = None,
input_types2 = None, device = None, customop_modules = None,
module_operators = None, optlevel = None, pnnxparam = None,
input_types2 = None, device = None, customop = None,
moduleop = None, optlevel = None, pnnxparam = None,
pnnxbin = None, pnnxpy = None, pnnxonnx = None, ncnnparam = None,
ncnnbin = None, ncnnpy = None):

Expand All @@ -38,8 +29,8 @@ def convert(ptpath, input_shapes, input_types, input_shapes2 = None,
check_type(input_shapes2, "input_shapes2", [list], "list of list with int type inside")
check_type(input_types2, "input_types2", [str, list], "str or list of str")
check_type(device, "device", [str], "str")
check_type(customop_modules, "customop_modules", [str, list], "str or list of str")
check_type(module_operators, "module_operators", [str, list], "str or list of str")
check_type(customop, "customop", [str, list], "str or list of str")
check_type(moduleop, "moduleop", [str, list], "str or list of str")
check_type(optlevel, "optlevel", [int], "int")

if input_shapes2 is None:
Expand All @@ -50,32 +41,19 @@ def convert(ptpath, input_shapes, input_types, input_shapes2 = None,
input_types2 = []
elif type(input_types2) != list:
input_types2 = [input_types2]
if customop_modules is None:
customop_modules = []
elif type(customop_modules) != list:
customop_modules = [customop_modules]
if module_operators is None:
module_operators = []
elif type(module_operators) != list:
module_operators = [module_operators]
if customop is None:
customop = []
elif type(customop) != list:
customop = [customop]
if moduleop is None:
moduleop = []
elif type(moduleop) != list:
moduleop = [moduleop]
if device is None:
device = "cpu"
if optlevel is None:
optlevel = 2
if pnnxparam is None:
pnnxparam = ""
if pnnxbin is None:
pnnxbin = ""
if pnnxpy is None:
pnnxpy = ""
if pnnxonnx is None:
pnnxonnx = ""
if ncnnparam is None:
ncnnparam = ""
if ncnnbin is None:
ncnnbin = ""
if ncnnpy is None:
ncnnpy = ""

if type(input_shapes[0]) != list:
input_shapes = [input_shapes]
if type(input_types) != list:
Expand All @@ -86,7 +64,31 @@ def convert(ptpath, input_shapes, input_types, input_shapes2 = None,
if len(input_shapes2) != len(input_types2):
raise Exception("input_shapes2 should has the same length with input_types2!")

pnnx.pnnx_export(ptpath, input_shapes, input_types, input_shapes2,
input_types2, device, customop_modules, module_operators,
optlevel, pnnxparam,pnnxbin, pnnxpy, pnnxonnx, ncnnparam,
ncnnbin, ncnnpy)
input_arg1 = generate_inputs_arg(input_shapes, input_types)

command_list = [EXEC_PATH, ptpath, "inputshape="+input_arg1,
"device="+device,
"optlevel="+str(optlevel)]
if not (len(input_shapes2) == 0):
input_arg2 = generate_inputs_arg(input_shapes2, input_types2)
command_list.append("inputshape2=" + input_arg2)
if not (len(customop) == 0):
command_list.append("customop=" + str_in_list_to_str(customop))
if not (len(moduleop) == 0):
command_list.append("moduleop=" + str_in_list_to_str(moduleop))
if not(pnnxparam is None):
command_list.append("pnnxparam="+pnnxparam)
if not(pnnxbin is None):
command_list.append("pnnxbin="+pnnxbin)
if not(pnnxpy is None):
command_list.append("pnnxpy="+pnnxpy)
if not(pnnxonnx is None):
command_list.append("pnnxonnx="+pnnxonnx)
if not(ncnnparam is None):
command_list.append("ncnnparam="+ncnnparam)
if not(ncnnbin is None):
command_list.append("ncnnbin="+ncnnbin)
if not(ncnnpy is None):
command_list.append("ncnnpy="+ncnnpy)
current_dir = os.getcwd()
subprocess.run(command_list, stdout=subprocess.PIPE, text=True, cwd=current_dir)
Loading

0 comments on commit 6beb4e6

Please sign in to comment.