Skip to content

Commit

Permalink
[XPU] fix a bug incase prior_box_compute that max_size.size() might b…
Browse files Browse the repository at this point in the history
  • Loading branch information
chenchen59 authored and WeiLi233 committed Mar 29, 2022
1 parent a9919b7 commit dbaa520
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lite/kernels/xpu/prior_box_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,16 @@ void PriorBoxCompute::PrepareForRun() {
XPUMemcpyKind::XPU_HOST_TO_DEVICE));
min_size_num = min_size.size();

CHECK_LE(max_size.size(), 8);
xpu_max_sizes_guard_ = TargetWrapperXPU::MallocScratchPad(8 * sizeof(float));
XPU_CALL(xpu_memcpy(xpu_max_sizes_guard_->addr_,
max_size.data(),
max_size.size() * sizeof(float),
XPUMemcpyKind::XPU_HOST_TO_DEVICE));
max_size_num = max_size.size();
if (max_size_num > 0) {
CHECK_LE(max_size.size(), 8);
xpu_max_sizes_guard_ =
TargetWrapperXPU::MallocScratchPad(8 * sizeof(float));
XPU_CALL(xpu_memcpy(xpu_max_sizes_guard_->addr_,
max_size.data(),
max_size.size() * sizeof(float),
XPUMemcpyKind::XPU_HOST_TO_DEVICE));
}

CHECK_EQ(variance.size(), 4);
variance_xpu_guard_ = TargetWrapperXPU::MallocScratchPad(4 * sizeof(float));
Expand Down Expand Up @@ -125,7 +128,10 @@ void PriorBoxCompute::Run() {
float* xpu_aspect_ratios =
reinterpret_cast<float*>(xpu_aspect_ratios_guard_->addr_);
float* xpu_min_sizes = reinterpret_cast<float*>(xpu_min_sizes_guard_->addr_);
float* xpu_max_sizes = reinterpret_cast<float*>(xpu_max_sizes_guard_->addr_);
float* xpu_max_sizes =
(max_size_num > 0)
? (reinterpret_cast<float*>(xpu_max_sizes_guard_->addr_))
: nullptr;

int r = xdnn::prior_box_gen(ctx.GetRawContext(),
param.boxes->mutable_data<float>(TARGET(kXPU)),
Expand Down

0 comments on commit dbaa520

Please sign in to comment.