Skip to content

Commit

Permalink
Add and apply optional_layout
Browse files Browse the repository at this point in the history
  • Loading branch information
yeonbok committed Jul 24, 2022
1 parent eb28f54 commit e34d1da
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 80 deletions.
34 changes: 34 additions & 0 deletions src/plugins/intel_gpu/include/intel_gpu/runtime/layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class optional_data_type {
storage_type storage;
};


/// Converts C++ type to @ref data_types .
template <typename T>
struct type_to_data_type;
Expand Down Expand Up @@ -528,6 +529,39 @@ struct layout {
std::string to_string() const;
};

class optional_layout {
public:
optional_layout() {}
optional_layout(const layout& lay) {
this->opt_layout_ptr = make_unique<layout>(lay);
}

optional_layout(const optional_layout& new_opt_lay) {
//this->opt_layout = std::move(*new_opt_lay);
if (new_opt_lay) {
layout copied_lay = *new_opt_lay;
this->opt_layout_ptr = make_unique<layout>(copied_lay);
}
}

operator bool() const {
return this->opt_layout_ptr != nullptr;
}

layout operator*() const {
if (opt_layout_ptr == nullptr)
throw std::runtime_error("Attempt to access uninitialized optional layout!");
return *this->opt_layout_ptr;
}

std::unique_ptr<layout>& get_layout_ptr() {
return opt_layout_ptr;
}

private:
std::unique_ptr<layout> opt_layout_ptr = nullptr;
};

/// @}
/// @}
} // namespace cldnn
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ struct binary_convolution_impl : typed_primitive_impl_ocl<binary_convolution> {
public:
static primitive_impl* create(const binary_convolution_node& arg, std::shared_ptr<kernel_impl_params> impl_param) {
const auto& primitive = arg.get_primitive();
const auto& weights_layout = impl_param->weights_layout.convert_to_weights_layout(false);
const auto& weights_layout = (*impl_param->weights_layout).convert_to_weights_layout(false);
const auto& weights_size = weights_layout.size;

const auto& split = primitive->split();
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/intel_gpu/src/graph/impls/ocl/deconvolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ struct deconvolution_impl : typed_primitive_impl_ocl<deconvolution> {
const auto& primitive = arg.get_primitive();
const auto& split = primitive->split();
const auto& stride = primitive->stride;
#if 0 // TODO: support dilation
const auto& dilation = primitive->dilation;
#else
const ov::Strides dilation(impl_param->output_layout.get_spatial_rank(), 1);
#endif
const auto actual_split = split;

const auto& pad = primitive->pad;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,19 @@ struct convolution_onednn : typed_primitive_onednn_impl<convolution, dnnl::convo
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);

const auto& bias_layout = arg.bias_term() ? arg.bias().get_output_layout() : layout(data_types::f32, format::any, tensor());
const auto& weights_zero_points_layout = arg.weights_zero_points_term() ? arg.weights_zero_points().get_output_layout()
: layout(data_types::f32, format::any, tensor());
const auto& activations_zero_points_layout = arg.activations_zero_points_term() ? arg.activations_zero_points().get_output_layout()
: layout(data_types::f32, format::any, tensor());
const auto& compensation_layout = arg.compensation_term() ? arg.compensation().get_output_layout()
: layout(data_types::f32, format::any, tensor());

const auto& param_info = kernel_impl_params(arg.get_program(), cldnn_prim, arg.get_unique_id(),
arg.get_input_layouts(), arg.get_output_layout(),
arg.get_fused_primitives(),
arg.get_fused_activations_funcs(), arg.get_fused_activations_params(),
arg.weights().get_output_layout(), arg.bias_term(), bias_layout,
arg.weights_zero_points_term(), weights_zero_points_layout,
arg.activations_zero_points_term(), activations_zero_points_layout,
arg.compensation_term(), compensation_layout);
optional_layout(weights_layout),
arg.bias_term() ? optional_layout(arg.bias().get_output_layout()) : optional_layout(),
arg.weights_zero_points_term() ? optional_layout(arg.weights_zero_points().get_output_layout())
: optional_layout(),
arg.activations_zero_points_term() ? optional_layout(arg.activations_zero_points().get_output_layout())
: optional_layout(),
arg.compensation_term() ? optional_layout(arg.compensation().get_output_layout())
: optional_layout());

set_params(param_info, r_params);
r_params.layerID = arg.id() + "_reorder_";
r_params.input = convert_weights_tensor(weights_layout, cldnn_prim->grouped_weights_shape);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ struct deconvolution_onednn : typed_primitive_onednn_impl<deconvolution, dnnl::d
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);

const auto& bias_layout = arg.bias_term() ? arg.bias().get_output_layout() : layout(data_types::f32, format::any, tensor());

const auto& param_info = kernel_impl_params(arg.get_program(), cldnn_prim, arg.get_unique_id(),
arg.get_input_layouts(), arg.get_output_layout(),
arg.get_fused_primitives(),
arg.get_fused_activations_funcs(), arg.get_fused_activations_params(),
arg.weights().get_output_layout(), arg.bias_term(), bias_layout);
optional_layout(weights_layout),
arg.bias_term() ? optional_layout(arg.bias().get_output_layout()) : optional_layout());

set_params(param_info, r_params);
r_params.layerID = arg.id() + "_reorder_";
r_params.input = convert_weights_tensor(weights_layout, cldnn_prim->grouped_weights_shape);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ struct fully_connected_onednn : typed_primitive_onednn_impl<fully_connected, dnn
static kernel_selector::WeightsReorderParams get_weights_reorder(const fully_connected_node& arg, const dnnl::primitive_desc& pd) {
auto weights_layout = arg.get_dependency(1).get_output_layout();
auto cldnn_prim = arg.get_primitive();
const auto& bias_layout = arg.bias_term() ? arg.bias().get_output_layout() : layout(data_types::f32, format::any, tensor());
const auto& param_info = kernel_impl_params(arg.get_program(), cldnn_prim, arg.get_unique_id(),
arg.get_input_layouts(), arg.get_output_layout(),
arg.get_fused_primitives(),
arg.get_fused_activations_funcs(), arg.get_fused_activations_params(),
arg.weights().get_output_layout(), arg.bias_term(), bias_layout);
optional_layout(weights_layout),
arg.bias_term() ? optional_layout(arg.bias().get_output_layout()) : optional_layout());

kernel_selector::WeightsReorderParams weights_reorder_params;
auto& reorderKS = kernel_selector::ReorderWeightsKernelSelctor::Instance();
kernel_selector::reorder_weights_params r_params;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,12 @@ struct typed_program_node<binary_convolution> : public typed_program_node_base<b
throw std::runtime_error("bias should not be used in binary convolution");
}

bool bias_term() const {
return false;
}

std::shared_ptr<kernel_impl_params> get_kernel_impl_params(const std::vector<layout>& in_layouts,
const layout& out_layout) const override {
const auto& bias_layout =
bias_term() ? bias().get_output_layout() : layout(data_types::f32, format::any, tensor());

return std::make_shared<kernel_impl_params>(get_program(), get_primitive(), get_unique_id(),
in_layouts, out_layout,
get_fused_primitives(), get_fused_activations_funcs(), get_fused_activations_params(),
weights().get_output_layout(), bias_term(), bias_layout);
optional_layout(weights().get_output_layout()));
}

private:
Expand Down
18 changes: 5 additions & 13 deletions src/plugins/intel_gpu/src/graph/include/convolution_inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,28 +115,20 @@ struct typed_program_node<convolution> : public typed_program_node_base<convolut
}

bool bias_term() const { return get_primitive()->bias.size() > 0; }

bool weights_zero_points_term() const { return get_primitive()->weights_zero_points.size() > 0; }
bool compensation_term() const { return get_primitive()->compensation.size() > 0; }
bool activations_zero_points_term() const { return get_primitive()->activations_zero_points.size() > 0; }

std::shared_ptr<kernel_impl_params> get_kernel_impl_params(const std::vector<layout>& in_layouts,
const layout& out_layout) const override {
const auto& bias_layout = bias_term() ? bias().get_output_layout() : layout(data_types::f32, format::any, tensor());
const auto& weights_zero_points_layout = weights_zero_points_term() ? weights_zero_points().get_output_layout()
: layout(data_types::f32, format::any, tensor());
const auto& activations_zero_points_layout = activations_zero_points_term() ? activations_zero_points().get_output_layout()
: layout(data_types::f32, format::any, tensor());
const auto& compensation_layout = compensation_term() ? compensation().get_output_layout()
: layout(data_types::f32, format::any, tensor());

return std::make_shared<kernel_impl_params>(get_program(), get_primitive(), get_unique_id(),
in_layouts, out_layout,
get_fused_primitives(), get_fused_activations_funcs(), get_fused_activations_params(),
weights().get_output_layout(), bias_term(), bias_layout,
weights_zero_points_term(), weights_zero_points_layout,
activations_zero_points_term(), activations_zero_points_layout,
compensation_term(), compensation_layout);
optional_layout(weights().get_output_layout()),
bias_term() ? optional_layout(bias().get_output_layout()) : optional_layout(),
weights_zero_points_term() ? optional_layout(weights_zero_points().get_output_layout()) : optional_layout(),
activations_zero_points_term() ? optional_layout(activations_zero_points().get_output_layout()) : optional_layout(),
compensation_term() ? optional_layout(compensation().get_output_layout()) : optional_layout());
}

private:
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_gpu/src/graph/include/deconvolution_inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ struct typed_program_node<deconvolution> : public typed_program_node_base<deconv

std::shared_ptr<kernel_impl_params> get_kernel_impl_params(const std::vector<layout>& in_layouts,
const layout& out_layout) const override {
const auto& bias_layout = bias_term() ? bias().get_output_layout() : layout(data_types::f32, format::any, tensor());
return std::make_shared<kernel_impl_params>(get_program(), get_primitive(), get_unique_id(),
in_layouts, out_layout,
get_fused_primitives(), get_fused_activations_funcs(), get_fused_activations_params(),
weights().get_output_layout(), bias_term(), bias_layout);
optional_layout(weights().get_output_layout()),
bias_term() ? optional_layout(bias().get_output_layout()) : optional_layout());
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ struct typed_program_node<deformable_conv> : public typed_program_node_base<defo

std::shared_ptr<kernel_impl_params> get_kernel_impl_params(const std::vector<layout>& in_layouts,
const layout& out_layout) const override {
const auto& bias_layout = bias_term() ? bias().get_output_layout() : layout(data_types::f32, format::any, tensor());

return std::make_shared<kernel_impl_params>(get_program(), get_primitive(), get_unique_id(),
in_layouts, out_layout,
get_fused_primitives(), get_fused_activations_funcs(), get_fused_activations_params(),
weights().get_output_layout(), bias_term(), bias_layout);
optional_layout(weights().get_output_layout()),
bias_term() ? optional_layout(bias().get_output_layout()) : optional_layout());
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ struct typed_program_node<fully_connected> : public typed_program_node_base<full
bool bias_term() const { return !get_primitive()->bias.empty(); }
std::shared_ptr<kernel_impl_params> get_kernel_impl_params(const std::vector<layout>& in_layouts,
const layout& out_layout) const override {
const auto& bias_layout = bias_term() ? bias().get_output_layout() : layout(data_types::f32, format::any, tensor());
return std::make_shared<kernel_impl_params>(get_program(), get_primitive(), get_unique_id(),
in_layouts, out_layout,
get_fused_primitives(), get_fused_activations_funcs(), get_fused_activations_params(),
weights().get_output_layout(), bias_term(), bias_layout);
optional_layout(weights().get_output_layout()),
bias_term() ? optional_layout(bias().get_output_layout()) : optional_layout());
}
};

Expand Down
Loading

0 comments on commit e34d1da

Please sign in to comment.