ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnop Namespace Reference

Data Structures

class  PadInfo
 
class  StrideInfo
 

Functions

template<typename OutputDType , typename InputDType , typename KernelDType >
void conv (const nncc::core::ADT::feature::Shape &out_shape, nncc::core::ADT::feature::Accessor< OutputDType > &out_data, const nncc::core::ADT::feature::Shape &in_shape, const nncc::core::ADT::feature::Reader< InputDType > &in_data, const nncc::core::ADT::kernel::Shape &ker_shape, const nncc::core::ADT::kernel::Reader< KernelDType > &ker_data, const PadInfo &pad_info, const StrideInfo &stride_info)
 

Function Documentation

◆ conv()

template<typename OutputDType , typename InputDType , typename KernelDType >
void nnop::conv ( const nncc::core::ADT::feature::Shape out_shape,
nncc::core::ADT::feature::Accessor< OutputDType > &  out_data,
const nncc::core::ADT::feature::Shape in_shape,
const nncc::core::ADT::feature::Reader< InputDType > &  in_data,
const nncc::core::ADT::kernel::Shape ker_shape,
const nncc::core::ADT::kernel::Reader< KernelDType > &  ker_data,
const PadInfo pad_info,
const StrideInfo stride_info 
)

Definition at line 34 of file Conv2D.h.

41{
42 for (uint32_t out_ch = 0; out_ch < out_shape.depth(); ++out_ch)
43 {
44 for (uint32_t out_row = 0; out_row < out_shape.height(); ++out_row)
45 {
46 for (uint32_t out_col = 0; out_col < out_shape.width(); ++out_col)
47 {
48 OutputDType out_value = 0;
49
50 for (uint32_t ker_ch = 0; ker_ch < ker_shape.depth(); ++ker_ch)
51 {
52 for (uint32_t ker_row = 0; ker_row < ker_shape.height(); ++ker_row)
53 {
54 for (uint32_t ker_col = 0; ker_col < ker_shape.width(); ++ker_col)
55 {
56 const int64_t vertical_stride = static_cast<int64_t>(stride_info.vertical());
57 const int64_t horizontal_stride = static_cast<int64_t>(stride_info.horizontal());
58 const int64_t top_padding = static_cast<int64_t>(pad_info.top());
59 const int64_t left_padding = static_cast<int64_t>(pad_info.left());
60
61 const uint32_t in_ch = ker_ch;
62 const int64_t in_row = vertical_stride * out_row - top_padding + ker_row;
63 const int64_t in_col = horizontal_stride * out_col - left_padding + ker_col;
64
65 const bool is_padding = (in_row < 0) || (in_row >= in_shape.height()) ||
66 (in_col < 0) || (in_col >= in_shape.width());
67
68 const auto in_value = (is_padding) ? 0
69 : in_data.at(in_ch, static_cast<uint32_t>(in_row),
70 static_cast<uint32_t>(in_col));
71
72 const auto ker_value = ker_data.at(out_ch, in_ch, ker_row, ker_col);
73
74 out_value += in_value * ker_value;
75 }
76 }
77 }
78
79 out_data.at(out_ch, out_row, out_col) = out_value;
80 }
81 }
82 }
83}
uint32_t depth(void) const
Definition Shape.h:44
uint32_t width(void) const
Definition Shape.h:46
uint32_t height(void) const
Definition Shape.h:45
uint32_t width(void) const
Definition Shape.h:47
uint32_t height(void) const
Definition Shape.h:46
uint32_t depth(void) const
Definition Shape.h:45
uint32_t left(void) const
Definition PadInfo.h:37
uint32_t top(void) const
Definition PadInfo.h:35
uint32_t vertical(void) const
Definition StrideInfo.h:34
uint32_t horizontal(void) const
Definition StrideInfo.h:35
virtual T & at(uint32_t ch, uint32_t row, uint32_t col)=0
virtual T at(uint32_t nth, uint32_t ch, uint32_t row, uint32_t col) const =0

References nncc::core::ADT::feature::Reader< T >::at(), nncc::core::ADT::feature::Accessor< T >::at(), nncc::core::ADT::kernel::Reader< T >::at(), nncc::core::ADT::feature::Shape::depth(), nncc::core::ADT::kernel::Shape::depth(), nncc::core::ADT::feature::Shape::height(), nncc::core::ADT::kernel::Shape::height(), nnop::StrideInfo::horizontal(), nnop::PadInfo::left(), nnop::PadInfo::top(), nnop::StrideInfo::vertical(), nncc::core::ADT::feature::Shape::width(), and nncc::core::ADT::kernel::Shape::width().