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

[OpenCL][Bugfix] Fix target choose in opencl_kernel_place_correct_pass #6079

Merged
merged 3 commits into from
May 14, 2021
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
12 changes: 6 additions & 6 deletions lite/backends/opencl/cl_kernel/image/concat_kernel.cl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ limitations under the License. */

#include <cl_common.h>

/********************************************************
* For case that All Axis C of inputs are aligned: Start
********************************************************/
/***************************************************************************
* For case: Axis N/H/W or Axis C that all input channels is aligned: Start
***************************************************************************/
#define CHECK_IDX \
int c_blk_idx = get_global_id(0); \
int w_idx = get_global_id(1); \
Expand Down Expand Up @@ -317,9 +317,9 @@ CONCAT3(3Input, Axis3)
CONCAT4(4Input, Axis3)
CONCAT5(5Input, Axis3)
CONCAT6(6Input, Axis3)
/********************************************************
* For case that All Axis C of inputs are aligned: End
********************************************************/
/*************************************************************************
* For case: Axis N/H/W or Axis C that all input channels is aligned: End
*************************************************************************/


// deprecated
Expand Down
24 changes: 17 additions & 7 deletions lite/core/mir/opencl_kernel_place_correct_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,25 @@ class OpenCLKernelPlaceCorrectPass : public ProgramPass {
VLOG(4) << "dims: " << dims << "\t dims[axis]: " << dims[axis];

// OpenCL parallelism is low at this case,
// so we use host backendkernel.
// so we use host backend kernel.
const int thres = 500;
if (dims[axis] > thres) {
VLOG(4) << "Correct opencl softmax kernel place from device to host.";
#if defined(LITE_WITH_ARM)
auto new_target = TargetType::kARM;
#elif defined(LITE_WITH_X86)
auto new_target = TargetType::kX86;
#endif
TargetType new_target = TARGET(kARM);
const auto& valid_places = graph->valid_places();
for (const auto& place : valid_places) {
if (place.target == TARGET(kARM)) {
new_target = place.target;
break;
} else if (place.target == TARGET(kX86)) {
new_target = place.target;
break;
}
}
VLOG(4) << string_format(
"Correct opencl %s kernel & tensor's place from %s to %s.",
op_type.c_str(),
TargetToStr(inst.place().target).c_str(),
TargetToStr(new_target).c_str());
UpdateTarget(inst, new_target);
UpdateTensor(inst, in, out, new_target);
}
Expand Down