Commit 338b9622 authored by Louis Feng's avatar Louis Feng

clean up.

parent 812a699a
...@@ -2445,6 +2445,7 @@ namespace ngraph ...@@ -2445,6 +2445,7 @@ namespace ngraph
throw ngraph_error("ConvolutionBias is only supported with MKLDNN kernel."); throw ngraph_error("ConvolutionBias is only supported with MKLDNN kernel.");
} }
} }
template <> template <>
void CPU_Emitter::EMITTER_DECL(ngraph::op::ConvolutionBiasBackpropFiltersBias) void CPU_Emitter::EMITTER_DECL(ngraph::op::ConvolutionBiasBackpropFiltersBias)
{ {
...@@ -2475,15 +2476,15 @@ namespace ngraph ...@@ -2475,15 +2476,15 @@ namespace ngraph
auto weights_delta_desc = mkldnn_emitter->build_memory_descriptor(weights_delta, weights_delta_format); auto weights_delta_desc = mkldnn_emitter->build_memory_descriptor(weights_delta, weights_delta_format);
auto bias_delta_desc = mkldnn_emitter->build_memory_descriptor(bias_delta, bias_delta_format); auto bias_delta_desc = mkldnn_emitter->build_memory_descriptor(bias_delta, bias_delta_format);
size_t conv_index = mkldnn_emitter->build_convolution_backward_filters_bias( size_t conv_index = mkldnn_emitter->build_convolution_backward_weights_bias(
data_desc, data_desc,
delta_desc, delta_desc,
weights_delta_desc, weights_delta_desc,
bias_delta_desc, bias_delta_desc,
convolution->get_window_movement_strides_forward(), convolution->get_window_movement_strides_forward(),
window_dilation_strides_adjusted, window_dilation_strides_adjusted,
convolution->get_padding_below_forward(), convolution->get_padding_below_forward(),
convolution->get_padding_above_forward()); convolution->get_padding_above_forward());
auto& deps = mkldnn_emitter->get_primitive_deps(conv_index); auto& deps = mkldnn_emitter->get_primitive_deps(conv_index);
writer << "cpu::mkldnn_utils::set_memory_ptr(ctx, " << to_string(deps[0]) writer << "cpu::mkldnn_utils::set_memory_ptr(ctx, " << to_string(deps[0])
......
...@@ -141,7 +141,7 @@ size_t MKLDNNEmitter::build_convolution_forward(const mkldnn::memory::desc& inpu ...@@ -141,7 +141,7 @@ size_t MKLDNNEmitter::build_convolution_forward(const mkldnn::memory::desc& inpu
return conv_index; return conv_index;
} }
size_t MKLDNNEmitter::build_convolution_backward_filters_bias(const mkldnn::memory::desc &in_data_desc, size_t MKLDNNEmitter::build_convolution_backward_weights_bias(const mkldnn::memory::desc &in_data_desc,
const mkldnn::memory::desc &in_delta_desc, const mkldnn::memory::desc &in_delta_desc,
const mkldnn::memory::desc &out_weights_delta_desc, const mkldnn::memory::desc &out_weights_delta_desc,
const mkldnn::memory::desc &out_bias_delta_desc, const mkldnn::memory::desc &out_bias_delta_desc,
......
...@@ -70,6 +70,7 @@ namespace ngraph ...@@ -70,6 +70,7 @@ namespace ngraph
const ngraph::Strides& dilation_strides, const ngraph::Strides& dilation_strides,
const ngraph::CoordinateDiff& padding_below, const ngraph::CoordinateDiff& padding_below,
const ngraph::CoordinateDiff& padding_above); const ngraph::CoordinateDiff& padding_above);
size_t size_t
build_convolution_backward_weights(const mkldnn::memory::desc& input_desc, build_convolution_backward_weights(const mkldnn::memory::desc& input_desc,
const mkldnn::memory::desc& delta_desc, const mkldnn::memory::desc& delta_desc,
...@@ -79,20 +80,17 @@ namespace ngraph ...@@ -79,20 +80,17 @@ namespace ngraph
const ngraph::CoordinateDiff& padding_below, const ngraph::CoordinateDiff& padding_below,
const ngraph::CoordinateDiff& padding_above); const ngraph::CoordinateDiff& padding_above);
size_t build_convolution_backward_data(const mkldnn::memory::desc& weights_desc,
const mkldnn::memory::desc& delta_desc,
const mkldnn::memory::desc& result_desc,
const ngraph::Strides& strides,
const ngraph::Strides& dilation_strides,
const ngraph::CoordinateDiff& padding_below,
const ngraph::CoordinateDiff& padding_above);
/** /**
* Convolution backprop for data * Convolution + bias backprop for weights and bias
*/
size_t build_convolution_backward_data(const mkldnn::memory::desc &in_weights_desc,
const mkldnn::memory::desc &in_delta_desc,
const mkldnn::memory::desc &out_data_delta_desc,
const ngraph::Strides &ng_strides,
const ngraph::Strides &ng_dilation_strides,
const ngraph::CoordinateDiff &ng_padding_below,
const ngraph::CoordinateDiff &ng_padding_above);
/**
* Convolution + bias backprop for filters and bias
*/ */
size_t build_convolution_backward_filters_bias(const mkldnn::memory::desc &in_data_desc, size_t build_convolution_backward_weights_bias(const mkldnn::memory::desc &in_data_desc,
const mkldnn::memory::desc &in_delta_desc, const mkldnn::memory::desc &in_delta_desc,
const mkldnn::memory::desc &out_weights_delta_desc, const mkldnn::memory::desc &out_weights_delta_desc,
const mkldnn::memory::desc &out_bias_delta_desc, const mkldnn::memory::desc &out_bias_delta_desc,
......
...@@ -46,9 +46,9 @@ static const std::unordered_set<std::type_index> s_op_registry{ ...@@ -46,9 +46,9 @@ static const std::unordered_set<std::type_index> s_op_registry{
TI(ngraph::op::BatchNorm), TI(ngraph::op::BatchNorm),
TI(ngraph::op::BatchNormBackprop), TI(ngraph::op::BatchNormBackprop),
TI(ngraph::op::Convolution), TI(ngraph::op::Convolution),
TI(ngraph::op::ConvolutionBias),
TI(ngraph::op::ConvolutionBackpropData), TI(ngraph::op::ConvolutionBackpropData),
TI(ngraph::op::ConvolutionBackpropFilters), TI(ngraph::op::ConvolutionBackpropFilters),
TI(ngraph::op::ConvolutionBias),
TI(ngraph::op::ConvolutionBiasBackpropFiltersBias), TI(ngraph::op::ConvolutionBiasBackpropFiltersBias),
TI(ngraph::op::MaxPool), TI(ngraph::op::MaxPool),
TI(ngraph::op::MaxPoolBackprop), TI(ngraph::op::MaxPoolBackprop),
......
...@@ -88,6 +88,7 @@ void op::ConvolutionBias::generate_adjoints(autodiff::Adjoints& adjoints, ...@@ -88,6 +88,7 @@ void op::ConvolutionBias::generate_adjoints(autodiff::Adjoints& adjoints,
auto bias = get_input_op(2); auto bias = get_input_op(2);
const auto bias_shape = bias->get_shape(); const auto bias_shape = bias->get_shape();
// using regular convolution backprop for data
adjoints.add_delta(data, adjoints.add_delta(data,
std::make_shared<op::ConvolutionBackpropData>(data_shape, std::make_shared<op::ConvolutionBackpropData>(data_shape,
filter, filter,
...@@ -124,8 +125,9 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias( ...@@ -124,8 +125,9 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias(
const CoordinateDiff& padding_below_forward, const CoordinateDiff& padding_below_forward,
const CoordinateDiff& padding_above_forward, const CoordinateDiff& padding_above_forward,
const Strides& data_dilation_strides_forward) const Strides& data_dilation_strides_forward)
: RequiresTensorViewArgs("ConvolutionBackpropFilters", {data_batch, output_delta}) : RequiresTensorViewArgs("ConvolutionBiasBackpropFiltersBias", {data_batch, output_delta})
, m_filters_shape(filters_shape) , m_filters_shape(filters_shape)
, m_bias_shape(bias_shape)
, m_window_movement_strides_forward(window_movement_strides_forward) , m_window_movement_strides_forward(window_movement_strides_forward)
, m_window_dilation_strides_forward(window_dilation_strides_forward) , m_window_dilation_strides_forward(window_dilation_strides_forward)
, m_padding_below_forward(padding_below_forward) , m_padding_below_forward(padding_below_forward)
...@@ -134,7 +136,6 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias( ...@@ -134,7 +136,6 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias(
{ {
auto& data_batch_shape = get_input_shape(0); auto& data_batch_shape = get_input_shape(0);
auto& data_batch_et = get_input_element_type(0); auto& data_batch_et = get_input_element_type(0);
auto& output_delta_shape = get_input_shape(1);
auto& output_delta_et = get_input_element_type(1); auto& output_delta_et = get_input_element_type(1);
// //
...@@ -143,7 +144,7 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias( ...@@ -143,7 +144,7 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias(
if (data_batch_et != output_delta_et) if (data_batch_et != output_delta_et)
{ {
throw ngraph_error( throw ngraph_error(
"ConvolutionBias filter backprop data batch and output delta element types do not match"); "ConvolutionBiasBackpropFilterBias data batch and output delta element types do not match");
} }
// Forward Backward // Forward Backward
...@@ -168,31 +169,6 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias( ...@@ -168,31 +169,6 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias(
m_data_dilation_strides_backward.push_back(data_dilation_strides_forward[i]); m_data_dilation_strides_backward.push_back(data_dilation_strides_forward[i]);
} }
// Shape inferred_convolution_filters_shape =
// infer_convolution_output_shape(data_batch_shape,
// filters_delta_shape,
// m_window_movement_strides_backward,
// m_window_dilation_strides_backward,
// m_padding_below_backward,
// m_padding_above_backward,
// m_data_dilation_strides_backward,
// 1,
// 0,
// 0,
// 1,
// 1,
// 0,
// "In ConvolutionBiasBackpropFiltersBias: ");
//
// // Not sure if this can ever actually happen (i.e., I think it will trip on something else
// // inside infer_convolution_output_shape before we get here) but it seems worth checking.
// if (inferred_convolution_filters_shape != filters_shape)
// {
// throw ngraph_error(
// "ConvolutionBias filter bias backprop inferred output shape does not match "
// "specified filter shape");
// }
add_output(data_batch_et, filters_shape); add_output(data_batch_et, filters_shape);
add_output(data_batch_et, bias_shape); add_output(data_batch_et, bias_shape);
} }
......
...@@ -23,6 +23,7 @@ namespace ngraph ...@@ -23,6 +23,7 @@ namespace ngraph
{ {
namespace op namespace op
{ {
/// \brief Convolution + bias forward prop for batched convolution operation.
class ConvolutionBias : public util::RequiresTensorViewArgs class ConvolutionBias : public util::RequiresTensorViewArgs
{ {
public: public:
...@@ -60,20 +61,11 @@ namespace ngraph ...@@ -60,20 +61,11 @@ namespace ngraph
const Strides& data_dilation_strides); const Strides& data_dilation_strides);
}; };
/// \brief Filters and bias backprop for batched convolution operation. /// \brief Filters and bias backprop for batched convolution operation. Data backprop is
/// the same as regular convolution backprop for data.
class ConvolutionBiasBackpropFiltersBias : public util::RequiresTensorViewArgs class ConvolutionBiasBackpropFiltersBias : public util::RequiresTensorViewArgs
{ {
public: public:
/// \brief Constructs a batched-convolution filter-backprop operation.
///
/// \param data_batch The tensor producing the data batch from forward-prop.
/// \param filters_shape The shape of the filters from forward-prop.
/// \param output_delta The node producing output delta.
/// \param window_movement_strides_forward The window movement strides from forward-prop.
/// \param window_dilation_strides_forward The window dilation strides from forward-prop.
/// \param padding_below_forward The padding-below sizes from forward-prop.
/// \param padding_above_forward The padding-above sizes from forward-prop.
/// \param data_dilation_strides_forward The data dilation strides from forward-prop.
ConvolutionBiasBackpropFiltersBias(const std::shared_ptr<Node>& data_batch, ConvolutionBiasBackpropFiltersBias(const std::shared_ptr<Node>& data_batch,
const Shape& filters_shape, const Shape& filters_shape,
const Shape& bias_shape, const Shape& bias_shape,
...@@ -88,6 +80,8 @@ namespace ngraph ...@@ -88,6 +80,8 @@ namespace ngraph
/// \return The filters tensor shape. /// \return The filters tensor shape.
const Shape& get_filters_shape() const { return m_filters_shape; } const Shape& get_filters_shape() const { return m_filters_shape; }
/// \return The bias tensor shape.
const Shape& get_bias_shape() const { return m_bias_shape; }
/// \return The window movement strides from the forward prop. /// \return The window movement strides from the forward prop.
const Strides& get_window_movement_strides_forward() const const Strides& get_window_movement_strides_forward() const
{ {
......
...@@ -99,9 +99,9 @@ namespace ngraph ...@@ -99,9 +99,9 @@ namespace ngraph
} }
template <> template <>
void CPUAssignment::ASSIGN_DECL(ngraph::op::ConvolutionBias) void CPUAssignment::ASSIGN_DECL(ngraph::op::ConvolutionBackpropData)
{ {
auto convolution = static_cast<op::ConvolutionBias*>(node); auto convolution = static_cast<op::ConvolutionBackpropData*>(node);
auto arg0_shape = node->get_input_shape(0); auto arg0_shape = node->get_input_shape(0);
auto arg1_shape = node->get_input_shape(1); auto arg1_shape = node->get_input_shape(1);
...@@ -110,7 +110,7 @@ namespace ngraph ...@@ -110,7 +110,7 @@ namespace ngraph
auto arg1_rank = arg1_shape.size(); auto arg1_rank = arg1_shape.size();
bool data_dilated = false; bool data_dilated = false;
for (size_t s : convolution->get_data_dilation_strides()) for (size_t s : convolution->get_data_dilation_strides_forward())
{ {
data_dilated = data_dilated || (s != 1); data_dilated = data_dilated || (s != 1);
} }
...@@ -126,9 +126,9 @@ namespace ngraph ...@@ -126,9 +126,9 @@ namespace ngraph
} }
template <> template <>
void CPUAssignment::ASSIGN_DECL(ngraph::op::ConvolutionBackpropData) void CPUAssignment::ASSIGN_DECL(ngraph::op::ConvolutionBackpropFilters)
{ {
auto convolution = static_cast<op::ConvolutionBackpropData*>(node); auto convolution = static_cast<op::ConvolutionBackpropFilters*>(node);
auto arg0_shape = node->get_input_shape(0); auto arg0_shape = node->get_input_shape(0);
auto arg1_shape = node->get_input_shape(1); auto arg1_shape = node->get_input_shape(1);
...@@ -153,23 +153,23 @@ namespace ngraph ...@@ -153,23 +153,23 @@ namespace ngraph
} }
template <> template <>
void CPUAssignment::ASSIGN_DECL(ngraph::op::ConvolutionBackpropFilters) void CPUAssignment::ASSIGN_DECL(ngraph::op::ConvolutionBias)
{ {
auto convolution = static_cast<op::ConvolutionBackpropFilters*>(node); auto convolution = static_cast<op::ConvolutionBias*>(node);
auto arg0_shape = node->get_input_shape(0); auto data_shape = node->get_input_shape(0);
auto arg1_shape = node->get_input_shape(1); auto weights_shape = node->get_input_shape(1);
auto result_shape = node->get_output_shape(0); auto result_shape = node->get_output_shape(0);
auto arg0_rank = arg0_shape.size(); auto data_rank = data_shape.size();
auto arg1_rank = arg1_shape.size(); auto weights_rank = weights_shape.size();
bool data_dilated = false; bool data_dilated = false;
for (size_t s : convolution->get_data_dilation_strides_forward()) for (size_t s : convolution->get_data_dilation_strides())
{ {
data_dilated = data_dilated || (s != 1); data_dilated = data_dilated || (s != 1);
} }
if (!data_dilated && arg0_rank == 4 && arg1_rank == 4 && if (!data_dilated && data_rank == 4 && weights_rank == 4 &&
node->get_input_element_type(0) == element::f32) node->get_input_element_type(0) == element::f32)
{ {
auto op_annotations = auto op_annotations =
...@@ -289,12 +289,12 @@ static const runtime::cpu::pass::AssignOpMap s_dispatcher{ ...@@ -289,12 +289,12 @@ static const runtime::cpu::pass::AssignOpMap s_dispatcher{
{TI(ngraph::op::Add), &runtime::cpu::pass::CPUAssignment::assign<ngraph::op::Add>}, {TI(ngraph::op::Add), &runtime::cpu::pass::CPUAssignment::assign<ngraph::op::Add>},
{TI(ngraph::op::Convolution), {TI(ngraph::op::Convolution),
&runtime::cpu::pass::CPUAssignment::assign<ngraph::op::Convolution>}, &runtime::cpu::pass::CPUAssignment::assign<ngraph::op::Convolution>},
{TI(ngraph::op::ConvolutionBias),
&runtime::cpu::pass::CPUAssignment::assign<ngraph::op::ConvolutionBias>},
{TI(ngraph::op::ConvolutionBackpropData), {TI(ngraph::op::ConvolutionBackpropData),
&runtime::cpu::pass::CPUAssignment::assign<ngraph::op::ConvolutionBackpropData>}, &runtime::cpu::pass::CPUAssignment::assign<ngraph::op::ConvolutionBackpropData>},
{TI(ngraph::op::ConvolutionBackpropFilters), {TI(ngraph::op::ConvolutionBackpropFilters),
&runtime::cpu::pass::CPUAssignment::assign<ngraph::op::ConvolutionBackpropFilters>}, &runtime::cpu::pass::CPUAssignment::assign<ngraph::op::ConvolutionBackpropFilters>},
{TI(ngraph::op::ConvolutionBias),
&runtime::cpu::pass::CPUAssignment::assign<ngraph::op::ConvolutionBias>},
{TI(ngraph::op::ConvolutionBiasBackpropFiltersBias), {TI(ngraph::op::ConvolutionBiasBackpropFiltersBias),
&runtime::cpu::pass::CPUAssignment::assign<ngraph::op::ConvolutionBiasBackpropFiltersBias>}, &runtime::cpu::pass::CPUAssignment::assign<ngraph::op::ConvolutionBiasBackpropFiltersBias>},
{TI(ngraph::op::AvgPool), &runtime::cpu::pass::CPUAssignment::assign<ngraph::op::AvgPool>}, {TI(ngraph::op::AvgPool), &runtime::cpu::pass::CPUAssignment::assign<ngraph::op::AvgPool>},
......
...@@ -52,5 +52,5 @@ private: ...@@ -52,5 +52,5 @@ private:
void construct_fprop_bn(); void construct_fprop_bn();
void construct_zero_padded_reshaped_conv(); void construct_zero_padded_reshaped_conv();
void construct_zero_padded_conv(); void construct_zero_padded_conv();
void construct_conv_bias(); void construct_conv_bias();
}; };
...@@ -695,10 +695,7 @@ TEST(cpu_fusion, conv_bias_fprop_n1c1h3w3) ...@@ -695,10 +695,7 @@ TEST(cpu_fusion, conv_bias_fprop_n1c1h3w3)
cf->call({conv_test.data_val, conv_test.weights_val, conv_test.bias_val}, {conv_test.result_val}); cf->call({conv_test.data_val, conv_test.weights_val, conv_test.bias_val}, {conv_test.result_val});
auto result_vec = read_vector<float>(conv_test.result_val); auto result_vec = read_vector<float>(conv_test.result_val);
for (size_t i = 0; i < result_vec.size(); ++i) {
std::cout << result_vec[i] << " ";
}
std::cout << std::endl;
EXPECT_TRUE(test::all_close(conv_test.expected_result_val, read_vector<float>(conv_test.result_val))); EXPECT_TRUE(test::all_close(conv_test.expected_result_val, read_vector<float>(conv_test.result_val)));
} }
...@@ -726,21 +723,7 @@ TEST(cpu_fusion, conv_bias_bprop_n1c1h3w3) ...@@ -726,21 +723,7 @@ TEST(cpu_fusion, conv_bias_bprop_n1c1h3w3)
auto cf = backend->make_call_frame(external); auto cf = backend->make_call_frame(external);
cf->call({conv_test.data_val, conv_test.weights_val, conv_test.bias_val, conv_test.delta_val}, {conv_test.d_data_val, conv_test.d_weights_val, conv_test.d_bias_val}); cf->call({conv_test.data_val, conv_test.weights_val, conv_test.bias_val, conv_test.delta_val}, {conv_test.d_data_val, conv_test.d_weights_val, conv_test.d_bias_val});
auto result_vec = read_vector<float>(conv_test.d_data_val);
for (size_t i = 0; i < result_vec.size(); ++i) {
std::cout << result_vec[i] << " ";
}
std::cout << std::endl;
result_vec = read_vector<float>(conv_test.d_weights_val);
for (size_t i = 0; i < result_vec.size(); ++i) {
std::cout << result_vec[i] << " ";
}
std::cout << std::endl;
result_vec = read_vector<float>(conv_test.d_bias_val);
for (size_t i = 0; i < result_vec.size(); ++i) {
std::cout << result_vec[i] << " ";
}
std::cout << std::endl;
EXPECT_TRUE(test::all_close(conv_test.expected_d_data_val, read_vector<float>(conv_test.d_data_val))); EXPECT_TRUE(test::all_close(conv_test.expected_d_data_val, read_vector<float>(conv_test.d_data_val)));
EXPECT_TRUE(test::all_close(conv_test.expected_d_weights_val, read_vector<float>(conv_test.d_weights_val))); EXPECT_TRUE(test::all_close(conv_test.expected_d_weights_val, read_vector<float>(conv_test.d_weights_val)));
EXPECT_TRUE(test::all_close(conv_test.expected_d_bias_val, read_vector<float>(conv_test.d_bias_val))); EXPECT_TRUE(test::all_close(conv_test.expected_d_bias_val, read_vector<float>(conv_test.d_bias_val)));
......
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