Commit 6f1664df authored by Anna Alberska's avatar Anna Alberska Committed by Robert Kimball

IntelGPU backend: SigmoidBackprop operation (#1507)

* IntelGPU backend: SigmoidBackprop operation

* Requested changes done

* Delete namespaces in function names

* Apply code format check
parent 33cd386b
...@@ -695,6 +695,19 @@ bool runtime::intelgpu::IntelGPUBackend::compile(shared_ptr<Function> func) ...@@ -695,6 +695,19 @@ bool runtime::intelgpu::IntelGPUBackend::compile(shared_ptr<Function> func)
{ {
do_unary_operation(topology, op, activation_logistic); do_unary_operation(topology, op, activation_logistic);
} }
else if ("SigmoidBackprop" == op->description())
{
arguments_check(op, 2, 1);
do_sigmoid_backprop_operation(topology,
get_input_name(op, 0),
get_input_shape(op, 0),
get_input_name(op, 1),
get_input_shape(op, 1),
get_output_name(op),
get_output_shape(op),
get_output_type(op));
}
else if ("Not" == op->description()) else if ("Not" == op->description())
{ {
arguments_check(op, 1, 1); arguments_check(op, 1, 1);
......
...@@ -204,18 +204,17 @@ void runtime::intelgpu::do_pad_operation(cldnn::topology& topology, ...@@ -204,18 +204,17 @@ void runtime::intelgpu::do_pad_operation(cldnn::topology& topology,
vector<size_t> gws; vector<size_t> gws;
// The kernel name and parameters // The kernel name and parameters
runtime::intelgpu::gen_func_def( gen_func_def(writer, entry_point_name, {2, "float"}, {input_shape, {1}}, "float", output_shape);
writer, entry_point_name, {2, "float"}, {input_shape, {1}}, "float", output_shape);
writer.block_begin(); writer.block_begin();
{ {
// Loop for Broadcast scalar over full output tensor // Loop for Broadcast scalar over full output tensor
gws = runtime::intelgpu::generate_loops(writer, output_shape, true); gws = generate_loops(writer, output_shape, true);
writer << "output" << access_dims(output_shape) << " = input1[0];\n"; writer << "output" << access_dims(output_shape) << " = input1[0];\n";
// Closing brackets for Broadcast loop // Closing brackets for Broadcast loop
runtime::intelgpu::generate_loops(writer, output_shape, false); generate_loops(writer, output_shape, false);
// Loop for Copy input matrix into output matrix with padding. // Loop for Copy input matrix into output matrix with padding.
// Padding include "pad_below" and "pad_interior" according nGraph documentation // Padding include "pad_below" and "pad_interior" according nGraph documentation
...@@ -887,19 +886,18 @@ void runtime::intelgpu::do_slice_operation(cldnn::topology& topology, ...@@ -887,19 +886,18 @@ void runtime::intelgpu::do_slice_operation(cldnn::topology& topology,
codegen::CodeWriter writer; codegen::CodeWriter writer;
vector<size_t> gws; vector<size_t> gws;
runtime::intelgpu::gen_func_def( gen_func_def(writer, entry_point_name, {"float"}, {input_shape}, "float", output_shape);
writer, entry_point_name, {"float"}, {input_shape}, "float", output_shape);
writer.block_begin(); writer.block_begin();
{ {
// Main loops // Main loops
gws = runtime::intelgpu::generate_loops(writer, output_shape, true); gws = generate_loops(writer, output_shape, true);
writer << "output" << access_dims(output_shape) << " = input0" writer << "output" << access_dims(output_shape) << " = input0"
<< access_dims_strided(input_shape, lower_bounds, strides, false) << ";\n"; << access_dims_strided(input_shape, lower_bounds, strides, false) << ";\n";
// Closing brackets for main loops // Closing brackets for main loops
runtime::intelgpu::generate_loops(writer, output_shape, false); generate_loops(writer, output_shape, false);
} }
writer.block_end(); writer.block_end();
...@@ -930,24 +928,24 @@ void runtime::intelgpu::do_select_operation(cldnn::topology& topology, ...@@ -930,24 +928,24 @@ void runtime::intelgpu::do_select_operation(cldnn::topology& topology,
codegen::CodeWriter writer; codegen::CodeWriter writer;
vector<size_t> gws; vector<size_t> gws;
runtime::intelgpu::gen_func_def(writer, gen_func_def(writer,
entry_point_name, entry_point_name,
{"char", "float", "float"}, {"char", "float", "float"},
{input0_shape, input1_shape, input2_shape}, {input0_shape, input1_shape, input2_shape},
"float", "float",
output_shape); output_shape);
writer.block_begin(); writer.block_begin();
{ {
// Main loops // Main loops
gws = runtime::intelgpu::generate_loops(writer, output_shape, true); gws = generate_loops(writer, output_shape, true);
writer << "output" << access_dims(output_shape) << " = input0" << access_dims(input0_shape) writer << "output" << access_dims(output_shape) << " = input0" << access_dims(input0_shape)
<< " ? input1" << access_dims(input1_shape) << " : input2" << " ? input1" << access_dims(input1_shape) << " : input2"
<< access_dims(input2_shape) << ";\n"; << access_dims(input2_shape) << ";\n";
// Closing brackets for main loops // Closing brackets for main loops
runtime::intelgpu::generate_loops(writer, output_shape, false); generate_loops(writer, output_shape, false);
} }
writer.block_end(); writer.block_end();
...@@ -979,23 +977,23 @@ void runtime::intelgpu::do_logic_kernel(cldnn::topology& topology, ...@@ -979,23 +977,23 @@ void runtime::intelgpu::do_logic_kernel(cldnn::topology& topology,
codegen::CodeWriter writer; codegen::CodeWriter writer;
vector<size_t> gws; vector<size_t> gws;
runtime::intelgpu::gen_func_def(writer, gen_func_def(writer,
entry_point_name, entry_point_name,
{2, input0_type}, {2, input0_type},
{input0_shape, input1_shape}, {input0_shape, input1_shape},
"char", "char",
output_shape); output_shape);
writer.block_begin(); writer.block_begin();
{ {
// Main loops // Main loops
gws = runtime::intelgpu::generate_loops(writer, output_shape, true); gws = generate_loops(writer, output_shape, true);
writer << "output" << access_dims(output_shape) << " = input0" << access_dims(input0_shape) writer << "output" << access_dims(output_shape) << " = input0" << access_dims(input0_shape)
<< operation << "input1" << access_dims(input1_shape) << " ? 1 : 0;\n"; << operation << "input1" << access_dims(input1_shape) << " ? 1 : 0;\n";
// Closing brackets for main loops // Closing brackets for main loops
runtime::intelgpu::generate_loops(writer, output_shape, false); generate_loops(writer, output_shape, false);
} }
writer.block_end(); writer.block_end();
...@@ -1023,8 +1021,7 @@ void runtime::intelgpu::do_reverse_operation(cldnn::topology& topology, ...@@ -1023,8 +1021,7 @@ void runtime::intelgpu::do_reverse_operation(cldnn::topology& topology,
codegen::CodeWriter writer; codegen::CodeWriter writer;
vector<size_t> gws; vector<size_t> gws;
runtime::intelgpu::gen_func_def( gen_func_def(writer, entry_point_name, {"float"}, {input_shape}, "float", output_shape);
writer, entry_point_name, {"float"}, {input_shape}, "float", output_shape);
writer.block_begin(); writer.block_begin();
{ {
...@@ -1060,17 +1057,16 @@ void runtime::intelgpu::do_not_operation(cldnn::topology& topology, ...@@ -1060,17 +1057,16 @@ void runtime::intelgpu::do_not_operation(cldnn::topology& topology,
codegen::CodeWriter writer; codegen::CodeWriter writer;
vector<size_t> gws; vector<size_t> gws;
runtime::intelgpu::gen_func_def( gen_func_def(writer, entry_point_name, {"char"}, {input_shape}, "char", output_shape);
writer, entry_point_name, {"char"}, {input_shape}, "char", output_shape);
writer.block_begin(); writer.block_begin();
{ {
gws = runtime::intelgpu::generate_loops(writer, output_shape, true); gws = generate_loops(writer, output_shape, true);
writer << "output" << access_dims(output_shape) << " = !input0" << access_dims(input_shape) writer << "output" << access_dims(output_shape) << " = !input0" << access_dims(input_shape)
<< ";\n"; << ";\n";
runtime::intelgpu::generate_loops(writer, output_shape, false); generate_loops(writer, output_shape, false);
} }
writer.block_end(); writer.block_end();
...@@ -1099,19 +1095,19 @@ void runtime::intelgpu::do_one_hot_operation(cldnn::topology& topology, ...@@ -1099,19 +1095,19 @@ void runtime::intelgpu::do_one_hot_operation(cldnn::topology& topology,
codegen::CodeWriter writer; codegen::CodeWriter writer;
vector<size_t> gws; vector<size_t> gws;
runtime::intelgpu::gen_func_def(writer, gen_func_def(writer,
entry_point_name, entry_point_name,
{input_type.c_type_string()}, {input_type.c_type_string()},
{input_shape}, {input_shape},
output_type.c_type_string(), output_type.c_type_string(),
output_shape); output_shape);
writer.block_begin(); writer.block_begin();
{ {
writer << "for (uint i = 0; i < " << output_shape.at(one_hot_axis) << "; ++i)\n"; writer << "for (uint i = 0; i < " << output_shape.at(one_hot_axis) << "; ++i)\n";
writer.block_begin(); writer.block_begin();
{ {
gws = runtime::intelgpu::generate_loops(writer, input_shape, true); gws = generate_loops(writer, input_shape, true);
size_t current_input = 0; size_t current_input = 0;
string buffer; string buffer;
...@@ -1132,7 +1128,7 @@ void runtime::intelgpu::do_one_hot_operation(cldnn::topology& topology, ...@@ -1132,7 +1128,7 @@ void runtime::intelgpu::do_one_hot_operation(cldnn::topology& topology,
writer << "output" << buffer << " = input0" << access_dims(input_shape) writer << "output" << buffer << " = input0" << access_dims(input_shape)
<< " == i ? 1 : 0;\n"; << " == i ? 1 : 0;\n";
runtime::intelgpu::generate_loops(writer, input_shape, false); generate_loops(writer, input_shape, false);
} }
writer.block_end(); writer.block_end();
} }
...@@ -1164,7 +1160,7 @@ void runtime::intelgpu::do_convert_operation(cldnn::topology& topology, ...@@ -1164,7 +1160,7 @@ void runtime::intelgpu::do_convert_operation(cldnn::topology& topology,
codegen::CodeWriter writer; codegen::CodeWriter writer;
vector<size_t> gws; vector<size_t> gws;
runtime::intelgpu::gen_func_def( gen_func_def(
writer, entry_point_name, {input_type_name}, {input_shape}, output_type_name, output_shape); writer, entry_point_name, {input_type_name}, {input_shape}, output_type_name, output_shape);
writer.block_begin(); writer.block_begin();
...@@ -1188,3 +1184,44 @@ void runtime::intelgpu::do_convert_operation(cldnn::topology& topology, ...@@ -1188,3 +1184,44 @@ void runtime::intelgpu::do_convert_operation(cldnn::topology& topology,
gws); gws);
topology.add(op_convert); topology.add(op_convert);
} }
void runtime::intelgpu::do_sigmoid_backprop_operation(cldnn::topology& topology,
const string& input_name,
const Shape& input_shape,
const string& delta_name,
const Shape& delta_shape,
const string& output_name,
const Shape& output_shape,
const element::Type& output_type)
{
const string entry_point_name = "op_sigmoid_backprop_" + output_name;
codegen::CodeWriter writer;
vector<size_t> gws;
gen_func_def(
writer, entry_point_name, {2, "float"}, {input_shape, delta_shape}, "float", output_shape);
writer.block_begin();
{
writer << "float func_x = 0.0f;\n";
gws = generate_loops(writer, output_shape, true);
writer << "func_x = 1.0f/(1.0f+ exp(-input0" << access_dims(input_shape) << "));\n";
writer << "output" << access_dims(output_shape) << " = input1" << access_dims(delta_shape)
<< " * func_x * (1.0f - func_x);\n";
generate_loops(writer, output_shape, false);
}
writer.block_end();
const cldnn::layout layout = IntelGPULayout::create_cldnn_layout(output_type, output_shape);
const cldnn::custom_gpu_primitive op_sigmoid_backprop(output_name,
{input_name, delta_name},
{writer.get_code()},
entry_point_name,
get_kernel_args(2, 1),
"",
layout,
gws);
topology.add(op_sigmoid_backprop);
}
...@@ -139,6 +139,15 @@ namespace ngraph ...@@ -139,6 +139,15 @@ namespace ngraph
const Shape& output_shape, const Shape& output_shape,
const element::Type& output_type); const element::Type& output_type);
void do_sigmoid_backprop_operation(cldnn::topology& topology,
const std::string& input_name,
const Shape& input_shape,
const std::string& delta_name,
const Shape& delta_shape,
const std::string& output_name,
const Shape& output_shape,
const element::Type& output_type);
// Helper functions used in cldnn::custom_gpu_primitive kernels // Helper functions used in cldnn::custom_gpu_primitive kernels
std::vector<cldnn_arg> get_kernel_args(size_t input, size_t output); std::vector<cldnn_arg> get_kernel_args(size_t input, size_t output);
std::string array_dims(const Shape& dimentions, const AxisSet& axis = {}); std::string array_dims(const Shape& dimentions, const AxisSet& axis = {});
......
...@@ -21,7 +21,6 @@ backwards_maxpool_n4_c1_hw4_2x2_max ...@@ -21,7 +21,6 @@ backwards_maxpool_n4_c1_hw4_2x2_max
backwards_replace_slice backwards_replace_slice
backwards_reverse_sequence_n3_c2_h3 backwards_reverse_sequence_n3_c2_h3
backwards_reverse_sequence_n4d2c3h2w2 backwards_reverse_sequence_n4d2c3h2w2
backwards_sigmoid
backwards_sign backwards_sign
backwards_slice backwards_slice
backwards_tan backwards_tan
...@@ -79,7 +78,6 @@ scalar_constant_int64 ...@@ -79,7 +78,6 @@ scalar_constant_int64
select_and_scatter_3d_without_overlap select_and_scatter_3d_without_overlap
select_and_scatter_without_overlap select_and_scatter_without_overlap
select_and_scatter_with_overlap select_and_scatter_with_overlap
sigmoid_bprop_n1c1h4
sign sign
tan tan
tensor_constant_int64 tensor_constant_int64
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment