| @@ -94,5 +94,9 @@ Status AscendResource::DeviceDataRelease() { | |||
| std::shared_ptr<void> AscendResource::GetInstance() { return processor_; } | |||
| void *AscendResource::GetContext() { return processor_->GetContext(); } | |||
| void *AscendResource::GetStream() { return processor_->GetStream(); } | |||
| } // namespace dataset | |||
| } // namespace mindspore | |||
| @@ -48,6 +48,10 @@ class AscendResource : public DeviceResource { | |||
| Status DeviceDataRelease() override; | |||
| void *GetContext() override; | |||
| void *GetStream() override; | |||
| private: | |||
| std::shared_ptr<MDAclProcess> processor_; | |||
| std::shared_ptr<ResourceManager> ascend_resource_; | |||
| @@ -54,5 +54,17 @@ std::shared_ptr<void> DeviceResource::GetInstance() { | |||
| return nullptr; | |||
| } | |||
| void *DeviceResource::GetContext() { | |||
| MS_LOG(ERROR) | |||
| << "Is this a device which contains context resource? If yes, please implement GetContext() in the derived class"; | |||
| return nullptr; | |||
| } | |||
| void *DeviceResource::GetStream() { | |||
| MS_LOG(ERROR) | |||
| << "Is this a device which contains stream resource? If yes, please implement GetContext() in the derived class"; | |||
| return nullptr; | |||
| } | |||
| } // namespace dataset | |||
| } // namespace mindspore | |||
| @@ -44,6 +44,10 @@ class DeviceResource { | |||
| virtual std::shared_ptr<void> GetInstance(); | |||
| virtual Status DeviceDataRelease(); | |||
| virtual void *GetContext(); | |||
| virtual void *GetStream(); | |||
| }; | |||
| } // namespace dataset | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Copyright (c) 2020.Huawei Technologies Co., Ltd. All rights reserved. | |||
| * Copyright (c) 2020-2021.Huawei Technologies Co., Ltd. All rights reserved. | |||
| * 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 | |||
| @@ -25,7 +25,8 @@ static auto g_picDescDeleter = [](acldvppPicDesc *picDesc) { acldvppDestroyPicDe | |||
| static auto g_roiConfigDeleter = [](acldvppRoiConfig *p) { acldvppDestroyRoiConfig(p); }; | |||
| static auto g_jpegeConfigDeleter = [](acldvppJpegeConfig *p) { acldvppDestroyJpegeConfig(p); }; | |||
| DvppCommon::DvppCommon(aclrtStream dvppStream) : dvppStream_(dvppStream) {} | |||
| DvppCommon::DvppCommon(aclrtContext dvppContext, aclrtStream dvppStream) | |||
| : dvppContext_(dvppContext), dvppStream_(dvppStream) {} | |||
| DvppCommon::DvppCommon(const VdecConfig &vdecConfig) : vdecConfig_(vdecConfig) {} | |||
| @@ -37,10 +38,11 @@ DvppCommon::DvppCommon(const VdecConfig &vdecConfig) : vdecConfig_(vdecConfig) { | |||
| APP_ERROR DvppCommon::Init(void) { | |||
| dvppChannelDesc_ = acldvppCreateChannelDesc(); | |||
| if (dvppChannelDesc_ == nullptr) { | |||
| return -1; | |||
| return APP_ERR_COMM_INVALID_POINTER; | |||
| } | |||
| APP_ERROR ret = acldvppCreateChannel(dvppChannelDesc_); | |||
| if (ret != 0) { | |||
| if (ret != APP_ERR_OK) { | |||
| MS_LOG(ERROR) << "Failed to create dvpp channel: " << GetAppErrCodeInfo(ret) << "."; | |||
| acldvppDestroyChannelDesc(dvppChannelDesc_); | |||
| dvppChannelDesc_ = nullptr; | |||
| @@ -117,7 +119,14 @@ APP_ERROR DvppCommon::DeInit(void) { | |||
| return DestroyResource(); | |||
| } | |||
| APP_ERROR ret = aclrtSynchronizeStream(dvppStream_); // APP_ERROR ret | |||
| // Obtain the dvppContext_ allocated by AscendResource which contains the dvppStream_, they mush bind each other | |||
| APP_ERROR ret = aclrtSetCurrentContext(dvppContext_); | |||
| if (ret != APP_ERR_OK) { | |||
| MS_LOG(ERROR) << "Failed to get ACL context, ret = " << ret; | |||
| return ret; | |||
| } | |||
| ret = aclrtSynchronizeStream(dvppStream_); // APP_ERROR ret | |||
| if (ret != APP_ERR_OK) { | |||
| MS_LOG(ERROR) << "Failed to synchronize stream, ret = " << ret << "."; | |||
| return ret; | |||
| @@ -1292,13 +1301,18 @@ APP_ERROR DvppCommon::SinkImageH2D(const RawData &imageInfo, acldvppPixelFormat | |||
| return APP_ERR_DVPP_OBJ_FUNC_MISMATCH; | |||
| } | |||
| APP_ERROR ret = aclrtSetCurrentContext(dvppContext_); | |||
| if (ret != APP_ERR_OK) { | |||
| MS_LOG(ERROR) << "Failed to get ACL context, ret = " << ret; | |||
| return ret; | |||
| } | |||
| int32_t components; | |||
| // Member variable of inputImage_, uint8_t *data will be on device | |||
| inputImage_ = std::make_shared<DvppDataInfo>(); | |||
| inputImage_->format = format; | |||
| APP_ERROR ret = | |||
| // GetJpegImageInfo(imageInfo.data.get(), imageInfo.lenOfByte, inputImage_->width, inputImage_->height, components); | |||
| GetJpegImageInfo(imageInfo.data, imageInfo.lenOfByte, inputImage_->width, inputImage_->height, components); | |||
| ret = GetJpegImageInfo(imageInfo.data, imageInfo.lenOfByte, inputImage_->width, inputImage_->height, components); | |||
| if (ret != APP_ERR_OK) { | |||
| MS_LOG(ERROR) << "Failed to get input image info, ret = " << ret << "."; | |||
| return ret; | |||
| @@ -1345,12 +1359,18 @@ APP_ERROR DvppCommon::SinkImageH2D(const RawData &imageInfo) { | |||
| return APP_ERR_DVPP_OBJ_FUNC_MISMATCH; | |||
| } | |||
| APP_ERROR ret = aclrtSetCurrentContext(dvppContext_); | |||
| if (ret != APP_ERR_OK) { | |||
| MS_LOG(ERROR) << "Failed to get ACL context, ret = " << ret; | |||
| return ret; | |||
| } | |||
| int32_t components; | |||
| inputImage_ = std::make_shared<DvppDataInfo>(); | |||
| acldvppPixelFormat format = PIXEL_FORMAT_RGB_888; | |||
| inputImage_->format = format; | |||
| APP_ERROR ret = | |||
| GetPngImageInfo(imageInfo.data, imageInfo.lenOfByte, inputImage_->width, inputImage_->height, components); | |||
| ret = GetPngImageInfo(imageInfo.data, imageInfo.lenOfByte, inputImage_->width, inputImage_->height, components); | |||
| if (ret != APP_ERR_OK) { | |||
| MS_LOG(ERROR) << "Failed to get input image info, ret = " << ret << "."; | |||
| return ret; | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Copyright (c) 2020.Huawei Technologies Co., Ltd. All rights reserved. | |||
| * Copyright (c) 2020-2021.Huawei Technologies Co., Ltd. All rights reserved. | |||
| * 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 | |||
| @@ -117,7 +117,7 @@ const uint8_t YUV_GREYER_VALUE = 128; // Filling value of the resized YUV im | |||
| class DvppCommon { | |||
| public: | |||
| explicit DvppCommon(aclrtStream dvppStream); | |||
| explicit DvppCommon(aclrtContext dvppContext, aclrtStream dvppStream); | |||
| explicit DvppCommon(const VdecConfig &vdecConfig); // Need by vdec | |||
| ~DvppCommon(); | |||
| APP_ERROR Init(void); | |||
| @@ -235,7 +235,11 @@ class DvppCommon { | |||
| std::shared_ptr<acldvppPicDesc> decodeOutputDesc_ = nullptr; | |||
| acldvppChannelDesc *dvppChannelDesc_ = nullptr; | |||
| // Ascend resource core: (context, stream) is a pair so must bind with each other to make all function perform well | |||
| aclrtContext dvppContext_ = nullptr; | |||
| aclrtStream dvppStream_ = nullptr; | |||
| std::shared_ptr<DvppDataInfo> inputImage_ = nullptr; | |||
| std::shared_ptr<DvppDataInfo> decodedImage_ = nullptr; | |||
| std::shared_ptr<DvppDataInfo> encodedImage_ = nullptr; | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Copyright (c) 2020.Huawei Technologies Co., Ltd. All rights reserved. | |||
| * Copyright (c) 2020-2021.Huawei Technologies Co., Ltd. All rights reserved. | |||
| * 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 | |||
| @@ -112,7 +112,7 @@ APP_ERROR MDAclProcess::Release() { | |||
| */ | |||
| APP_ERROR MDAclProcess::InitModule() { | |||
| // Create Dvpp JpegD object | |||
| dvppCommon_ = std::make_shared<DvppCommon>(stream_); | |||
| dvppCommon_ = std::make_shared<DvppCommon>(context_, stream_); | |||
| if (dvppCommon_ == nullptr) { | |||
| MS_LOG(ERROR) << "Failed to create dvppCommon_ object"; | |||
| return APP_ERR_COMM_INIT_FAIL; | |||
| @@ -153,20 +153,31 @@ APP_ERROR MDAclProcess::InitResource() { | |||
| std::shared_ptr<DvppCommon> MDAclProcess::GetDeviceModule() { return dvppCommon_; } | |||
| aclrtContext MDAclProcess::GetContext() { return context_; } | |||
| aclrtStream MDAclProcess::GetStream() { return stream_; } | |||
| /* | |||
| * Sink data from Tensor(On host) to DeviceTensor(On device) | |||
| * Two cases are different, jpeg and png | |||
| */ | |||
| APP_ERROR MDAclProcess::H2D_Sink(const std::shared_ptr<mindspore::dataset::Tensor> &input, | |||
| std::shared_ptr<mindspore::dataset::DeviceTensor> &device_input) { | |||
| // Recall the context created in InitResource() | |||
| APP_ERROR ret = aclrtSetCurrentContext(context_); | |||
| if (ret != APP_ERR_OK) { | |||
| MS_LOG(ERROR) << "Failed to get ACL context, ret = " << ret; | |||
| return ret; | |||
| } | |||
| RawData imageinfo; | |||
| uint32_t filesize = input->SizeInBytes(); | |||
| // MS_LOG(INFO) << "Filesize on host is: " << filesize; | |||
| imageinfo.lenOfByte = filesize; | |||
| unsigned char *buffer = const_cast<unsigned char *>(input->GetBuffer()); | |||
| imageinfo.data = static_cast<void *>(buffer); | |||
| // Transfer RawData(Raw image) from host to device, which we call sink | |||
| APP_ERROR ret; | |||
| if (IsNonEmptyJPEG(input)) { // case JPEG | |||
| ret = dvppCommon_->SinkImageH2D(imageinfo, PIXEL_FORMAT_YUV_SEMIPLANAR_420); | |||
| } else { // case PNG | |||
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Copyright (c) 2020.Huawei Technologies Co., Ltd. All rights reserved. | |||
| * Copyright (c) 2020-2021.Huawei Technologies Co., Ltd. All rights reserved. | |||
| * 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 | |||
| @@ -57,6 +57,10 @@ class MDAclProcess { | |||
| APP_ERROR Release(); | |||
| // Create resource for this sample | |||
| APP_ERROR InitResource(); | |||
| // Get Ascend Resource core: context and stream which are created when InitResource() | |||
| aclrtContext GetContext(); | |||
| aclrtContext GetStream(); | |||
| // Process the result | |||
| APP_ERROR JPEG_DRC(const RawData &ImageInfo); | |||
| APP_ERROR JPEG_DRC(); | |||