Commit d37b30ad authored by Louis Feng's avatar Louis Feng

clang format.

parent 78c57f10
......@@ -2404,9 +2404,11 @@ namespace ngraph
auto& mkldnn_emitter = external_function->get_mkldnn_emitter();
auto data_desc = mkldnn_emitter->build_memory_descriptor(data, data_format);
auto weights_desc = mkldnn_emitter->build_memory_descriptor(weights, weights_format);
auto weights_desc =
mkldnn_emitter->build_memory_descriptor(weights, weights_format);
auto bias_desc = mkldnn_emitter->build_memory_descriptor(bias, bias_format);
auto result_desc = mkldnn_emitter->build_memory_descriptor(result, result_format);
auto result_desc =
mkldnn_emitter->build_memory_descriptor(result, result_format);
// For dilation, MKLDNN wants to know how many elements to insert between, not how far
// apart to space the elements like nGraph. So we have to subtract 1 from each pos.
......@@ -2418,14 +2420,14 @@ namespace ngraph
}
size_t conv_index = mkldnn_emitter->build_convolution_forward(
data_desc,
weights_desc,
bias_desc,
result_desc,
convolution->get_window_movement_strides(),
window_dilation_strides_adjusted,
convolution->get_padding_below(),
convolution->get_padding_above());
data_desc,
weights_desc,
bias_desc,
result_desc,
convolution->get_window_movement_strides(),
window_dilation_strides_adjusted,
convolution->get_padding_below(),
convolution->get_padding_above());
auto& deps = mkldnn_emitter->get_primitive_deps(conv_index);
writer << "cpu::mkldnn_utils::set_memory_ptr(ctx, " << to_string(deps[0])
......@@ -2445,11 +2447,12 @@ namespace ngraph
throw ngraph_error("ConvolutionBias is only supported with MKLDNN kernel.");
}
}
template <>
void CPU_Emitter::EMITTER_DECL(ngraph::op::ConvolutionBiasBackpropFiltersBias)
{
auto convolution = static_cast<const ngraph::op::ConvolutionBiasBackpropFiltersBias*>(node);
auto convolution =
static_cast<const ngraph::op::ConvolutionBiasBackpropFiltersBias*>(node);
const TensorViewWrapper& data = args[0];
const TensorViewWrapper& delta = args[1];
const TensorViewWrapper& weights_delta = out[0];
......@@ -2473,8 +2476,10 @@ namespace ngraph
auto& mkldnn_emitter = external_function->get_mkldnn_emitter();
auto data_desc = mkldnn_emitter->build_memory_descriptor(data, data_format);
auto delta_desc = mkldnn_emitter->build_memory_descriptor(delta, 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 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);
size_t conv_index = mkldnn_emitter->build_convolution_backward_weights_bias(
data_desc,
......@@ -2501,7 +2506,8 @@ namespace ngraph
}
else
{
throw ngraph_error("ConvolutionBiasBackpropFiltersBias is only supported with MKLDNN kernel.");
throw ngraph_error(
"ConvolutionBiasBackpropFiltersBias is only supported with MKLDNN kernel.");
}
}
......
......@@ -120,35 +120,36 @@ size_t MKLDNNEmitter::build_convolution_forward(const mkldnn::memory::desc& inpu
const size_t result_index = build_memory_primitive(result_desc);
const size_t conv_index = insert_primitive(new mkldnn::convolution_forward(
{{mkldnn::prop_kind::forward,
mkldnn::algorithm::convolution_direct,
input_data_desc,
weights_desc,
bias_desc,
result_desc,
mkldnn::memory::dims(strides.begin(), strides.end()),
mkldnn::memory::dims(dilation_strides.begin(), dilation_strides.end()),
mkldnn::memory::dims(padding_below.begin(), padding_below.end()),
mkldnn::memory::dims(padding_above.begin(), padding_above.end()),
mkldnn::padding_kind::zero},
mkldnn_utils::global_cpu_engine},
*m_mkldnn_primitives[input_data_index],
*m_mkldnn_primitives[weights_index],
*m_mkldnn_primitives[bias_index],
*m_mkldnn_primitives[result_index]));
{{mkldnn::prop_kind::forward,
mkldnn::algorithm::convolution_direct,
input_data_desc,
weights_desc,
bias_desc,
result_desc,
mkldnn::memory::dims(strides.begin(), strides.end()),
mkldnn::memory::dims(dilation_strides.begin(), dilation_strides.end()),
mkldnn::memory::dims(padding_below.begin(), padding_below.end()),
mkldnn::memory::dims(padding_above.begin(), padding_above.end()),
mkldnn::padding_kind::zero},
mkldnn_utils::global_cpu_engine},
*m_mkldnn_primitives[input_data_index],
*m_mkldnn_primitives[weights_index],
*m_mkldnn_primitives[bias_index],
*m_mkldnn_primitives[result_index]));
m_primitive_deps[conv_index] = {input_data_index, weights_index, bias_index, result_index};
return conv_index;
}
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 &out_weights_delta_desc,
const mkldnn::memory::desc &out_bias_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)
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& out_weights_delta_desc,
const mkldnn::memory::desc& out_bias_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)
{
const size_t in_data_index = build_memory_primitive(in_data_desc);
const size_t in_delta_index = build_memory_primitive(in_delta_desc);
......@@ -172,26 +173,29 @@ size_t MKLDNNEmitter::build_convolution_backward_weights_bias(const mkldnn::memo
mkldnn::padding_kind::zero},
mkldnn_utils::global_cpu_engine};
mkldnn::convolution_backward_weights::primitive_desc bwd_pd{{mkldnn::algorithm::convolution_direct,
in_data_desc,
out_weights_delta_desc,
out_bias_delta_desc,
in_delta_desc,
strides,
dilation,
padding_l,
padding_r,
mkldnn::padding_kind::zero},
mkldnn_utils::global_cpu_engine,
fwd_pd};
const size_t conv_index = insert_primitive(new mkldnn::convolution_backward_weights(bwd_pd,
*m_mkldnn_primitives[in_data_index],
*m_mkldnn_primitives[in_delta_index],
*m_mkldnn_primitives[out_weights_delta_index],
*m_mkldnn_primitives[out_bias_delta_index]));
m_primitive_deps[conv_index] = {in_data_index, in_delta_index, out_weights_delta_index, out_bias_delta_index};
mkldnn::convolution_backward_weights::primitive_desc bwd_pd{
{mkldnn::algorithm::convolution_direct,
in_data_desc,
out_weights_delta_desc,
out_bias_delta_desc,
in_delta_desc,
strides,
dilation,
padding_l,
padding_r,
mkldnn::padding_kind::zero},
mkldnn_utils::global_cpu_engine,
fwd_pd};
const size_t conv_index = insert_primitive(
new mkldnn::convolution_backward_weights(bwd_pd,
*m_mkldnn_primitives[in_data_index],
*m_mkldnn_primitives[in_delta_index],
*m_mkldnn_primitives[out_weights_delta_index],
*m_mkldnn_primitives[out_bias_delta_index]));
m_primitive_deps[conv_index] = {
in_data_index, in_delta_index, out_weights_delta_index, out_bias_delta_index};
return conv_index;
}
......
......@@ -90,14 +90,15 @@ namespace ngraph
/**
* Convolution + bias backprop for weights and bias
*/
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 &out_weights_delta_desc,
const mkldnn::memory::desc &out_bias_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);
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& out_weights_delta_desc,
const mkldnn::memory::desc& out_bias_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);
size_t build_pooling_forward(mkldnn::algorithm pooling_algorithm,
const mkldnn::memory::desc& input_desc,
const mkldnn::memory::desc& result_desc,
......
......@@ -17,8 +17,8 @@
#include <numeric>
#include "ngraph/ops/convolution.hpp"
#include "ngraph/runtime/cpu/ops/conv_bias.hpp"
#include "ngraph/ops/get_output_element.hpp"
#include "ngraph/runtime/cpu/ops/conv_bias.hpp"
#include "ngraph/util.hpp"
using namespace std;
......@@ -99,15 +99,16 @@ void op::ConvolutionBias::generate_adjoints(autodiff::Adjoints& adjoints,
m_padding_above,
m_data_dilation_strides));
auto filter_bias_backprop = std::make_shared<op::ConvolutionBiasBackpropFiltersBias>(data,
filter_shape,
bias_shape,
delta,
m_window_movement_strides,
m_window_dilation_strides,
m_padding_below,
m_padding_above,
m_data_dilation_strides);
auto filter_bias_backprop =
std::make_shared<op::ConvolutionBiasBackpropFiltersBias>(data,
filter_shape,
bias_shape,
delta,
m_window_movement_strides,
m_window_dilation_strides,
m_padding_below,
m_padding_above,
m_data_dilation_strides);
auto filter_delta = std::make_shared<op::GetOutputElement>(filter_bias_backprop, 0);
auto bias_delta = std::make_shared<op::GetOutputElement>(filter_bias_backprop, 1);
......@@ -116,23 +117,23 @@ void op::ConvolutionBias::generate_adjoints(autodiff::Adjoints& adjoints,
}
op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias(
const std::shared_ptr<Node>& data_batch,
const Shape& filters_shape,
const Shape& bias_shape,
const std::shared_ptr<Node>& output_delta,
const Strides& window_movement_strides_forward,
const Strides& window_dilation_strides_forward,
const CoordinateDiff& padding_below_forward,
const CoordinateDiff& padding_above_forward,
const Strides& data_dilation_strides_forward)
: RequiresTensorViewArgs("ConvolutionBiasBackpropFiltersBias", {data_batch, output_delta})
, m_filters_shape(filters_shape)
, m_bias_shape(bias_shape)
, m_window_movement_strides_forward(window_movement_strides_forward)
, m_window_dilation_strides_forward(window_dilation_strides_forward)
, m_padding_below_forward(padding_below_forward)
, m_padding_above_forward(padding_above_forward)
, m_data_dilation_strides_forward(data_dilation_strides_forward)
const std::shared_ptr<Node>& data_batch,
const Shape& filters_shape,
const Shape& bias_shape,
const std::shared_ptr<Node>& output_delta,
const Strides& window_movement_strides_forward,
const Strides& window_dilation_strides_forward,
const CoordinateDiff& padding_below_forward,
const CoordinateDiff& padding_above_forward,
const Strides& data_dilation_strides_forward)
: RequiresTensorViewArgs("ConvolutionBiasBackpropFiltersBias", {data_batch, output_delta})
, m_filters_shape(filters_shape)
, m_bias_shape(bias_shape)
, m_window_movement_strides_forward(window_movement_strides_forward)
, m_window_dilation_strides_forward(window_dilation_strides_forward)
, m_padding_below_forward(padding_below_forward)
, m_padding_above_forward(padding_above_forward)
, m_data_dilation_strides_forward(data_dilation_strides_forward)
{
auto& data_batch_shape = get_input_shape(0);
auto& data_batch_et = get_input_element_type(0);
......@@ -144,7 +145,8 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias(
if (data_batch_et != output_delta_et)
{
throw ngraph_error(
"ConvolutionBiasBackpropFilterBias data batch and output delta element types do not match");
"ConvolutionBiasBackpropFilterBias data batch and output delta element types do not "
"match");
}
// Forward Backward
......@@ -160,11 +162,11 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias(
m_window_dilation_strides_backward.push_back(window_movement_strides_forward[i]);
m_padding_below_backward.push_back(padding_below_forward[i]);
m_padding_above_backward.push_back(
padding_above_forward[i] -
(padding_below_forward[i] +
(data_batch_shape[i + 2] - 1) * data_dilation_strides_forward[i] +
padding_above_forward[i] -
(filters_shape[i + 2] - 1) * window_dilation_strides_forward[i]) %
padding_above_forward[i] -
(padding_below_forward[i] +
(data_batch_shape[i + 2] - 1) * data_dilation_strides_forward[i] +
padding_above_forward[i] -
(filters_shape[i + 2] - 1) * window_dilation_strides_forward[i]) %
window_movement_strides_forward[i]);
m_data_dilation_strides_backward.push_back(data_dilation_strides_forward[i]);
}
......@@ -173,8 +175,8 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias(
add_output(data_batch_et, bias_shape);
}
std::shared_ptr<Node> op::ConvolutionBiasBackpropFiltersBias::copy_with_new_args(
const NodeVector& new_args) const
std::shared_ptr<Node>
op::ConvolutionBiasBackpropFiltersBias::copy_with_new_args(const NodeVector& new_args) const
{
if (new_args.size() != 2)
{
......
......@@ -38,7 +38,8 @@ namespace ngraph
std::shared_ptr<Node> get_bias() { return get_input_op(2); }
std::shared_ptr<Node> get_filters() { return get_input_op(1); }
std::shared_ptr<Node> get_data_batch() { return get_input_op(0); }
virtual std::shared_ptr<Node> copy_with_new_args(const NodeVector& new_args) const override;
virtual std::shared_ptr<Node>
copy_with_new_args(const NodeVector& new_args) const override;
void generate_adjoints(autodiff::Adjoints& adjoints,
const std::shared_ptr<Node>& delta) override;
......@@ -67,16 +68,17 @@ namespace ngraph
{
public:
ConvolutionBiasBackpropFiltersBias(const std::shared_ptr<Node>& data_batch,
const Shape& filters_shape,
const Shape& bias_shape,
const std::shared_ptr<Node>& output_delta,
const Strides& window_movement_strides_forward,
const Strides& window_dilation_strides_forward,
const CoordinateDiff& padding_below_forward,
const CoordinateDiff& padding_above_forward,
const Strides& data_dilation_strides_forward);
const Shape& filters_shape,
const Shape& bias_shape,
const std::shared_ptr<Node>& output_delta,
const Strides& window_movement_strides_forward,
const Strides& window_dilation_strides_forward,
const CoordinateDiff& padding_below_forward,
const CoordinateDiff& padding_above_forward,
const Strides& data_dilation_strides_forward);
virtual std::shared_ptr<Node> copy_with_new_args(const NodeVector& new_args) const override;
virtual std::shared_ptr<Node>
copy_with_new_args(const NodeVector& new_args) const override;
/// \return The filters tensor shape.
const Shape& get_filters_shape() const { return m_filters_shape; }
......
......@@ -195,7 +195,8 @@ namespace ngraph
data_dilated = data_dilated || (s != 1);
}
if (!data_dilated && data_rank == 4 && delta_rank == 4 && node->get_input_element_type(0) == element::f32)
if (!data_dilated && data_rank == 4 && delta_rank == 4 &&
node->get_input_element_type(0) == element::f32)
{
auto op_annotations =
std::make_shared<ngraph::runtime::cpu::CPUOpAnnotations>();
......@@ -293,7 +294,7 @@ static const runtime::cpu::pass::AssignOpMap s_dispatcher{
&runtime::cpu::pass::CPUAssignment::assign<ngraph::op::ConvolutionBackpropData>},
{TI(ngraph::op::ConvolutionBackpropFilters),
&runtime::cpu::pass::CPUAssignment::assign<ngraph::op::ConvolutionBackpropFilters>},
{TI(ngraph::op::ConvolutionBias),
{TI(ngraph::op::ConvolutionBias),
&runtime::cpu::pass::CPUAssignment::assign<ngraph::op::ConvolutionBias>},
{TI(ngraph::op::ConvolutionBiasBackpropFiltersBias),
&runtime::cpu::pass::CPUAssignment::assign<ngraph::op::ConvolutionBiasBackpropFiltersBias>},
......
......@@ -548,4 +548,3 @@ void ngraph::runtime::cpu::pass::CPUFusion::construct_conv_bias()
auto m = std::make_shared<ngraph::pattern::Matcher>(p_conv_bias, callback);
this->add_matcher(m);
}
......@@ -43,7 +43,7 @@ public:
construct_fprop_bn();
construct_zero_padded_reshaped_conv();
construct_zero_padded_conv();
construct_conv_bias();
construct_conv_bias();
}
private:
......
......@@ -21,6 +21,7 @@
#include <memory>
#include "gtest/gtest.h"
#include "ngraph/file_util.hpp"
#include "ngraph/graph_util.hpp"
#include "ngraph/log.hpp"
#include "ngraph/ngraph.hpp"
......@@ -29,12 +30,11 @@
#include "ngraph/ops/sum.hpp"
#include "ngraph/pass/graph_rewrite.hpp"
#include "ngraph/pass/manager.hpp"
#include "ngraph/pass/reshape_elimination.hpp"
#include "ngraph/pass/visualize_tree.hpp"
#include "ngraph/pattern/matcher.hpp"
#include "ngraph/pattern/op/any.hpp"
#include "ngraph/pattern/op/label.hpp"
#include "ngraph/file_util.hpp"
#include "ngraph/pass/reshape_elimination.hpp"
#include "ngraph/pass/visualize_tree.hpp"
#include "ngraph/runtime/cpu/ops/conv_bias.hpp"
#include "ngraph/runtime/cpu/ops/matmul_bias.hpp"
#include "ngraph/runtime/cpu/pass/cpu_fusion.hpp"
......@@ -619,7 +619,8 @@ struct ConvolutionBiasTestData
shared_ptr<op::Parameter> bias;
shared_ptr<op::Parameter> delta;
void n1c1h3w3(shared_ptr<runtime::Backend> backend) {
void n1c1h3w3(shared_ptr<runtime::Backend> backend)
{
n = 1;
c = 1;
filter = 1;
......@@ -633,47 +634,68 @@ struct ConvolutionBiasTestData
weights = make_shared<op::Parameter>(element::f32, weights_shape);
bias_shape = Shape{filter};
bias = make_shared<op::Parameter>(element::f32, bias_shape);
result_shape = Shape{n,filter,1,1};
result_shape = Shape{n, filter, 1, 1};
data_val = backend->make_primary_tensor_view(element::f32, data_shape);
copy_data(data_val, vector<float>{-0.67765152f, 0.10073948f, 0.57595438f,
-0.3469252f, -0.22134334f, -1.80471897f,
-0.80642909f, 1.22033095f, 2.23235631f});
copy_data(data_val,
vector<float>{-0.67765152f,
0.10073948f,
0.57595438f,
-0.3469252f,
-0.22134334f,
-1.80471897f,
-0.80642909f,
1.22033095f,
2.23235631f});
weights_val = backend->make_primary_tensor_view(element::f32, weights_shape);
copy_data(weights_val, vector<float>{0.20070229f, -0.54968649f, -0.19819015f,
-0.38577855f, 1.37109005f, -0.23789984f,
0.14867957f, -0.49851316f, -0.84815776f});
copy_data(weights_val,
vector<float>{0.20070229f,
-0.54968649f,
-0.19819015f,
-0.38577855f,
1.37109005f,
-0.23789984f,
0.14867957f,
-0.49851316f,
-0.84815776f});
bias_val = backend->make_primary_tensor_view(element::f32, bias_shape);
copy_data(bias_val, vector<float>{0.07811152f});
result_val = backend->make_primary_tensor_view(element::f32, result_shape);
copy_data(result_val, vector<float>{0});
delta = make_shared<op::Parameter>(element::f32, result_shape);
delta_val = backend->make_primary_tensor_view(element::f32, result_shape);
copy_data(delta_val, vector<float>{-2.58936238f});
d_data_val = backend->make_primary_tensor_view(element::f32, data_shape);
copy_data(d_data_val, vector<float>{0,0,0,
0,0,0,
0,0,0});
copy_data(d_data_val, vector<float>{0, 0, 0, 0, 0, 0, 0, 0, 0});
d_weights_val = backend->make_primary_tensor_view(element::f32, weights_shape);
copy_data(d_weights_val, vector<float>{0,0,0,
0,0,0,
0,0,0});
copy_data(d_weights_val, vector<float>{0, 0, 0, 0, 0, 0, 0, 0, 0});
d_bias_val = backend->make_primary_tensor_view(element::f32, bias_shape);
copy_data(d_bias_val, vector<float>{0});
expected_result_val = vector<float>{-2.58936238f};
expected_d_data_val = vector<float>{-0.51969099f, 1.42333758f, 0.5131861f,
0.99892044f, -3.5502491f, 0.61600888f,
-0.3849853f, 1.29083121f, 2.19618773f};
expected_d_weights_val = vector<float>{1.7546854f, -0.26085103f, -1.49135458f,
0.89831507f, 0.57313812f, 4.67307138f,
2.08813715f, -3.15987897f, -5.7803793f};
expected_d_data_val = vector<float>{-0.51969099f,
1.42333758f,
0.5131861f,
0.99892044f,
-3.5502491f,
0.61600888f,
-0.3849853f,
1.29083121f,
2.19618773f};
expected_d_weights_val = vector<float>{1.7546854f,
-0.26085103f,
-1.49135458f,
0.89831507f,
0.57313812f,
4.67307138f,
2.08813715f,
-3.15987897f,
-5.7803793f};
expected_d_bias_val = vector<float>{-2.58936238f};
}
};
......@@ -689,14 +711,17 @@ TEST(cpu_fusion, conv_bias_fprop_n1c1h3w3)
auto convolution = make_shared<op::Convolution>(conv_test.data, conv_test.weights);
auto convolution_bias = make_shared<op::ConvolutionBias>(convolution, conv_test.bias);
auto f = make_shared<Function>(convolution_bias, op::ParameterVector{conv_test.data, conv_test.weights, conv_test.bias});
auto f = make_shared<Function>(
convolution_bias, op::ParameterVector{conv_test.data, conv_test.weights, conv_test.bias});
auto external = manager->compile(f);
auto cf = backend->make_call_frame(external);
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);
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)));
}
TEST(cpu_fusion, conv_bias_bprop_n1c1h3w3)
......@@ -710,22 +735,27 @@ TEST(cpu_fusion, conv_bias_bprop_n1c1h3w3)
auto convolution = make_shared<op::Convolution>(conv_test.data, conv_test.weights);
auto convolution_bias = make_shared<op::ConvolutionBias>(convolution, conv_test.bias);
auto f = make_shared<Function>(convolution_bias, op::ParameterVector{conv_test.data, conv_test.weights, conv_test.bias});
auto f = make_shared<Function>(
convolution_bias, op::ParameterVector{conv_test.data, conv_test.weights, conv_test.bias});
auto d_data = convolution_bias->backprop_node(conv_test.data, conv_test.delta);
auto d_weights = convolution_bias->backprop_node(conv_test.weights, conv_test.delta);
auto d_bias = convolution_bias->backprop_node(conv_test.bias, conv_test.delta);
auto df = make_shared<Function>(NodeVector{d_data, d_weights, d_bias},
op::ParameterVector{conv_test.data, conv_test.weights, conv_test.bias, conv_test.delta});
auto df = make_shared<Function>(
NodeVector{d_data, d_weights, d_bias},
op::ParameterVector{conv_test.data, conv_test.weights, conv_test.bias, conv_test.delta});
auto external = manager->compile(df);
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});
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_bias_val, read_vector<float>(conv_test.d_bias_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_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