ONE - On-device Neural Engine
Loading...
Searching...
No Matches
ConvolutionSpec Class Reference

#include <ConvolutionSpec.h>

Public Member Functions

 ConvolutionSpec (const ::caffe::ConvolutionParameter &param)
 
uint32_t ifm_rank (void) const
 
uint32_t ifm_dim (uint32_t axis) const
 
uint32_t group (void) const
 
uint32_t channel_axis (void) const
 
uint32_t num_batch_axes (void) const
 
uint32_t num_spatial_axes (void) const
 
uint32_t pad (uint32_t spatial_axis) const
 
uint32_t stride (uint32_t spatial_axis) const
 
uint32_t ker_dim (uint32_t spatial_axis) const
 
const nncc::core::ADT::tensor::Shapeifm_shape (void) const
 
void ifm_shape (const nncc::core::ADT::tensor::Shape &shape)
 
uint32_t ker_count (void) const
 
nncc::core::ADT::tensor::Shape ker_shape (void) const
 
nncc::core::ADT::tensor::Shape ofm_shape (void) const
 

Detailed Description

Definition at line 24 of file ConvolutionSpec.h.

Constructor & Destructor Documentation

◆ ConvolutionSpec()

ConvolutionSpec::ConvolutionSpec ( const ::caffe::ConvolutionParameter &  param)

Definition at line 23 of file ConvolutionSpec.cpp.

23 : _param(param)
24{
25 // NOTE Dilation is not supported, yet
26 // TODO Support dilation
27 assert(param.dilation().size() == 0);
28}

Member Function Documentation

◆ channel_axis()

uint32_t ConvolutionSpec::channel_axis ( void  ) const

Definition at line 32 of file ConvolutionSpec.cpp.

33{
34 return query_on(ifm_shape()).axis(axis_specifier(_param.axis()));
35}
ShapeQuery query_on(const nncc::core::ADT::tensor::Shape &shape)
AxisSpecifier axis_specifier(int32_t value)
const nncc::core::ADT::tensor::Shape & ifm_shape(void) const
uint32_t axis(const AxisSpecifier &) const
Return the dimension number (axis) specified by a given axis specifier.

References ShapeQuery::axis(), axis_specifier(), ifm_shape(), and query_on().

Referenced by ker_shape(), num_batch_axes(), and num_spatial_axes().

◆ group()

uint32_t ConvolutionSpec::group ( void  ) const

Definition at line 30 of file ConvolutionSpec.cpp.

30{ return _param.group(); }

Referenced by ker_shape().

◆ ifm_dim()

uint32_t ConvolutionSpec::ifm_dim ( uint32_t  axis) const
inline

Definition at line 31 of file ConvolutionSpec.h.

31{ return _ifm_shape.dim(axis); }
uint32_t & dim(uint32_t axis)
Definition Shape.cpp:42

References nncc::core::ADT::tensor::Shape::dim().

Referenced by ker_shape(), and ofm_shape().

◆ ifm_rank()

uint32_t ConvolutionSpec::ifm_rank ( void  ) const
inline

Definition at line 30 of file ConvolutionSpec.h.

30{ return _ifm_shape.rank(); }
uint32_t rank(void) const
Definition Shape.cpp:35

References nncc::core::ADT::tensor::Shape::rank().

Referenced by num_spatial_axes().

◆ ifm_shape() [1/2]

void ConvolutionSpec::ifm_shape ( const nncc::core::ADT::tensor::Shape shape)
inline

Definition at line 46 of file ConvolutionSpec.h.

46{ _ifm_shape = shape; }

◆ ifm_shape() [2/2]

const nncc::core::ADT::tensor::Shape & ConvolutionSpec::ifm_shape ( void  ) const
inline

Definition at line 45 of file ConvolutionSpec.h.

45{ return _ifm_shape; }

Referenced by caffeimport::ConvolutionBuilder::build(), and channel_axis().

◆ ker_count()

uint32_t ConvolutionSpec::ker_count ( void  ) const
inline

Definition at line 49 of file ConvolutionSpec.h.

49{ return _param.num_output(); }

Referenced by ker_shape(), and ofm_shape().

◆ ker_dim()

uint32_t ConvolutionSpec::ker_dim ( uint32_t  spatial_axis) const

Definition at line 70 of file ConvolutionSpec.cpp.

71{
72 assert(spatial_axis < num_spatial_axes());
73 if (_param.kernel_size().size() == 0)
74 {
75 if (_param.has_kernel_h() && (spatial_axis == 0))
76 {
77 assert(num_spatial_axes() == 2);
78 return _param.kernel_h();
79 }
80
81 if (_param.has_kernel_w() && (spatial_axis == 1))
82 {
83 assert(num_spatial_axes() == 2);
84 return _param.kernel_w();
85 }
86
87 return 0;
88 }
89
90 assert(!_param.has_kernel_h());
91 assert(!_param.has_kernel_w());
92 if (_param.kernel_size().size() == 1)
93 {
94 return _param.kernel_size(0);
95 }
96 else
97 {
98 assert(_param.kernel_size().size() == num_spatial_axes());
99 return _param.kernel_size(spatial_axis);
100 }
101}
uint32_t num_spatial_axes(void) const

References num_spatial_axes().

Referenced by ker_shape(), and ofm_shape().

◆ ker_shape()

nncc::core::ADT::tensor::Shape ConvolutionSpec::ker_shape ( void  ) const

Definition at line 103 of file ConvolutionSpec.cpp.

104{
106
107 res.resize(2 + num_spatial_axes());
108
109 res.dim(0) = ker_count();
110 assert(ifm_dim(channel_axis()) % group() == 0);
111 res.dim(1) = ifm_dim(channel_axis()) / group();
112 for (uint32_t axis = 0; axis < num_spatial_axes(); ++axis)
113 {
114 res.dim(2 + axis) = ker_dim(axis);
115 }
116
117 return res;
118}
uint32_t channel_axis(void) const
uint32_t ifm_dim(uint32_t axis) const
uint32_t group(void) const
uint32_t ker_count(void) const
uint32_t ker_dim(uint32_t spatial_axis) const
Shape & resize(uint32_t size)
Definition Shape.cpp:36

References channel_axis(), nncc::core::ADT::tensor::Shape::dim(), group(), ifm_dim(), ker_count(), ker_dim(), num_spatial_axes(), and nncc::core::ADT::tensor::Shape::resize().

◆ num_batch_axes()

uint32_t ConvolutionSpec::num_batch_axes ( void  ) const
inline

Definition at line 37 of file ConvolutionSpec.h.

37{ return channel_axis(); }

References channel_axis().

Referenced by ofm_shape().

◆ num_spatial_axes()

uint32_t ConvolutionSpec::num_spatial_axes ( void  ) const
inline

Definition at line 38 of file ConvolutionSpec.h.

38{ return ifm_rank() - channel_axis() - 1; }
uint32_t ifm_rank(void) const

References channel_axis(), and ifm_rank().

Referenced by ker_dim(), ker_shape(), ofm_shape(), pad(), and stride().

◆ ofm_shape()

nncc::core::ADT::tensor::Shape ConvolutionSpec::ofm_shape ( void  ) const

Definition at line 120 of file ConvolutionSpec.cpp.

121{
123
125
126 for (uint32_t axis = 0; axis < num_batch_axes(); ++axis)
127 {
128 res.dim(axis) = ifm_dim(axis);
129 }
130
131 res.dim(num_batch_axes()) = ker_count();
132
133 for (uint32_t spatial_axis = 0; spatial_axis < num_spatial_axes(); ++spatial_axis)
134 {
135 const uint32_t full_axis = num_batch_axes() + 1 + spatial_axis;
136
137 uint32_t dim = 0;
138
139 dim += ifm_dim(full_axis) - ker_dim(spatial_axis) + 2 * pad(spatial_axis);
140 dim /= stride(spatial_axis);
141 dim += 1;
142
143 res.dim(full_axis) = dim;
144 }
145
146 return res;
147}
uint32_t stride(uint32_t spatial_axis) const
uint32_t num_batch_axes(void) const
uint32_t pad(uint32_t spatial_axis) const

References nncc::core::ADT::tensor::Shape::dim(), ifm_dim(), ker_count(), ker_dim(), num_batch_axes(), num_spatial_axes(), pad(), nncc::core::ADT::tensor::Shape::resize(), and stride().

◆ pad()

uint32_t ConvolutionSpec::pad ( uint32_t  spatial_axis) const

Definition at line 37 of file ConvolutionSpec.cpp.

38{
39 assert(spatial_axis < num_spatial_axes());
40
41 auto raw_padding = build_raw_padding().with(_param);
42 auto spatial_padding = build_spatial_padding(num_spatial_axes()).with(raw_padding);
43
44 return spatial_padding.value(spatial_axis);
45}
SpatialPaddingBuilder build_spatial_padding(uint32_t spatial_rank)
RawPaddingBuilder build_raw_padding(void)
uint32_t & value(uint32_t n)
Definition Padding.h:39
RawPadding with(const ::caffe::ConvolutionParameter &) const
SpatialPadding with(const RawPadding &raw) const

References build_raw_padding(), build_spatial_padding(), num_spatial_axes(), PaddingBase< Derived >::value(), RawPaddingBuilder::with(), and SpatialPaddingBuilder::with().

Referenced by ofm_shape().

◆ stride()

uint32_t ConvolutionSpec::stride ( uint32_t  spatial_axis) const

Definition at line 47 of file ConvolutionSpec.cpp.

48{
49 assert(spatial_axis < num_spatial_axes());
50
51 // TODO Support stride_h/stride_w parameters
52 assert(!_param.has_stride_h());
53 assert(!_param.has_stride_w());
54
55 if (_param.stride().size() == 0)
56 {
57 // NOTE default stride is 1
58 return 1;
59 }
60
61 if (_param.stride().size() == 1)
62 {
63 return _param.stride(0);
64 }
65
66 assert(_param.stride().size() == num_spatial_axes());
67 return _param.stride(spatial_axis);
68}

References num_spatial_axes().

Referenced by ofm_shape().


The documentation for this class was generated from the following files: