!41866 dvpp decouple

Merge pull request !41866 from zhoufeng/minddata-dvpp-decouple
This commit is contained in:
i-robot 2022-09-20 06:13:57 +00:00 committed by Gitee
commit 60da2ecf2f
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
58 changed files with 1424 additions and 612 deletions

View File

@ -253,6 +253,13 @@ if(ENABLE_D OR ENABLE_ACL)
COMPONENT mindspore
)
endif()
if(ENABLE_ACL)
install(
TARGETS dvpp_utils
DESTINATION ${INSTALL_LIB_DIR}
COMPONENT mindspore
)
endif()
endif()
if(MS_BUILD_GRPC)

View File

@ -96,6 +96,14 @@ if(ENABLE_MINDDATA)
DESTINATION ${INSTALL_LIB_DIR}
COMPONENT mindspore
)
if(ENABLE_ACL)
install(
TARGETS dvpp_utils
DESTINATION ${INSTALL_LIB_DIR}
COMPONENT mindspore
)
endif()
endif()
# CPU mode

View File

@ -1,26 +0,0 @@
/**
* Copyright 2021-2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_INCLUDE_COMMON_UTILS_RUNTIME_ERROR_CODES_H_
#define MINDSPORE_CCSRC_INCLUDE_COMMON_UTILS_RUNTIME_ERROR_CODES_H_
#include <string>
#include "include/common/visible.h"
namespace mindspore {
COMMON_EXPORT std::string GetErrorMsg(uint32_t rt_error_code);
} // namespace mindspore
#endif // MINDSPORE_CCSRC_INCLUDE_COMMON_UTILS_RUNTIME_ERROR_CODES_H_

View File

@ -35,10 +35,6 @@ if(ENABLE_ACL)
add_definitions(-D ENABLE_ACL)
message(STATUS "ACL module is enabled")
endif()
if(ENABLE_TDTQUE)
add_definitions(-D ENABLE_TDTQUE)
message(STATUS "TDT queue is enabled")
endif()
if(MS_BUILD_GRPC)
set(ENABLE_CACHE true)
add_definitions(-D ENABLE_CACHE)
@ -118,11 +114,7 @@ add_dependencies(engine-ir-cache core)
add_dependencies(kernels-ir core)
add_dependencies(kernels-ir-data core)
add_dependencies(kernels-ir-vision core)
if(ENABLE_ACL)
add_dependencies(kernels-dvpp-image core dvpp-utils)
endif()
add_dependencies(kernels-dvpp-image core)
if(ENABLE_PYTHON)
add_dependencies(APItoPython core)
@ -193,14 +185,8 @@ set(dataengine_submodules
$<TARGET_OBJECTS:kernels-ir>
$<TARGET_OBJECTS:kernels-ir-data>
$<TARGET_OBJECTS:kernels-ir-vision>
$<TARGET_OBJECTS:md_plugin>)
if(ENABLE_ACL)
set(dataengine_submodules
${dataengine_submodules}
$<TARGET_OBJECTS:kernels-dvpp-image>
$<TARGET_OBJECTS:dvpp-utils>)
endif()
$<TARGET_OBJECTS:md_plugin>
$<TARGET_OBJECTS:kernels-dvpp-image>)
if(ENABLE_PYTHON)
set(dataengine_submodules
@ -208,15 +194,10 @@ if(ENABLE_PYTHON)
$<TARGET_OBJECTS:APItoPython>)
endif()
if(ENABLE_TDTQUE)
if(NOT ENABLE_SECURITY)
set(dataengine_submodules ${dataengine_submodules} $<TARGET_OBJECTS:engine-perf>)
endif()
else()
if(NOT ENABLE_SECURITY)
set(dataengine_submodules ${dataengine_submodules} $<TARGET_OBJECTS:engine-perf>)
endif()
if(NOT ENABLE_SECURITY)
set(dataengine_submodules ${dataengine_submodules} $<TARGET_OBJECTS:engine-perf>)
endif()
set(dataengine_submodules ${dataengine_submodules} CACHE INTERNAL "_c_dataengine objects")
add_library(_c_dataengine SHARED ${dataengine_submodules})
if(ENABLE_PYTHON)

View File

@ -26,11 +26,9 @@
#include "minddata/dataset/kernels/ir/tensor_operation.h"
#include "minddata/dataset/kernels/tensor_op.h"
#include "minddata/dataset/util/log_adapter.h"
#ifdef ENABLE_ACL
#include "minddata/dataset/core/ascend_resource.h"
#include "minddata/dataset/kernels/image/dvpp/utils/CommonDataType.h"
#include "minddata/dataset/kernels/ir/vision/ascend_vision_ir.h"
#endif
namespace mindspore {
namespace dataset {
@ -39,7 +37,7 @@ using json = nlohmann::json;
struct Execute::ExtraInfo {
std::multimap<std::string, std::vector<uint32_t>> aipp_cfg_;
bool init_with_shared_ptr_ = true; // Initial execute object with shared_ptr as default
#ifdef ENABLE_ACL
#if defined(WITH_BACKEND) || defined(ENABLE_ACL)
std::multimap<std::string, std::string> op2para_map_ = {{vision::kDvppCropJpegOperation, "size"},
{vision::kDvppDecodeResizeOperation, "size"},
{vision::kDvppDecodeResizeCropOperation, "crop_size"},
@ -51,8 +49,8 @@ struct Execute::ExtraInfo {
};
Status Execute::InitResource(MapTargetDevice device_type, uint32_t device_id) {
#ifdef ENABLE_ACL
if (device_type_ == MapTargetDevice::kAscend310) {
#if defined(WITH_BACKEND) || defined(ENABLE_ACL)
device_resource_ = std::make_shared<AscendResource>();
Status rc = device_resource_->InitResource(device_id);
if (!rc.IsOk()) {
@ -61,8 +59,8 @@ Status Execute::InitResource(MapTargetDevice device_type, uint32_t device_id) {
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_UNEXPECTED(err_msg);
}
}
#endif
}
return Status::OK();
}
@ -154,7 +152,6 @@ Execute::Execute(const std::vector<TensorTransform *> &ops, MapTargetDevice devi
}
Execute::~Execute() {
#ifdef ENABLE_ACL
if (device_type_ == MapTargetDevice::kAscend310) {
if (device_resource_) {
auto rc = device_resource_->FinalizeResource();
@ -165,7 +162,6 @@ Execute::~Execute() {
MS_LOG(ERROR) << "Device resource is nullptr which is illegal under case Ascend310";
}
}
#endif
}
Status Execute::BuildTransforms() {
@ -240,7 +236,7 @@ Status Execute::operator()(const mindspore::MSTensor &input, mindspore::MSTensor
*output = mindspore::MSTensor(std::make_shared<DETensor>(de_tensor));
} else if (device_type_ ==
MapTargetDevice::kAscend310) { // Ascend310 case, where we must set Ascend resource on each operators
#ifdef ENABLE_ACL
#if defined(WITH_BACKEND) || defined(ENABLE_ACL)
CHECK_FAIL_RETURN_UNEXPECTED(device_resource_, "Device resource is nullptr which is illegal under case Ascend310.");
// Sink data from host into device
std::shared_ptr<mindspore::dataset::DeviceTensor> device_input;
@ -318,7 +314,6 @@ Status Execute::operator()(const std::vector<MSTensor> &input_tensor_list, std::
CHECK_FAIL_RETURN_UNEXPECTED(!output_tensor_list->empty(), "Output Tensor is not valid.");
} else if (device_type_ ==
MapTargetDevice::kAscend310) { // Ascend310 case, where we must set Ascend resource on each operators
#ifdef ENABLE_ACL
CHECK_FAIL_RETURN_UNEXPECTED(device_resource_, "Device resource is nullptr which is illegal under case Ascend310.");
for (auto &input_tensor : input_tensor_list) {
// Sink each data from host into device
@ -346,7 +341,6 @@ Status Execute::operator()(const std::vector<MSTensor> &input_tensor_list, std::
RETURN_IF_NOT_OK(device_resource_->DeviceDataRelease());
}
CHECK_FAIL_RETURN_UNEXPECTED(!output_tensor_list->empty(), "Output Tensor vector is empty.");
#endif
} else {
std::string err_msg = "Your input device is not supported. (Option: CPU or Ascend310)";
MS_LOG(ERROR) << err_msg;
@ -449,10 +443,8 @@ std::vector<uint32_t> AippSizeFilter(const std::vector<uint32_t> &resize_para, c
}
}
#ifdef ENABLE_ACL
aipp_size[0] = DVPP_ALIGN_UP(aipp_size[0], VPC_HEIGHT_ALIGN); // H
aipp_size[1] = DVPP_ALIGN_UP(aipp_size[1], VPC_WIDTH_ALIGN); // W
#endif
return aipp_size;
}
@ -540,7 +532,7 @@ std::string Execute::AippCfgGenerator() {
MS_LOG(ERROR) << "info_ is null";
return "";
}
#ifdef ENABLE_ACL
#if defined(WITH_BACKEND) || defined(ENABLE_ACL)
if (info_->init_with_shared_ptr_) {
auto rc = ParseTransforms();
RETURN_SECOND_IF_ERROR(rc, "");

View File

@ -15,10 +15,8 @@
*/
#include "minddata/dataset/include/dataset/vision.h"
#ifdef ENABLE_ACL
#include "minddata/dataset/include/dataset/vision_ascend.h"
#include "minddata/dataset/kernels/ir/vision/ascend_vision_ir.h"
#endif
#include "minddata/dataset/kernels/ir/vision/adjust_brightness_ir.h"
#include "minddata/dataset/kernels/ir/vision/adjust_contrast_ir.h"
@ -279,13 +277,13 @@ std::shared_ptr<TensorOperation> CenterCrop::Parse() { return std::make_shared<C
std::shared_ptr<TensorOperation> CenterCrop::Parse(const MapTargetDevice &env) {
if (env == MapTargetDevice::kAscend310) {
#ifdef ENABLE_ACL
#if defined(WITH_BACKEND) || defined(ENABLE_ACL)
std::vector<uint32_t> usize_;
usize_.reserve(data_->size_.size());
std::transform(data_->size_.begin(), data_->size_.end(), std::back_inserter(usize_),
[](int32_t i) { return (uint32_t)i; });
return std::make_shared<DvppCropJpegOperation>(usize_);
#endif // ENABLE_ACL
#endif
} else if (env == MapTargetDevice::kCpu) {
return std::make_shared<CenterCropOperation>(data_->size_);
}
@ -368,17 +366,16 @@ std::shared_ptr<TensorOperation> Decode::Parse() { return std::make_shared<Decod
std::shared_ptr<TensorOperation> Decode::Parse(const MapTargetDevice &env) {
if (env == MapTargetDevice::kAscend310) {
#ifdef ENABLE_ACL
#if defined(WITH_BACKEND) || defined(ENABLE_ACL)
return std::make_shared<DvppDecodeJpegOperation>();
#endif // ENABLE_ACL
#endif
} else if (env == MapTargetDevice::kCpu) {
return std::make_shared<DecodeOperation>(data_->rgb_);
}
MS_LOG(ERROR) << "Unsupported MapTargetDevice, only supported kCpu and kAscend310.";
return nullptr;
}
#ifdef ENABLE_ACL
#if defined(WITH_BACKEND) || defined(ENABLE_ACL)
// DvppDecodeVideo Transform Operation.
struct DvppDecodeVideo::Data {
Data(const std::vector<uint32_t> &size, VdecStreamFormat type, VdecOutputFormat out_format, const std::string &output)
@ -444,7 +441,9 @@ std::shared_ptr<TensorOperation> DvppDecodeResizeCropJpeg::Parse() {
std::shared_ptr<TensorOperation> DvppDecodeResizeCropJpeg::Parse(const MapTargetDevice &env) {
if (env == MapTargetDevice::kAscend310) {
#if defined(WITH_BACKEND) || defined(ENABLE_ACL)
return std::make_shared<DvppDecodeResizeCropOperation>(data_->crop_, data_->resize_);
#endif
}
MS_LOG(ERROR) << "Unsupported MapTargetDevice, only supported kAscend310.";
return nullptr;
@ -462,8 +461,7 @@ std::shared_ptr<TensorOperation> DvppDecodePng::Parse(const MapTargetDevice &env
MS_LOG(ERROR) << "Unsupported MapTargetDevice, only supported kAscend310.";
return nullptr;
}
#endif // ENABLE_ACL
#endif
#ifndef ENABLE_ANDROID
// Equalize Transform Operation.
Equalize::Equalize() = default;
@ -581,9 +579,9 @@ std::shared_ptr<TensorOperation> Normalize::Parse(const MapTargetDevice &env) {
}
#endif
if (env == MapTargetDevice::kAscend310) {
#ifdef ENABLE_ACL
#if defined(WITH_BACKEND) || defined(ENABLE_ACL)
return std::make_shared<DvppNormalizeOperation>(data_->mean_, data_->std_);
#endif // ENABLE_ACL
#endif
} else if (env == MapTargetDevice::kCpu) {
return std::make_shared<NormalizeOperation>(data_->mean_, data_->std_, data_->is_hwc_);
}
@ -1159,13 +1157,13 @@ std::shared_ptr<TensorOperation> Resize::Parse() {
std::shared_ptr<TensorOperation> Resize::Parse(const MapTargetDevice &env) {
if (env == MapTargetDevice::kAscend310) {
#ifdef ENABLE_ACL
#if defined(WITH_BACKEND) || defined(ENABLE_ACL)
std::vector<uint32_t> usize_;
usize_.reserve(data_->size_.size());
std::transform(data_->size_.begin(), data_->size_.end(), std::back_inserter(usize_),
[](int32_t i) { return (uint32_t)i; });
return std::make_shared<DvppResizeJpegOperation>(usize_);
#endif // ENABLE_ACL
#endif
} else if (env == MapTargetDevice::kCpu) {
return std::make_shared<ResizeOperation>(data_->size_, data_->interpolation_);
}

View File

@ -13,14 +13,9 @@ set(DATASET_CORE_SRC_FILES
tensor_helpers.cc
tensor_row.cc
tensor_shape.cc
ascend_resource.cc
)
if(ENABLE_ACL)
set(DATASET_CORE_SRC_FILES
${DATASET_CORE_SRC_FILES}
ascend_resource.cc)
endif()
ms_protobuf_generate(EXAMPLE_SRCS EXAMPLE_HDRS example.proto)
ms_protobuf_generate(FEATURE_SRCS FEATURE_HDRS feature.proto)
add_library(core OBJECT ${DATASET_CORE_SRC_FILES} ${EXAMPLE_SRCS} ${FEATURE_SRCS})

View File

@ -17,28 +17,30 @@
#include "include/api/types.h"
#include "minddata/dataset/core/ascend_resource.h"
#include "minddata/dataset/core/type_id.h"
#include "minddata/dataset/kernels/image/dvpp/acl_adapter.h"
#include "minddata/dataset/kernels/image/dvpp/utils/CommonDataType.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ErrorCode.h"
#include "minddata/dataset/kernels/image/image_utils.h"
namespace mindspore {
namespace dataset {
Status AscendResource::InitResource(uint32_t device_id) {
ResourceInfo resource;
resource.deviceIds.insert(device_id);
ascend_resource_ = ResourceManager::GetInstance();
APP_ERROR ret = ascend_resource_->InitResource(resource);
APP_ERROR ret = AclAdapter::GetInstance().InitResource(&resource);
if (ret != APP_ERR_OK) {
ascend_resource_->Release();
AclAdapter::GetInstance().Release();
std::string err_msg = "Error in Init D-chip:" + std::to_string(ret);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_UNEXPECTED(err_msg);
}
int cur_device_id = *(resource.deviceIds.begin());
aclrtContext context = ascend_resource_->GetContext(cur_device_id);
processor_ = std::make_shared<MDAclProcess>(context, false);
ret = processor_->InitResource();
void *context = AclAdapter::GetInstance().GetContext(cur_device_id);
processor_ = std::shared_ptr<void>(AclAdapter::GetInstance().CreateAclProcess(context, false, nullptr, nullptr),
[](void *ptr) { AclAdapter::GetInstance().DestroyAclProcess(ptr); });
ret = AclAdapter::GetInstance().InitAclProcess(processor_.get());
if (ret != APP_ERR_OK) {
ascend_resource_->Release();
AclAdapter::GetInstance().Release();
std::string err_msg = "Error in Init resource:" + std::to_string(ret);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_UNEXPECTED(err_msg);
@ -48,7 +50,7 @@ Status AscendResource::InitResource(uint32_t device_id) {
}
Status AscendResource::FinalizeResource() {
processor_->Release();
AclAdapter::GetInstance().ReleaseAclProcess(processor_.get());
return Status::OK();
}
@ -64,9 +66,9 @@ Status AscendResource::Sink(const mindspore::MSTensor &host_input, std::shared_p
RETURN_STATUS_UNEXPECTED(err_msg);
}
APP_ERROR ret = processor_->H2D_Sink(de_input, *device_input);
APP_ERROR ret = AclAdapter::GetInstance().H2D_Sink(processor_.get(), de_input, device_input);
if (ret != APP_ERR_OK) {
ascend_resource_->Release();
AclAdapter::GetInstance().Release();
std::string err_msg = "Error in data sink process:" + std::to_string(ret);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_UNEXPECTED(err_msg);
@ -76,9 +78,9 @@ Status AscendResource::Sink(const mindspore::MSTensor &host_input, std::shared_p
}
Status AscendResource::Pop(const std::shared_ptr<DeviceTensor> &device_output, std::shared_ptr<Tensor> *host_output) {
APP_ERROR ret = processor_->D2H_Pop(device_output, *host_output);
APP_ERROR ret = AclAdapter::GetInstance().D2H_Pop(processor_.get(), device_output, host_output);
if (ret != APP_ERR_OK) {
ascend_resource_->Release();
AclAdapter::GetInstance().Release();
std::string err_msg = "Error in data pop processing:" + std::to_string(ret);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_UNEXPECTED(err_msg);
@ -87,9 +89,9 @@ Status AscendResource::Pop(const std::shared_ptr<DeviceTensor> &device_output, s
}
Status AscendResource::DeviceDataRelease() {
APP_ERROR ret = processor_->device_memory_release();
APP_ERROR ret = AclAdapter::GetInstance().DeviceMemoryRelease(processor_.get());
if (ret != APP_ERR_OK) {
ascend_resource_->Release();
AclAdapter::GetInstance().Release();
std::string err_msg = "Error in device data release:" + std::to_string(ret);
MS_LOG(ERROR) << err_msg;
RETURN_STATUS_UNEXPECTED(err_msg);
@ -99,9 +101,9 @@ Status AscendResource::DeviceDataRelease() {
std::shared_ptr<void> AscendResource::GetInstance() { return processor_; }
void *AscendResource::GetContext() { return processor_->GetContext(); }
void *AscendResource::GetContext() { return AclAdapter::GetInstance().GetContextFromAclProcess(processor_.get()); }
void *AscendResource::GetStream() { return processor_->GetStream(); }
void *AscendResource::GetStream() { return AclAdapter::GetInstance().GetStreamFromAclProcess(processor_.get()); }
} // namespace dataset
} // namespace mindspore

View File

@ -19,14 +19,9 @@
#include <memory>
#include <string>
#include "acl/acl.h"
#include "minddata/dataset/core/device_resource.h"
#include "minddata/dataset/core/device_tensor.h"
#include "minddata/dataset/core/tensor.h"
#include "minddata/dataset/kernels/image/dvpp/utils/CommonDataType.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ErrorCode.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ResourceManager.h"
namespace mindspore {
namespace dataset {
@ -53,8 +48,7 @@ class AscendResource : public DeviceResource {
void *GetStream() override;
private:
std::shared_ptr<MDAclProcess> processor_;
std::shared_ptr<ResourceManager> ascend_resource_;
std::shared_ptr<void> processor_;
};
} // namespace dataset

View File

@ -16,9 +16,7 @@
#include "minddata/dataset/core/global_context.h"
#include "minddata/dataset/core/device_tensor.h"
#ifdef ENABLE_ACL
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#endif
#include "minddata/dataset/kernels/image/dvpp/acl_adapter.h"
#include "minddata/dataset/util/status.h"
namespace mindspore {
@ -93,13 +91,14 @@ Status DeviceTensor::CreateFromDeviceMemory(const TensorShape &shape, const Data
}
const unsigned char *DeviceTensor::GetHostBuffer() {
#ifdef ENABLE_ACL
Status rc = DataPop_(&host_data_tensor_);
if (!rc.IsOk()) {
MS_LOG(ERROR) << "Pop device data onto host fail, a nullptr will be returned";
return nullptr;
if (AclAdapter::GetInstance().HasAclPlugin()) {
Status rc = DataPop_(&host_data_tensor_);
if (!rc.IsOk()) {
MS_LOG(ERROR) << "Pop device data onto host fail, a nullptr will be returned";
return nullptr;
}
}
#endif
if (!host_data_tensor_) {
return nullptr;
}
@ -136,21 +135,20 @@ Status DeviceTensor::SetSize_(const uint32_t &new_size) {
return Status::OK();
}
#ifdef ENABLE_ACL
Status DeviceTensor::DataPop_(std::shared_ptr<Tensor> *host_tensor) {
CHECK_FAIL_RETURN_UNEXPECTED(host_tensor != nullptr, "host tensor pointer is NULL.");
void *resHostBuf = nullptr;
APP_ERROR ret = aclrtMallocHost(&resHostBuf, this->DeviceDataSize());
APP_ERROR ret = AclAdapter::GetInstance().MallocHost(&resHostBuf, this->DeviceDataSize());
if (ret != APP_ERR_OK) {
MS_LOG(ERROR) << "Failed to allocate memory from host ret = " << ret;
return Status(StatusCode::kMDNoSpace);
}
std::shared_ptr<void> outBuf(resHostBuf, aclrtFreeHost);
std::shared_ptr<void> outBuf(resHostBuf, [](void *ptr) { AclAdapter::GetInstance().FreeHost(ptr); });
auto processedInfo_ = outBuf;
// Memcpy the output data from device to host
ret = aclrtMemcpy(outBuf.get(), this->DeviceDataSize(), this->GetDeviceBuffer(), this->DeviceDataSize(),
ACL_MEMCPY_DEVICE_TO_HOST);
ret = AclAdapter::GetInstance().Memcpy(outBuf.get(), this->DeviceDataSize(), this->GetDeviceBuffer(),
this->DeviceDataSize(), 2); // 2 means ACL_MEMCPY_DEVICE_TO_HOST
if (ret != APP_ERR_OK) {
MS_LOG(ERROR) << "Failed to copy memory from device to host, ret = " << ret;
return Status(StatusCode::kMDOutOfMemory);
@ -182,6 +180,5 @@ Status DeviceTensor::DataPop_(std::shared_ptr<Tensor> *host_tensor) {
MS_LOG(INFO) << "Successfully pop DeviceTensor data onto host";
return Status::OK();
}
#endif
} // namespace dataset
} // namespace mindspore

View File

@ -28,7 +28,7 @@
namespace mindspore {
namespace dataset {
class Tensor;
class DeviceTensor : public Tensor {
class DATASET_API DeviceTensor : public Tensor {
public:
DeviceTensor(const TensorShape &shape, const DataType &type);
@ -63,9 +63,7 @@ class DeviceTensor : public Tensor {
Status SetYuvStrideShape_(const uint32_t &width, const uint32_t &widthStride, const uint32_t &height,
const uint32_t &heightStride);
#ifdef ENABLE_ACL
Status DataPop_(std::shared_ptr<Tensor> *host_tensor);
#endif
std::vector<uint32_t> YUV_shape_; // YUV_shape_ = {width, widthStride, height, heightStride}

View File

@ -60,7 +60,7 @@ using TensorAllocPtr = std::shared_ptr<Allocator<Tensor>>; // An allocator shar
using offset_t = uint32_t; // type of offset values to store strings locations
using TensorPtr = std::shared_ptr<Tensor>;
class Tensor {
class DATASET_API Tensor {
public:
Tensor() = delete;
Tensor(const Tensor &other) = delete;

View File

@ -50,7 +50,7 @@ namespace dataset {
// <2,?,?,?> (all dims but the 0th dim are unknown)
/// \brief TensorShape supports any dim > 0 and < 2^31-1
class TensorShape {
class DATASET_API TensorShape {
public:
static constexpr dsize_t kDimUnknown = -1; // constant for an unknown dimension

View File

@ -75,39 +75,23 @@ if(ENABLE_CACHE)
endif()
add_executable(cache_server cache_main.cc)
if(ENABLE_GPU)
target_link_libraries(cache_server
engine-cache-server
_c_dataengine
_c_mindrecord
mindspore_core
mindspore::protobuf
${CUDNN_LIBRARY_PATH}
${PYTHON_LIBRARIES}
${SECUREC_LIBRARY}
pthread
-ldl
-Wl,--no-as-needed
mindspore::grpc++)
target_link_libraries(cache_server
engine-cache-server
_c_dataengine
_c_mindrecord
mindspore_core
mindspore::protobuf
${PYTHON_LIBRARIES}
${SECUREC_LIBRARY}
pthread
-ldl)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
target_link_libraries(cache_server mindspore::grpc++)
else()
target_link_libraries(cache_server
engine-cache-server
_c_dataengine
_c_mindrecord
mindspore_core
mindspore::protobuf
${PYTHON_LIBRARIES}
${SECUREC_LIBRARY}
pthread
-ldl)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
target_link_libraries(cache_server mindspore::grpc++)
else()
target_link_libraries(cache_server
-Wl,--no-as-needed
mindspore::grpc++
-Wl,--as-needed)
endif()
-Wl,--no-as-needed
mindspore::grpc++
-Wl,--as-needed)
endif()
if(USE_GLOG)
@ -120,16 +104,11 @@ if(ENABLE_CACHE)
add_executable(cache_admin cache_admin.cc cache_admin_arg.cc)
target_link_libraries(cache_admin _c_dataengine _c_mindrecord ${PYTHON_LIBRARIES} pthread -ldl)
if(ENABLE_TDTQUE)
target_link_libraries(cache_admin
-Wl,--start-group mindspore::protobuf mindspore_core mindspore_shared_lib ${ACL_TDT_CHANNEL} -Wl,--end-group)
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
target_link_libraries(cache_admin mindspore::protobuf mindspore_core mindspore_shared_lib)
else()
if(CMAKE_SYSTEM_NAME MATCHES "Darwin")
target_link_libraries(cache_admin mindspore::protobuf mindspore_core mindspore_shared_lib)
else()
target_link_libraries(cache_admin
-Wl,--start-group mindspore::protobuf mindspore_core mindspore_shared_lib -Wl,--end-group)
endif()
target_link_libraries(cache_admin
-Wl,--start-group mindspore::protobuf mindspore_core mindspore_shared_lib -Wl,--end-group)
endif()
if(USE_GLOG)

View File

@ -335,12 +335,15 @@ Status ToDevice::GetDataInfo(std::vector<DataType> *const types, std::vector<Ten
}
Status ToDevice::Terminate() {
#ifdef ENABLE_TDTQUE
std::shared_ptr<DatasetOp> root = std::shared_ptr<DatasetOp>(tree_adapter_->GetRoot());
CHECK_FAIL_RETURN_UNEXPECTED(root != nullptr, "Root is a nullptr.");
DataQueueOp *op = dynamic_cast<DataQueueOp *>(root.get());
CHECK_FAIL_RETURN_UNEXPECTED(op != nullptr, "StopSend only supported by DataQueueOp");
op->StopWaiting();
#ifdef WITH_BACKEND
RETURN_UNEXPECTED_IF_NULL(MsContext::GetInstance());
if (MsContext::GetInstance()->get_param<std::string>(MS_CTX_DEVICE_TARGET) == kAscendDevice) {
std::shared_ptr<DatasetOp> root = std::shared_ptr<DatasetOp>(tree_adapter_->GetRoot());
CHECK_FAIL_RETURN_UNEXPECTED(root != nullptr, "Root is a nullptr.");
DataQueueOp *op = dynamic_cast<DataQueueOp *>(root.get());
CHECK_FAIL_RETURN_UNEXPECTED(op != nullptr, "StopSend only supported by DataQueueOp");
op->StopWaiting();
}
#endif
return TreeConsumer::Terminate();
}

View File

@ -56,12 +56,10 @@ ExecutionTree::~ExecutionTree() {
if (numa_enable_) {
handle_ = nullptr;
}
#if defined(ENABLE_TDTQUE)
DataQueueOp *op = dynamic_cast<DataQueueOp *>(root_.get());
if (op != nullptr) {
op->StopWaiting();
}
#endif
#endif
(void)tg_->ServiceStop();
}

View File

@ -26,6 +26,7 @@
#else
#include "mindspore/lite/src/common/file_utils.h"
#endif
#include "minddata/dataset/kernels/image/dvpp/acl_adapter.h"
namespace mindspore {
namespace dataset {
@ -299,12 +300,14 @@ Serdes::InitializeFuncPtr() {
ops_ptr[vision::kCutMixBatchOperation] = &(vision::CutMixBatchOperation::from_json);
ops_ptr[vision::kCutOutOperation] = &(vision::CutOutOperation::from_json);
ops_ptr[vision::kDecodeOperation] = &(vision::DecodeOperation::from_json);
#ifdef ENABLE_ACL
ops_ptr[vision::kDvppCropJpegOperation] = &(vision::DvppCropJpegOperation::from_json);
ops_ptr[vision::kDvppDecodeResizeOperation] = &(vision::DvppDecodeResizeOperation::from_json);
ops_ptr[vision::kDvppDecodeResizeCropOperation] = &(vision::DvppDecodeResizeCropOperation::from_json);
ops_ptr[vision::kDvppNormalizeOperation] = &(vision::DvppNormalizeOperation::from_json);
ops_ptr[vision::kDvppResizeJpegOperation] = &(vision::DvppResizeJpegOperation::from_json);
#if defined(WITH_BACKEND) || defined(ENABLE_ACL)
if (AclAdapter::GetInstance().HasAclPlugin()) {
ops_ptr[vision::kDvppCropJpegOperation] = &(vision::DvppCropJpegOperation::from_json);
ops_ptr[vision::kDvppDecodeResizeOperation] = &(vision::DvppDecodeResizeOperation::from_json);
ops_ptr[vision::kDvppDecodeResizeCropOperation] = &(vision::DvppDecodeResizeCropOperation::from_json);
ops_ptr[vision::kDvppNormalizeOperation] = &(vision::DvppNormalizeOperation::from_json);
ops_ptr[vision::kDvppResizeJpegOperation] = &(vision::DvppResizeJpegOperation::from_json);
}
#endif
ops_ptr[vision::kEqualizeOperation] = &(vision::EqualizeOperation::from_json);
ops_ptr[vision::kGaussianBlurOperation] = &(vision::GaussianBlurOperation::from_json);

View File

@ -1,9 +1,7 @@
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_subdirectory(lite_cv)
if(ENABLE_ACL)
add_subdirectory(dvpp)
endif()
add_subdirectory(dvpp)
add_library(kernels-image OBJECT
adjust_brightness_op.cc
adjust_contrast_op.cc
@ -81,6 +79,5 @@ add_library(kernels-image OBJECT
vertical_flip_op.cc
to_tensor_op.cc
)
if(ENABLE_ACL)
add_dependencies(kernels-image kernels-dvpp-image)
endif()
add_dependencies(kernels-image kernels-dvpp-image)

View File

@ -1,7 +1,6 @@
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_subdirectory(utils)
add_library(kernels-dvpp-image OBJECT
dvpp_crop_jpeg_op.cc
dvpp_decode_resize_crop_jpeg_op.cc
@ -11,6 +10,8 @@ add_library(kernels-dvpp-image OBJECT
dvpp_decode_video_op.cc
dvpp_normalize_op.cc
dvpp_resize_jpeg_op.cc
dvpp_video.cc
)
add_dependencies(kernels-dvpp-image dvpp-utils)
acl_adapter.cc
)
if(ENABLE_ACL)
add_subdirectory(utils)
endif()

View File

@ -0,0 +1,416 @@
/**
* Copyright 2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "minddata/dataset/kernels/image/dvpp/acl_adapter.h"
#include <algorithm>
namespace mindspore {
namespace dataset {
namespace {
constexpr auto kAclPluginFileName = "libdvpp_utils.so";
} // namespace
AclAdapter &AclAdapter::GetInstance() {
static AclAdapter instance{};
static std::once_flag flag;
std::call_once(flag, []() { instance.InitPlugin(); });
return instance;
}
void AclAdapter::InitPlugin() {
if (plugin_handle_ != nullptr) {
return;
}
#if !defined(_WIN32) && !defined(_WIN64)
plugin_handle_ = dlopen(kAclPluginFileName, RTLD_LAZY | RTLD_LOCAL);
if (plugin_handle_ == nullptr) {
MS_LOG(WARNING) << "Dlopen " << kAclPluginFileName << " failed, result = " << GetDlErrorMsg()
<< ", it can be ignored if not running on ascend.";
return;
}
create_dvpp_video_fun_obj_ = DlsymFuncObj(CreateDvppVideo, plugin_handle_);
init_dvpp_video_fun_obj_ = DlsymFuncObj(InitDvppVideo, plugin_handle_);
close_dvpp_video_fun_obj_ = DlsymFuncObj(CloseDvppVideo, plugin_handle_);
dvpp_video_dump_frame_fun_obj_ = DlsymFuncObj(DvppVideoDumpFrame, plugin_handle_);
init_resource_fun_obj_ = DlsymFuncObj(InitResource, plugin_handle_);
get_context_fun_obj_ = DlsymFuncObj(GetContext, plugin_handle_);
release_fun_obj_ = DlsymFuncObj(Release, plugin_handle_);
create_acl_process_with_resize_fun_obj_ = DlsymFuncObj(CreateAclProcessWithResize, plugin_handle_);
create_acl_process_with_para_fun_obj_ = DlsymFuncObj(CreateAclProcessWithPara, plugin_handle_);
create_acl_process_fun_obj_ = DlsymFuncObj(CreateAclProcess, plugin_handle_);
destroy_acl_process_fun_obj_ = DlsymFuncObj(DestroyAclProcess, plugin_handle_);
release_acl_process_fun_obj_ = DlsymFuncObj(ReleaseAclProcess, plugin_handle_);
init_acl_process_fun_obj_ = DlsymFuncObj(InitAclProcess, plugin_handle_);
get_context_from_acl_process_fun_obj_ = DlsymFuncObj(GetContextFromAclProcess, plugin_handle_);
get_stream_from_acl_process_fun_obj_ = DlsymFuncObj(GetStreamFromAclProcess, plugin_handle_);
jpeg_drc_with_data_fun_obj_ = DlsymFuncObj(JPEG_DRC_WITH_DATA, plugin_handle_);
jpeg_dr_with_data_fun_obj_ = DlsymFuncObj(JPEG_DR_WITH_DATA, plugin_handle_);
jpeg_d_with_data_fun_obj_ = DlsymFuncObj(JPEG_D_WITH_DATA, plugin_handle_);
jpeg_r_with_data_fun_obj_ = DlsymFuncObj(JPEG_R_WITH_DATA, plugin_handle_);
jpeg_c_with_data_fun_obj_ = DlsymFuncObj(JPEG_C_WITH_DATA, plugin_handle_);
png_d_with_data_fun_obj_ = DlsymFuncObj(PNG_D_WITH_DATA, plugin_handle_);
jpeg_drc_fun_obj_ = DlsymFuncObj(JPEG_DRC, plugin_handle_);
jpeg_dr_fun_obj_ = DlsymFuncObj(JPEG_DR, plugin_handle_);
jpeg_d_fun_obj_ = DlsymFuncObj(JPEG_D, plugin_handle_);
jpeg_r_fun_obj_ = DlsymFuncObj(JPEG_R, plugin_handle_);
jpeg_c_fun_obj_ = DlsymFuncObj(JPEG_C, plugin_handle_);
png_d_fun_obj_ = DlsymFuncObj(PNG_D, plugin_handle_);
get_memory_data_fun_obj_ = DlsymFuncObj(GetMemoryData, plugin_handle_);
get_croped_device_data_fun_obj_ = DlsymFuncObj(GetCropedDeviceData, plugin_handle_);
get_resized_device_data_fun_obj_ = DlsymFuncObj(GetResizedDeviceData, plugin_handle_);
get_decode_device_data_fun_obj_ = DlsymFuncObj(GetDecodeDeviceData, plugin_handle_);
h_2_d_sink_fun_obj_ = DlsymFuncObj(H2D_Sink, plugin_handle_);
d_2_h_pop_fun_obj_ = DlsymFuncObj(D2H_Pop, plugin_handle_);
device_memory_release_fun_obj_ = DlsymFuncObj(DeviceMemoryRelease, plugin_handle_);
set_resize_paras_fun_obj_ = DlsymFuncObj(SetResizeParas, plugin_handle_);
set_crop_paras_fun_obj_ = DlsymFuncObj(SetCropParas, plugin_handle_);
aclrt_malloc_host_fun_obj_ = DlsymFuncObj(aclrtMallocHost, plugin_handle_);
aclrt_free_host_fun_obj_ = DlsymFuncObj(aclrtFreeHost, plugin_handle_);
aclrt_memcpy_fun_obj_ = DlsymFuncObj(aclrtMemcpy, plugin_handle_);
#endif
}
void AclAdapter::FinalizePlugin() {
if (plugin_handle_ == nullptr) {
return;
}
create_dvpp_video_fun_obj_ = nullptr;
init_dvpp_video_fun_obj_ = nullptr;
close_dvpp_video_fun_obj_ = nullptr;
dvpp_video_dump_frame_fun_obj_ = nullptr;
init_resource_fun_obj_ = nullptr;
get_context_fun_obj_ = nullptr;
release_fun_obj_ = nullptr;
create_acl_process_with_resize_fun_obj_ = nullptr;
create_acl_process_with_para_fun_obj_ = nullptr;
create_acl_process_fun_obj_ = nullptr;
destroy_acl_process_fun_obj_ = nullptr;
release_acl_process_fun_obj_ = nullptr;
init_acl_process_fun_obj_ = nullptr;
get_context_from_acl_process_fun_obj_ = nullptr;
get_stream_from_acl_process_fun_obj_ = nullptr;
jpeg_drc_with_data_fun_obj_ = nullptr;
jpeg_dr_with_data_fun_obj_ = nullptr;
jpeg_d_with_data_fun_obj_ = nullptr;
jpeg_r_with_data_fun_obj_ = nullptr;
jpeg_c_with_data_fun_obj_ = nullptr;
png_d_with_data_fun_obj_ = nullptr;
jpeg_drc_fun_obj_ = nullptr;
jpeg_dr_fun_obj_ = nullptr;
jpeg_d_fun_obj_ = nullptr;
jpeg_r_fun_obj_ = nullptr;
jpeg_c_fun_obj_ = nullptr;
png_d_fun_obj_ = nullptr;
get_memory_data_fun_obj_ = nullptr;
get_croped_device_data_fun_obj_ = nullptr;
get_resized_device_data_fun_obj_ = nullptr;
get_decode_device_data_fun_obj_ = nullptr;
h_2_d_sink_fun_obj_ = nullptr;
d_2_h_pop_fun_obj_ = nullptr;
device_memory_release_fun_obj_ = nullptr;
set_resize_paras_fun_obj_ = nullptr;
set_crop_paras_fun_obj_ = nullptr;
aclrt_malloc_host_fun_obj_ = nullptr;
aclrt_free_host_fun_obj_ = nullptr;
aclrt_memcpy_fun_obj_ = nullptr;
#if !defined(_WIN32) && !defined(_WIN64)
(void)dlclose(plugin_handle_);
#endif
plugin_handle_ = nullptr;
}
void *AclAdapter::CreateDvppVideo(void *context, uint8_t *data, uint32_t size, uint32_t width, uint32_t height,
uint32_t type, uint32_t out_format, const std::string &output) const {
if (!HasAclPlugin() || create_dvpp_video_fun_obj_ == nullptr) {
return nullptr;
}
return create_dvpp_video_fun_obj_(context, data, size, width, height, type, out_format, output);
}
AclLiteError AclAdapter::InitDvppVideo(void *dvpp_video) const {
if (!HasAclPlugin() || init_dvpp_video_fun_obj_ == nullptr) {
return ACLLITE_ERROR;
}
return init_dvpp_video_fun_obj_(dvpp_video);
}
AclLiteError AclAdapter::CloseDvppVideo(void *dvpp_video) const {
if (!HasAclPlugin() || close_dvpp_video_fun_obj_ == nullptr) {
return ACLLITE_ERROR;
}
return close_dvpp_video_fun_obj_(dvpp_video);
}
AclLiteError AclAdapter::DvppVideoDumpFrame(void *dvpp_video) const {
if (!HasAclPlugin() || dvpp_video_dump_frame_fun_obj_ == nullptr) {
return ACLLITE_ERROR;
}
return dvpp_video_dump_frame_fun_obj_(dvpp_video);
}
APP_ERROR AclAdapter::InitResource(ResourceInfo *resource_info) const {
if (!HasAclPlugin() || init_resource_fun_obj_ == nullptr || resource_info == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return init_resource_fun_obj_(*resource_info);
}
void *AclAdapter::GetContext(int device_id) const {
if (!HasAclPlugin() || get_context_fun_obj_ == nullptr) {
return nullptr;
}
return get_context_fun_obj_(device_id);
}
void AclAdapter::Release() const {
if (!HasAclPlugin() || release_fun_obj_ == nullptr) {
return;
}
release_fun_obj_();
}
void *AclAdapter::CreateAclProcessWithResize(uint32_t resize_width, uint32_t resize_height, uint32_t crop_width,
uint32_t crop_height, void *context, bool is_crop, void *stream,
const std::shared_ptr<DvppCommon> &dvpp_common) const {
if (!HasAclPlugin() || create_acl_process_with_resize_fun_obj_ == nullptr) {
return nullptr;
}
return create_acl_process_with_resize_fun_obj_(resize_width, resize_height, crop_width, crop_height, context, is_crop,
stream, dvpp_common);
}
void *AclAdapter::CreateAclProcessWithPara(uint32_t para_width, uint32_t para_height, void *context, bool is_crop,
void *stream, const std::shared_ptr<DvppCommon> &dvpp_common) const {
if (!HasAclPlugin() || create_acl_process_with_para_fun_obj_ == nullptr) {
return nullptr;
}
return create_acl_process_with_para_fun_obj_(para_width, para_height, context, is_crop, stream, dvpp_common);
}
void *AclAdapter::CreateAclProcess(void *context, bool is_crop, void *stream,
const std::shared_ptr<DvppCommon> &dvpp_common) const {
if (!HasAclPlugin() || create_acl_process_fun_obj_ == nullptr) {
return nullptr;
}
return create_acl_process_fun_obj_(context, is_crop, stream, dvpp_common);
}
void AclAdapter::DestroyAclProcess(void *acl_process) const {
if (!HasAclPlugin() || destroy_acl_process_fun_obj_ == nullptr) {
return;
}
destroy_acl_process_fun_obj_(acl_process);
}
APP_ERROR AclAdapter::ReleaseAclProcess(void *acl_process) const {
if (!HasAclPlugin() || release_acl_process_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return release_acl_process_fun_obj_(acl_process);
}
APP_ERROR AclAdapter::InitAclProcess(void *acl_process) const {
if (!HasAclPlugin() || init_acl_process_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return init_acl_process_fun_obj_(acl_process);
}
void *AclAdapter::GetContextFromAclProcess(void *acl_process) const {
if (!HasAclPlugin() || get_context_from_acl_process_fun_obj_ == nullptr) {
return nullptr;
}
return get_context_from_acl_process_fun_obj_(acl_process);
}
void *AclAdapter::GetStreamFromAclProcess(void *acl_process) const {
if (!HasAclPlugin() || get_stream_from_acl_process_fun_obj_ == nullptr) {
return nullptr;
}
return get_stream_from_acl_process_fun_obj_(acl_process);
}
APP_ERROR AclAdapter::JPEG_DRC_WITH_DATA(void *acl_process, const RawData &data) const {
if (!HasAclPlugin() || jpeg_drc_with_data_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return jpeg_drc_with_data_fun_obj_(acl_process, data);
}
APP_ERROR AclAdapter::JPEG_DR_WITH_DATA(void *acl_process, const RawData &data) const {
if (!HasAclPlugin() || jpeg_dr_with_data_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return jpeg_dr_with_data_fun_obj_(acl_process, data);
}
APP_ERROR AclAdapter::JPEG_D_WITH_DATA(void *acl_process, const RawData &data) const {
if (!HasAclPlugin() || jpeg_d_with_data_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return jpeg_d_with_data_fun_obj_(acl_process, data);
}
APP_ERROR AclAdapter::JPEG_R_WITH_DATA(void *acl_process, const DvppDataInfo &data) const {
if (!HasAclPlugin() || jpeg_r_with_data_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return jpeg_r_with_data_fun_obj_(acl_process, data);
}
APP_ERROR AclAdapter::JPEG_C_WITH_DATA(void *acl_process, const DvppDataInfo &data) const {
if (!HasAclPlugin() || jpeg_c_with_data_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return jpeg_c_with_data_fun_obj_(acl_process, data);
}
APP_ERROR AclAdapter::PNG_D_WITH_DATA(void *acl_process, const RawData &data) const {
if (!HasAclPlugin() || png_d_with_data_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return png_d_with_data_fun_obj_(acl_process, data);
}
APP_ERROR AclAdapter::JPEG_DRC(void *acl_process) const {
if (!HasAclPlugin() || jpeg_drc_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return jpeg_drc_fun_obj_(acl_process);
}
APP_ERROR AclAdapter::JPEG_DR(void *acl_process) const {
if (!HasAclPlugin() || jpeg_dr_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return jpeg_dr_fun_obj_(acl_process);
}
APP_ERROR AclAdapter::JPEG_D(void *acl_process) const {
if (!HasAclPlugin() || jpeg_d_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return jpeg_d_fun_obj_(acl_process);
}
APP_ERROR AclAdapter::JPEG_R(void *acl_process, const std::string &last_step) const {
if (!HasAclPlugin() || jpeg_r_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return jpeg_r_fun_obj_(acl_process, last_step);
}
APP_ERROR AclAdapter::JPEG_C(void *acl_process, const std::string &last_step) const {
if (!HasAclPlugin() || jpeg_c_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return jpeg_c_fun_obj_(acl_process, last_step);
}
APP_ERROR AclAdapter::PNG_D(void *acl_process) const {
if (!HasAclPlugin() || png_d_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return png_d_fun_obj_(acl_process);
}
void *AclAdapter::GetMemoryData(void *acl_process) const {
if (!HasAclPlugin() || get_memory_data_fun_obj_ == nullptr) {
return nullptr;
}
return get_memory_data_fun_obj_(acl_process);
}
DvppDataInfo *AclAdapter::GetCropedDeviceData(void *acl_process) const {
if (!HasAclPlugin() || get_croped_device_data_fun_obj_ == nullptr) {
return nullptr;
}
return get_croped_device_data_fun_obj_(acl_process);
}
DvppDataInfo *AclAdapter::GetResizedDeviceData(void *acl_process) const {
if (!HasAclPlugin() || get_resized_device_data_fun_obj_ == nullptr) {
return nullptr;
}
return get_resized_device_data_fun_obj_(acl_process);
}
DvppDataInfo *AclAdapter::GetDecodeDeviceData(void *acl_process) const {
if (!HasAclPlugin() || get_decode_device_data_fun_obj_ == nullptr) {
return nullptr;
}
return get_decode_device_data_fun_obj_(acl_process);
}
APP_ERROR AclAdapter::H2D_Sink(void *acl_process, const std::shared_ptr<mindspore::dataset::Tensor> &input,
std::shared_ptr<mindspore::dataset::DeviceTensor> *device_input) const {
if (!HasAclPlugin() || h_2_d_sink_fun_obj_ == nullptr || device_input == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return h_2_d_sink_fun_obj_(acl_process, input, *device_input);
}
APP_ERROR AclAdapter::D2H_Pop(void *acl_process, const std::shared_ptr<mindspore::dataset::DeviceTensor> &device_output,
std::shared_ptr<mindspore::dataset::Tensor> *output) const {
if (!HasAclPlugin() || d_2_h_pop_fun_obj_ == nullptr || output == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return d_2_h_pop_fun_obj_(acl_process, device_output, *output);
}
APP_ERROR AclAdapter::DeviceMemoryRelease(void *acl_process) const {
if (!HasAclPlugin() || device_memory_release_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return device_memory_release_fun_obj_(acl_process);
}
APP_ERROR AclAdapter::SetResizeParas(void *acl_process, uint32_t width, uint32_t height) const {
if (!HasAclPlugin() || set_resize_paras_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return set_resize_paras_fun_obj_(acl_process, width, height);
}
APP_ERROR AclAdapter::SetCropParas(void *acl_process, uint32_t width, uint32_t height) const {
if (!HasAclPlugin() || set_crop_paras_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return set_crop_paras_fun_obj_(acl_process, width, height);
}
int AclAdapter::Memcpy(void *dst, size_t dest_max, const void *src, size_t count, int kind) const {
if (!HasAclPlugin() || aclrt_memcpy_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return aclrt_memcpy_fun_obj_(dst, dest_max, src, count, kind);
}
int AclAdapter::MallocHost(void **host_ptr, size_t size) const {
if (!HasAclPlugin() || aclrt_malloc_host_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return aclrt_malloc_host_fun_obj_(host_ptr, size);
}
int AclAdapter::FreeHost(void *host_ptr) const {
if (!HasAclPlugin() || aclrt_free_host_fun_obj_ == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return aclrt_free_host_fun_obj_(host_ptr);
}
} // namespace dataset
} // namespace mindspore

View File

@ -0,0 +1,132 @@
/**
* Copyright 2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_DVPP_ACL_ADAPTER_H
#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_DVPP_ACL_ADAPTER_H
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
#include "minddata/dataset/kernels/image/dvpp/utils/acl_plugin.h"
#include "minddata/dataset/kernels/image/dvpp/utils/AclLiteError.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ErrorCode.h"
namespace mindspore::dataset {
class AclAdapter {
public:
static AclAdapter &GetInstance();
bool HasAclPlugin() const { return plugin_handle_ != nullptr; }
void *CreateDvppVideo(void *context, uint8_t *data, uint32_t size, uint32_t width, uint32_t height, uint32_t type,
uint32_t out_format, const std::string &output) const;
AclLiteError InitDvppVideo(void *dvpp_video) const;
AclLiteError CloseDvppVideo(void *dvpp_video) const;
AclLiteError DvppVideoDumpFrame(void *dvpp_video) const;
APP_ERROR InitResource(ResourceInfo *resource_info) const;
void *GetContext(int device_id) const;
void Release() const;
void *CreateAclProcessWithResize(uint32_t resize_width, uint32_t resize_height, uint32_t crop_width,
uint32_t crop_height, void *context, bool is_crop, void *stream,
const std::shared_ptr<DvppCommon> &dvpp_common) const;
void *CreateAclProcessWithPara(uint32_t para_width, uint32_t para_height, void *context, bool is_crop, void *stream,
const std::shared_ptr<DvppCommon> &dvpp_common) const;
void *CreateAclProcess(void *context, bool is_crop, void *stream,
const std::shared_ptr<DvppCommon> &dvpp_common) const;
void DestroyAclProcess(void *acl_process) const;
APP_ERROR ReleaseAclProcess(void *acl_process) const;
APP_ERROR InitAclProcess(void *acl_process) const;
void *GetContextFromAclProcess(void *acl_process) const;
void *GetStreamFromAclProcess(void *acl_process) const;
APP_ERROR JPEG_DRC_WITH_DATA(void *acl_process, const RawData &data) const;
APP_ERROR JPEG_DR_WITH_DATA(void *acl_process, const RawData &data) const;
APP_ERROR JPEG_D_WITH_DATA(void *acl_process, const RawData &data) const;
APP_ERROR JPEG_R_WITH_DATA(void *acl_process, const DvppDataInfo &data) const;
APP_ERROR JPEG_C_WITH_DATA(void *acl_process, const DvppDataInfo &data) const;
APP_ERROR PNG_D_WITH_DATA(void *acl_process, const RawData &data) const;
APP_ERROR JPEG_DRC(void *acl_process) const;
APP_ERROR JPEG_DR(void *acl_process) const;
APP_ERROR JPEG_D(void *acl_process) const;
APP_ERROR JPEG_R(void *acl_process, const std::string &last_step) const;
APP_ERROR JPEG_C(void *acl_process, const std::string &last_step) const;
APP_ERROR PNG_D(void *acl_process) const;
void *GetMemoryData(void *acl_process) const;
DvppDataInfo *GetCropedDeviceData(void *acl_process) const;
DvppDataInfo *GetResizedDeviceData(void *acl_process) const;
DvppDataInfo *GetDecodeDeviceData(void *acl_process) const;
APP_ERROR H2D_Sink(void *acl_process, const std::shared_ptr<mindspore::dataset::Tensor> &input,
std::shared_ptr<mindspore::dataset::DeviceTensor> *device_input) const;
APP_ERROR D2H_Pop(void *acl_process, const std::shared_ptr<mindspore::dataset::DeviceTensor> &device_output,
std::shared_ptr<mindspore::dataset::Tensor> *output) const;
APP_ERROR DeviceMemoryRelease(void *acl_process) const;
APP_ERROR SetResizeParas(void *acl_process, uint32_t width, uint32_t height) const;
APP_ERROR SetCropParas(void *acl_process, uint32_t width, uint32_t height) const;
int Memcpy(void *dst, size_t dest_max, const void *src, size_t count, int kind) const;
int MallocHost(void **host_ptr, size_t size) const;
int FreeHost(void *host_ptr) const;
private:
AclAdapter() = default;
~AclAdapter() { FinalizePlugin(); }
void InitPlugin();
void FinalizePlugin();
void *plugin_handle_ = nullptr;
CreateDvppVideoFunObj create_dvpp_video_fun_obj_;
InitDvppVideoFunObj init_dvpp_video_fun_obj_;
CloseDvppVideoFunObj close_dvpp_video_fun_obj_;
DvppVideoDumpFrameFunObj dvpp_video_dump_frame_fun_obj_;
InitResourceFunObj init_resource_fun_obj_;
GetContextFunObj get_context_fun_obj_;
ReleaseFunObj release_fun_obj_;
CreateAclProcessWithResizeFunObj create_acl_process_with_resize_fun_obj_;
CreateAclProcessWithParaFunObj create_acl_process_with_para_fun_obj_;
CreateAclProcessFunObj create_acl_process_fun_obj_;
DestroyAclProcessFunObj destroy_acl_process_fun_obj_;
ReleaseAclProcessFunObj release_acl_process_fun_obj_;
InitAclProcessFunObj init_acl_process_fun_obj_;
GetContextFromAclProcessFunObj get_context_from_acl_process_fun_obj_;
GetStreamFromAclProcessFunObj get_stream_from_acl_process_fun_obj_;
JPEG_DRC_WITH_DATAFunObj jpeg_drc_with_data_fun_obj_;
JPEG_DR_WITH_DATAFunObj jpeg_dr_with_data_fun_obj_;
JPEG_D_WITH_DATAFunObj jpeg_d_with_data_fun_obj_;
JPEG_R_WITH_DATAFunObj jpeg_r_with_data_fun_obj_;
JPEG_C_WITH_DATAFunObj jpeg_c_with_data_fun_obj_;
PNG_D_WITH_DATAFunObj png_d_with_data_fun_obj_;
JPEG_DRCFunObj jpeg_drc_fun_obj_;
JPEG_DRFunObj jpeg_dr_fun_obj_;
JPEG_DFunObj jpeg_d_fun_obj_;
JPEG_RFunObj jpeg_r_fun_obj_;
JPEG_CFunObj jpeg_c_fun_obj_;
PNG_DFunObj png_d_fun_obj_;
GetMemoryDataFunObj get_memory_data_fun_obj_;
GetCropedDeviceDataFunObj get_croped_device_data_fun_obj_;
GetResizedDeviceDataFunObj get_resized_device_data_fun_obj_;
GetDecodeDeviceDataFunObj get_decode_device_data_fun_obj_;
H2D_SinkFunObj h_2_d_sink_fun_obj_;
D2H_PopFunObj d_2_h_pop_fun_obj_;
DeviceMemoryReleaseFunObj device_memory_release_fun_obj_;
SetResizeParasFunObj set_resize_paras_fun_obj_;
SetCropParasFunObj set_crop_paras_fun_obj_;
aclrtMallocHostFunObj aclrt_malloc_host_fun_obj_;
aclrtFreeHostFunObj aclrt_free_host_fun_obj_;
aclrtMemcpyFunObj aclrt_memcpy_fun_obj_;
};
} // namespace mindspore::dataset
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_DVPP_ACL_ADAPTER_H

View File

@ -13,16 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "minddata/dataset/kernels/image/dvpp/dvpp_crop_jpeg_op.h"
#include <string>
#include <vector>
#include <iostream>
#include "include/api/context.h"
#include "minddata/dataset/core/data_type.h"
#include "minddata/dataset/core/device_tensor.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#include "minddata/dataset/kernels/image/dvpp/utils/CommonDataType.h"
#include "minddata/dataset/kernels/image/dvpp/dvpp_crop_jpeg_op.h"
#include "minddata/dataset/kernels/image/image_utils.h"
namespace mindspore {
@ -32,18 +30,18 @@ Status DvppCropJpegOp::Compute(const std::shared_ptr<DeviceTensor> &input, std::
try {
CHECK_FAIL_RETURN_UNEXPECTED(input->GetDeviceBuffer() != nullptr, "The input image buffer is empty.");
std::string last_step = "Resize";
std::shared_ptr<DvppDataInfo> imageinfo(processor_->Get_Resized_DeviceData());
DvppDataInfo *imageinfo = AclAdapter::GetInstance().GetResizedDeviceData(processor_.get());
if (!imageinfo->data) {
last_step = "Decode";
}
APP_ERROR ret = processor_->JPEG_C(last_step);
APP_ERROR ret = AclAdapter::GetInstance().JPEG_C(processor_.get(), last_step);
if (ret != APP_ERR_OK) {
ret = processor_->Release();
ret = AclAdapter::GetInstance().ReleaseAclProcess(processor_.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release memory failed.");
std::string error = "Error in dvpp crop processing:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
std::shared_ptr<DvppDataInfo> CropOut(processor_->Get_Croped_DeviceData());
DvppDataInfo *CropOut = AclAdapter::GetInstance().GetCropedDeviceData(processor_.get());
const TensorShape dvpp_shape({1, 1, 1});
const DataType dvpp_data_type(DataType::DE_UINT8);
RETURN_IF_NOT_OK(mindspore::dataset::DeviceTensor::CreateEmpty(dvpp_shape, dvpp_data_type, output));
@ -78,38 +76,38 @@ Status DvppCropJpegOp::Compute(const std::shared_ptr<Tensor> &input, std::shared
imageinfo.widthStride = yuv_shape_[1];
imageinfo.height = yuv_shape_[2];
imageinfo.heightStride = yuv_shape_[3];
imageinfo.format = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
imageinfo.format = 1; // 1 means PIXEL_FORMAT_YUV_SEMIPLANAR_420
ResourceInfo resource;
resource.deviceIds.insert(0);
std::shared_ptr<ResourceManager> instance = ResourceManager::GetInstance();
APP_ERROR ret = instance->InitResource(resource);
APP_ERROR ret = AclAdapter::GetInstance().InitResource(&resource);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in Init D-chip:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
int deviceId = *(resource.deviceIds.begin());
aclrtContext context = instance->GetContext(deviceId);
void *context = AclAdapter::GetInstance().GetContext(deviceId);
// Second part end where we initialize the resource of D-chip and set up all configures
MDAclProcess process(crop_width_, crop_height_, context, true);
ret = process.InitResource();
std::shared_ptr<void> process(
AclAdapter::GetInstance().CreateAclProcessWithPara(crop_width_, crop_height_, context, true, nullptr, nullptr),
[](void *ptr) { AclAdapter::GetInstance().DestroyAclProcess(ptr); });
ret = AclAdapter::GetInstance().InitAclProcess(process.get());
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in Init resource:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
ret = process.JPEG_C(imageinfo);
ret = AclAdapter::GetInstance().JPEG_C_WITH_DATA(process.get(), imageinfo);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in dvpp crop processing:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
// Third part end where we execute the core function of dvpp
auto data = std::static_pointer_cast<unsigned char>(process.Get_Memory_Data());
unsigned char *ret_ptr = data.get();
std::shared_ptr<DvppDataInfo> CropOut(process.Get_Croped_DeviceData());
unsigned char *ret_ptr = static_cast<unsigned char *>(AclAdapter::GetInstance().GetMemoryData(process.get()));
DvppDataInfo *CropOut(AclAdapter::GetInstance().GetCropedDeviceData(process.get()));
dsize_t dvpp_length = CropOut->dataSize;
const TensorShape dvpp_shape({dvpp_length, 1, 1});
uint32_t crop_height = CropOut->height;
@ -123,9 +121,9 @@ Status DvppCropJpegOp::Compute(const std::shared_ptr<Tensor> &input, std::shared
std::string error = "[ERROR] Fail to get the Output result from memory!";
RETURN_STATUS_UNEXPECTED(error);
}
ret = process.device_memory_release();
ret = AclAdapter::GetInstance().DeviceMemoryRelease(process.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release device memory failed.");
ret = process.Release();
ret = AclAdapter::GetInstance().ReleaseAclProcess(process.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release host memory failed.");
// Last part end where we transform the processed data into a tensor which can be applied in later units.
} catch (const std::exception &e) {
@ -152,11 +150,11 @@ Status DvppCropJpegOp::OutputShape(const std::vector<TensorShape> &inputs, std::
}
Status DvppCropJpegOp::SetAscendResource(const std::shared_ptr<DeviceResource> &resource) {
processor_ = std::static_pointer_cast<MDAclProcess>(resource->GetInstance());
processor_ = resource->GetInstance();
if (!processor_) {
RETURN_STATUS_UNEXPECTED("Resource initialize fail, please check your env");
}
APP_ERROR ret = processor_->SetCropParas(crop_width_, crop_height_);
APP_ERROR ret = AclAdapter::GetInstance().SetCropParas(processor_.get(), crop_width_, crop_height_);
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "SetCropParas failed.");
return Status::OK();
}

View File

@ -21,14 +21,12 @@
#include <string>
#include <vector>
#include "acl/acl.h"
#include "minddata/dataset/core/data_type.h"
#include "minddata/dataset/core/device_resource.h"
#include "minddata/dataset/core/device_tensor.h"
#include "minddata/dataset/core/tensor.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ErrorCode.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ResourceManager.h"
#include "minddata/dataset/kernels/image/dvpp/acl_adapter.h"
#include "minddata/dataset/kernels/tensor_op.h"
#include "minddata/dataset/util/log_adapter.h"
#include "minddata/dataset/util/status.h"
@ -56,7 +54,7 @@ class DvppCropJpegOp : public TensorOp {
uint32_t crop_height_;
uint32_t crop_width_;
std::shared_ptr<MDAclProcess> processor_;
std::shared_ptr<void> processor_;
};
} // namespace dataset
} // namespace mindspore

View File

@ -33,14 +33,14 @@ Status DvppDecodeJpegOp::Compute(const std::shared_ptr<DeviceTensor> &input, std
IO_CHECK(input, output);
try {
CHECK_FAIL_RETURN_UNEXPECTED(input->GetDeviceBuffer() != nullptr, "The input image buffer on device is empty");
APP_ERROR ret = processor_->JPEG_D();
APP_ERROR ret = AclAdapter::GetInstance().JPEG_D(processor_.get());
if (ret != APP_ERR_OK) {
ret = processor_->Release();
ret = AclAdapter::GetInstance().ReleaseAclProcess(processor_.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release memory failed.");
std::string error = "Error in dvpp processing:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
std::shared_ptr<DvppDataInfo> DecodeOut(processor_->Get_Decode_DeviceData());
DvppDataInfo *DecodeOut = AclAdapter::GetInstance().GetDecodeDeviceData(processor_.get());
const TensorShape dvpp_shape({1, 1, 1});
const DataType dvpp_data_type(DataType::DE_UINT8);
RETURN_IF_NOT_OK(mindspore::dataset::DeviceTensor::CreateEmpty(dvpp_shape, dvpp_data_type, output));
@ -72,33 +72,32 @@ Status DvppDecodeJpegOp::Compute(const std::shared_ptr<Tensor> &input, std::shar
imageInfo.data = static_cast<void *>(buffer);
ResourceInfo resource;
resource.deviceIds.insert(0);
std::shared_ptr<ResourceManager> instance = ResourceManager::GetInstance();
APP_ERROR ret = instance->InitResource(resource);
APP_ERROR ret = AclAdapter::GetInstance().InitResource(&resource);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in Init D-chip:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
int deviceId = *(resource.deviceIds.begin());
aclrtContext context = instance->GetContext(deviceId);
void *context = AclAdapter::GetInstance().GetContext(deviceId);
// Second part end where we initialize the resource of D-chip and set up all configures
MDAclProcess process(context, false);
ret = process.InitResource();
std::shared_ptr<void> process(AclAdapter::GetInstance().CreateAclProcess(context, false, nullptr, nullptr),
[](void *ptr) { AclAdapter::GetInstance().DestroyAclProcess(ptr); });
ret = AclAdapter::GetInstance().InitAclProcess(process.get());
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in Init resource:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
ret = process.JPEG_D(imageInfo);
ret = AclAdapter::GetInstance().JPEG_D_WITH_DATA(process.get(), imageInfo);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in dvpp processing:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
// Third part end where we execute the core function of dvpp
auto data = std::static_pointer_cast<unsigned char>(process.Get_Memory_Data());
unsigned char *ret_ptr = data.get();
std::shared_ptr<DvppDataInfo> DecodeOut(process.Get_Decode_DeviceData());
unsigned char *ret_ptr = static_cast<unsigned char *>(AclAdapter::GetInstance().GetMemoryData(process.get()));
DvppDataInfo *DecodeOut = AclAdapter::GetInstance().GetDecodeDeviceData(process.get());
dsize_t dvpp_length = DecodeOut->dataSize;
uint32_t decoded_height = DecodeOut->height;
uint32_t decoded_heightStride = DecodeOut->heightStride;
@ -113,9 +112,9 @@ Status DvppDecodeJpegOp::Compute(const std::shared_ptr<Tensor> &input, std::shar
std::string error = "[ERROR] Fail to get the Output result from device memory!";
RETURN_STATUS_UNEXPECTED(error);
}
ret = process.device_memory_release();
ret = AclAdapter::GetInstance().DeviceMemoryRelease(process.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release device memory failed.");
ret = process.Release();
ret = AclAdapter::GetInstance().ReleaseAclProcess(process.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release host memory failed.");
// Last part end where we transform the processed data into a tensor which can be applied in later units.
} catch (const std::exception &e) {
@ -126,7 +125,7 @@ Status DvppDecodeJpegOp::Compute(const std::shared_ptr<Tensor> &input, std::shar
}
Status DvppDecodeJpegOp::SetAscendResource(const std::shared_ptr<DeviceResource> &resource) {
processor_ = std::static_pointer_cast<MDAclProcess>(resource->GetInstance());
processor_ = resource->GetInstance();
if (!processor_) {
RETURN_STATUS_UNEXPECTED("Resource initialize fail, please check your env");
}

View File

@ -21,13 +21,11 @@
#include <string>
#include <vector>
#include "acl/acl.h"
#include "minddata/dataset/core/data_type.h"
#include "minddata/dataset/core/device_resource.h"
#include "minddata/dataset/core/tensor.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ErrorCode.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ResourceManager.h"
#include "minddata/dataset/kernels/image/dvpp/acl_adapter.h"
#include "minddata/dataset/kernels/tensor_op.h"
#include "minddata/dataset/util/log_adapter.h"
#include "minddata/dataset/util/status.h"
@ -52,7 +50,7 @@ class DvppDecodeJpegOp : public TensorOp {
Status SetAscendResource(const std::shared_ptr<DeviceResource> &resource) override;
private:
std::shared_ptr<MDAclProcess> processor_;
std::shared_ptr<void> processor_;
};
} // namespace dataset
} // namespace mindspore

View File

@ -23,7 +23,6 @@
#include "minddata/dataset/kernels/image/dvpp/dvpp_decode_resize_crop_jpeg_op.h"
#include "minddata/dataset/kernels/image/dvpp/dvpp_decode_png_op.h"
#include "minddata/dataset/kernels/image/dvpp/utils/CommonDataType.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#include "minddata/dataset/kernels/image/image_utils.h"
namespace mindspore {
@ -32,14 +31,14 @@ Status DvppDecodePngOp::Compute(const std::shared_ptr<DeviceTensor> &input, std:
IO_CHECK(input, output);
try {
CHECK_FAIL_RETURN_UNEXPECTED(input->GetDeviceBuffer() != nullptr, "The input image buffer on device is empty");
APP_ERROR ret = processor_->PNG_D();
APP_ERROR ret = AclAdapter::GetInstance().PNG_D(processor_.get());
if (ret != APP_ERR_OK) {
ret = processor_->Release();
ret = AclAdapter::GetInstance().ReleaseAclProcess(processor_.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release memory failed.");
std::string error = "Error in dvpp processing:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
std::shared_ptr<DvppDataInfo> DecodeOut(processor_->Get_Decode_DeviceData());
DvppDataInfo *DecodeOut = AclAdapter::GetInstance().GetDecodeDeviceData(processor_.get());
const TensorShape dvpp_shape({1, 1, 1});
const DataType dvpp_data_type(DataType::DE_UINT8);
RETURN_IF_NOT_OK(mindspore::dataset::DeviceTensor::CreateEmpty(dvpp_shape, dvpp_data_type, output));
@ -70,35 +69,34 @@ Status DvppDecodePngOp::Compute(const std::shared_ptr<Tensor> &input, std::share
imageInfo.data = static_cast<void *>(buffer);
ResourceInfo resource;
resource.deviceIds.insert(0);
std::shared_ptr<ResourceManager> instance = ResourceManager::GetInstance();
APP_ERROR ret = instance->InitResource(resource);
APP_ERROR ret = AclAdapter::GetInstance().InitResource(&resource);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in Init D-chip:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
int deviceId = *(resource.deviceIds.begin());
aclrtContext context = instance->GetContext(deviceId);
void *context = AclAdapter::GetInstance().GetContext(deviceId);
// Second part end where we initialize the resource of D-chip and set up all configures
MDAclProcess process(context, false);
ret = process.InitResource();
std::shared_ptr<void> process(AclAdapter::GetInstance().CreateAclProcess(context, false, nullptr, nullptr),
[](void *ptr) { AclAdapter::GetInstance().DestroyAclProcess(ptr); });
ret = AclAdapter::GetInstance().InitAclProcess(process.get());
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in Init resource:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
ret = process.PNG_D(imageInfo);
ret = AclAdapter::GetInstance().PNG_D_WITH_DATA(process.get(), imageInfo);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in dvpp processing:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
// Third part end where we execute the core function of dvpp
auto data = std::static_pointer_cast<unsigned char>(process.Get_Memory_Data());
unsigned char *ret_ptr = data.get();
std::shared_ptr<DvppDataInfo> DecodeOut(process.Get_Decode_DeviceData());
unsigned char *ret_ptr = static_cast<unsigned char *>(AclAdapter::GetInstance().GetMemoryData(process.get()));
DvppDataInfo *DecodeOut = AclAdapter::GetInstance().GetDecodeDeviceData(process.get());
dsize_t dvpp_length = DecodeOut->dataSize;
const TensorShape dvpp_shape({dvpp_length, 1, 1});
@ -108,9 +106,9 @@ Status DvppDecodePngOp::Compute(const std::shared_ptr<Tensor> &input, std::share
std::string error = "[ERROR] Fail to get the Output result from memory!";
RETURN_STATUS_UNEXPECTED(error);
}
ret = process.device_memory_release();
ret = AclAdapter::GetInstance().DeviceMemoryRelease(process.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release device memory failed.");
ret = process.Release();
ret = AclAdapter::GetInstance().ReleaseAclProcess(process.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release host memory failed.");
// Last part end where we transform the processed data into a tensor which can be applied in later units.
} catch (const std::exception &e) {
@ -137,7 +135,7 @@ Status DvppDecodePngOp::OutputShape(const std::vector<TensorShape> &inputs, std:
}
Status DvppDecodePngOp::SetAscendResource(const std::shared_ptr<DeviceResource> &resource) {
processor_ = std::static_pointer_cast<MDAclProcess>(resource->GetInstance());
processor_ = resource->GetInstance();
if (!processor_) {
RETURN_STATUS_UNEXPECTED("Resource initialize fail, please check your env");
}

View File

@ -21,13 +21,11 @@
#include <string>
#include <vector>
#include "acl/acl.h"
#include "minddata/dataset/core/data_type.h"
#include "minddata/dataset/core/device_resource.h"
#include "minddata/dataset/core/tensor.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ErrorCode.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ResourceManager.h"
#include "minddata/dataset/kernels/image/dvpp/acl_adapter.h"
#include "minddata/dataset/kernels/tensor_op.h"
#include "minddata/dataset/util/log_adapter.h"
#include "minddata/dataset/util/status.h"
@ -52,7 +50,7 @@ class DvppDecodePngOp : public TensorOp {
Status SetAscendResource(const std::shared_ptr<DeviceResource> &resource) override;
private:
std::shared_ptr<MDAclProcess> processor_;
std::shared_ptr<void> processor_;
};
} // namespace dataset
} // namespace mindspore

View File

@ -22,7 +22,6 @@
#include "minddata/dataset/core/data_type.h"
#include "minddata/dataset/kernels/image/dvpp/dvpp_decode_resize_crop_jpeg_op.h"
#include "minddata/dataset/kernels/image/dvpp/utils/CommonDataType.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#include "minddata/dataset/kernels/image/image_utils.h"
namespace mindspore {
@ -32,14 +31,14 @@ Status DvppDecodeResizeCropJpegOp::Compute(const std::shared_ptr<DeviceTensor> &
IO_CHECK(input, output);
try {
CHECK_FAIL_RETURN_UNEXPECTED(input->GetDeviceBuffer() != nullptr, "The input image buffer on device is empty");
APP_ERROR ret = processor_->JPEG_DRC();
APP_ERROR ret = AclAdapter::GetInstance().JPEG_DRC(processor_.get());
if (ret != APP_ERR_OK) {
ret = processor_->Release();
ret = AclAdapter::GetInstance().ReleaseAclProcess(processor_.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release memory failed.");
std::string error = "Error in dvpp processing:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
std::shared_ptr<DvppDataInfo> CropOut(processor_->Get_Croped_DeviceData());
DvppDataInfo *CropOut = AclAdapter::GetInstance().GetCropedDeviceData(processor_.get());
const TensorShape dvpp_shape({1, 1, 1});
const DataType dvpp_data_type(DataType::DE_UINT8);
@ -71,35 +70,37 @@ Status DvppDecodeResizeCropJpegOp::Compute(const std::shared_ptr<Tensor> &input,
imageInfo.data = static_cast<void *>(buffer);
ResourceInfo resource;
resource.deviceIds.insert(0);
std::shared_ptr<ResourceManager> instance = ResourceManager::GetInstance();
APP_ERROR ret = instance->InitResource(resource);
APP_ERROR ret = AclAdapter::GetInstance().InitResource(&resource);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in Init D-chip:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
int deviceId = *(resource.deviceIds.begin());
aclrtContext context = instance->GetContext(deviceId);
void *context = AclAdapter::GetInstance().GetContext(deviceId);
// Second part end where we initialize the resource of D chip and set up all configures
MDAclProcess processor(resized_width_, resized_height_, crop_width_, crop_height_, context, true);
ret = processor.InitResource();
std::shared_ptr<void> processor(
AclAdapter::GetInstance().CreateAclProcessWithResize(resized_width_, resized_height_, crop_width_, crop_height_,
context, true, nullptr, nullptr),
[](void *ptr) { AclAdapter::GetInstance().DestroyAclProcess(ptr); });
ret = AclAdapter::GetInstance().InitAclProcess(processor.get());
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in Init resource:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
ret = processor.JPEG_DRC(imageInfo);
ret = AclAdapter::GetInstance().JPEG_DRC_WITH_DATA(processor.get(), imageInfo);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in dvpp processing:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
// Third part end where we execute the core function of dvpp
auto data = std::static_pointer_cast<unsigned char>(processor.Get_Memory_Data());
unsigned char *ret_ptr = data.get();
std::shared_ptr<DvppDataInfo> CropOut(processor.Get_Croped_DeviceData());
unsigned char *ret_ptr = static_cast<unsigned char *>(AclAdapter::GetInstance().GetMemoryData(processor.get()));
DvppDataInfo *CropOut = AclAdapter::GetInstance().GetCropedDeviceData(processor.get());
uint32_t dvpp_length = CropOut->dataSize;
const TensorShape dvpp_shape({dvpp_length, 1, 1});
const DataType dvpp_data_type(DataType::DE_UINT8);
@ -108,9 +109,9 @@ Status DvppDecodeResizeCropJpegOp::Compute(const std::shared_ptr<Tensor> &input,
std::string error = "[ERROR] Fail to get the Output result from memory!";
RETURN_STATUS_UNEXPECTED(error);
}
ret = processor.device_memory_release();
ret = AclAdapter::GetInstance().DeviceMemoryRelease(processor.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release device memory failed.");
ret = processor.Release();
ret = AclAdapter::GetInstance().ReleaseAclProcess(processor.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release host memory failed.");
// Last part end where we transform the processed data into a tensor which can be applied in later units.
} catch (const std::exception &e) {
@ -138,13 +139,13 @@ Status DvppDecodeResizeCropJpegOp::OutputShape(const std::vector<TensorShape> &i
}
Status DvppDecodeResizeCropJpegOp::SetAscendResource(const std::shared_ptr<DeviceResource> &resource) {
processor_ = std::static_pointer_cast<MDAclProcess>(resource->GetInstance());
processor_ = resource->GetInstance();
if (!processor_) {
RETURN_STATUS_UNEXPECTED("Resource initialize fail, please check your env");
}
APP_ERROR ret = processor_->SetResizeParas(resized_width_, resized_height_);
APP_ERROR ret = AclAdapter::GetInstance().SetResizeParas(processor_.get(), resized_width_, resized_height_);
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "SetResizeParas failed.");
ret = processor_->SetCropParas(crop_width_, crop_height_);
ret = AclAdapter::GetInstance().SetCropParas(processor_.get(), crop_width_, crop_height_);
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "SetCropParas failed.");
return Status::OK();
}

View File

@ -21,13 +21,11 @@
#include <string>
#include <vector>
#include "acl/acl.h"
#include "minddata/dataset/core/data_type.h"
#include "minddata/dataset/core/device_resource.h"
#include "minddata/dataset/core/tensor.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ResourceManager.h"
#include "minddata/dataset/kernels/image/dvpp/acl_adapter.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ErrorCode.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#include "minddata/dataset/kernels/tensor_op.h"
#include "minddata/dataset/util/log_adapter.h"
#include "minddata/dataset/util/status.h"
@ -60,7 +58,7 @@ class DvppDecodeResizeCropJpegOp : public TensorOp {
int32_t crop_width_;
int32_t resized_height_;
int32_t resized_width_;
std::shared_ptr<MDAclProcess> processor_;
std::shared_ptr<void> processor_;
};
} // namespace dataset
} // namespace mindspore

View File

@ -13,16 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "minddata/dataset/kernels/image/dvpp/dvpp_decode_resize_jpeg_op.h"
#include <string>
#include <vector>
#include <iostream>
#include "include/api/context.h"
#include "minddata/dataset/core/cv_tensor.h"
#include "minddata/dataset/core/data_type.h"
#include "minddata/dataset/kernels/image/dvpp/dvpp_decode_resize_jpeg_op.h"
#include "minddata/dataset/kernels/image/dvpp/utils/CommonDataType.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#include "minddata/dataset/kernels/image/image_utils.h"
namespace mindspore {
@ -32,14 +28,14 @@ Status DvppDecodeResizeJpegOp::Compute(const std::shared_ptr<DeviceTensor> &inpu
IO_CHECK(input, output);
try {
CHECK_FAIL_RETURN_UNEXPECTED(input->GetDeviceBuffer() != nullptr, "The input image buffer on device is empty");
APP_ERROR ret = processor_->JPEG_DR();
APP_ERROR ret = AclAdapter::GetInstance().JPEG_DR(processor_.get());
if (ret != APP_ERR_OK) {
ret = processor_->Release();
ret = AclAdapter::GetInstance().ReleaseAclProcess(processor_.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release memory failed.");
std::string error = "Error in dvpp processing:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
std::shared_ptr<DvppDataInfo> ResizeOut(processor_->Get_Resized_DeviceData());
DvppDataInfo *ResizeOut = AclAdapter::GetInstance().GetResizedDeviceData(processor_.get());
const TensorShape dvpp_shape({1, 1, 1});
const DataType dvpp_data_type(DataType::DE_UINT8);
RETURN_IF_NOT_OK(mindspore::dataset::DeviceTensor::CreateEmpty(dvpp_shape, dvpp_data_type, output));
@ -70,35 +66,35 @@ Status DvppDecodeResizeJpegOp::Compute(const std::shared_ptr<Tensor> &input, std
imageInfo.data = static_cast<void *>(buffer);
ResourceInfo resource;
resource.deviceIds.insert(0);
std::shared_ptr<ResourceManager> instance = ResourceManager::GetInstance();
APP_ERROR ret = instance->InitResource(resource);
APP_ERROR ret = AclAdapter::GetInstance().InitResource(&resource);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in Init D-chip:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
int deviceId = *(resource.deviceIds.begin());
aclrtContext context = instance->GetContext(deviceId);
void *context = AclAdapter::GetInstance().GetContext(deviceId);
// Second part end where we initialize the resource of D-chip and set up all configures
MDAclProcess process(resized_width_, resized_height_, context, false);
ret = process.InitResource();
std::shared_ptr<void> process(AclAdapter::GetInstance().CreateAclProcessWithPara(resized_width_, resized_height_,
context, false, nullptr, nullptr),
[](void *ptr) { AclAdapter::GetInstance().DestroyAclProcess(ptr); });
ret = AclAdapter::GetInstance().InitAclProcess(process.get());
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in Init resource:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
ret = process.JPEG_DR(imageInfo);
ret = AclAdapter::GetInstance().JPEG_DR_WITH_DATA(process.get(), imageInfo);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in dvpp processing:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
// Third part end where we execute the core function of dvpp
auto data = std::static_pointer_cast<unsigned char>(process.Get_Memory_Data());
unsigned char *ret_ptr = data.get();
std::shared_ptr<DvppDataInfo> ResizeOut(process.Get_Resized_DeviceData());
unsigned char *ret_ptr = static_cast<unsigned char *>(AclAdapter::GetInstance().GetMemoryData(process.get()));
DvppDataInfo *ResizeOut = AclAdapter::GetInstance().GetResizedDeviceData(process.get());
dsize_t dvpp_length = ResizeOut->dataSize;
const TensorShape dvpp_shape({dvpp_length, 1, 1});
const DataType dvpp_data_type(DataType::DE_UINT8);
@ -107,9 +103,9 @@ Status DvppDecodeResizeJpegOp::Compute(const std::shared_ptr<Tensor> &input, std
std::string error = "[ERROR] Fail to get the Output result from memory!";
RETURN_STATUS_UNEXPECTED(error);
}
ret = process.device_memory_release();
ret = AclAdapter::GetInstance().DeviceMemoryRelease(process.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release device memory failed.");
ret = process.Release();
ret = AclAdapter::GetInstance().ReleaseAclProcess(process.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release host memory failed.");
// Last part end where we transform the processed data into a tensor which can be applied in later units.
} catch (const std::exception &e) {
@ -132,11 +128,11 @@ Status DvppDecodeResizeJpegOp::OutputShape(const std::vector<TensorShape> &input
}
Status DvppDecodeResizeJpegOp::SetAscendResource(const std::shared_ptr<DeviceResource> &resource) {
processor_ = std::static_pointer_cast<MDAclProcess>(resource->GetInstance());
processor_ = resource->GetInstance();
if (!processor_) {
RETURN_STATUS_UNEXPECTED("Resource initialize fail, please check your env");
}
APP_ERROR ret = processor_->SetResizeParas(resized_width_, resized_height_);
APP_ERROR ret = AclAdapter::GetInstance().SetResizeParas(processor_.get(), resized_width_, resized_height_);
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "SetResizeParas failed.");
return Status::OK();
}

View File

@ -21,13 +21,11 @@
#include <string>
#include <vector>
#include "acl/acl.h"
#include "minddata/dataset/core/data_type.h"
#include "minddata/dataset/core/device_resource.h"
#include "minddata/dataset/core/tensor.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ErrorCode.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ResourceManager.h"
#include "minddata/dataset/kernels/image/dvpp/acl_adapter.h"
#include "minddata/dataset/kernels/tensor_op.h"
#include "minddata/dataset/util/log_adapter.h"
#include "minddata/dataset/util/status.h"
@ -56,7 +54,7 @@ class DvppDecodeResizeJpegOp : public TensorOp {
int32_t resized_height_;
int32_t resized_width_;
std::shared_ptr<MDAclProcess> processor_;
std::shared_ptr<void> processor_;
};
} // namespace dataset
} // namespace mindspore

View File

@ -23,7 +23,7 @@
#include "minddata/dataset/core/data_type.h"
#include "minddata/dataset/core/device_tensor.h"
#include "minddata/dataset/kernels/image/dvpp/dvpp_decode_video_op.h"
#include "minddata/dataset/kernels/image/dvpp/dvpp_video.h"
#include "minddata/dataset/kernels/image/dvpp/acl_adapter.h"
#include "minddata/dataset/util/path.h"
namespace mindspore {
@ -43,34 +43,35 @@ Status DvppDecodeVideoOp::Compute(const std::shared_ptr<Tensor> &input, std::sha
ResourceInfo resource;
resource.deviceIds.insert(0);
std::shared_ptr<ResourceManager> instance = ResourceManager::GetInstance();
APP_ERROR ret = instance->InitResource(resource);
APP_ERROR ret = AclAdapter::GetInstance().InitResource(&resource);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "DvppDecodeVideo: Error in Init D-chip: " + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
int deviceId = *(resource.deviceIds.begin());
aclrtContext context = instance->GetContext(deviceId);
void *context = AclAdapter::GetInstance().GetContext(deviceId);
// initialize the resource of D-chip and set up all configures
auto dvpp_video = std::make_shared<DvppVideo>(context, buffer, data_size, width_, height_, (uint32_t)en_type_,
(uint32_t)format_, output_);
AclLiteError res = dvpp_video->Init();
auto dvpp_video = AclAdapter::GetInstance().CreateDvppVideo(context, buffer, data_size, width_, height_,
static_cast<uint32_t>(en_type_),
static_cast<uint32_t>(format_), output_);
AclLiteError res = AclAdapter::GetInstance().InitDvppVideo(dvpp_video);
if (res != ACLLITE_OK) {
instance->Release();
(void)AclAdapter::GetInstance().CloseDvppVideo(dvpp_video);
AclAdapter::GetInstance().Release();
std::string error = "DvppDecodeVideo: Failed to initialize DvppVideo:" + std::to_string(res);
RETURN_STATUS_UNEXPECTED(error);
}
res = dvpp_video->DumpFrame();
res = AclAdapter::GetInstance().DvppVideoDumpFrame(dvpp_video);
if (res != ACLLITE_OK) {
dvpp_video->Close();
instance->Release();
(void)AclAdapter::GetInstance().CloseDvppVideo(dvpp_video);
AclAdapter::GetInstance().Release();
std::string error = "DvppDecodeVideo: Error in DumpFrame:" + std::to_string(res);
RETURN_STATUS_UNEXPECTED(error);
}
dvpp_video->Close();
(void)AclAdapter::GetInstance().CloseDvppVideo(dvpp_video);
} catch (const std::exception &e) {
std::string error = "[ERROR] Error in DvppDecodeVideoOp:" + std::string(e.what());
RETURN_STATUS_UNEXPECTED(error);

View File

@ -25,7 +25,7 @@
#include "minddata/dataset/core/data_type.h"
#include "minddata/dataset/core/device_resource.h"
#include "minddata/dataset/core/tensor.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ResourceManager.h"
#include "minddata/dataset/kernels/image/dvpp/acl_adapter.h"
#include "minddata/dataset/kernels/tensor_op.h"
#include "minddata/dataset/util/status.h"

View File

@ -16,14 +16,11 @@
#include <string>
#include <vector>
#include <iostream>
#include "include/api/context.h"
#include "minddata/dataset/core/cv_tensor.h"
#include "minddata/dataset/core/data_type.h"
#include "minddata/dataset/core/device_tensor.h"
#include "minddata/dataset/kernels/image/dvpp/dvpp_resize_jpeg_op.h"
#include "minddata/dataset/kernels/image/dvpp/utils/CommonDataType.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#include "minddata/dataset/kernels/image/image_utils.h"
namespace mindspore {
@ -33,18 +30,18 @@ Status DvppResizeJpegOp::Compute(const std::shared_ptr<DeviceTensor> &input, std
try {
CHECK_FAIL_RETURN_UNEXPECTED(input->GetDeviceBuffer() != nullptr, "The input image buffer is empty.");
std::string last_step = "Decode";
std::shared_ptr<DvppDataInfo> imageinfo(processor_->Get_Decode_DeviceData());
DvppDataInfo *imageinfo(AclAdapter::GetInstance().GetDecodeDeviceData(processor_.get()));
if (!imageinfo->data) {
last_step = "Crop";
}
APP_ERROR ret = processor_->JPEG_R(last_step);
APP_ERROR ret = AclAdapter::GetInstance().JPEG_R(processor_.get(), last_step);
if (ret != APP_ERR_OK) {
ret = processor_->Release();
ret = AclAdapter::GetInstance().ReleaseAclProcess(processor_.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release memory failed.");
std::string error = "Error in dvpp processing:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
std::shared_ptr<DvppDataInfo> ResizeOut(processor_->Get_Resized_DeviceData());
DvppDataInfo *ResizeOut(AclAdapter::GetInstance().GetResizedDeviceData(processor_.get()));
const TensorShape dvpp_shape({1, 1, 1});
const DataType dvpp_data_type(DataType::DE_UINT8);
RETURN_IF_NOT_OK(mindspore::dataset::DeviceTensor::CreateEmpty(dvpp_shape, dvpp_data_type, output));
@ -77,38 +74,39 @@ Status DvppResizeJpegOp::Compute(const std::shared_ptr<Tensor> &input, std::shar
imageinfo.widthStride = yuv_shape_[1];
imageinfo.height = yuv_shape_[2];
imageinfo.heightStride = yuv_shape_[3];
imageinfo.format = PIXEL_FORMAT_YUV_SEMIPLANAR_420;
imageinfo.format = 1; // 1 means PIXEL_FORMAT_YUV_SEMIPLANAR_420
ResourceInfo resource;
resource.deviceIds.insert(0);
std::shared_ptr<ResourceManager> instance = ResourceManager::GetInstance();
APP_ERROR ret = instance->InitResource(resource);
APP_ERROR ret = AclAdapter::GetInstance().InitResource(&resource);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in Init D-chip:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
int deviceId = *(resource.deviceIds.begin());
aclrtContext context = instance->GetContext(deviceId);
void *context = AclAdapter::GetInstance().GetContext(deviceId);
// Second part end where we initialize the resource of D-chip and set up all configures
MDAclProcess process(resized_width_, resized_height_, context, false);
ret = process.InitResource();
std::shared_ptr<void> process(AclAdapter::GetInstance().CreateAclProcessWithPara(resized_width_, resized_height_,
context, false, nullptr, nullptr),
[](void *ptr) { AclAdapter::GetInstance().DestroyAclProcess(ptr); });
ret = AclAdapter::GetInstance().InitAclProcess(process.get());
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in Init resource:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
ret = process.JPEG_R(imageinfo);
ret = AclAdapter::GetInstance().JPEG_R_WITH_DATA(process.get(), imageinfo);
if (ret != APP_ERR_OK) {
instance->Release();
AclAdapter::GetInstance().Release();
std::string error = "Error in dvpp processing:" + std::to_string(ret);
RETURN_STATUS_UNEXPECTED(error);
}
// Third part end where we execute the core function of dvpp
auto data = std::static_pointer_cast<unsigned char>(process.Get_Memory_Data());
unsigned char *ret_ptr = data.get();
std::shared_ptr<DvppDataInfo> ResizeOut(process.Get_Resized_DeviceData());
unsigned char *ret_ptr = static_cast<unsigned char *>(AclAdapter::GetInstance().GetMemoryData(process.get()));
DvppDataInfo *ResizeOut = AclAdapter::GetInstance().GetResizedDeviceData(process.get());
dsize_t dvpp_length = ResizeOut->dataSize;
const TensorShape dvpp_shape({dvpp_length, 1, 1});
uint32_t resized_height = ResizeOut->height;
@ -122,9 +120,9 @@ Status DvppResizeJpegOp::Compute(const std::shared_ptr<Tensor> &input, std::shar
std::string error = "[ERROR] Fail to get the Output result from memory!";
RETURN_STATUS_UNEXPECTED(error);
}
ret = process.device_memory_release();
ret = AclAdapter::GetInstance().DeviceMemoryRelease(process.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release device memory failed.");
ret = process.Release();
ret = AclAdapter::GetInstance().ReleaseAclProcess(process.get());
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "Release host memory failed.");
// Last part end where we transform the processed data into a tensor which can be applied in later units.
} catch (const std::exception &e) {
@ -135,11 +133,11 @@ Status DvppResizeJpegOp::Compute(const std::shared_ptr<Tensor> &input, std::shar
}
Status DvppResizeJpegOp::SetAscendResource(const std::shared_ptr<DeviceResource> &resource) {
processor_ = std::static_pointer_cast<MDAclProcess>(resource->GetInstance());
processor_ = resource->GetInstance();
if (!processor_) {
RETURN_STATUS_UNEXPECTED("Resource initialize fail, please check your env");
}
APP_ERROR ret = processor_->SetResizeParas(resized_width_, resized_height_);
APP_ERROR ret = AclAdapter::GetInstance().SetResizeParas(processor_.get(), resized_width_, resized_height_);
CHECK_FAIL_RETURN_UNEXPECTED(ret == APP_ERR_OK, "SetResizeParas failed.");
return Status::OK();
}

View File

@ -21,14 +21,12 @@
#include <string>
#include <vector>
#include "acl/acl.h"
#include "minddata/dataset/core/data_type.h"
#include "minddata/dataset/core/device_tensor.h"
#include "minddata/dataset/core/device_resource.h"
#include "minddata/dataset/core/tensor.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ErrorCode.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ResourceManager.h"
#include "minddata/dataset/kernels/image/dvpp/acl_adapter.h"
#include "minddata/dataset/kernels/tensor_op.h"
#include "minddata/dataset/util/log_adapter.h"
#include "minddata/dataset/util/status.h"
@ -57,7 +55,7 @@ class DvppResizeJpegOp : public TensorOp {
int32_t resized_height_;
int32_t resized_width_;
std::shared_ptr<MDAclProcess> processor_;
std::shared_ptr<void> processor_;
};
} // namespace dataset
} // namespace mindspore

View File

@ -1,14 +1,20 @@
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 OBJECT
add_library(dvpp_utils SHARED
MDAclProcess.cc
DvppCommon.cc
ErrorCode.cpp
ResourceManager.cc
AclLiteUtils.cc
VdecHelper.cc
dvpp_video.cc
acl_plugin.cc
)
target_link_libraries(dvpp_utils PRIVATE _c_dataengine ${ACL} ${ACL_DVPP} mindspore_core mindspore_shared_lib)
if(MSLITE_ENABLE_CLOUD_MIND_DATA)
add_dependencies(dvpp-utils fbs_src)
add_dependencies(dvpp_utils fbs_src)
endif()

View File

@ -22,8 +22,6 @@
#include <iostream>
#include <memory>
#include <vector>
#include "acl/acl.h"
#include "acl/ops/acl_dvpp.h"
#define DVPP_ALIGN_UP(x, align) ((((x) + ((align)-1)) / (align)) * (align))
@ -43,15 +41,15 @@ const int VPC_OFFSET_ALIGN = 2;
// Data type of tensor
enum OpAttrType {
BOOL = 0,
INT = 1,
FLOAT = 2,
STRING = 3,
LIST_BOOL = 4,
LIST_INT = 6,
LIST_FLOAT = 7,
LIST_STRING = 8,
LIST_LIST_INT = 9,
kBool = 0,
kInt = 1,
kFloat = 2,
kString = 3,
kListBool = 4,
kListInt = 6,
kListFloat = 7,
kListString = 8,
kListListInt = 9,
};
// operator attribution describe
@ -80,12 +78,6 @@ struct ImageInfo {
std::shared_ptr<uint8_t> data; // Smart pointer of image data
};
// Description of data in device
struct RawData {
size_t lenOfByte; // Size of memory, bytes
void *data; // Pointer of data
};
// Description of data in device
struct StreamData {
size_t size; // Size of memory, bytes
@ -112,7 +104,7 @@ struct Rectangle {
struct ObjectDetectInfo {
int32_t classId;
float confidence;
Rectangle location;
struct Rectangle location;
};
enum VpcProcessType {
@ -123,14 +115,14 @@ enum VpcProcessType {
};
struct DvppDataInfo {
uint32_t width = 0; // Width of image
uint32_t height = 0; // Height of image
uint32_t widthStride = 0; // Width after align up
uint32_t heightStride = 0; // Height after align up
acldvppPixelFormat format = PIXEL_FORMAT_YUV_SEMIPLANAR_420; // Format of image
uint32_t frameId = 0; // Needed by video
uint32_t dataSize = 0; // Size of data in byte
uint8_t *data = nullptr; // Image data
uint32_t width = 0; // Width of image
uint32_t height = 0; // Height of image
uint32_t widthStride = 0; // Width after align up
uint32_t heightStride = 0; // Height after align up
int format = 1; // Format of image
uint32_t frameId = 0; // Needed by video
uint32_t dataSize = 0; // Size of data in byte
uint8_t *data = nullptr; // Image data
};
struct CropRoiConfig {
@ -141,8 +133,8 @@ struct CropRoiConfig {
};
struct DvppCropInputInfo {
DvppDataInfo dataInfo;
CropRoiConfig roi;
struct DvppDataInfo dataInfo;
struct CropRoiConfig roi;
};
// Description of matrix info
@ -151,13 +143,13 @@ struct MatrixInfo {
uint32_t col = 0; // col of matrix
uint32_t dataSize = 0; // size of memory, bytes
std::shared_ptr<void> data = nullptr; // data of matrix
aclDataType dataType = ACL_FLOAT16; // data Type of matrix
int dataType = 1; // data Type of matrix
};
// Description of coefficient info
struct CoefficientInfo {
std::shared_ptr<void> data = nullptr; // data of coefficient
aclDataType dataType = ACL_FLOAT16; // dataType
int dataType = 1; // dataType
};
// define the input of BLAS operator such as producing:
@ -166,8 +158,8 @@ struct BlasInput {
MatrixInfo A;
MatrixInfo B;
MatrixInfo C;
CoefficientInfo alpha;
CoefficientInfo beta;
struct CoefficientInfo alpha;
struct CoefficientInfo beta;
};
extern bool g_vdecNotified[VIDEO_PROCESS_THREAD];

View File

@ -354,7 +354,7 @@ APP_ERROR DvppCommon::SetDvppPicDescData(const DvppDataInfo &dataInfo, acldvppPi
MS_LOG(ERROR) << "Failed to set size for dvpp picture description, ret = " << ret << ".";
return ret;
}
ret = acldvppSetPicDescFormat(&picDesc, dataInfo.format);
ret = acldvppSetPicDescFormat(&picDesc, static_cast<enum acldvppPixelFormat>(dataInfo.format));
if (ret != APP_ERR_OK) {
MS_LOG(ERROR) << "Failed to set format for dvpp picture description, ret = " << ret << ".";
return ret;
@ -610,8 +610,8 @@ APP_ERROR DvppCommon::CombineResizeProcess(DvppDataInfo &input, const DvppDataIn
return ret;
}
// Get widthStride and heightStride for input and output image according to the format
ret =
GetVpcInputStrideSize(input.widthStride, input.heightStride, input.format, input.widthStride, input.heightStride);
ret = GetVpcInputStrideSize(input.widthStride, input.heightStride, static_cast<enum acldvppPixelFormat>(input.format),
input.widthStride, input.heightStride);
if (ret != APP_ERR_OK) {
return ret;
}
@ -620,13 +620,14 @@ APP_ERROR DvppCommon::CombineResizeProcess(DvppDataInfo &input, const DvppDataIn
resizedImage_->width = output.width;
resizedImage_->height = output.height;
resizedImage_->format = output.format;
ret = GetVpcOutputStrideSize(output.width, output.height, output.format, resizedImage_->widthStride,
resizedImage_->heightStride);
ret = GetVpcOutputStrideSize(output.width, output.height, static_cast<enum acldvppPixelFormat>(output.format),
resizedImage_->widthStride, resizedImage_->heightStride);
if (ret != APP_ERR_OK) {
return ret;
}
// Get output buffer size for resize output
ret = GetVpcDataSize(output.width, output.height, output.format, resizedImage_->dataSize);
ret = GetVpcDataSize(output.width, output.height, static_cast<enum acldvppPixelFormat>(output.format),
resizedImage_->dataSize);
if (ret != APP_ERR_OK) {
return ret;
}
@ -783,7 +784,8 @@ APP_ERROR DvppCommon::CombineCropProcess(DvppCropInputInfo &input, const DvppDat
}
// Get widthStride and heightStride for input and output image according to the format
APP_ERROR ret = GetVpcInputStrideSize(input.dataInfo.width, input.dataInfo.height, input.dataInfo.format,
APP_ERROR ret = GetVpcInputStrideSize(input.dataInfo.width, input.dataInfo.height,
static_cast<enum acldvppPixelFormat>(input.dataInfo.format),
input.dataInfo.widthStride, input.dataInfo.heightStride);
if (ret != APP_ERR_OK) {
return ret;
@ -797,13 +799,14 @@ APP_ERROR DvppCommon::CombineCropProcess(DvppCropInputInfo &input, const DvppDat
cropImage_->width = output.width;
cropImage_->height = output.height;
cropImage_->format = output.format;
ret = GetVpcOutputStrideSize(output.width, output.height, output.format, cropImage_->widthStride,
cropImage_->heightStride);
ret = GetVpcOutputStrideSize(output.width, output.height, static_cast<enum acldvppPixelFormat>(output.format),
cropImage_->widthStride, cropImage_->heightStride);
if (ret != APP_ERR_OK) {
return ret;
}
// Get output buffer size for resize output
ret = GetVpcDataSize(output.width, output.height, output.format, cropImage_->dataSize);
ret = GetVpcDataSize(output.width, output.height, static_cast<enum acldvppPixelFormat>(output.format),
cropImage_->dataSize);
if (ret != APP_ERR_OK) {
return ret;
}
@ -1646,7 +1649,7 @@ APP_ERROR DvppCommon::JpegEncode(const DvppDataInfo &input, DvppDataInfo &output
APP_ERROR DvppCommon::GetJpegEncodeStrideSize(const std::shared_ptr<DvppDataInfo> &inputImage) {
uint32_t inputWidth = inputImage->width;
uint32_t inputHeight = inputImage->height;
acldvppPixelFormat format = inputImage->format;
acldvppPixelFormat format = static_cast<enum acldvppPixelFormat>(inputImage->format);
uint32_t widthStride;
uint32_t heightStride;
uint32_t encodedBufferSize;

View File

@ -18,21 +18,12 @@
#include "CommonDataType.h"
#include "ErrorCode.h"
#include "resouce_info.h"
#include "acl/ops/acl_dvpp.h"
const int MODULUS_NUM_2 = 2;
const uint32_t ODD_NUM_1 = 1;
struct Rect {
/* left location of the rectangle */
uint32_t x;
/* top location of the rectangle */
uint32_t y;
/* with of the rectangle */
uint32_t width;
/* height of the rectangle */
uint32_t height;
};
struct DvppBaseData {
uint32_t dataSize; // Size of data in byte
uint8_t *data;

View File

@ -398,7 +398,7 @@ APP_ERROR MDAclProcess::JPEG_R(const DvppDataInfo &ImageInfo) {
return APP_ERR_OK;
}
APP_ERROR MDAclProcess::JPEG_R(std::string &last_step) {
APP_ERROR MDAclProcess::JPEG_R(const std::string &last_step) {
RunTimeUtil time_util;
time_util.Start();
// deal with image
@ -446,7 +446,7 @@ APP_ERROR MDAclProcess::JPEG_R_(const DvppDataInfo &ImageInfo) {
return APP_ERR_OK;
}
APP_ERROR MDAclProcess::JPEG_R_(std::string &last_step) {
APP_ERROR MDAclProcess::JPEG_R_(const std::string &last_step) {
std::shared_ptr<DvppDataInfo> input_image;
if (last_step == "Decode") {
input_image = dvppCommon_->GetDecodedImage();
@ -516,7 +516,7 @@ APP_ERROR MDAclProcess::JPEG_C(const DvppDataInfo &ImageInfo) {
return APP_ERR_OK;
}
APP_ERROR MDAclProcess::JPEG_C(std::string &last_step) {
APP_ERROR MDAclProcess::JPEG_C(const std::string &last_step) {
RunTimeUtil time_util;
time_util.Start();
// deal with image
@ -572,7 +572,7 @@ APP_ERROR MDAclProcess::JPEG_C_(const DvppDataInfo &ImageInfo) {
return APP_ERR_OK;
}
APP_ERROR MDAclProcess::JPEG_C_(std::string &last_step) {
APP_ERROR MDAclProcess::JPEG_C_(const std::string &last_step) {
std::shared_ptr<DvppDataInfo> input_image;
if (last_step == "Resize") {
input_image = dvppCommon_->GetResizedImage();

View File

@ -86,10 +86,10 @@ class MDAclProcess {
APP_ERROR JPEG_D();
// Process the JPEG image only with resize
APP_ERROR JPEG_R(const DvppDataInfo &ImageInfo);
APP_ERROR JPEG_R(std::string &last_step);
APP_ERROR JPEG_R(const std::string &last_step);
// Process the JPEG image only with crop
APP_ERROR JPEG_C(const DvppDataInfo &ImageInfo);
APP_ERROR JPEG_C(std::string &last_step);
APP_ERROR JPEG_C(const std::string &last_step);
// Process the PNG image only with decode
APP_ERROR PNG_D(const RawData &ImageInfo);
APP_ERROR PNG_D();
@ -135,10 +135,10 @@ class MDAclProcess {
APP_ERROR JPEG_D_();
// Impl of JPEG_R
APP_ERROR JPEG_R_(const DvppDataInfo &ImageInfo);
APP_ERROR JPEG_R_(std::string &last_step);
APP_ERROR JPEG_R_(const std::string &last_step);
// Impl of JPEG_C
APP_ERROR JPEG_C_(const DvppDataInfo &ImageInfo);
APP_ERROR JPEG_C_(std::string &last_step);
APP_ERROR JPEG_C_(const std::string &last_step);
// Impl of PNG_D
APP_ERROR PNG_D_(const RawData &ImageInfo);
APP_ERROR PNG_D_();

View File

@ -27,35 +27,9 @@
#include "mindspore/ccsrc/cxx_api/graph/acl/acl_env_guard.h"
#include "minddata/dataset/kernels/image/dvpp/utils/CommonDataType.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ErrorCode.h"
#include "minddata/dataset/kernels/image/dvpp/utils/resouce_info.h"
#include "minddata/dataset/util/log_adapter.h"
enum ModelLoadMethod {
LOAD_FROM_FILE = 0, // Loading from file, memory of model and weights are managed by ACL
LOAD_FROM_MEM, // Loading from memory, memory of model and weights are managed by ACL
LOAD_FROM_FILE_WITH_MEM, // Loading from file, memory of model and weight are managed by user
LOAD_FROM_MEM_WITH_MEM // Loading from memory, memory of model and weight are managed by user
};
struct ModelInfo {
std::string modelName;
std::string modelPath; // Path of om model file
size_t modelFileSize; // Size of om model file
std::shared_ptr<void> modelFilePtr; // Smart pointer of model file data
uint32_t modelWidth; // Input width of model
uint32_t modelHeight; // Input height of model
ModelLoadMethod method; // Loading method of model
};
// Device resource info, such as model infos, etc
struct DeviceResInfo {
std::vector<ModelInfo> modelInfos;
};
struct ResourceInfo {
std::set<int> deviceIds;
std::string singleOpFolderPath;
std::unordered_map<int, DeviceResInfo> deviceResInfos; // map <deviceId, deviceResourceInfo>
};
#include "acl/acl.h"
APP_ERROR ExistFile(const std::string &filePath);

View File

@ -0,0 +1,275 @@
/**
* Copyright 2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "minddata/dataset/kernels/image/dvpp/utils/acl_plugin.h"
#include <string>
#include "acl/acl_rt.h"
#include "minddata/dataset/kernels/image/dvpp/utils/dvpp_video.h"
#include "minddata/dataset/kernels/image/dvpp/utils/ResourceManager.h"
#include "minddata/dataset/kernels/image/dvpp/utils/MDAclProcess.h"
void *PluginCreateDvppVideo(aclrtContext context, uint8_t *data, uint32_t size, uint32_t width, uint32_t height,
uint32_t type, uint32_t out_format, const std::string &output) {
return new DvppVideo(context, data, size, width, height, type, out_format, output);
}
AclLiteError PluginInitDvppVideo(void *dvpp_video) {
if (dvpp_video == nullptr) {
return ACLLITE_ERROR;
}
return static_cast<DvppVideo *>(dvpp_video)->Init();
}
AclLiteError PluginCloseDvppVideo(void *dvpp_video) {
if (dvpp_video == nullptr) {
return ACLLITE_ERROR;
}
auto ret = static_cast<DvppVideo *>(dvpp_video)->Close();
delete static_cast<DvppVideo *>(dvpp_video);
return ret;
}
AclLiteError PluginDvppVideoDumpFrame(void *dvpp_video) {
if (dvpp_video == nullptr) {
return ACLLITE_ERROR;
}
return static_cast<DvppVideo *>(dvpp_video)->DumpFrame();
}
APP_ERROR PluginInitResource(ResourceInfo &resource_info) {
if (ResourceManager::GetInstance() == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return ResourceManager::GetInstance()->InitResource(resource_info);
}
aclrtContext PluginGetContext(int device_id) {
if (ResourceManager::GetInstance() == nullptr) {
return nullptr;
}
return ResourceManager::GetInstance()->GetContext(device_id);
}
void PluginRelease() {
if (ResourceManager::GetInstance() != nullptr) {
return ResourceManager::GetInstance()->Release();
}
}
void *PluginCreateAclProcessWithResize(uint32_t resize_width, uint32_t resize_height, uint32_t crop_width,
uint32_t crop_height, aclrtContext context, bool is_crop, aclrtStream stream,
const std::shared_ptr<DvppCommon> &dvpp_common) {
return new MDAclProcess(resize_width, resize_height, crop_width, crop_height, context, is_crop, stream, dvpp_common);
}
void *PluginCreateAclProcessWithPara(uint32_t para_width, uint32_t para_height, aclrtContext context, bool is_crop,
aclrtStream stream, const std::shared_ptr<DvppCommon> &dvpp_common) {
return new MDAclProcess(para_width, para_height, context, is_crop, stream, dvpp_common);
}
void *PluginCreateAclProcess(aclrtContext context, bool is_crop, aclrtStream stream,
const std::shared_ptr<DvppCommon> &dvpp_common) {
return new MDAclProcess(context, is_crop, stream, dvpp_common);
}
void PluginDestroyAclProcess(void *acl_process) {
if (acl_process != nullptr) {
delete static_cast<MDAclProcess *>(acl_process);
}
}
APP_ERROR PluginReleaseAclProcess(void *acl_process) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->Release();
}
APP_ERROR PluginInitAclProcess(void *acl_process) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->InitResource();
}
aclrtContext PluginGetContextFromAclProcess(void *acl_process) {
if (acl_process == nullptr) {
return nullptr;
}
return static_cast<MDAclProcess *>(acl_process)->GetContext();
}
aclrtStream PluginGetStreamFromAclProcess(void *acl_process) {
if (acl_process == nullptr) {
return nullptr;
}
return static_cast<MDAclProcess *>(acl_process)->GetStream();
}
APP_ERROR PluginJPEG_DRC_WITH_DATA(void *acl_process, const RawData &data) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->JPEG_DRC(data);
}
APP_ERROR PluginJPEG_DR_WITH_DATA(void *acl_process, const RawData &data) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->JPEG_DR(data);
}
APP_ERROR PluginJPEG_D_WITH_DATA(void *acl_process, const RawData &data) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->JPEG_D(data);
}
APP_ERROR PluginJPEG_R_WITH_DATA(void *acl_process, const DvppDataInfo &data) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->JPEG_R(data);
}
APP_ERROR PluginJPEG_C_WITH_DATA(void *acl_process, const DvppDataInfo &data) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->JPEG_C(data);
}
APP_ERROR PluginPNG_D_WITH_DATA(void *acl_process, const RawData &data) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->PNG_D(data);
}
APP_ERROR PluginJPEG_DRC(void *acl_process) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->JPEG_DRC();
}
APP_ERROR PluginJPEG_DR(void *acl_process) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->JPEG_DR();
}
APP_ERROR PluginJPEG_D(void *acl_process) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->JPEG_D();
}
APP_ERROR PluginJPEG_R(void *acl_process, const std::string &last_step) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->JPEG_R(last_step);
}
APP_ERROR PluginJPEG_C(void *acl_process, const std::string &last_step) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->JPEG_C(last_step);
}
APP_ERROR PluginPNG_D(void *acl_process) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->PNG_D();
}
void *PluginGetMemoryData(void *acl_process) {
if (acl_process == nullptr) {
return nullptr;
}
return static_cast<MDAclProcess *>(acl_process)->Get_Memory_Data().get();
}
DvppDataInfo *PluginGetCropedDeviceData(void *acl_process) {
if (acl_process == nullptr) {
return nullptr;
}
return static_cast<MDAclProcess *>(acl_process)->Get_Croped_DeviceData().get();
}
DvppDataInfo *PluginGetResizedDeviceData(void *acl_process) {
if (acl_process == nullptr) {
return nullptr;
}
return static_cast<MDAclProcess *>(acl_process)->Get_Resized_DeviceData().get();
}
DvppDataInfo *PluginGetDecodeDeviceData(void *acl_process) {
if (acl_process == nullptr) {
return nullptr;
}
return static_cast<MDAclProcess *>(acl_process)->Get_Decode_DeviceData().get();
}
APP_ERROR PluginH2D_Sink(void *acl_process, const std::shared_ptr<mindspore::dataset::Tensor> &input,
std::shared_ptr<mindspore::dataset::DeviceTensor> &device_input) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->H2D_Sink(input, device_input);
}
APP_ERROR PluginD2H_Pop(void *acl_process, const std::shared_ptr<mindspore::dataset::DeviceTensor> &device_output,
std::shared_ptr<mindspore::dataset::Tensor> &output) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->D2H_Pop(device_output, output);
}
APP_ERROR PluginDeviceMemoryRelease(void *acl_process) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->device_memory_release();
}
APP_ERROR PluginSetResizeParas(void *acl_process, uint32_t width, uint32_t height) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->SetResizeParas(width, height);
}
APP_ERROR PluginSetCropParas(void *acl_process, uint32_t width, uint32_t height) {
if (acl_process == nullptr) {
return APP_ERR_ACL_FAILURE;
}
return static_cast<MDAclProcess *>(acl_process)->SetCropParas(width, height);
}
int PluginaclrtMemcpy(void *dst, size_t dest_max, const void *src, size_t count, int kind) {
return aclrtMemcpy(dst, dest_max, src, count, static_cast<aclrtMemcpyKind>(kind));
}

View File

@ -0,0 +1,76 @@
/**
* Copyright 2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_DVPP_UTILS_ACL_PLUGIN_H
#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_DVPP_UTILS_ACL_PLUGIN_H
#include <memory>
#include "minddata/dataset/core/device_tensor.h"
#include "minddata/dataset/core/tensor.h"
#include "minddata/dataset/kernels/image/dvpp/utils/resouce_info.h"
#include "utils/dlopen_macro.h"
class DvppCommon;
struct DvppDataInfo;
PLUGIN_METHOD(CreateDvppVideo, void *, void *, uint8_t *, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t,
const std::string &);
PLUGIN_METHOD(InitDvppVideo, int, void *);
PLUGIN_METHOD(CloseDvppVideo, int, void *);
PLUGIN_METHOD(DvppVideoDumpFrame, int, void *);
PLUGIN_METHOD(InitResource, int, ResourceInfo &);
PLUGIN_METHOD(GetContext, void *, int);
PLUGIN_METHOD(Release, void);
PLUGIN_METHOD(CreateAclProcessWithResize, void *, uint32_t, uint32_t, uint32_t, uint32_t, void *, bool, void *,
const std::shared_ptr<DvppCommon> &);
PLUGIN_METHOD(CreateAclProcessWithPara, void *, uint32_t, uint32_t, void *, bool, void *,
const std::shared_ptr<DvppCommon> &);
PLUGIN_METHOD(CreateAclProcess, void *, void *, bool, void *, const std::shared_ptr<DvppCommon> &);
PLUGIN_METHOD(DestroyAclProcess, void, void *);
PLUGIN_METHOD(ReleaseAclProcess, int, void *);
PLUGIN_METHOD(InitAclProcess, int, void *);
PLUGIN_METHOD(GetContextFromAclProcess, void *, void *);
PLUGIN_METHOD(GetStreamFromAclProcess, void *, void *);
PLUGIN_METHOD(JPEG_DRC_WITH_DATA, int, void *, const RawData &);
PLUGIN_METHOD(JPEG_DR_WITH_DATA, int, void *, const RawData &);
PLUGIN_METHOD(JPEG_D_WITH_DATA, int, void *, const RawData &);
PLUGIN_METHOD(JPEG_R_WITH_DATA, int, void *, const DvppDataInfo &);
PLUGIN_METHOD(JPEG_C_WITH_DATA, int, void *, const DvppDataInfo &);
PLUGIN_METHOD(PNG_D_WITH_DATA, int, void *, const RawData &);
PLUGIN_METHOD(JPEG_DRC, int, void *);
PLUGIN_METHOD(JPEG_DR, int, void *);
PLUGIN_METHOD(JPEG_D, int, void *);
PLUGIN_METHOD(JPEG_R, int, void *, const std::string &);
PLUGIN_METHOD(JPEG_C, int, void *, const std::string &);
PLUGIN_METHOD(PNG_D, int, void *);
PLUGIN_METHOD(GetMemoryData, void *, void *);
PLUGIN_METHOD(GetCropedDeviceData, DvppDataInfo *, void *);
PLUGIN_METHOD(GetResizedDeviceData, DvppDataInfo *, void *);
PLUGIN_METHOD(GetDecodeDeviceData, DvppDataInfo *, void *);
PLUGIN_METHOD(H2D_Sink, int, void *, const std::shared_ptr<mindspore::dataset::Tensor> &,
std::shared_ptr<mindspore::dataset::DeviceTensor> &);
PLUGIN_METHOD(D2H_Pop, int, void *, const std::shared_ptr<mindspore::dataset::DeviceTensor> &,
std::shared_ptr<mindspore::dataset::Tensor> &);
PLUGIN_METHOD(DeviceMemoryRelease, int, void *);
PLUGIN_METHOD(SetResizeParas, int, void *, uint32_t, uint32_t);
PLUGIN_METHOD(SetCropParas, int, void *, uint32_t, uint32_t);
ORIGIN_METHOD(aclrtMallocHost, int, void **, size_t);
PLUGIN_METHOD(aclrtMemcpy, int, void *, size_t, const void *, size_t, int);
ORIGIN_METHOD(aclrtFreeHost, int, void *);
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_DVPP_UTILS_ACL_PLUGIN_H

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "minddata/dataset/kernels/image/dvpp/utils/dvpp_video.h"
#include <malloc.h>
#include <sys/prctl.h>
#include <sys/time.h>
@ -27,8 +28,7 @@
#include <thread>
#include "mindspore/core/utils/log_adapter.h"
#include "minddata/dataset/kernels/image/dvpp/dvpp_video.h"
#include "utils/AclLiteUtils.h"
#include "AclLiteUtils.h"
namespace {
const int64_t kUsec = 1000000;
@ -159,7 +159,7 @@ void FrameExtarct::Decode(FrameProcessCallBack callback, void *callbackParam) {
}
DvppVideo::DvppVideo(aclrtContext context, uint8_t *data, uint32_t size, uint32_t width, uint32_t height, uint32_t type,
uint32_t out_format, const std::string output)
uint32_t out_format, const std::string &output)
: data_(data),
size_(size),
frameWidth_(width),

View File

@ -26,8 +26,8 @@
#include <thread>
#include <vector>
#include "utils/ThreadSafeQueue.h"
#include "utils/VdecHelper.h"
#include "ThreadSafeQueue.h"
#include "VdecHelper.h"
constexpr int INVALID_CHANNEL_ID = -1;
constexpr int INVALID_STREAM_FORMAT = -1;
@ -139,7 +139,7 @@ class DvppVideo {
* @brief DvppVideo constructor
*/
DvppVideo(aclrtContext context, uint8_t *data, uint32_t size, uint32_t width, uint32_t height, uint32_t type,
uint32_t out_format, std::string output);
uint32_t out_format, const std::string &output);
/**
* @brief DvppVideo destructor

View File

@ -0,0 +1,58 @@
/**
* Copyright 2022 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_DVPP_UTILS_RESOURCE_INFO_H
#define MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_DVPP_UTILS_RESOURCE_INFO_H
#include <string>
#include <memory>
#include <vector>
#include <set>
#include <unordered_map>
// Description of data in device
struct RawData {
size_t lenOfByte; // Size of memory, bytes
void *data; // Pointer of data
};
enum ModelLoadMethod {
LOAD_FROM_FILE = 0, // Loading from file, memory of model and weights are managed by ACL
LOAD_FROM_MEM, // Loading from memory, memory of model and weights are managed by ACL
LOAD_FROM_FILE_WITH_MEM, // Loading from file, memory of model and weight are managed by user
LOAD_FROM_MEM_WITH_MEM // Loading from memory, memory of model and weight are managed by user
};
struct ModelInfo {
std::string modelName;
std::string modelPath; // Path of om model file
size_t modelFileSize; // Size of om model file
std::shared_ptr<void> modelFilePtr; // Smart pointer of model file data
uint32_t modelWidth; // Input width of model
uint32_t modelHeight; // Input height of model
ModelLoadMethod method; // Loading method of model
};
// Device resource info, such as model infos, etc
struct DeviceResInfo {
std::vector<ModelInfo> modelInfos;
};
struct ResourceInfo {
std::set<int> deviceIds;
std::string singleOpFolderPath;
std::unordered_map<int, DeviceResInfo> deviceResInfos; // map <deviceId, deviceResourceInfo>
};
#endif // MINDSPORE_CCSRC_MINDDATA_DATASET_KERNELS_IMAGE_DVPP_UTILS_RESOURCE_INFO_H

View File

@ -151,7 +151,7 @@ Status Decode(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *out
Status DecodeCv(const std::shared_ptr<Tensor> &input, std::shared_ptr<Tensor> *output);
bool IsNonEmptyJPEG(const std::shared_ptr<Tensor> &input);
DATASET_API bool IsNonEmptyJPEG(const std::shared_ptr<Tensor> &input);
bool IsNonEmptyPNG(const std::shared_ptr<Tensor> &input);

View File

@ -73,12 +73,7 @@ set(DATASET_KERNELS_IR_VISION_SRC_FILES
trivial_augment_wide_ir.cc
uniform_aug_ir.cc
vertical_flip_ir.cc
ascend_vision_ir.cc
)
if(ENABLE_ACL)
set(DATASET_KERNELS_IR_VISION_SRC_FILES
${DATASET_KERNELS_IR_VISION_SRC_FILES}
ascend_vision_ir.cc)
endif()
add_library(kernels-ir-vision OBJECT ${DATASET_KERNELS_IR_VISION_SRC_FILES})

View File

@ -63,6 +63,7 @@ if(MODE_ASCEND_ALL)
find_library(DATATRANSFER datatransfer HINTS ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
find_library(PROFILING msprofiler ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
find_library(ACL ascendcl ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
find_library(ACL_DVPP acl_dvpp ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
find_library(ACL_TDT_CHANNEL acl_tdt_channel ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
find_library(PLATFORM platform ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})
find_library(OPT_FEATURE opt_feature ${ASCEND_CANN_RUNTIME_PATH} ${ASCEND_TOOLKIT_RUNTIME_PATH})

View File

@ -17,18 +17,91 @@
#include "plugin/device/ascend/hal/common/ascend_utils.h"
#include <vector>
#include <string>
#include <map>
#include "common/util/error_manager/error_manager.h"
#include "include/common/utils/anfalgo.h"
#include "backend/common/session/anf_runtime_algorithm.h"
#include "runtime/device/ms_device_shape_transfer.h"
#include "utils/ms_context.h"
#include "runtime/dev.h"
#include "acl/error_codes/rt_error_codes.h"
namespace mindspore {
namespace device {
namespace ascend {
namespace {
const std::map<uint32_t, std::string> error_msg = {
{ACL_RT_SUCCESS, "success"},
{ACL_ERROR_RT_PARAM_INVALID, "param invalid"},
{ACL_ERROR_RT_INVALID_DEVICEID, "invalid device id"},
{ACL_ERROR_RT_CONTEXT_NULL, "current context null"},
{ACL_ERROR_RT_STREAM_CONTEXT, "stream not in current context"},
{ACL_ERROR_RT_MODEL_CONTEXT, "model not in current context"},
{ACL_ERROR_RT_STREAM_MODEL, "stream not in model"},
{ACL_ERROR_RT_EVENT_TIMESTAMP_INVALID, "event timestamp invalid"},
{ACL_ERROR_RT_EVENT_TIMESTAMP_REVERSAL, " event timestamp reversal"},
{ACL_ERROR_RT_ADDR_UNALIGNED, "memory address unaligned"},
{ACL_ERROR_RT_FILE_OPEN, "open file failed"},
{ACL_ERROR_RT_FILE_WRITE, "write file failed"},
{ACL_ERROR_RT_STREAM_SUBSCRIBE, "error subscribe stream"},
{ACL_ERROR_RT_THREAD_SUBSCRIBE, "error subscribe thread"},
{ACL_ERROR_RT_GROUP_NOT_SET, "group not set"},
{ACL_ERROR_RT_GROUP_NOT_CREATE, "group not create"},
{ACL_ERROR_RT_STREAM_NO_CB_REG, "callback not register to stream"},
{ACL_ERROR_RT_INVALID_MEMORY_TYPE, "invalid memory type"},
{ACL_ERROR_RT_INVALID_HANDLE, "invalid handle"},
{ACL_ERROR_RT_INVALID_MALLOC_TYPE, "invalid malloc type"},
{ACL_ERROR_RT_FEATURE_NOT_SUPPORT, "feature not support"},
{ACL_ERROR_RT_MEMORY_ALLOCATION, "memory allocation error"},
{ACL_ERROR_RT_MEMORY_FREE, "memory free error"},
{ACL_ERROR_RT_AICORE_OVER_FLOW, "aicore over flow"},
{ACL_ERROR_RT_NO_DEVICE, "no device"},
{ACL_ERROR_RT_RESOURCE_ALLOC_FAIL, "resource alloc fail"},
{ACL_ERROR_RT_NO_PERMISSION, "no permission"},
{ACL_ERROR_RT_NO_EVENT_RESOURCE, "no event resource"},
{ACL_ERROR_RT_NO_STREAM_RESOURCE, "no stream resource"},
{ACL_ERROR_RT_NO_NOTIFY_RESOURCE, "no notify resource"},
{ACL_ERROR_RT_NO_MODEL_RESOURCE, "no model resource"},
{ACL_ERROR_RT_INTERNAL_ERROR, "runtime internal error"},
{ACL_ERROR_RT_TS_ERROR, "ts internal error"},
{ACL_ERROR_RT_STREAM_TASK_FULL, "task full in stream"},
{ACL_ERROR_RT_STREAM_TASK_EMPTY, " task empty in stream"},
{ACL_ERROR_RT_STREAM_NOT_COMPLETE, "stream not complete"},
{ACL_ERROR_RT_END_OF_SEQUENCE, "end of sequence"},
{ACL_ERROR_RT_EVENT_NOT_COMPLETE, "event not complete"},
{ACL_ERROR_RT_CONTEXT_RELEASE_ERROR, "context release error"},
{ACL_ERROR_RT_SOC_VERSION, "soc version error"},
{ACL_ERROR_RT_TASK_TYPE_NOT_SUPPORT, "task type not support"},
{ACL_ERROR_RT_LOST_HEARTBEAT, "ts lost heartbeat"},
{ACL_ERROR_RT_MODEL_EXECUTE, " model execute failed"},
{ACL_ERROR_RT_REPORT_TIMEOUT, "report timeout"},
{ACL_ERROR_RT_SYS_DMA, "sys dma error"},
{ACL_ERROR_RT_AICORE_TIMEOUT, "aicore timeout"},
{ACL_ERROR_RT_AICORE_EXCEPTION, "aicore exception"},
{ACL_ERROR_RT_AICORE_TRAP_EXCEPTION, " aicore trap exception"},
{ACL_ERROR_RT_AICPU_TIMEOUT, " aicpu timeout"},
{ACL_ERROR_RT_AICPU_EXCEPTION, "aicpu exception"},
{ACL_ERROR_RT_AICPU_DATADUMP_RSP_ERR, " aicpu datadump response error"},
{ACL_ERROR_RT_AICPU_MODEL_RSP_ERR, "aicpu model operate response error"},
{ACL_ERROR_RT_PROFILING_ERROR, "profiling error"},
{ACL_ERROR_RT_IPC_ERROR, "ipc error"},
{ACL_ERROR_RT_MODEL_ABORT_NORMAL, "model abort normal"},
{ACL_ERROR_RT_KERNEL_UNREGISTERING, "kernel unregistering"},
{ACL_ERROR_RT_RINGBUFFER_NOT_INIT, "ringbuffer not init"},
{ACL_ERROR_RT_RINGBUFFER_NO_DATA, "ringbuffer no data"},
{ACL_ERROR_RT_KERNEL_LOOKUP, "kernel lookup error"},
{ACL_ERROR_RT_KERNEL_DUPLICATE, "kernel register duplicate"},
{ACL_ERROR_RT_DEBUG_REGISTER_FAIL, "debug register failed"},
{ACL_ERROR_RT_DEBUG_UNREGISTER_FAIL, "debug unregister failed"},
{ACL_ERROR_RT_LABEL_CONTEXT, "label not in current context"},
{ACL_ERROR_RT_PROGRAM_USE_OUT, "program register num use out"},
{ACL_ERROR_RT_DEV_SETUP_ERROR, "device setup error"},
{ACL_ERROR_RT_DRV_INTERNAL_ERROR, "drv internal error"},
};
constexpr auto kUnknowErrorString = "Unknown error occurred";
constexpr auto kSOC_VERSION = "SOC_VERSION";
} // namespace
std::string GetErrorMessage(bool add_title) {
const string &error_message = ErrorManager::GetInstance().GetErrorMessage();
@ -133,6 +206,14 @@ void AssignOutputNopNodeDeviceAddress(const KernelGraphPtr &graph, const device:
MS_LOG(INFO) << "Assign device address to output nop node " << output->fullname_with_scope();
}
}
std::string GetErrorMsg(uint32_t rt_error_code) {
auto find_iter = error_msg.find(rt_error_code);
if (find_iter == error_msg.end()) {
return "Return error code unknown, ret code: " + std::to_string(rt_error_code);
}
return find_iter->second;
}
} // namespace ascend
} // namespace device
} // namespace mindspore

View File

@ -37,6 +37,8 @@ std::string GetSocVersion();
// Some NOP nodes have be hide in execution order, it doesn't have output device address, this function creates
// output device address for these nodes, and the output device address is the same with input device address.
void AssignOutputNopNodeDeviceAddress(const KernelGraphPtr &graph, const device::DeviceContext *device_context);
std::string GetErrorMsg(uint32_t rt_error_code);
} // namespace ascend
} // namespace device
} // namespace mindspore

View File

@ -57,7 +57,6 @@
#include "include/common/debug/anf_ir_dump.h"
#include "include/common/utils/parallel_context.h"
#include "include/common/utils/comm_manager.h"
#include "include/common/utils/runtime_error_codes.h"
#ifdef MEM_REUSE_DEBUG
#include "common/mem_reuse/mem_reuse_checker.h"
#include "include/common/debug/env_config_parser.h"

View File

@ -22,7 +22,7 @@
#include "runtime/rt.h"
#include "utils/log_adapter.h"
#include "include/common/utils/convert_utils.h"
#include "include/common/utils/runtime_error_codes.h"
#include "plugin/device/ascend/hal/common/ascend_utils.h"
namespace mindspore {
namespace kernel {
@ -78,7 +78,7 @@ bool AkgKernelMod::Launch(const std::vector<AddressPtr> &inputs, const std::vect
SizeToUint(sizeof(void *) * runtime_args.size()), l2ctrl, stream);
if (ret != RT_ERROR_NONE) {
MS_LOG(ERROR) << "Call runtime rtKernelLaunch error. Kernel name: " << kernel_name_
<< ". Error message: " << GetErrorMsg(static_cast<uint32_t>(ret));
<< ". Error message: " << device::ascend::GetErrorMsg(static_cast<uint32_t>(ret));
return false;
}

View File

@ -4,10 +4,6 @@ if(CMAKE_SYSTEM_NAME MATCHES "Windows")
list(REMOVE_ITEM _UTILS_SRC_LIST ${_UTILS_SIGNAL_SRC_FILES})
endif()
if(NOT ENABLE_D AND NOT ENABLE_TESTCASES)
file(GLOB_RECURSE _UTILS_D_SRC_FILES ./runtime_error_codes.cc)
list(REMOVE_ITEM _UTILS_SRC_LIST ${_UTILS_D_SRC_FILES})
endif()
if(ENABLE_SECURITY)
file(GLOB_RECURSE _UTILS_SUMMARY_FILES ./summary/event_writer.cc)
list(REMOVE_ITEM _UTILS_SRC_LIST ${_UTILS_SUMMARY_FILES})

View File

@ -1,98 +0,0 @@
/**
* Copyright 2021 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "include/common/utils/runtime_error_codes.h"
#include <map>
#include <vector>
#include "graphengine/inc/external/runtime/rt_error_codes.h"
const std::map<uint32_t, std::string> error_msg = {
{ACL_RT_SUCCESS, "success"},
{ACL_ERROR_RT_PARAM_INVALID, "param invalid"},
{ACL_ERROR_RT_INVALID_DEVICEID, "invalid device id"},
{ACL_ERROR_RT_CONTEXT_NULL, "current context null"},
{ACL_ERROR_RT_STREAM_CONTEXT, "stream not in current context"},
{ACL_ERROR_RT_MODEL_CONTEXT, "model not in current context"},
{ACL_ERROR_RT_STREAM_MODEL, "stream not in model"},
{ACL_ERROR_RT_EVENT_TIMESTAMP_INVALID, "event timestamp invalid"},
{ACL_ERROR_RT_EVENT_TIMESTAMP_REVERSAL, " event timestamp reversal"},
{ACL_ERROR_RT_ADDR_UNALIGNED, "memory address unaligned"},
{ACL_ERROR_RT_FILE_OPEN, "open file failed"},
{ACL_ERROR_RT_FILE_WRITE, "write file failed"},
{ACL_ERROR_RT_STREAM_SUBSCRIBE, "error subscribe stream"},
{ACL_ERROR_RT_THREAD_SUBSCRIBE, "error subscribe thread"},
{ACL_ERROR_RT_GROUP_NOT_SET, "group not set"},
{ACL_ERROR_RT_GROUP_NOT_CREATE, "group not create"},
{ACL_ERROR_RT_STREAM_NO_CB_REG, "callback not register to stream"},
{ACL_ERROR_RT_INVALID_MEMORY_TYPE, "invalid memory type"},
{ACL_ERROR_RT_INVALID_HANDLE, "invalid handle"},
{ACL_ERROR_RT_INVALID_MALLOC_TYPE, "invalid malloc type"},
{ACL_ERROR_RT_FEATURE_NOT_SUPPORT, "feature not support"},
{ACL_ERROR_RT_MEMORY_ALLOCATION, "memory allocation error"},
{ACL_ERROR_RT_MEMORY_FREE, "memory free error"},
{ACL_ERROR_RT_AICORE_OVER_FLOW, "aicore over flow"},
{ACL_ERROR_RT_NO_DEVICE, "no device"},
{ACL_ERROR_RT_RESOURCE_ALLOC_FAIL, "resource alloc fail"},
{ACL_ERROR_RT_NO_PERMISSION, "no permission"},
{ACL_ERROR_RT_NO_EVENT_RESOURCE, "no event resource"},
{ACL_ERROR_RT_NO_STREAM_RESOURCE, "no stream resource"},
{ACL_ERROR_RT_NO_NOTIFY_RESOURCE, "no notify resource"},
{ACL_ERROR_RT_NO_MODEL_RESOURCE, "no model resource"},
{ACL_ERROR_RT_INTERNAL_ERROR, "runtime internal error"},
{ACL_ERROR_RT_TS_ERROR, "ts internal error"},
{ACL_ERROR_RT_STREAM_TASK_FULL, "task full in stream"},
{ACL_ERROR_RT_STREAM_TASK_EMPTY, " task empty in stream"},
{ACL_ERROR_RT_STREAM_NOT_COMPLETE, "stream not complete"},
{ACL_ERROR_RT_END_OF_SEQUENCE, "end of sequence"},
{ACL_ERROR_RT_EVENT_NOT_COMPLETE, "event not complete"},
{ACL_ERROR_RT_CONTEXT_RELEASE_ERROR, "context release error"},
{ACL_ERROR_RT_SOC_VERSION, "soc version error"},
{ACL_ERROR_RT_TASK_TYPE_NOT_SUPPORT, "task type not support"},
{ACL_ERROR_RT_LOST_HEARTBEAT, "ts lost heartbeat"},
{ACL_ERROR_RT_MODEL_EXECUTE, " model execute failed"},
{ACL_ERROR_RT_REPORT_TIMEOUT, "report timeout"},
{ACL_ERROR_RT_SYS_DMA, "sys dma error"},
{ACL_ERROR_RT_AICORE_TIMEOUT, "aicore timeout"},
{ACL_ERROR_RT_AICORE_EXCEPTION, "aicore exception"},
{ACL_ERROR_RT_AICORE_TRAP_EXCEPTION, " aicore trap exception"},
{ACL_ERROR_RT_AICPU_TIMEOUT, " aicpu timeout"},
{ACL_ERROR_RT_AICPU_EXCEPTION, "aicpu exception"},
{ACL_ERROR_RT_AICPU_DATADUMP_RSP_ERR, " aicpu datadump response error"},
{ACL_ERROR_RT_AICPU_MODEL_RSP_ERR, "aicpu model operate response error"},
{ACL_ERROR_RT_PROFILING_ERROR, "profiling error"},
{ACL_ERROR_RT_IPC_ERROR, "ipc error"},
{ACL_ERROR_RT_MODEL_ABORT_NORMAL, "model abort normal"},
{ACL_ERROR_RT_KERNEL_UNREGISTERING, "kernel unregistering"},
{ACL_ERROR_RT_RINGBUFFER_NOT_INIT, "ringbuffer not init"},
{ACL_ERROR_RT_RINGBUFFER_NO_DATA, "ringbuffer no data"},
{ACL_ERROR_RT_KERNEL_LOOKUP, "kernel lookup error"},
{ACL_ERROR_RT_KERNEL_DUPLICATE, "kernel register duplicate"},
{ACL_ERROR_RT_DEBUG_REGISTER_FAIL, "debug register failed"},
{ACL_ERROR_RT_DEBUG_UNREGISTER_FAIL, "debug unregister failed"},
{ACL_ERROR_RT_LABEL_CONTEXT, "label not in current context"},
{ACL_ERROR_RT_PROGRAM_USE_OUT, "program register num use out"},
{ACL_ERROR_RT_DEV_SETUP_ERROR, "device setup error"},
{ACL_ERROR_RT_DRV_INTERNAL_ERROR, "drv internal error"},
};
namespace mindspore {
std::string GetErrorMsg(uint32_t rt_error_code) {
auto find_iter = error_msg.find(rt_error_code);
if (find_iter == error_msg.end()) {
return "Return error code unknown, ret code: " + std::to_string(rt_error_code);
}
return find_iter->second;
}
} // namespace mindspore

View File

@ -26,53 +26,60 @@ parse_device()
# Parse device
# Process build option
if [[ "X$DEVICE" == "Xgpu" ]]; then
export ENABLE_GPU="on"
ENABLE_CPU="on"
ENABLE_MPI="on"
# version default 10.1
if [[ "X$DEVICE_VERSION" == "X" ]]; then
DEVICE_VERSION=10.1
fi
if [[ "X$DEVICE_VERSION" != "X11.6" && "X$DEVICE_VERSION" != "X11.1" && "X$DEVICE_VERSION" != "X10.1" ]]; then
echo "Invalid value ${DEVICE_VERSION} for option -V"
usage
exit 1
fi
export CUDA_VERSION="$DEVICE_VERSION"
export ENABLE_AKG="on"
elif [[ "X$DEVICE" == "Xd" || "X$DEVICE" == "Xascend" ]]; then
# version default 910
if [[ "X$DEVICE_VERSION" == "X" ]]; then
DEVICE_VERSION=910
fi
# building 310 package by giving specific -V 310 instruction
if [[ "X$DEVICE_VERSION" == "X310" ]]; then
ENABLE_ACL="on"
export ENABLE_AKG="off"
# universal ascend package
elif [[ "X$DEVICE_VERSION" == "X910" ]]; then
export ENABLE_D="on"
export ENABLE_ACL="on"
export IFS_ORIGIN=$IFS
export IFS=":"
for D in $DEVICE;
do
if [[ "X$D" == "Xgpu" ]]; then
export ENABLE_GPU="on"
ENABLE_CPU="on"
export ENABLE_MPI="on"
ENABLE_MPI="on"
# version default 10.1
if [[ "X$DEVICE_VERSION" == "X" ]]; then
DEVICE_VERSION=10.1
fi
if [[ "X$DEVICE_VERSION" != "X11.6" && "X$DEVICE_VERSION" != "X11.1" && "X$DEVICE_VERSION" != "X10.1" ]]; then
echo "Invalid value ${DEVICE_VERSION} for option -V"
usage
exit 1
fi
export CUDA_VERSION="$DEVICE_VERSION"
export ENABLE_AKG="on"
export DEVICE_VERSION=
elif [[ "X$D" == "Xd" || "X$D" == "Xascend" ]]; then
# version default 910
if [[ "X$DEVICE_VERSION" == "X" ]]; then
DEVICE_VERSION=910
fi
# building 310 package by giving specific -V 310 instruction
if [[ "X$DEVICE_VERSION" == "X310" ]]; then
ENABLE_ACL="on"
export ENABLE_AKG="off"
# universal ascend package
elif [[ "X$DEVICE_VERSION" == "X910" ]]; then
export ENABLE_D="on"
export ENABLE_ACL="on"
ENABLE_CPU="on"
export ENABLE_MPI="on"
export ENABLE_AKG="on"
else
echo "Invalid value ${DEVICE_VERSION} for option -V"
usage
exit 1
fi
export DEVICE_VERSION=
elif [[ "X$D" == "Xcpu" ]]; then
export ENABLE_CPU="on"
export ENABLE_AKG="on"
elif [[ "X$D" == "X" ]]; then
:
else
echo "Invalid value ${DEVICE_VERSION} for option -V"
echo "Invalid value ${DEVICE} for option -e"
usage
exit 1
fi
elif [[ "X$DEVICE" == "Xcpu" ]]; then
export ENABLE_CPU="on"
export ENABLE_AKG="on"
elif [[ "X$DEVICE" == "X" ]]; then
:
else
echo "Invalid value ${DEVICE} for option -e"
usage
exit 1
fi
done
export IFS=$IFS_ORIGIN
if [[ "X$ENABLE_AKG" == "Xon" && "X$ENABLE_D" != "Xon" && "X$ENABLE_CPU" == "Xon" ]]; then
# check llvm version for akg
HAS_LLVM=`bash ${BASEPATH}/scripts/build/akg_find_llvm.sh`

View File

@ -67,7 +67,7 @@ process_options()
export ENABLE_MAKE_CLEAN="$OPTARG"
echo "enable make clean" ;;
e)
export DEVICE=$OPTARG ;;
export DEVICE=$DEVICE:$OPTARG ;;
M)
check_on_off $OPTARG M
export ENABLE_MPI="$OPTARG" ;;