diff --git a/CMakeLists.txt b/CMakeLists.txt index 141c2d1c5..de2370213 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -199,10 +199,10 @@ else() set_target_properties(${LIBRARY_NAME} PROPERTIES LINK_FLAGS_RELEASE -s) endif() -find_package(OpenMP) -if(OpenMP_CXX_FOUND) - list(APPEND DEPEND_LIBS OpenMP::OpenMP_CXX) -endif() +#find_package(OpenMP) +#if(OpenMP_CXX_FOUND) +# list(APPEND DEPEND_LIBS OpenMP::OpenMP_CXX) +#endif() set_target_properties(${LIBRARY_NAME} PROPERTIES VERSION ${FASTDEPLOY_VERSION}) target_link_libraries(${LIBRARY_NAME} ${DEPEND_LIBS}) diff --git a/VERSION_NUMBER b/VERSION_NUMBER index 0d91a54c7..0ea3a944b 100644 --- a/VERSION_NUMBER +++ b/VERSION_NUMBER @@ -1 +1 @@ -0.3.0 +0.2.0 diff --git a/fastdeploy/__init__.py b/fastdeploy/__init__.py index 948f988b8..17858f7e9 100644 --- a/fastdeploy/__init__.py +++ b/fastdeploy/__init__.py @@ -13,7 +13,7 @@ # limitations under the License. from __future__ import absolute_import import logging -from .fastdeploy_main import Frontend, Backend, FDDataType, TensorInfo, RuntimeOption, Device +from .fastdeploy_main import Frontend, Backend, FDDataType, TensorInfo, Device from .fastdeploy_runtime import * from . import fastdeploy_main as C from . import vision @@ -26,6 +26,71 @@ def TensorInfoStr(tensor_info): return message +class RuntimeOption: + def __init__(self): + self._option = C.RuntimeOption() + + def set_model_path(self, model_path, params_path="", model_format="paddle"): + return self._option.set_model_path(model_path, params_path, model_format) + + def use_gpu(self, device_id=0): + return self._option.use_gpu(device_id) + + def use_cpu(self): + return self._option.use_cpu() + + def set_cpu_thread_num(self, thread_num=8): + return self._option.set_cpu_thread_num(thread_num) + + def use_paddle_backend(self): + return self._option.use_paddle_backend() + + def use_ort_backend(self): + return self._option.use_ort_backend() + + def use_trt_backend(self): + return self._option.use_trt_backend() + + def enable_paddle_mkldnn(self): + return self._option.enable_paddle_mkldnn() + + def disable_paddle_mkldnn(self): + return self._option.disable_paddle_mkldnn() + + def set_paddle_mkldnn_cache_size(self, cache_size): + return self._option.set_paddle_mkldnn_cache_size(cache_size) + + def set_trt_input_shape(self, tensor_name, min_shape, opt_shape=None, max_shape=None): + if opt_shape is None and max_shape is None: + opt_shape = min_shape + max_shape = min_shape + else: + assert opt_shape is not None and max_shape is not None, "Set min_shape only, or set min_shape, opt_shape, max_shape both." + return self._option.set_trt_input_shape(tensor_name, min_shape, opt_shape, max_shape) + + def set_trt_cache_file(self, cache_file_path): + return self._option.set_trt_cache_file(cache_file_path) + + def enable_trt_fp16(self): + return self._option.enable_trt_fp16() + + def dissable_trt_fp16(self): + return self._option.disable_trt_fp16() + + def __repr__(self): + attrs = dir(self._option) + message = "RuntimeOption(\n" + for attr in attrs: + if attr.startswith("__"): + continue + if hasattr(getattr(self._option, attr), "__call__"): + continue + message += " {} : {}\t\n".format(attr, getattr(self._option, attr)) + message.strip("\n") + message += ")" + return message + + def RuntimeOptionStr(runtime_option): attrs = dir(runtime_option) message = "RuntimeOption(\n" @@ -38,7 +103,5 @@ def RuntimeOptionStr(runtime_option): message.strip("\n") message += ")" return message - - C.TensorInfo.__repr__ = TensorInfoStr C.RuntimeOption.__repr__ = RuntimeOptionStr diff --git a/fastdeploy/fastdeploy_runtime.cc b/fastdeploy/fastdeploy_runtime.cc index 66efd22e5..1f782a54a 100644 --- a/fastdeploy/fastdeploy_runtime.cc +++ b/fastdeploy/fastdeploy_runtime.cc @@ -208,6 +208,11 @@ void RuntimeOption::EnableTrtFP16() { trt_enable_fp16 = true; } void RuntimeOption::DisableTrtFP16() { trt_enable_fp16 = false; } +void RuntimeOption::SetTrtCacheFile(const std::string& cache_file_path) { + trt_serialize_file = cache_file_path; +} + + bool Runtime::Init(const RuntimeOption& _option) { option = _option; if (option.model_format == Frontend::AUTOREC) { diff --git a/fastdeploy/fastdeploy_runtime.h b/fastdeploy/fastdeploy_runtime.h index cdd2b3e4b..32ca7ab10 100644 --- a/fastdeploy/fastdeploy_runtime.h +++ b/fastdeploy/fastdeploy_runtime.h @@ -87,16 +87,14 @@ struct FASTDEPLOY_DECL RuntimeOption { // disable half precision, change to full precision(float32) void DisableTrtFP16(); + void SetTrtCacheFile(const std::string& cache_file_path); + Backend backend = Backend::UNKNOWN; // for cpu inference and preprocess int cpu_thread_num = 8; int device_id = 0; -#ifdef WITH_GPU - Device device = Device::GPU; -#else Device device = Device::CPU; -#endif // ======Only for ORT Backend======== // -1 means use default value by ort diff --git a/fastdeploy/fastdeploy_runtime.py b/fastdeploy/fastdeploy_runtime.py index b23879b36..4ab88082b 100644 --- a/fastdeploy/fastdeploy_runtime.py +++ b/fastdeploy/fastdeploy_runtime.py @@ -19,7 +19,7 @@ from . import fastdeploy_main as C class FastDeployModel: def __init__(self, option): self._model = None - self._runtime_option = option + self._runtime_option = option._option if self._runtime_option is None: self._runtime_option = C.RuntimeOption() diff --git a/fastdeploy/pybind/fastdeploy_runtime.cc b/fastdeploy/pybind/fastdeploy_runtime.cc index 5f27509ca..3ede38040 100644 --- a/fastdeploy/pybind/fastdeploy_runtime.cc +++ b/fastdeploy/pybind/fastdeploy_runtime.cc @@ -33,6 +33,7 @@ void BindRuntime(pybind11::module& m) { .def("set_trt_input_shape", &RuntimeOption::SetTrtInputShape) .def("enable_trt_fp16", &RuntimeOption::EnableTrtFP16) .def("disable_trt_fp16", &RuntimeOption::DisableTrtFP16) + .def("set_trt_cache_file", &RuntimeOption::SetTrtCacheFile) .def_readwrite("model_file", &RuntimeOption::model_file) .def_readwrite("params_file", &RuntimeOption::params_file) .def_readwrite("model_format", &RuntimeOption::model_format) diff --git a/fastdeploy/vision/ppdet/__init__.py b/fastdeploy/vision/ppdet/__init__.py index 93aad6405..661ef0e1f 100644 --- a/fastdeploy/vision/ppdet/__init__.py +++ b/fastdeploy/vision/ppdet/__init__.py @@ -23,9 +23,9 @@ class PPYOLOE(FastDeployModel): model_file, params_file, config_file, - backend_option=None, + runtime_option=None, model_format=Frontend.PADDLE): - super(PPYOLOE, self).__init__(backend_option) + super(PPYOLOE, self).__init__(runtime_option) assert model_format == Frontend.PADDLE, "PPYOLOE only support model format of Frontend.Paddle now." self._model = C.vision.ppdet.PPYOLOE(model_file, params_file, diff --git a/setup.py b/setup.py index cb705376c..8575c4296 100644 --- a/setup.py +++ b/setup.py @@ -345,7 +345,7 @@ if sys.argv[1] == "install" or sys.argv[1] == "bdist_wheel": shutil.copy( os.path.join(".setuptools-cmake-build", f), "fastdeploy/libs") if f.count("fastdeploy_main.cpython-"): - pybind_so_file = f + pybind_so_file = os.path.join(".setuptools-cmake-build", f) if not os.path.exists(".setuptools-cmake-build/third_libs/install"): raise Exception( @@ -360,7 +360,7 @@ if sys.argv[1] == "install" or sys.argv[1] == "bdist_wheel": symlinks=True) if platform.system().lower() == "linux": - rpaths = ["${ORIGIN}"] + rpaths = ["$ORIGIN:$ORIGIN/libs"] for root, dirs, files in os.walk( ".setuptools-cmake-build/third_libs/install"): for d in dirs: @@ -368,11 +368,10 @@ if sys.argv[1] == "install" or sys.argv[1] == "bdist_wheel": path = os.path.relpath( os.path.join(root, d), ".setuptools-cmake-build/third_libs/install") - rpaths.append("${ORIGIN}/" + os.path.join( + rpaths.append("$ORIGIN/" + os.path.join( "libs/third_libs", path)) rpaths = ":".join(rpaths) - command = "patchelf --set-rpath '{}' ".format(rpaths) + os.path.join( - "fastdeploy/libs", pybind_so_file) + command = "patchelf --set-rpath '{}' ".format(rpaths) + pybind_so_file # The sw_64 not suppot patchelf, so we just disable that. if platform.machine() != 'sw_64' and platform.machine() != 'mips64': assert os.system(