-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmsis_nn_quant.hpp
More file actions
125 lines (108 loc) · 4.83 KB
/
Copy pathcmsis_nn_quant.hpp
File metadata and controls
125 lines (108 loc) · 4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once
#include "netkit_config.h"
#include "nk_format.hpp"
#include "quant_plan_types.hpp"
#include <cstdint>
class Arena;
namespace CmsisNnQuant
{
#if defined(NETKIT_USE_CMSIS_NN) && NETKIT_USE_CMSIS_NN && NETKIT_CMSIS_NN_ALLOWED
constexpr bool kEnabled = true;
#else
constexpr bool kEnabled = false;
#endif
bool TryConv2dNhwcQuantPlan(const CmsisQuantPlan::Conv2DPlan& plan,
const int8_t* input,
const int8_t* weights,
const int32_t* bias,
int8_t* output);
bool TryDepthwiseConv2dNhwcQuantPlan(const CmsisQuantPlan::DepthwiseConv2DPlan& plan,
const int8_t* input,
const int8_t* weights,
const int32_t* bias,
int8_t* output);
bool TryMaxPool2dNhwcQuantPlan(const CmsisQuantPlan::Pool2DPlan& plan,
const int8_t* input,
int8_t* output);
bool TryFullyConnectedQuantPlan(const CmsisQuantPlan::FcPlan& plan,
const int8_t* input,
const int8_t* weights,
const int32_t* bias,
int8_t* output_int8);
bool TrySoftmaxS8Plan(const CmsisQuantPlan::SoftmaxPlan& plan, const int8_t* input, int8_t* output);
void FinalizeConv2DPlan(CmsisQuantPlan::Conv2DPlan& plan);
void FinalizeDepthwiseConv2DPlan(CmsisQuantPlan::DepthwiseConv2DPlan& plan);
void FinalizePool2DPlan(CmsisQuantPlan::Pool2DPlan& plan);
bool FinalizeFcPlan(CmsisQuantPlan::FcPlan& plan,
const int8_t* weights,
const int32_t* bias,
Arena& arena);
bool TryConv2dNhwcQuant(const int8_t* input,
uint32_t in_h,
uint32_t in_w,
uint32_t in_c,
const int8_t* weights,
const int32_t* bias,
int kernel_size,
int stride,
int pad_h,
int pad_w,
int pad_h_end,
int pad_w_end,
int out_channels,
const NkFormat::MlpLayerQuantDesc& quant,
bool apply_relu,
int8_t* output);
bool TryDepthwiseConv2dNhwcQuant(const int8_t* input,
uint32_t in_h,
uint32_t in_w,
uint32_t channels,
const int8_t* weights,
const int32_t* bias,
int kernel_h,
int kernel_w,
int stride,
int pad_h,
int pad_w,
int pad_h_end,
int pad_w_end,
const NkFormat::MlpLayerQuantDesc& quant,
bool apply_relu,
int8_t* output);
bool TryMaxPool2dNhwcQuant(const int8_t* input,
uint32_t in_h,
uint32_t in_w,
uint32_t in_c,
int pool_h,
int pool_w,
int stride,
int pad_h,
int pad_w,
int pad_h_end,
int pad_w_end,
int8_t* output);
bool TryFullyConnectedQuant(const int8_t* input,
uint32_t batch,
uint32_t in_features,
const int8_t* weights,
const int32_t* bias,
uint32_t out_features,
const NkFormat::MlpLayerQuantDesc& quant,
bool apply_relu,
int8_t* output_int8);
bool TrySoftmaxS8(const int8_t* input,
uint32_t num_rows,
uint32_t row_size,
float logit_scale,
int8_t* output);
bool TryElementwiseAddS8(const int8_t* input1,
const int8_t* input2,
uint32_t count,
float input1_scale,
int32_t input1_zero_point,
float input2_scale,
int32_t input2_zero_point,
float output_scale,
int32_t output_zero_point,
int8_t* output);
} // namespace CmsisNnQuant