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

[Metal] fix Conv2d image #8496

Merged
merged 4 commits into from
Mar 4, 2022
Merged
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
18 changes: 11 additions & 7 deletions lite/kernels/metal/image_op/conv2d_image_compute.mm
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,22 @@
if (metal_context_->use_mps()) {
int input_c = static_cast<int>(input_buffer_->tensor_dim_[1]);
int output_c = static_cast<int>(output_buffer_->tensor_dim_[1]);
// intput & output C channel must >=3
// input channel must >=3
// attention: should be >=4, texture data layout is RGBA
if (input_c >= 3 && output_c >= 3) {
should_use_mps = true;
if (is_depthwise_) {
if (input_c >= 3 && output_c >= 3) {
should_use_mps = true;
}
} else {
if (input_c >= 3) {
should_use_mps = true;
}
}
}
}
if (IsWinoGrad(function_name_) || IsQuadruple(function_name_)) {
should_use_mps = false;
}
if (!is_depthwise_ && param.groups > 1) {
should_use_mps = false;
}
if (param.bias) {
if (!canMPSAddByChannel()) {
should_use_mps = false;
Expand Down Expand Up @@ -472,7 +475,7 @@
auto filter_h = static_cast<int>(param.filter->dims()[2]);
auto filter_w = static_cast<int>(param.filter->dims()[3]);
auto input_c = static_cast<int>(input_buffer_->tensor_dim_[1]);
auto output_c = static_cast<int>(output_buffer_->tensor_dim_[1]);
auto output_c = fmax(4, static_cast<int>(output_buffer_->tensor_dim_[1]));
MPSCNNConvolutionDescriptor* description = nil;
if (is_depthwise_) {
description = [MPSCNNDepthWiseConvolutionDescriptor
Expand All @@ -491,6 +494,7 @@
description.strideInPixelsY = param.strides[1];
description.dilationRateX = (*param.dilations)[0];
description.dilationRateY = (*param.dilations)[1];
if (!is_depthwise_) description.groups = param.groups;
// active function
switch (param.activation_param.active_type) {
case lite_api::ActivationType::kRelu: {
Expand Down