diff --git a/cmake/package_lite.cmake b/cmake/package_lite.cmake index 79facc7e8bb..5d3f07b5e58 100644 --- a/cmake/package_lite.cmake +++ b/cmake/package_lite.cmake @@ -265,6 +265,12 @@ if(MSLITE_MINDDATA_IMPLEMENT STREQUAL "full") DESTINATION ${MIND_DATA_INC_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) if(PLATFORM_ARM64) + if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE AND MSLITE_ENABLE_ACL) + install(FILES ${TOP_DIR}/mindspore/ccsrc/minddata/dataset/include/dataset/vision_ascend.h + DESTINATION ${MIND_DATA_INC_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${TOP_DIR}/mindspore/lite/build/minddata/kernels-dvpp-image/utils/libdvpp_utils.so + DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + endif() install(FILES ${TOP_DIR}/mindspore/lite/build/minddata/libminddata-lite.so DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${TOP_DIR}/mindspore/lite/build/minddata/libminddata-lite.a DESTINATION @@ -281,6 +287,12 @@ if(MSLITE_MINDDATA_IMPLEMENT STREQUAL "full") install(FILES ${TOP_DIR}/mindspore/lite/build/securec/src/libsecurec.a DESTINATION ${SECUREC_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) else() + if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE AND MSLITE_ENABLE_ACL) + install(FILES ${TOP_DIR}/mindspore/ccsrc/minddata/dataset/include/dataset/vision_ascend.h + DESTINATION ${MIND_DATA_INC_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + install(FILES ${TOP_DIR}/mindspore/lite/build/minddata/kernels-dvpp-image/utils/libdvpp_utils.so + DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) + endif() install(FILES ${TOP_DIR}/mindspore/lite/build/minddata/libminddata-lite.so DESTINATION ${RUNTIME_LIB_DIR} COMPONENT ${RUNTIME_COMPONENT_NAME}) install(FILES ${TOP_DIR}/mindspore/lite/build/minddata/libminddata-lite.a DESTINATION diff --git a/mindspore/ccsrc/minddata/dataset/api/vision.cc b/mindspore/ccsrc/minddata/dataset/api/vision.cc index 9bd980f79d5..0f525b8600f 100755 --- a/mindspore/ccsrc/minddata/dataset/api/vision.cc +++ b/mindspore/ccsrc/minddata/dataset/api/vision.cc @@ -15,7 +15,7 @@ */ #include "minddata/dataset/include/dataset/vision.h" -#if defined(WITH_BACKEND) || defined(ENABLE_ACL) +#if defined(WITH_BACKEND) || defined(ENABLE_ACL) || defined(ENABLE_DVPP) #include "minddata/dataset/include/dataset/vision_ascend.h" #endif #include "minddata/dataset/kernels/ir/vision/ascend_vision_ir.h" @@ -282,7 +282,7 @@ std::shared_ptr CenterCrop::Parse() { return std::make_shared CenterCrop::Parse(const MapTargetDevice &env) { if (env == MapTargetDevice::kAscend310) { -#if defined(WITH_BACKEND) || defined(ENABLE_ACL) +#if defined(WITH_BACKEND) || defined(ENABLE_ACL) || defined(ENABLE_DVPP) std::vector usize_; usize_.reserve(data_->size_.size()); std::transform(data_->size_.begin(), data_->size_.end(), std::back_inserter(usize_), @@ -371,7 +371,7 @@ std::shared_ptr Decode::Parse() { return std::make_shared Decode::Parse(const MapTargetDevice &env) { if (env == MapTargetDevice::kAscend310) { -#if defined(WITH_BACKEND) || defined(ENABLE_ACL) +#if defined(WITH_BACKEND) || defined(ENABLE_ACL) || defined(ENABLE_DVPP) return std::make_shared(); #endif } else if (env == MapTargetDevice::kCpu) { @@ -380,7 +380,7 @@ std::shared_ptr Decode::Parse(const MapTargetDevice &env) { MS_LOG(ERROR) << "Unsupported MapTargetDevice, only supported kCpu and kAscend310."; return nullptr; } -#if defined(WITH_BACKEND) || defined(ENABLE_ACL) +#if defined(WITH_BACKEND) || defined(ENABLE_ACL) || defined(ENABLE_DVPP) // DvppDecodeVideo Transform Operation. struct DvppDecodeVideo::Data { Data(const std::vector &size, VdecStreamFormat type, VdecOutputFormat out_format, const std::string &output) @@ -597,7 +597,7 @@ std::shared_ptr Normalize::Parse(const MapTargetDevice &env) { } #endif if (env == MapTargetDevice::kAscend310) { -#if defined(WITH_BACKEND) || defined(ENABLE_ACL) +#if defined(WITH_BACKEND) || defined(ENABLE_ACL) || defined(ENABLE_DVPP) return std::make_shared(data_->mean_, data_->std_); #endif } else if (env == MapTargetDevice::kCpu) { @@ -1187,7 +1187,7 @@ std::shared_ptr Resize::Parse() { std::shared_ptr Resize::Parse(const MapTargetDevice &env) { if (env == MapTargetDevice::kAscend310) { -#if defined(WITH_BACKEND) || defined(ENABLE_ACL) +#if defined(WITH_BACKEND) || defined(ENABLE_ACL) || defined(ENABLE_DVPP) std::vector usize_; usize_.reserve(data_->size_.size()); std::transform(data_->size_.begin(), data_->size_.end(), std::back_inserter(usize_), diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/dvpp/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/kernels/image/dvpp/CMakeLists.txt index 9aae6435d60..a37294e3d82 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/dvpp/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/dvpp/CMakeLists.txt @@ -12,6 +12,6 @@ add_library(kernels-dvpp-image OBJECT dvpp_resize_jpeg_op.cc acl_adapter.cc ) -if(ENABLE_ACL) +if(ENABLE_ACL OR MSLITE_ENABLE_ACL) add_subdirectory(utils) endif() diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/dvpp/utils/CMakeLists.txt b/mindspore/ccsrc/minddata/dataset/kernels/image/dvpp/utils/CMakeLists.txt index 2f133cf3fe2..5ba7bc62129 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/dvpp/utils/CMakeLists.txt +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/dvpp/utils/CMakeLists.txt @@ -2,19 +2,32 @@ file(GLOB_RECURSE _CURRENT_SRC_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cc" set_property(SOURCE ${_CURRENT_SRC_FILES} PROPERTY COMPILE_DEFINITIONS SUBMODULE_ID=mindspore::SubModuleId::SM_MD) add_definitions(-DENABLE_DVPP_INTERFACE) -add_library(dvpp_utils SHARED - MDAclProcess.cc - DvppCommon.cc - ErrorCode.cpp - ResourceManager.cc - AclLiteUtils.cc - VdecHelper.cc - dvpp_video.cc - acl_plugin.cc - ${CMAKE_SOURCE_DIR}/mindspore/ccsrc/cxx_api/graph/acl/acl_env_guard.cc - ) +set(DVPP_UTILS_SRC + MDAclProcess.cc + DvppCommon.cc + ErrorCode.cpp + ResourceManager.cc + AclLiteUtils.cc + VdecHelper.cc + dvpp_video.cc + acl_plugin.cc + ) +if(NOT MSLITE_ENABLE_ACL) + set(DVPP_UTILS_SRC + ${DVPP_UTILS_SRC} + ${CMAKE_SOURCE_DIR}/mindspore/ccsrc/cxx_api/graph/acl/acl_env_guard.cc + ) +endif() -target_link_libraries(dvpp_utils PRIVATE _c_dataengine ${ACL} ${ACL_DVPP} mindspore_core mindspore_shared_lib) +add_library(dvpp_utils SHARED ${DVPP_UTILS_SRC}) + +if(MSLITE_ENABLE_ACL) + find_library(acl_dvpp libacl_dvpp.so ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH}) + find_library(acl libascendcl.so ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH}) + target_link_libraries(dvpp_utils PRIVATE ${acl} ${acl_dvpp} mindspore_core) +else() + target_link_libraries(dvpp_utils PRIVATE _c_dataengine ${ACL} ${ACL_DVPP} mindspore_core mindspore_shared_lib) +endif() if(MSLITE_ENABLE_CLOUD_MIND_DATA) add_dependencies(dvpp_utils fbs_src) diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.cc b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.cc index 94d6e1d6d4b..56216646392 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.cc @@ -37,6 +37,12 @@ namespace mindspore { namespace dataset { #if defined(ENABLE_CLOUD_FUSION_INFERENCE) +bool IsNonEmptyPNG(const std::shared_ptr &input) { + const unsigned char kPngMagic[] = "\x89\x50\x4E\x47"; + constexpr dsize_t kPngMagicLen = 4; + return input->SizeInBytes() > kPngMagicLen && memcmp(input->GetBuffer(), kPngMagic, kPngMagicLen) == 0; +} + Status Rescale(const std::shared_ptr &input, std::shared_ptr *output, float rescale, float shift) { std::shared_ptr input_cv = CVTensor::AsCVTensor(input); if (!input_cv->mat().data) { diff --git a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h index 7266a26afd9..65d1ce4651b 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h +++ b/mindspore/ccsrc/minddata/dataset/kernels/image/lite_image_utils.h @@ -66,6 +66,8 @@ struct JpegErrorManagerCustom { }; #if defined(ENABLE_CLOUD_FUSION_INFERENCE) +bool IsNonEmptyPNG(const std::shared_ptr &input); + /// \brief Returns Rescaled image /// \param input: Tensor of shape or and any OpenCv compatible type, see CVTensor. /// \param rescale: rescale parameter diff --git a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/ascend_vision_ir.cc b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/ascend_vision_ir.cc index d49ffa35d66..dfd72155dcf 100644 --- a/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/ascend_vision_ir.cc +++ b/mindspore/ccsrc/minddata/dataset/kernels/ir/vision/ascend_vision_ir.cc @@ -264,7 +264,7 @@ Status DvppDecodeResizeCropOperation::ValidateParams() { LOG_AND_RETURN_STATUS_SYNTAX_ERROR(err_msg); } if (crop_.size() < resize_.size()) { - if (crop_[0] > MIN(resize_[0], resize_[1])) { + if (crop_[0] > std::min(resize_[0], resize_[1])) { std::string err_msg = "Each value of crop parameter must be smaller than corresponding resize parameter, for example: x[0] <= " "y[0], and x[1] <= y[1], please verify your input parameters."; @@ -272,7 +272,7 @@ Status DvppDecodeResizeCropOperation::ValidateParams() { } } if (crop_.size() > resize_.size()) { - if (MAX(crop_[0], crop_[1]) > resize_[0]) { + if (std::max(crop_[0], crop_[1]) > resize_[0]) { std::string err_msg = "Each value of crop parameter must be smaller than corresponding resize parameter, for example: x[0] <= " "y[0], and x[1] <= y[1], please verify your input parameters."; diff --git a/mindspore/ccsrc/minddata/dataset/util/log_adapter.h b/mindspore/ccsrc/minddata/dataset/util/log_adapter.h index e83b10fcf08..bca1ab04b98 100644 --- a/mindspore/ccsrc/minddata/dataset/util/log_adapter.h +++ b/mindspore/ccsrc/minddata/dataset/util/log_adapter.h @@ -16,7 +16,7 @@ #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_LOG_ADAPTER_H_ #define MINDSPORE_CCSRC_MINDDATA_DATASET_UTIL_LOG_ADAPTER_H_ -#ifndef ENABLE_ANDROID +#if !defined(ENABLE_ANDROID) || defined(ENABLE_CLOUD_FUSION_INFERENCE) #include "mindspore/core/utils/log_adapter.h" #define DATASET_SRC_FILE_NAME FILE_NAME #else diff --git a/mindspore/lite/build_lite.sh b/mindspore/lite/build_lite.sh index 9b73c39f45d..d8df1593175 100755 --- a/mindspore/lite/build_lite.sh +++ b/mindspore/lite/build_lite.sh @@ -193,6 +193,10 @@ build_python_wheel_package() { find src/extendrt/convert/ -name "*.so" -exec cp '{}' package/mindspore_lite/lib/ \; if [[ "${MSLITE_ENABLE_ACL}" ]]; then cp src/extendrt/kernel/ascend/*.so package/mindspore_lite/lib/ + local dvpp_utils=minddata/kernels-dvpp-image/utils/libdvpp_utils.so + if [ -f ${dvpp_utils} ]; then + cp ${dvpp_utils} package/mindspore_lite/lib/ + fi fi if [ -f "${INSTALL_PREFIX}/${pkg_name}/runtime/lib/libtransformer-shared.so" ]; then cp ${INSTALL_PREFIX}/${pkg_name}/runtime/lib/libtransformer-shared.so package/mindspore_lite/lib/ diff --git a/mindspore/lite/minddata/CMakeLists.txt b/mindspore/lite/minddata/CMakeLists.txt index ae893b0c159..6220520b0fc 100644 --- a/mindspore/lite/minddata/CMakeLists.txt +++ b/mindspore/lite/minddata/CMakeLists.txt @@ -55,6 +55,21 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default") set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS} -s") +if(MSLITE_ENABLE_RUNTIME_GLOG AND MSLITE_ENABLE_CLOUD_FUSION_INFERENCE) + add_definitions(-DUSE_GLOG) + string(REPLACE "-fno-rtti" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) + string(REPLACE "-fno-rtti" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) +endif() + +if(MSLITE_ENABLE_ACL) +include_directories(${TOP_DIR}/graphengine/metadef/inc/external) +include_directories(${TOP_DIR}/graphengine/metadef/inc) +include_directories(${TOP_DIR}/graphengine/inc) +include_directories(${TOP_DIR}/graphengine/inc/external) +include_directories(${TOP_DIR}/graphengine/third_party/fwkacllib/inc) +include_directories(${CCSRC_DIR}) +endif() + AUX_SOURCE_DIRECTORY(${MINDDATA_DIR}/api MINDDATA_API_SRC_FILES) AUX_SOURCE_DIRECTORY(${MINDDATA_DIR}/callback MINDDATA_CALLBACK_SRC_FILES) @@ -304,6 +319,16 @@ if(MSLITE_MINDDATA_IMPLEMENT STREQUAL "full") ${MINDDATA_DIR}/kernels/ir/vision/rescale_ir.cc ${MINDDATA_DIR}/core/cv_tensor.cc ) + + if(MSLITE_ENABLE_ACL) + add_definitions(-DENABLE_DVPP) + set(MINDDATA_FULL_SRC + ${MINDDATA_FULL_SRC} + ${MINDDATA_DIR}/core/device_tensor.cc + ${MINDDATA_DIR}/kernels/ir/vision/ascend_vision_ir.cc) + add_subdirectory(${MINDDATA_DIR}/kernels/image/dvpp kernels-dvpp-image) + endif() + endif() add_library(minddata-lite-obj OBJECT @@ -313,9 +338,19 @@ if(MSLITE_MINDDATA_IMPLEMENT STREQUAL "full") ${MINDDATA_FULL_SRC} ) add_dependencies(minddata-lite-obj fbs_src) + set(minddata_lite_submodules + $ + ) + if(MSLITE_ENABLE_CLOUD_FUSION_INFERENCE AND MSLITE_ENABLE_ACL) + add_dependencies(minddata-lite-obj kernels-dvpp-image) + set(minddata_lite_submodules + ${minddata_lite_submodules} + $ + ) + endif() - add_library(minddata-lite SHARED $) - add_library(minddata-lite_static STATIC $) + add_library(minddata-lite SHARED ${minddata_lite_submodules}) + add_library(minddata-lite_static STATIC ${minddata_lite_submodules}) set_target_properties(minddata-lite_static PROPERTIES OUTPUT_NAME "minddata-lite") find_package(Threads REQUIRED)