Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions lite/kernels/xpu/__xpu__conv2d_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,20 @@ bool QuantFilter<int8_t>(const float* filter_on_host,

template <typename T, PrecisionType PType>
void XPUConv2dCompute<T, PType>::PrepareForRun() {
auto& ctx = this->ctx_->template As<XPUContext>();
auto& param = this->template Param<param_t>();
auto filter_ptr = param.filter->template data<float>();
auto filter_len = param.filter->numel();
// max
float max_f = paddle::lite::xpu::math::FindMaxAbs(filter_ptr, filter_len);
std::vector<float> max_f_v(4, max_f);
filter_max_guard_ = TargetWrapperXPU::MallocScratchPad(4 * sizeof(float));
int max_ptr_size = get_max_ptr_size(ctx.GetRawContext());
std::vector<float> max_f_v(max_ptr_size, max_f);
filter_max_guard_ =
TargetWrapperXPU::MallocScratchPad(max_ptr_size * sizeof(float));
filter_max_ = reinterpret_cast<float*>(filter_max_guard_->addr_);
XPU_CALL(xpu_memcpy(filter_max_,
max_f_v.data(),
4 * sizeof(float),
max_ptr_size * sizeof(float),
XPUMemcpyKind::XPU_HOST_TO_DEVICE));
// quant
quant_filter_guard_ =
Expand Down
14 changes: 8 additions & 6 deletions lite/kernels/xpu/__xpu__fc_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace kernels {
namespace xpu {

void XPUFcCompute::PrepareForRun() {
auto& ctx = this->ctx_->As<XPUContext>();
auto& param = this->Param<param_t>();
auto w_ptr = param.w->data<float>();
auto w_len = param.w->numel();
Expand All @@ -36,15 +37,16 @@ void XPUFcCompute::PrepareForRun() {
// max
if (!quant_int8) {
w_max = paddle::lite::xpu::math::FindMaxAbs(w_ptr, w_len);
std::vector<float> w_max_v(lite::XPU_QUANT_SCALE_NUM, w_max);
weight_max_guard_ = TargetWrapperXPU::MallocScratchPad(
lite::XPU_QUANT_SCALE_NUM * sizeof(float));
int max_ptr_size = get_max_ptr_size(ctx.GetRawContext());
std::vector<float> w_max_v(max_ptr_size, w_max);
weight_max_guard_ =
TargetWrapperXPU::MallocScratchPad(max_ptr_size * sizeof(float));
XPU_CALL(xpu_memcpy(reinterpret_cast<float*>(weight_max_guard_->addr_),
w_max_v.data(),
lite::XPU_QUANT_SCALE_NUM * sizeof(float),
max_ptr_size * sizeof(float),
XPUMemcpyKind::XPU_HOST_TO_DEVICE));
input_max_guard_ = TargetWrapperXPU::MallocScratchPad(
lite::XPU_QUANT_SCALE_NUM * sizeof(float));
input_max_guard_ =
TargetWrapperXPU::MallocScratchPad(max_ptr_size * sizeof(float));
}
// transpose
if (quant_int8) {
Expand Down
8 changes: 5 additions & 3 deletions lite/kernels/xpu/match_matrix_tensor_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ namespace kernels {
namespace xpu {

void MatchMatrixTensorCompute::PrepareForRun() {
auto& ctx = this->ctx_->As<XPUContext>();
auto& param = this->Param<param_t>();
float w_max = param.__xpu__w_max;
std::vector<float> w_max_v(XPU_QUANT_SCALE_NUM, w_max);
int max_ptr_size = get_max_ptr_size(ctx.GetRawContext());
std::vector<float> w_max_v(max_ptr_size, w_max);
weight_max_xpu_guard_ =
TargetWrapperXPU::MallocScratchPad(XPU_QUANT_SCALE_NUM * sizeof(float));
TargetWrapperXPU::MallocScratchPad(max_ptr_size * sizeof(float));
XPU_CALL(xpu_memcpy(reinterpret_cast<float*>(weight_max_xpu_guard_->addr_),
w_max_v.data(),
XPU_QUANT_SCALE_NUM * sizeof(float),
max_ptr_size * sizeof(float),
XPUMemcpyKind::XPU_HOST_TO_DEVICE));

offset_l_xpu_guard_ =
Expand Down