Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
ngraph
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
ngraph
Commits
d37b30ad
Commit
d37b30ad
authored
Mar 07, 2018
by
Louis Feng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang format.
parent
78c57f10
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
196 additions
and
151 deletions
+196
-151
cpu_emitter.cpp
src/ngraph/runtime/cpu/cpu_emitter.cpp
+21
-15
mkldnn_emitter.cpp
src/ngraph/runtime/cpu/mkldnn_emitter.cpp
+48
-44
mkldnn_emitter.hpp
src/ngraph/runtime/cpu/mkldnn_emitter.hpp
+9
-8
conv_bias.cpp
src/ngraph/runtime/cpu/ops/conv_bias.cpp
+37
-35
conv_bias.hpp
src/ngraph/runtime/cpu/ops/conv_bias.hpp
+12
-10
cpu_assignment.cpp
src/ngraph/runtime/cpu/pass/cpu_assignment.cpp
+3
-2
cpu_fusion.cpp
src/ngraph/runtime/cpu/pass/cpu_fusion.cpp
+0
-1
cpu_fusion.hpp
src/ngraph/runtime/cpu/pass/cpu_fusion.hpp
+1
-1
cpu_fusion.cpp
test/cpu_fusion.cpp
+65
-35
No files found.
src/ngraph/runtime/cpu/cpu_emitter.cpp
View file @
d37b30ad
...
...
@@ -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."
);
}
}
...
...
src/ngraph/runtime/cpu/mkldnn_emitter.cpp
View file @
d37b30ad
...
...
@@ -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
;
}
...
...
src/ngraph/runtime/cpu/mkldnn_emitter.hpp
View file @
d37b30ad
...
...
@@ -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
,
...
...
src/ngraph/runtime/cpu/ops/conv_bias.cpp
View file @
d37b30ad
...
...
@@ -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
)
{
...
...
src/ngraph/runtime/cpu/ops/conv_bias.hpp
View file @
d37b30ad
...
...
@@ -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
;
}
...
...
src/ngraph/runtime/cpu/pass/cpu_assignment.cpp
View file @
d37b30ad
...
...
@@ -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
>
},
...
...
src/ngraph/runtime/cpu/pass/cpu_fusion.cpp
View file @
d37b30ad
...
...
@@ -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
);
}
src/ngraph/runtime/cpu/pass/cpu_fusion.hpp
100755 → 100644
View file @
d37b30ad
...
...
@@ -43,7 +43,7 @@ public:
construct_fprop_bn
();
construct_zero_padded_reshaped_conv
();
construct_zero_padded_conv
();
construct_conv_bias
();
construct_conv_bias
();
}
private
:
...
...
test/cpu_fusion.cpp
View file @
d37b30ad
...
...
@@ -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.67765152
f
,
0.10073948
f
,
0.57595438
f
,
-
0.3469252
f
,
-
0.22134334
f
,
-
1.80471897
f
,
-
0.80642909
f
,
1.22033095
f
,
2.23235631
f
});
copy_data
(
data_val
,
vector
<
float
>
{
-
0.67765152
f
,
0.10073948
f
,
0.57595438
f
,
-
0.3469252
f
,
-
0.22134334
f
,
-
1.80471897
f
,
-
0.80642909
f
,
1.22033095
f
,
2.23235631
f
});
weights_val
=
backend
->
make_primary_tensor_view
(
element
::
f32
,
weights_shape
);
copy_data
(
weights_val
,
vector
<
float
>
{
0.20070229
f
,
-
0.54968649
f
,
-
0.19819015
f
,
-
0.38577855
f
,
1.37109005
f
,
-
0.23789984
f
,
0.14867957
f
,
-
0.49851316
f
,
-
0.84815776
f
});
copy_data
(
weights_val
,
vector
<
float
>
{
0.20070229
f
,
-
0.54968649
f
,
-
0.19819015
f
,
-
0.38577855
f
,
1.37109005
f
,
-
0.23789984
f
,
0.14867957
f
,
-
0.49851316
f
,
-
0.84815776
f
});
bias_val
=
backend
->
make_primary_tensor_view
(
element
::
f32
,
bias_shape
);
copy_data
(
bias_val
,
vector
<
float
>
{
0.07811152
f
});
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.58936238
f
});
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.58936238
f
};
expected_d_data_val
=
vector
<
float
>
{
-
0.51969099
f
,
1.42333758
f
,
0.5131861
f
,
0.99892044
f
,
-
3.5502491
f
,
0.61600888
f
,
-
0.3849853
f
,
1.29083121
f
,
2.19618773
f
};
expected_d_weights_val
=
vector
<
float
>
{
1.7546854
f
,
-
0.26085103
f
,
-
1.49135458
f
,
0.89831507
f
,
0.57313812
f
,
4.67307138
f
,
2.08813715
f
,
-
3.15987897
f
,
-
5.7803793
f
};
expected_d_data_val
=
vector
<
float
>
{
-
0.51969099
f
,
1.42333758
f
,
0.5131861
f
,
0.99892044
f
,
-
3.5502491
f
,
0.61600888
f
,
-
0.3849853
f
,
1.29083121
f
,
2.19618773
f
};
expected_d_weights_val
=
vector
<
float
>
{
1.7546854
f
,
-
0.26085103
f
,
-
1.49135458
f
,
0.89831507
f
,
0.57313812
f
,
4.67307138
f
,
2.08813715
f
,
-
3.15987897
f
,
-
5.7803793
f
};
expected_d_bias_val
=
vector
<
float
>
{
-
2.58936238
f
};
}
};
...
...
@@ -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
)));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment