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
338b9622
Commit
338b9622
authored
Mar 07, 2018
by
Louis Feng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up.
parent
812a699a
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
49 additions
and
97 deletions
+49
-97
cpu_emitter.cpp
src/ngraph/runtime/cpu/cpu_emitter.cpp
+10
-9
mkldnn_emitter.cpp
src/ngraph/runtime/cpu/mkldnn_emitter.cpp
+1
-1
mkldnn_emitter.hpp
src/ngraph/runtime/cpu/mkldnn_emitter.hpp
+10
-12
mkldnn_utils.cpp
src/ngraph/runtime/cpu/mkldnn_utils.cpp
+1
-1
conv_bias.cpp
src/ngraph/runtime/cpu/ops/conv_bias.cpp
+4
-28
conv_bias.hpp
src/ngraph/runtime/cpu/ops/conv_bias.hpp
+5
-11
cpu_assignment.cpp
src/ngraph/runtime/cpu/pass/cpu_assignment.cpp
+15
-15
cpu_fusion.hpp
src/ngraph/runtime/cpu/pass/cpu_fusion.hpp
+1
-1
cpu_fusion.cpp
test/cpu_fusion.cpp
+2
-19
No files found.
src/ngraph/runtime/cpu/cpu_emitter.cpp
View file @
338b9622
...
...
@@ -2445,6 +2445,7 @@ namespace ngraph
throw
ngraph_error
(
"ConvolutionBias is only supported with MKLDNN kernel."
);
}
}
template
<>
void
CPU_Emitter
::
EMITTER_DECL
(
ngraph
::
op
::
ConvolutionBiasBackpropFiltersBias
)
{
...
...
@@ -2475,15 +2476,15 @@ namespace ngraph
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_
filter
s_bias
(
data_desc
,
delta_desc
,
weights_delta_desc
,
bias_delta_desc
,
convolution
->
get_window_movement_strides_forward
(),
window_dilation_strides_adjusted
,
convolution
->
get_padding_below_forward
(),
convolution
->
get_padding_above_forward
());
size_t
conv_index
=
mkldnn_emitter
->
build_convolution_backward_
weight
s_bias
(
data_desc
,
delta_desc
,
weights_delta_desc
,
bias_delta_desc
,
convolution
->
get_window_movement_strides_forward
(),
window_dilation_strides_adjusted
,
convolution
->
get_padding_below_forward
(),
convolution
->
get_padding_above_forward
());
auto
&
deps
=
mkldnn_emitter
->
get_primitive_deps
(
conv_index
);
writer
<<
"cpu::mkldnn_utils::set_memory_ptr(ctx, "
<<
to_string
(
deps
[
0
])
...
...
src/ngraph/runtime/cpu/mkldnn_emitter.cpp
View file @
338b9622
...
...
@@ -141,7 +141,7 @@ size_t MKLDNNEmitter::build_convolution_forward(const mkldnn::memory::desc& inpu
return
conv_index
;
}
size_t
MKLDNNEmitter
::
build_convolution_backward_
filter
s_bias
(
const
mkldnn
::
memory
::
desc
&
in_data_desc
,
size_t
MKLDNNEmitter
::
build_convolution_backward_
weight
s_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
,
...
...
src/ngraph/runtime/cpu/mkldnn_emitter.hpp
View file @
338b9622
...
...
@@ -70,6 +70,7 @@ namespace ngraph
const
ngraph
::
Strides
&
dilation_strides
,
const
ngraph
::
CoordinateDiff
&
padding_below
,
const
ngraph
::
CoordinateDiff
&
padding_above
);
size_t
build_convolution_backward_weights
(
const
mkldnn
::
memory
::
desc
&
input_desc
,
const
mkldnn
::
memory
::
desc
&
delta_desc
,
...
...
@@ -79,20 +80,17 @@ namespace ngraph
const
ngraph
::
CoordinateDiff
&
padding_below
,
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
*/
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
* Convolution + bias backprop for weights and bias
*/
size_t
build_convolution_backward_
filter
s_bias
(
const
mkldnn
::
memory
::
desc
&
in_data_desc
,
size_t
build_convolution_backward_
weight
s_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
,
...
...
src/ngraph/runtime/cpu/mkldnn_utils.cpp
View file @
338b9622
...
...
@@ -46,9 +46,9 @@ static const std::unordered_set<std::type_index> s_op_registry{
TI
(
ngraph
::
op
::
BatchNorm
),
TI
(
ngraph
::
op
::
BatchNormBackprop
),
TI
(
ngraph
::
op
::
Convolution
),
TI
(
ngraph
::
op
::
ConvolutionBias
),
TI
(
ngraph
::
op
::
ConvolutionBackpropData
),
TI
(
ngraph
::
op
::
ConvolutionBackpropFilters
),
TI
(
ngraph
::
op
::
ConvolutionBias
),
TI
(
ngraph
::
op
::
ConvolutionBiasBackpropFiltersBias
),
TI
(
ngraph
::
op
::
MaxPool
),
TI
(
ngraph
::
op
::
MaxPoolBackprop
),
...
...
src/ngraph/runtime/cpu/ops/conv_bias.cpp
View file @
338b9622
...
...
@@ -88,6 +88,7 @@ void op::ConvolutionBias::generate_adjoints(autodiff::Adjoints& adjoints,
auto
bias
=
get_input_op
(
2
);
const
auto
bias_shape
=
bias
->
get_shape
();
// using regular convolution backprop for data
adjoints
.
add_delta
(
data
,
std
::
make_shared
<
op
::
ConvolutionBackpropData
>
(
data_shape
,
filter
,
...
...
@@ -124,8 +125,9 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias(
const
CoordinateDiff
&
padding_below_forward
,
const
CoordinateDiff
&
padding_above_forward
,
const
Strides
&
data_dilation_strides_forward
)
:
RequiresTensorViewArgs
(
"ConvolutionB
ackpropFilter
s"
,
{
data_batch
,
output_delta
})
:
RequiresTensorViewArgs
(
"ConvolutionB
iasBackpropFiltersBia
s"
,
{
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
)
...
...
@@ -134,7 +136,6 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias(
{
auto
&
data_batch_shape
=
get_input_shape
(
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
);
//
...
...
@@ -143,7 +144,7 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias(
if
(
data_batch_et
!=
output_delta_et
)
{
throw
ngraph_error
(
"ConvolutionBias
filter backprop
data batch and output delta element types do not match"
);
"ConvolutionBias
BackpropFilterBias
data batch and output delta element types do not match"
);
}
// Forward Backward
...
...
@@ -168,31 +169,6 @@ op::ConvolutionBiasBackpropFiltersBias::ConvolutionBiasBackpropFiltersBias(
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
,
bias_shape
);
}
...
...
src/ngraph/runtime/cpu/ops/conv_bias.hpp
View file @
338b9622
...
...
@@ -23,6 +23,7 @@ namespace ngraph
{
namespace
op
{
/// \brief Convolution + bias forward prop for batched convolution operation.
class
ConvolutionBias
:
public
util
::
RequiresTensorViewArgs
{
public
:
...
...
@@ -60,20 +61,11 @@ namespace ngraph
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
{
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
,
const
Shape
&
filters_shape
,
const
Shape
&
bias_shape
,
...
...
@@ -88,6 +80,8 @@ namespace ngraph
/// \return The filters tensor 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.
const
Strides
&
get_window_movement_strides_forward
()
const
{
...
...
src/ngraph/runtime/cpu/pass/cpu_assignment.cpp
View file @
338b9622
...
...
@@ -99,9 +99,9 @@ namespace ngraph
}
template
<>
void
CPUAssignment
::
ASSIGN_DECL
(
ngraph
::
op
::
ConvolutionB
ias
)
void
CPUAssignment
::
ASSIGN_DECL
(
ngraph
::
op
::
ConvolutionB
ackpropData
)
{
auto
convolution
=
static_cast
<
op
::
ConvolutionB
ias
*>
(
node
);
auto
convolution
=
static_cast
<
op
::
ConvolutionB
ackpropData
*>
(
node
);
auto
arg0_shape
=
node
->
get_input_shape
(
0
);
auto
arg1_shape
=
node
->
get_input_shape
(
1
);
...
...
@@ -110,7 +110,7 @@ namespace ngraph
auto
arg1_rank
=
arg1_shape
.
size
();
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
);
}
...
...
@@ -126,9 +126,9 @@ namespace ngraph
}
template
<>
void
CPUAssignment
::
ASSIGN_DECL
(
ngraph
::
op
::
ConvolutionBackprop
Data
)
void
CPUAssignment
::
ASSIGN_DECL
(
ngraph
::
op
::
ConvolutionBackprop
Filters
)
{
auto
convolution
=
static_cast
<
op
::
ConvolutionBackprop
Data
*>
(
node
);
auto
convolution
=
static_cast
<
op
::
ConvolutionBackprop
Filters
*>
(
node
);
auto
arg0_shape
=
node
->
get_input_shape
(
0
);
auto
arg1_shape
=
node
->
get_input_shape
(
1
);
...
...
@@ -153,23 +153,23 @@ namespace ngraph
}
template
<>
void
CPUAssignment
::
ASSIGN_DECL
(
ngraph
::
op
::
ConvolutionB
ackpropFilter
s
)
void
CPUAssignment
::
ASSIGN_DECL
(
ngraph
::
op
::
ConvolutionB
ia
s
)
{
auto
convolution
=
static_cast
<
op
::
ConvolutionB
ackpropFilter
s
*>
(
node
);
auto
convolution
=
static_cast
<
op
::
ConvolutionB
ia
s
*>
(
node
);
auto
arg0
_shape
=
node
->
get_input_shape
(
0
);
auto
arg1
_shape
=
node
->
get_input_shape
(
1
);
auto
data
_shape
=
node
->
get_input_shape
(
0
);
auto
weights
_shape
=
node
->
get_input_shape
(
1
);
auto
result_shape
=
node
->
get_output_shape
(
0
);
auto
arg0_rank
=
arg0
_shape
.
size
();
auto
arg1_rank
=
arg1
_shape
.
size
();
auto
data_rank
=
data
_shape
.
size
();
auto
weights_rank
=
weights
_shape
.
size
();
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
);
}
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
)
{
auto
op_annotations
=
...
...
@@ -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
::
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
),
&
runtime
::
cpu
::
pass
::
CPUAssignment
::
assign
<
ngraph
::
op
::
ConvolutionBackpropData
>
},
{
TI
(
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
),
&
runtime
::
cpu
::
pass
::
CPUAssignment
::
assign
<
ngraph
::
op
::
ConvolutionBiasBackpropFiltersBias
>
},
{
TI
(
ngraph
::
op
::
AvgPool
),
&
runtime
::
cpu
::
pass
::
CPUAssignment
::
assign
<
ngraph
::
op
::
AvgPool
>
},
...
...
src/ngraph/runtime/cpu/pass/cpu_fusion.hpp
View file @
338b9622
...
...
@@ -52,5 +52,5 @@ private:
void
construct_fprop_bn
();
void
construct_zero_padded_reshaped_conv
();
void
construct_zero_padded_conv
();
void
construct_conv_bias
();
void
construct_conv_bias
();
};
test/cpu_fusion.cpp
View file @
338b9622
...
...
@@ -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
});
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
)));
}
...
...
@@ -726,21 +723,7 @@ TEST(cpu_fusion, conv_bias_bprop_n1c1h3w3)
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
});
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_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