Skip to content

Commit

Permalink
[GPU] Fixes after review openvinotoolkit#2
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyamin-Roman committed Jun 15, 2023
1 parent f44ca5c commit cbeced0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ struct WeightsReorderParams {
_out_layout(out_layout),
_transposed(transposed) {}

virtual size_t hash() const {
size_t hash() const {
size_t seed = hash_combine(_in_layout.hash(), _out_layout.hash());
seed = hash_combine(seed, _transposed);
return seed;
}

virtual bool operator==(const WeightsReorderParams& rhs) const {
bool operator==(const WeightsReorderParams& rhs) const {
if (typeid(*this) != typeid(rhs))
return false;

Expand All @@ -46,8 +46,6 @@ struct WeightsReorderParams {

void set_input_layout(const layout& layout) { _in_layout = layout; }

virtual ~WeightsReorderParams() = default;

protected:
layout _in_layout;
layout _out_layout;
Expand Down
6 changes: 3 additions & 3 deletions src/plugins/intel_gpu/src/graph/impls/ocl/reorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ struct reorder_impl : typed_primitive_impl_ocl<reorder> {
bool is_reorder_weights = format::is_weights_format(impl_param.get_input_layout().format) ||
format::is_weights_format(impl_param.get_output_layout().format);
if (is_reorder_weights) {
return create_reorder_weigths(impl_param);
return create_reorder_weights(impl_param);
} else {
return typed_primitive_impl_ocl<reorder>::create<reorder_impl>(arg, impl_param);
}
}

static std::unique_ptr<primitive_impl> create_reorder_weigths(const kernel_impl_params& impl_param) {
static std::unique_ptr<primitive_impl> create_reorder_weights(const kernel_impl_params& impl_param) {
const auto& prim = impl_param.typed_desc<reorder>();
const auto& weights_params = prim->weights_reorder_params;
auto& kernel_selector = kernel_selector::ReorderWeightsKernelSelector::Instance();
Expand Down Expand Up @@ -166,7 +166,7 @@ attach_reorder_impl::attach_reorder_impl() {
};
implementation_map<reorder>::add(impl_types::ocl, shape_types::dynamic_shape, reorder_impl::create, types, formats);

WeightsReordersFactory::add(cldnn::impl_types::ocl, shape_types::static_shape, reorder_impl::create_reorder_weigths);
WeightsReordersFactory::add(cldnn::impl_types::ocl, shape_types::static_shape, reorder_impl::create_reorder_weights);
}

} // namespace detail
Expand Down
27 changes: 10 additions & 17 deletions src/plugins/intel_gpu/src/graph/impls/onednn/convolution_onednn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,17 @@ struct convolution_onednn : typed_primitive_onednn_impl<convolution> {
return attrs;
}

static kernel_selector::WeightsReorderParams get_weights_reorder(const kernel_impl_params& impl_params, const dnnl::primitive_desc& pd, bool rotate) {
kernel_selector::WeightsReorderParams weights_reorder_params;

static std::shared_ptr<WeightsReorderParams> get_weights_reorder(const kernel_impl_params& impl_params, const dnnl::primitive_desc& pd, bool rotate) {
auto cldnn_prim = impl_params.typed_desc<convolution>();
auto weights_layout = impl_params.get_input_layout(1);
auto grouped_weights = format::is_grouped(weights_layout.format) || cldnn_prim->grouped_weights_shape;
cldnn::format out_fmt = onednn::find_format(pd.weights_desc(0), grouped_weights);
kernel_selector::WeightsLayout reqLayout = to_weights_layout(out_fmt, cldnn_prim->grouped_weights_shape);

weights_reorder_params.src = convert_weights_tensor(weights_layout, cldnn_prim->grouped_weights_shape);
weights_reorder_params.dest = weights_reorder_params.src.TransformIgnorePadding(reqLayout,
weights_reorder_params.src.GetDType(),
cldnn_prim->groups,
false);
weights_reorder_params.rotate = rotate;
weights_reorder_params.is_initialized = true;

return weights_reorder_params;

auto input_weights_layout = impl_params.get_input_layout(1);
auto grouped_weights = format::is_grouped(input_weights_layout.format) || cldnn_prim->grouped_weights_shape;
format out_fmt = onednn::find_format(pd.weights_desc(0), grouped_weights);

auto output_weights_layout = input_weights_layout;
output_weights_layout.format = out_fmt;

return std::make_shared<WeightsReorderParams>(input_weights_layout, output_weights_layout, rotate);
}

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,17 @@ struct deconvolution_onednn : typed_primitive_onednn_impl<deconvolution> {
return arg.get_onednn_primitive_attributes();
}

static kernel_selector::WeightsReorderParams get_weights_reorder(const kernel_impl_params& impl_params, const dnnl::primitive_desc& pd) {
kernel_selector::WeightsReorderParams weights_reorder_params;

static std::shared_ptr<WeightsReorderParams> get_weights_reorder(const kernel_impl_params& impl_params, const dnnl::primitive_desc& pd) {
auto cldnn_prim = impl_params.typed_desc<deconvolution>();
auto weights_layout = impl_params.get_input_layout(1);
auto grouped_weights = format::is_grouped(weights_layout.format) || cldnn_prim->grouped_weights_shape;
cldnn::format out_fmt = onednn::find_format(pd.weights_desc(0), grouped_weights);
kernel_selector::WeightsLayout reqLayout = to_weights_layout(out_fmt, cldnn_prim->grouped_weights_shape);

weights_reorder_params.src = convert_weights_tensor(weights_layout, cldnn_prim->grouped_weights_shape);
weights_reorder_params.dest = weights_reorder_params.src.TransformIgnorePadding(reqLayout,
weights_reorder_params.src.GetDType(),
cldnn_prim->groups,
false);
weights_reorder_params.rotate = false;
weights_reorder_params.is_initialized = true;

return weights_reorder_params;

auto input_weights_layout = impl_params.get_input_layout(1);
auto grouped_weights = format::is_grouped(input_weights_layout.format) || cldnn_prim->grouped_weights_shape;
format out_fmt = onednn::find_format(pd.weights_desc(0), grouped_weights);

auto output_weights_layout = input_weights_layout;
output_weights_layout.format = out_fmt;

return std::make_shared<WeightsReorderParams>(input_weights_layout, output_weights_layout, false);
}

public:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct fully_connected_onednn : typed_primitive_onednn_impl<fully_connected> {
return args;
}

static kernel_selector::WeightsReorderParams get_weights_reorder(const kernel_impl_params& impl_params, const dnnl::primitive_desc& pd) {
static std::shared_ptr<WeightsReorderParams> get_weights_reorder(const kernel_impl_params& impl_params, const dnnl::primitive_desc& pd) {
auto input_layout = impl_params.get_input_layout(0);
auto weights_layout = impl_params.get_input_layout(1);
auto cldnn_prim = impl_params.typed_desc<fully_connected>();
Expand All @@ -66,20 +66,12 @@ struct fully_connected_onednn : typed_primitive_onednn_impl<fully_connected> {
weights_layout.set_partial_shape(reshape_to_2d(weights_pshape, feature));
}

kernel_selector::WeightsReorderParams weights_reorder_params;
format out_fmt = onednn::find_format(pd.weights_desc(0));

cldnn::format out_fmt = onednn::find_format(pd.weights_desc(0));
kernel_selector::WeightsLayout req_layout = to_weights_layout(out_fmt, false);
auto output_weights_layout = weights_layout;
output_weights_layout.format = out_fmt;

weights_reorder_params.src = convert_weights_tensor(weights_layout, false);
weights_reorder_params.dest = weights_reorder_params.src.TransformIgnorePadding(req_layout,
weights_reorder_params.src.GetDType(),
1,
false);
weights_reorder_params.rotate = false;
weights_reorder_params.is_initialized = true;

return weights_reorder_params;
return std::make_shared<WeightsReorderParams>(weights_layout, output_weights_layout, false);
}

static std::shared_ptr<dnnl::inner_product_forward::primitive_desc> get_fully_connected_primitive_descriptor(const kernel_impl_params& impl_params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ struct typed_primitive_onednn_impl : public typed_primitive_impl<PType> {
const ExecutionConfig& config,
std::shared_ptr<dnnl::primitive_attr> attrs,
const PrimDescType& pd,
kernel_selector::WeightsReorderParams weights_reorder = {})
: typed_primitive_impl<PType>(create_weights_reorder_params(weights_reorder), pd.impl_info_str()),
std::shared_ptr<WeightsReorderParams> weights_reorder = {})
: typed_primitive_impl<PType>(weights_reorder, pd.impl_info_str()),
_engine(&engine),
_attrs(attrs),
_pd(pd) {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/intel_gpu/src/graph/include/primitive_inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ struct primitive_impl {

bool need_weights_reorder() const { return _weights_reorder_params != nullptr; }
std::shared_ptr<WeightsReorderParams> get_weights_reorder_params() const { return _weights_reorder_params; }
void reset_weights_reorder_params() { _weights_reorder_params = nullptr; }

std::shared_ptr<kernel_impl_params> get_weights_reorder_kernel_params() const;

Expand Down

0 comments on commit cbeced0

Please sign in to comment.