fix softdvpp coredump

This commit is contained in:
qianlong 2020-08-25 18:06:09 +08:00
parent 9e20e17590
commit bc8aec007f
5 changed files with 57 additions and 16 deletions

View File

@ -18,10 +18,22 @@
#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_dp_check.h"
#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_jpegd.h"
#include "minddata/dataset/kernels/image/soft_dvpp/utils/soft_vpc.h"
#include <thread>
const int32_t decodeSucc = 0;
const int32_t checkParamErr = 1;
const int32_t num2 = 2;
uint32_t DecodeAndResizeJpeg(SoftDpProcsessInfo *soft_dp_process_info) {
if (soft_dp_process_info == nullptr || soft_dp_process_info->input_buffer == nullptr ||
soft_dp_process_info->input_buffer_size <= 0 || soft_dp_process_info->output_buffer == nullptr ||
soft_dp_process_info->output_buffer_size <= 0) {
API_LOGE("The input buffer or out buffer is null or size is 0");
return checkParamErr;
}
if (soft_dp_process_info->output_width % 2 == 1 || soft_dp_process_info->output_height % 2 == 1) {
API_LOGE("odd width and height dose not support");
return checkParamErr;
}
VpcInfo vpc_input_info;
SoftJpegd soft_handler;
int32_t ret = soft_handler.JpegdSoftwareDecodeProcess(&vpc_input_info, soft_dp_process_info);
@ -47,6 +59,12 @@ uint32_t DecodeAndResizeJpeg(SoftDpProcsessInfo *soft_dp_process_info) {
}
uint32_t DecodeAndCropAndResizeJpeg(SoftDpProcsessInfo *soft_dp_process_info, const SoftDpCropInfo &crop_info) {
if (soft_dp_process_info == nullptr || soft_dp_process_info->input_buffer == nullptr ||
soft_dp_process_info->input_buffer_size <= 0 || soft_dp_process_info->output_buffer == nullptr ||
soft_dp_process_info->output_buffer_size <= 0) {
API_LOGE("The input buffer or out buffer is null or size is 0");
return checkParamErr;
}
VpcInfo vpc_input_info;
SoftJpegd soft_handler;
@ -63,6 +81,15 @@ uint32_t DecodeAndCropAndResizeJpeg(SoftDpProcsessInfo *soft_dp_process_info, co
output.height = soft_dp_process_info->output_height;
SoftDpCropInfo crop = crop_info;
if ((vpc_input_info.real_width % num2 == 1) && ((uint32_t)vpc_input_info.real_width == crop.right)) {
API_LOGD("crop width is equal the real width.");
crop.right = vpc_input_info.real_width - 1;
}
if ((vpc_input_info.real_height % num2 == 1) && ((uint32_t)vpc_input_info.real_height == crop.down)) {
API_LOGD("crop height is equal the real height.");
crop.down = vpc_input_info.real_height - 1;
}
SoftVpc soft_vpc;
ret = soft_vpc.Process(vpc_input_info, crop, output);
return ret;

View File

@ -26,6 +26,7 @@
#include <cstdint>
#include <cstdio>
#include <string>
#include <thread>
const uint32_t yuv400UvValue = 0x80;
const int32_t num2 = 2;
@ -129,13 +130,17 @@ uint32_t SoftJpegd::AllocOutputBuffer(struct VpcInfo *vpc_input_info, int32_t *w
int32_t *sub_sample) {
CheckInputParam(*height, *width);
uint32_t output_size = tjBufSizeYUV2(*width, decodePadding, *height, *sub_sample);
JPEGD_LOGD("In this case the format= %d, output size=%d, real width=%d, the real height=%d, thread_id=%lu.",
vpc_input_info->format, output_size, *width, *height, std::this_thread::get_id());
if (output_size == zeroBufSize) {
JPEGD_LOGE("get outbuffer size failed!");
return decodeErr;
}
if (vpc_input_info->is_fake420) {
output_size = output_size * channel3 / num2;
*width = AlignUp(*width, num2);
*height = AlignUp(*height, num2);
output_size = (*width) * (*height) * channel3 / num2;
}
soft_decode_out_buf_ = new (std::nothrow) uint8_t[output_size];
@ -172,7 +177,8 @@ uint32_t SoftJpegd::ConfigVpcInputData(struct VpcInfo *vpc_input_info, int32_t *
int32_t uv_size = vpc_input_info->width * vpc_input_info->height / num2;
int32_t safe_ret = memset_s(reinterpret_cast<void *>((uintptr_t)u_start), uv_size, yuv400UvValue, uv_size);
if (safe_ret != 0) {
JPEGD_LOGE("config yuv400 uv memory failed.");
JPEGD_LOGE("config yuv400 uv memory failed.addr = 0x%llx, thread id = %lu", soft_decode_out_buf_,
std::this_thread::get_id());
delete[] soft_decode_out_buf_;
soft_decode_out_buf_ = nullptr;
vpc_input_info->addr = nullptr;
@ -229,7 +235,8 @@ uint32_t SoftJpegd::JpegdSoftwareDecodeProcess(struct VpcInfo *vpc_input_info,
tjDecompressToYUV2(handle, soft_dp_process_info->input_buffer, soft_dp_process_info->input_buffer_size,
soft_decode_out_buf_, width, decodePadding, height, JDCT_ISLOW);
if (decode_res != decodeSucc) {
JPEGD_LOGE("Decompress jpeg failed.");
JPEGD_LOGE("Decompress jpeg failed, addr is 0x%llx, thread id= %lu.", soft_decode_out_buf_,
std::this_thread::get_id());
delete[] soft_decode_out_buf_;
soft_decode_out_buf_ = nullptr;
DestoryLibjpegSource(&libjpeg_handler, handle);

View File

@ -109,21 +109,21 @@ int32_t SoftVpc::CheckParamter() {
uint32_t out_width = out_width_;
uint32_t out_height = out_height_;
bool flag = (out_width * 16 >= crop_width) ? true : false; // Up to 16x magnification
bool flag = (out_width * 32 >= crop_width) ? true : false; // A maximum of 32x zoom-out
VPC_CHECK_COND_FAIL_PRINT_RETURN(flag, dpFail,
"Max reduction multiple is 32. Please check left(%u), right(%u), out_width(%u).",
left_, right_, out_width); // Up to 16x magnification
flag = (crop_width * 16 >= out_width) ? true : false;
VPC_CHECK_COND_FAIL_PRINT_RETURN(flag, dpFail,
"Max magnification is 16. Please check left(%u), right(%u), out_width(%u).", left_,
right_, out_width);
flag = (crop_width * 32 >= out_width) ? true : false; // A maximum of 32x zoom-out
VPC_CHECK_COND_FAIL_PRINT_RETURN(flag, dpFail,
"Max reduction multiple is 32. Please check left(%u), right(%u), out_width(%u).",
left_, right_, out_width);
flag = (out_height * 16 >= crop_height) ? true : false; // Up to 16x magnification
VPC_CHECK_COND_FAIL_PRINT_RETURN(
flag, dpFail, "Max magnification is 16. Please check up(%u), down(%u), out_height(%u).", up_, down_, out_height);
flag = (crop_height * 32 >= out_height) ? true : false; // A maximum of 32x zoom-out
flag = (out_height * 32 >= crop_height) ? true : false; // A maximum of 32x zoom-out
VPC_CHECK_COND_FAIL_PRINT_RETURN(flag, dpFail,
"Max reduction multiple is 32. Please check up(%u), down(%u), out_height(%u).", up_,
down_, out_height);
flag = (crop_height * 16 >= out_height) ? true : false; // Up to 16x magnification
VPC_CHECK_COND_FAIL_PRINT_RETURN(
flag, dpFail, "Max magnification is 16. Please check up(%u), down(%u), out_height(%u).", up_, down_, out_height);
return dpSucc;
}

View File

@ -980,6 +980,9 @@ class SoftDvppDecodeResizeJpeg(cde.SoftDvppDecodeResizeJpegOp):
When training, the DVPP of the ascend chip is not used,
and the DVPP of the ascend chip is used during inference,
and the accuracy of inference is lower than the accuracy of training.
And the input image size should be in range [32*32, 8192*8192].
The zoom-out and zoom-in multiples of the image length and width should in range [1/32, 16].
Only images with an even resolution can be output. The output of odd resolution is not supported.
Args:
size (Union[int, sequence]): The output size of the resized image.
@ -1002,6 +1005,9 @@ class SoftDvppDecodeRandomCropResizeJpeg(cde.SoftDvppDecodeRandomCropResizeJpegO
ascend series chip DVPP module.
The usage scenario is consistent with SoftDvppDecodeReiszeJpeg.
And the input image size should be in range [32*32, 8192*8192].
The zoom-out and zoom-in multiples of the image length and width should in range [1/32, 16].
Only images with an even resolution can be output. The output of odd resolution is not supported.
Args:
size (Union[int, sequence]): The size of the output image.

View File

@ -84,6 +84,7 @@ def test_soft_dvpp_decode_random_crop_resize_jpeg(plot=False):
visualize_image(image1, image2, mse)
num_iter += 1
def test_soft_dvpp_decode_resize_jpeg_supplement(plot=False):
"""
Test SoftDvppDecodeResizeJpeg op
@ -93,12 +94,12 @@ def test_soft_dvpp_decode_resize_jpeg_supplement(plot=False):
# First dataset
data1 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
decode_op = vision.Decode()
resize_op = vision.Resize(256)
resize_op = vision.Resize(1134)
data1 = data1.map(input_columns=["image"], operations=[decode_op, resize_op])
# Second dataset
data2 = ds.TFRecordDataset(DATA_DIR, SCHEMA_DIR, columns_list=["image"], shuffle=False)
soft_dvpp_decode_resize_op = vision.SoftDvppDecodeResizeJpeg(256)
soft_dvpp_decode_resize_op = vision.SoftDvppDecodeResizeJpeg(1134)
data2 = data2.map(input_columns=["image"], operations=soft_dvpp_decode_resize_op)
num_iter = 0
@ -114,8 +115,8 @@ def test_soft_dvpp_decode_resize_jpeg_supplement(plot=False):
visualize_image(image1, image2, mse)
num_iter += 1
if __name__ == "__main__":
test_soft_dvpp_decode_resize_jpeg(plot=True)
test_soft_dvpp_decode_random_crop_resize_jpeg(plot=True)
test_soft_dvpp_decode_resize_jpeg_supplement(plot=True)