!45006 [MS][LITE]add dvpp to lite minddata

Merge pull request !45006 from 张学同/new_api
This commit is contained in:
i-robot 2022-11-04 03:36:00 +00:00 committed by Gitee
commit b0b30f6447
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
10 changed files with 96 additions and 24 deletions

View File

@ -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

View File

@ -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<TensorOperation> CenterCrop::Parse() { return std::make_shared<C
std::shared_ptr<TensorOperation> 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<uint32_t> 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<TensorOperation> Decode::Parse() { return std::make_shared<Decod
std::shared_ptr<TensorOperation> 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<DvppDecodeJpegOperation>();
#endif
} else if (env == MapTargetDevice::kCpu) {
@ -380,7 +380,7 @@ std::shared_ptr<TensorOperation> 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<uint32_t> &size, VdecStreamFormat type, VdecOutputFormat out_format, const std::string &output)
@ -597,7 +597,7 @@ std::shared_ptr<TensorOperation> 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<DvppNormalizeOperation>(data_->mean_, data_->std_);
#endif
} else if (env == MapTargetDevice::kCpu) {
@ -1187,7 +1187,7 @@ std::shared_ptr<TensorOperation> Resize::Parse() {
std::shared_ptr<TensorOperation> 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<uint32_t> usize_;
usize_.reserve(data_->size_.size());
std::transform(data_->size_.begin(), data_->size_.end(), std::back_inserter(usize_),

View File

@ -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()

View File

@ -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)

View File

@ -37,6 +37,12 @@
namespace mindspore {
namespace dataset {
#if defined(ENABLE_CLOUD_FUSION_INFERENCE)
bool IsNonEmptyPNG(const std::shared_ptr<Tensor> &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<Tensor> &input, std::shared_ptr<Tensor> *output, float rescale, float shift) {
std::shared_ptr<CVTensor> input_cv = CVTensor::AsCVTensor(input);
if (!input_cv->mat().data) {

View File

@ -66,6 +66,8 @@ struct JpegErrorManagerCustom {
};
#if defined(ENABLE_CLOUD_FUSION_INFERENCE)
bool IsNonEmptyPNG(const std::shared_ptr<Tensor> &input);
/// \brief Returns Rescaled image
/// \param input: Tensor of shape <H,W,C> or <H,W> and any OpenCv compatible type, see CVTensor.
/// \param rescale: rescale parameter

View File

@ -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.";

View File

@ -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

View File

@ -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/

View File

@ -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
$<TARGET_OBJECTS:minddata-lite-obj>
)
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}
$<TARGET_OBJECTS:kernels-dvpp-image>
)
endif()
add_library(minddata-lite SHARED $<TARGET_OBJECTS:minddata-lite-obj>)
add_library(minddata-lite_static STATIC $<TARGET_OBJECTS:minddata-lite-obj>)
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)