diff --git a/fastdeploy/function/gather_scatter_along_axis.h b/fastdeploy/function/gather_scatter_along_axis.h index bd1093af1..fa627a411 100644 --- a/fastdeploy/function/gather_scatter_along_axis.h +++ b/fastdeploy/function/gather_scatter_along_axis.h @@ -26,7 +26,8 @@ namespace function { @param out The output tensor which stores the result. @param axis Axis which will be gathered. */ -void GatherAlongAxis(const FDTensor& x, const FDTensor& index, FDTensor* result, +FASTDEPLOY_DECL void GatherAlongAxis(const FDTensor& x, + const FDTensor& index, FDTensor* result, int axis); } // namespace function diff --git a/fastdeploy/pybind/main.cc.in b/fastdeploy/pybind/main.cc.in index 5da3ef9fc..5e11ee808 100755 --- a/fastdeploy/pybind/main.cc.in +++ b/fastdeploy/pybind/main.cc.in @@ -156,6 +156,8 @@ PYBIND11_MODULE(@PY_LIBRARY_NAME@, m) { "Make programer easier to deploy deeplearning model, save time to save " "the world!"; + m.def("set_logger", &SetLogger); + BindFDTensor(m); BindRuntime(m); BindFDModel(m); diff --git a/fastdeploy/utils/utils.cc b/fastdeploy/utils/utils.cc index 760c10406..c39b6adab 100644 --- a/fastdeploy/utils/utils.cc +++ b/fastdeploy/utils/utils.cc @@ -13,18 +13,27 @@ // limitations under the License. #include "fastdeploy/utils/utils.h" + #include namespace fastdeploy { +bool FDLogger::enable_info = true; +bool FDLogger::enable_warning = true; + +void SetLogger(bool enable_info, bool enable_warning) { + FDLogger::enable_info = enable_info; + FDLogger::enable_warning = enable_warning; +} + FDLogger::FDLogger(bool verbose, const std::string& prefix) { verbose_ = verbose; line_ = ""; -#ifdef __ANDROID__ +#ifdef __ANDROID__ prefix_ = std::string("[FastDeploy]") + prefix; #else prefix_ = prefix; -#endif +#endif } FDLogger& FDLogger::operator<<(std::ostream& (*os)(std::ostream&)) { diff --git a/fastdeploy/utils/utils.h b/fastdeploy/utils/utils.h index d44b7f187..cfc666bb2 100644 --- a/fastdeploy/utils/utils.h +++ b/fastdeploy/utils/utils.h @@ -43,6 +43,9 @@ namespace fastdeploy { class FASTDEPLOY_DECL FDLogger { public: + static bool enable_info; + static bool enable_warning; + FDLogger() { line_ = ""; prefix_ = "[FastDeploy]"; @@ -90,11 +93,12 @@ FASTDEPLOY_DECL bool ReadBinaryFromFile(const std::string& file, << __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t" #define FDWARNING \ - FDLogger(true, "[WARNING]") \ + FDLogger(fastdeploy::FDLogger::enable_warning, "[WARNING]") \ << __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t" #define FDINFO \ - FDLogger(true, "[INFO]") << __REL_FILE__ << "(" << __LINE__ \ + FDLogger(fastdeploy::FDLogger::enable_info, "[INFO]") \ + << __REL_FILE__ << "(" << __LINE__ \ << ")::" << __FUNCTION__ << "\t" #define FDASSERT(condition, format, ...) \ @@ -214,6 +218,10 @@ std::string Str(const std::vector& shape) { return oss.str(); } +/// Set behaviour of logging while using FastDeploy +FASTDEPLOY_DECL void SetLogger(bool enable_info = true, + bool enable_warning = true); + template void CalculateStatisInfo(const void* src_ptr, int size, double* mean, double* max, double* min) { diff --git a/python/fastdeploy/__init__.py b/python/fastdeploy/__init__.py index 1d9640c7b..ac982fcfb 100755 --- a/python/fastdeploy/__init__.py +++ b/python/fastdeploy/__init__.py @@ -30,6 +30,17 @@ from .c_lib_wrap import ( is_built_with_trt, get_default_cuda_directory, ) + +def set_logger(enable_info=True, enable_warning=True): + """Set behaviour of logger while using FastDeploy + + :param enable_info: (boolean)Whether to print out log level of INFO + :param enable_warning: (boolean)Whether to print out log level of WARNING, recommend to set to True + """ + from .c_lib_wrap import set_logger + set_logger(enable_info, enable_warning) + + from .runtime import Runtime, RuntimeOption from .model import FastDeployModel from . import c_lib_wrap as C