提交 d1b53a88 编写于 作者: C chenjiaoAngel

fix format. test=develop

上级 bdbca339
...@@ -41,7 +41,8 @@ class BoxCoderComputeImage : public KernelLite<TARGET(kOpenCL), ...@@ -41,7 +41,8 @@ class BoxCoderComputeImage : public KernelLite<TARGET(kOpenCL),
boxcoder_param_->box_normalized == true) { boxcoder_param_->box_normalized == true) {
kernel_func_name_ = "decode_center_size"; kernel_func_name_ = "decode_center_size";
} else { } else {
printf("This code_type %s doesn't support \n", boxcoder_param_->code_type.c_str()); printf("This code_type %s doesn't support \n",
boxcoder_param_->code_type.c_str());
return; return;
} }
CHECK(context.cl_context() != nullptr); CHECK(context.cl_context() != nullptr);
...@@ -69,7 +70,8 @@ class BoxCoderComputeImage : public KernelLite<TARGET(kOpenCL), ...@@ -69,7 +70,8 @@ class BoxCoderComputeImage : public KernelLite<TARGET(kOpenCL),
const auto& code_type = boxcoder_param_->code_type; const auto& code_type = boxcoder_param_->code_type;
if (code_type == "decode_center_size") { if (code_type == "decode_center_size") {
auto* prior_box_image = input_priorbox->data<half_t, cl::Image2D>(); auto* prior_box_image = input_priorbox->data<half_t, cl::Image2D>();
auto* prior_box_var_image = input_priorboxvar->data<half_t, cl::Image2D>(); auto* prior_box_var_image =
input_priorboxvar->data<half_t, cl::Image2D>();
auto* target_box_image = input_targetbox->data<half_t, cl::Image2D>(); auto* target_box_image = input_targetbox->data<half_t, cl::Image2D>();
int new_dims[4] = {1, 1, 1, 1}; int new_dims[4] = {1, 1, 1, 1};
...@@ -82,19 +84,18 @@ class BoxCoderComputeImage : public KernelLite<TARGET(kOpenCL), ...@@ -82,19 +84,18 @@ class BoxCoderComputeImage : public KernelLite<TARGET(kOpenCL),
kernel_key << kernel_func_name_ << build_options_; kernel_key << kernel_func_name_ << build_options_;
auto kernel = context.cl_context()->GetKernel(kernel_key.str()); auto kernel = context.cl_context()->GetKernel(kernel_key.str());
auto default_work_size = DefaultWorkSize(out_dims, auto default_work_size =
DDim(std::vector<DDim::value_type>{ DefaultWorkSize(out_dims,
static_cast<int64_t>(image_shape["width"]), DDim(std::vector<DDim::value_type>{
static_cast<int64_t>(image_shape["height"])})); static_cast<int64_t>(image_shape["width"]),
static_cast<int64_t>(image_shape["height"])}));
int out_C = new_dims[1]; int out_C = new_dims[1];
int out_H = new_dims[2]; int out_H = new_dims[2];
#ifndef LITE_SHUTDOWN_LOG #ifndef LITE_SHUTDOWN_LOG
VLOG(4) << TargetToStr(boxcoder_param_->proposals->target()); VLOG(4) << TargetToStr(boxcoder_param_->proposals->target());
VLOG(4) << "output shape: " << out_dims[0] << ", " VLOG(4) << "output shape: " << out_dims[0] << ", " << out_dims[1] << ", "
<< out_dims[1] << ", " << out_dims[2] << ", " << out_dims[3];
<< out_dims[2] << ", "
<< out_dims[3];
VLOG(4) << "image_shape(w,h):" << image_shape["width"] << " " VLOG(4) << "image_shape(w,h):" << image_shape["width"] << " "
<< image_shape["height"]; << image_shape["height"];
VLOG(4) << "out_C = " << out_C; VLOG(4) << "out_C = " << out_C;
......
...@@ -104,11 +104,10 @@ TEST(box_coder_image2d, compute) { ...@@ -104,11 +104,10 @@ TEST(box_coder_image2d, compute) {
LOG(INFO) << "======== parameters: norm = " << norm LOG(INFO) << "======== parameters: norm = " << norm
<< ", axis = " << axis << "code_type: " << code_type; << ", axis = " << axis << "code_type: " << code_type;
auto kernels = KernelRegistry::Global().Create( auto kernels = KernelRegistry::Global().Create("box_coder",
"box_coder", TARGET(kOpenCL),
TARGET(kOpenCL), PRECISION(kFP16),
PRECISION(kFP16), DATALAYOUT(kImageDefault));
DATALAYOUT(kImageDefault));
ASSERT_FALSE(kernels.empty()); ASSERT_FALSE(kernels.empty());
auto kernel = std::move(kernels.front()); auto kernel = std::move(kernels.front());
LOG(INFO) << "get kernel:" << kernel->doc(); LOG(INFO) << "get kernel:" << kernel->doc();
...@@ -147,7 +146,8 @@ TEST(box_coder_image2d, compute) { ...@@ -147,7 +146,8 @@ TEST(box_coder_image2d, compute) {
output_box.Resize(out_dim); output_box.Resize(out_dim);
std::vector<float> prior_box_data(prior_box_dims.production()); std::vector<float> prior_box_data(prior_box_dims.production());
std::vector<float> prior_box_var_data(prior_box_var_dims.production()); std::vector<float> prior_box_var_data(
prior_box_var_dims.production());
std::vector<float> target_box_data(target_box_dims.production()); std::vector<float> target_box_data(target_box_dims.production());
for (int i = 0; i < prior_box_dims.production(); i++) { for (int i = 0; i < prior_box_dims.production(); i++) {
prior_box_data[i] = i * 1.1 / prior_box_dims.production(); prior_box_data[i] = i * 1.1 / prior_box_dims.production();
...@@ -164,14 +164,13 @@ TEST(box_coder_image2d, compute) { ...@@ -164,14 +164,13 @@ TEST(box_coder_image2d, compute) {
new CLImageConverterDefault(); new CLImageConverterDefault();
DDim prior_box_image_shape = DDim prior_box_image_shape =
default_converter->InitImageDimInfoWith(prior_box_dims); default_converter->InitImageDimInfoWith(prior_box_dims);
LOG(INFO) << "prior_box_image_shape = " << prior_box_image_shape[0] << " " LOG(INFO) << "prior_box_image_shape = " << prior_box_image_shape[0]
<< prior_box_image_shape[1]; << " " << prior_box_image_shape[1];
std::vector<half_t> prior_box_image_data( std::vector<half_t> prior_box_image_data(
prior_box_image_shape.production() * 4); // 4 : RGBA prior_box_image_shape.production() * 4); // 4 : RGBA
default_converter->NCHWToImage( default_converter->NCHWToImage(prior_box_data.data(),
prior_box_data.data(), prior_box_image_data.data(),
prior_box_image_data.data(), prior_box_dims);
prior_box_dims);
auto* prior_box_image = prior_box.mutable_data<half_t, cl::Image2D>( auto* prior_box_image = prior_box.mutable_data<half_t, cl::Image2D>(
prior_box_image_shape[0], prior_box_image_shape[0],
prior_box_image_shape[1], prior_box_image_shape[1],
...@@ -179,33 +178,34 @@ TEST(box_coder_image2d, compute) { ...@@ -179,33 +178,34 @@ TEST(box_coder_image2d, compute) {
DDim prior_box_var_image_shape = DDim prior_box_var_image_shape =
default_converter->InitImageDimInfoWith(prior_box_var_dims); default_converter->InitImageDimInfoWith(prior_box_var_dims);
LOG(INFO) << "prior_box_var_image_shape = " << prior_box_var_image_shape[0] << " " LOG(INFO) << "prior_box_var_image_shape = " << prior_box_var_image_shape[0]
<< prior_box_var_image_shape[1]; << " " << prior_box_var_image_shape[1];
std::vector<half_t> prior_box_var_image_data( std::vector<half_t> prior_box_var_image_data(
prior_box_var_image_shape.production() * 4); // 4 : RGBA prior_box_var_image_shape.production() * 4); // 4 : RGBA
default_converter->NCHWToImage( default_converter->NCHWToImage(prior_box_var_data.data(),
prior_box_var_data.data(), prior_box_var_image_data.data(),
prior_box_var_image_data.data(), prior_box_var_dims);
prior_box_var_dims); auto* prior_box_var_image =
auto* prior_box_var_image = prior_box_var.mutable_data<half_t, cl::Image2D>( prior_box_var.mutable_data<half_t, cl::Image2D>(
prior_box_var_image_shape[0], prior_box_var_image_shape[0],
prior_box_var_image_shape[1], prior_box_var_image_shape[1],
prior_box_var_image_data.data()); prior_box_var_image_data.data());
DDim target_box_image_shape = DDim target_box_image_shape =
default_converter->InitImageDimInfoWith(target_box_dims); default_converter->InitImageDimInfoWith(target_box_dims);
LOG(INFO) << "target_box_image_shape = " << target_box_image_shape[0] << " " LOG(INFO) << "target_box_image_shape = "
<< target_box_image_shape[0] << " "
<< target_box_image_shape[1]; << target_box_image_shape[1];
std::vector<half_t> target_box_image_data( std::vector<half_t> target_box_image_data(
target_box_image_shape.production() * 4); // 4 : RGBA target_box_image_shape.production() * 4); // 4 : RGBA
default_converter->NCHWToImage( default_converter->NCHWToImage(target_box_data.data(),
target_box_data.data(), target_box_image_data.data(),
target_box_image_data.data(), target_box_dims);
target_box_dims); auto* target_box_image =
auto* target_box_image = target_box.mutable_data<half_t, cl::Image2D>( target_box.mutable_data<half_t, cl::Image2D>(
target_box_image_shape[0], target_box_image_shape[0],
target_box_image_shape[1], target_box_image_shape[1],
target_box_image_data.data()); target_box_image_data.data());
DDim out_image_shape = DDim out_image_shape =
default_converter->InitImageDimInfoWith(out_dim); default_converter->InitImageDimInfoWith(out_dim);
...@@ -220,12 +220,12 @@ TEST(box_coder_image2d, compute) { ...@@ -220,12 +220,12 @@ TEST(box_coder_image2d, compute) {
auto it = wait_list->find(out_ptr); auto it = wait_list->find(out_ptr);
if (it != wait_list->end()) { if (it != wait_list->end()) {
VLOG(4) << "--- Find the sync event for the target cl " VLOG(4) << "--- Find the sync event for the target cl "
"tensor. ---"; "tensor. ---";
auto& event = *(it->second); auto& event = *(it->second);
event.wait(); event.wait();
} else { } else {
LOG(FATAL) << "Could not find the sync event for the " LOG(FATAL) << "Could not find the sync event for the "
"target cl tensor."; "target cl tensor.";
} }
lite::Tensor out_ref_tensor; lite::Tensor out_ref_tensor;
...@@ -243,7 +243,7 @@ TEST(box_coder_image2d, compute) { ...@@ -243,7 +243,7 @@ TEST(box_coder_image2d, compute) {
const size_t cl_image2d_row_pitch{0}; const size_t cl_image2d_row_pitch{0};
const size_t cl_image2d_slice_pitch{0}; const size_t cl_image2d_slice_pitch{0};
half_t* out_image_data = half_t* out_image_data =
new half_t[out_image_shape.production() * 4]; new half_t[40000]; // [out_image_shape.production() * 4];
TargetWrapperCL::ImgcpySync(out_image_data, TargetWrapperCL::ImgcpySync(out_image_data,
out_image, out_image,
out_image_shape[0], out_image_shape[0],
...@@ -269,24 +269,23 @@ TEST(box_coder_image2d, compute) { ...@@ -269,24 +269,23 @@ TEST(box_coder_image2d, compute) {
COMPUTE_RELATIVE_DIFF(out_data[i], out_ref[i]); COMPUTE_RELATIVE_DIFF(out_data[i], out_ref[i]);
EXPECT_EQ((relative_diff <= FP16_MAX_DIFF) || EXPECT_EQ((relative_diff <= FP16_MAX_DIFF) ||
(abs_diff <= FP16_MAX_DIFF), (abs_diff <= FP16_MAX_DIFF),
true); true);
if ((relative_diff > FP16_MAX_DIFF) && if ((relative_diff > FP16_MAX_DIFF) &&
(abs_diff > FP16_MAX_DIFF)) { (abs_diff > FP16_MAX_DIFF)) {
LOG(ERROR) << "error idx:" << i << ", in_data[" << i LOG(ERROR) << "error idx:" << i << ", in_data[" << i
<< "]: " << target_box_data[i] << ", out_data[" << i << "]: " << target_box_data[i] << ", out_data[" << i
<< "]: " << out_data[i] << ", out_ref[" << i << "]: " << out_data[i] << ", out_ref[" << i
<< "]: " << out_ref[i] << "]: " << out_ref[i] << ", abs_diff: " << abs_diff
<< ", abs_diff: " << abs_diff
<< ", relative_diff: " << relative_diff << ", relative_diff: " << relative_diff
<< ", FP16_MAX_DIFF: " << FP16_MAX_DIFF; << ", FP16_MAX_DIFF: " << FP16_MAX_DIFF;
} }
} }
#ifdef BOXCODER_FP16_LOOP_TEST #ifdef BOXCODER_FP16_LOOP_TEST
} // axis } // axis
} // code_type } // code_type
} // norm } // norm
} // m } // m
} // n } // n
#else #else
// nothing to do. // nothing to do.
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册