Skip to content

Commit

Permalink
[GPU] clean up for extend pad/stride/dilation (openvinotoolkit#20828)
Browse files Browse the repository at this point in the history
* clean up for extend pad/stride/dilation
  • Loading branch information
sungeunk authored Nov 9, 2023
1 parent 9cc4c25 commit b1705e8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
11 changes: 11 additions & 0 deletions src/plugins/intel_gpu/include/intel_gpu/plugin/common_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <ostream>
#include <tuple>
#include "intel_gpu/runtime/layout.hpp"
#include "openvino/core/layout.hpp"
#include "openvino/core/type/element_type.hpp"
Expand Down Expand Up @@ -39,6 +40,16 @@ inline cldnn::tensor tensor_from_dims(const ov::Shape& dims, int def = 1) {
}
}

template<typename T, typename V>
std::tuple<V, V, V> get_xyz(const T data, V def) {
switch (data.size()) {
case 1: return std::make_tuple(def, static_cast<V>(data[0]), def);
case 2: return std::make_tuple(static_cast<V>(data[1]), static_cast<V>(data[0]), def);
case 3: return std::make_tuple(static_cast<V>(data[2]), static_cast<V>(data[1]), static_cast<V>(data[0]));
default: return std::make_tuple(def, def, def);
}
}

inline cldnn::layout make_layout(const ov::element::Type type, const ov::Shape& shape) {
return cldnn::layout{ov::PartialShape{shape},
cldnn::element_type_to_data_type(type),
Expand Down
27 changes: 9 additions & 18 deletions src/plugins/intel_gpu/src/graph/impls/ocl/convolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "convolution/convolution_kernel_selector.h"
#include "convolution/convolution_params.h"
#include "ngraph/validation_util.hpp"
#include "intel_gpu/plugin/common_utils.hpp"

namespace cldnn {
namespace ocl {
Expand Down Expand Up @@ -113,30 +114,20 @@ struct convolution_impl : typed_primitive_impl_ocl<convolution> {
uint32_t kz = weights_layout.spatial(2);
conv_params.filterSize = { kx, ky, kz };

// WA: If 1d conv and dynamic shape, 1d pad should be applied to y axis.
if (pads_begin.size() == 1) pads_begin.push_back(0);
if (pads_end.size() == 1) pads_end.push_back(0);
if (stride.size() == 1) stride.push_back(1);
if (dilation.size() == 1) dilation.push_back(1);

uint32_t pad_begin_z = std::max<std::ptrdiff_t>(pads_begin.size() >= 3 ? pads_begin[pads_begin.size() - 3] : 0, 0);
uint32_t pad_begin_y = std::max<std::ptrdiff_t>(pads_begin.size() >= 2 ? pads_begin[pads_begin.size() - 2] : 0, 0);
uint32_t pad_begin_x = std::max<std::ptrdiff_t>(pads_begin.size() >= 1 ? pads_begin[pads_begin.size() - 1] : 0, 0);
uint32_t pad_begin_x, pad_begin_y, pad_begin_z;
std::tie(pad_begin_x, pad_begin_y, pad_begin_z) = ov::intel_gpu::get_xyz<ov::CoordinateDiff, uint32_t>(pads_begin, 0);
conv_params.padding_begin = {pad_begin_x, pad_begin_y, pad_begin_z};

uint32_t pad_end_z = std::max<std::ptrdiff_t>(pads_end.size() >= 3 ? pads_end[pads_end.size() - 3] : 0, 0);
uint32_t pad_end_y = std::max<std::ptrdiff_t>(pads_end.size() >= 2 ? pads_end[pads_end.size() - 2] : 0, 0);
uint32_t pad_end_x = std::max<std::ptrdiff_t>(pads_end.size() >= 1 ? pads_end[pads_end.size() - 1] : 0, 0);
uint32_t pad_end_x, pad_end_y, pad_end_z;
std::tie(pad_end_x, pad_end_y, pad_end_z) = ov::intel_gpu::get_xyz<ov::CoordinateDiff, uint32_t>(pads_end, 0);
conv_params.padding_end = {pad_end_x, pad_end_y, pad_end_z};

uint32_t stride_z = stride.size() >= 3 ? static_cast<uint32_t>(stride[stride.size() - 3]) : 1;
uint32_t stride_y = stride.size() >= 2 ? static_cast<uint32_t>(stride[stride.size() - 2]) : 1;
uint32_t stride_x = stride.size() >= 1 ? static_cast<uint32_t>(stride[stride.size() - 1]) : 1;
uint32_t stride_x, stride_y, stride_z;
std::tie(stride_x, stride_y, stride_z) = ov::intel_gpu::get_xyz<ov::Strides, uint32_t>(stride, 1);
conv_params.stride = {stride_x, stride_y, stride_z};

uint32_t dilation_z = dilation.size() >= 3 ? static_cast<uint32_t>(dilation[dilation.size() - 3]) : 1;
uint32_t dilation_y = dilation.size() >= 2 ? static_cast<uint32_t>(dilation[dilation.size() - 2]) : 1;
uint32_t dilation_x = dilation.size() >= 1 ? static_cast<uint32_t>(dilation[dilation.size() - 1]) : 1;
uint32_t dilation_x, dilation_y, dilation_z;
std::tie(dilation_x, dilation_y, dilation_z) = ov::intel_gpu::get_xyz<ov::Strides, uint32_t>(dilation, 1);
conv_params.dilation = {dilation_x, dilation_y, dilation_z};

if ((impl_param.input_layouts[0].data_type == data_types::u8 ||
Expand Down

0 comments on commit b1705e8

Please sign in to comment.