Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cherry-Pick][OpenCL] Fix OpenCL opt #9630

Merged
merged 3 commits into from
Nov 4, 2022
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
2 changes: 2 additions & 0 deletions lite/api/tools/opt_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ void OptBase::SetValidPlaces(const std::string& valid_places) {
Place{TARGET(kOpenCL), PRECISION(kFP16), DATALAYOUT(kImageDefault)});
valid_places_.emplace_back(
Place{TARGET(kOpenCL), PRECISION(kFP16), DATALAYOUT(kImageFolder)});
valid_places_.emplace_back(
Place{TARGET(kOpenCL), PRECISION(kFP16), DATALAYOUT(kNCHW)});
valid_places_.emplace_back(
Place{TARGET(kOpenCL), PRECISION(kFloat), DATALAYOUT(kNCHW)});
valid_places_.emplace_back(
Expand Down
19 changes: 18 additions & 1 deletion lite/core/optimizer/mir/opencl_memory_object_config_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,20 @@ void OpenCLMemoryObjectConfigPass::CorrectArgumentPlace(SSAGraph* graph) {
};

// 1. op unsupport persistable
if (op_type == "reshape2" || op_type == "unsqueeze2") {
const std::vector<std::string> op_cases_unsupport_persistable{
"elementwise_floordiv",
"elementwise_add",
"elementwise_sub",
"elementwise_mul",
"elementwise_div",
"elementwise_pow",
"elementwise_mod",
"reshape2",
"unsqueeze2",
"split"};
if (std::find(op_cases_unsupport_persistable.begin(),
op_cases_unsupport_persistable.end(),
op_type) != op_cases_unsupport_persistable.end()) {
for (std::list<Node*>::iterator i = x->inlinks.begin();
i != x->inlinks.end();
++i) {
Expand Down Expand Up @@ -287,6 +300,10 @@ void OpenCLMemoryObjectConfigPass::CorrectArgumentPlace(SSAGraph* graph) {
}
}
}

// 7. reshape change target
if (op_type == "reshape" || op_type == "reshape2")
change_image2d_to_buffer = true;
}

if (change_image2d_to_cpu) {
Expand Down
6 changes: 4 additions & 2 deletions lite/kernels/opencl/io_copy_buffer_compute.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ class IoCopyHostToOpenCLCompute
CHECK(param.x->target() == TARGET(kHost) ||
param.x->target() == TARGET(kARM));

auto mem_size = param.x->memory_size();
auto mem_size = param.x->dims().production() *
PrecisionTypeLength(param.x->precision());
#ifdef LITE_WITH_LOG
VLOG(2) << "param.x->memory_size():" << mem_size;
VLOG(2) << "param.x->dims().size():" << param.x->dims().size();
Expand Down Expand Up @@ -212,7 +213,8 @@ class IoCopykOpenCLToHostCompute
void Run() override {
auto& param = Param<operators::IoCopyParam>();
CHECK(param.x->target() == TARGET(kOpenCL));
auto mem_size = param.x->memory_size();
auto mem_size = param.x->dims().production() *
PrecisionTypeLength(param.x->precision());
const cl::Buffer* x_ptr;
if (param.process_type == 1) {
x_ptr = param.x->data<uint8_t, cl::Buffer>();
Expand Down