-
Notifications
You must be signed in to change notification settings - Fork 90
/
cnn.h
116 lines (89 loc) · 3.68 KB
/
cnn.h
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
/******************************************************************************
*
* Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
* Analog Devices, Inc.),
* Copyright (C) 2023-2024 Analog Devices, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* This header file was automatically generated for the mnist-riscv network from a template.
* Please do not edit; instead, edit the template and regenerate.
*/
#ifndef __CNN_H__
#define __CNN_H__
#include <stdint.h>
typedef int32_t q31_t;
typedef int16_t q15_t;
/* Return codes */
#define CNN_FAIL 0
#define CNN_OK 1
/*
SUMMARY OF OPS
Hardware: 10,883,968 ops (10,751,808 macc; 128,576 comp; 3,584 add; 0 mul; 0 bitwise)
Layer 0: 470,400 ops (423,360 macc; 47,040 comp; 0 add; 0 mul; 0 bitwise)
Layer 1: 8,356,800 ops (8,294,400 macc; 62,400 comp; 0 add; 0 mul; 0 bitwise)
Layer 2: 1,954,304 ops (1,935,360 macc; 18,944 comp; 0 add; 0 mul; 0 bitwise)
Layer 3: 100,544 ops (96,768 macc; 192 comp; 3,584 add; 0 mul; 0 bitwise)
Layer 4: 1,920 ops (1,920 macc; 0 comp; 0 add; 0 mul; 0 bitwise)
RESOURCE USAGE
Weight memory: 71,148 bytes out of 442,368 bytes total (16%)
Bias memory: 10 bytes out of 2,048 bytes total (0%)
*/
/* Number of outputs for this network */
#define CNN_NUM_OUTPUTS 10
/* Use this timer to time the inference */
#define CNN_INFERENCE_TIMER MXC_TMR0
/* Port pin actions used to signal that processing is active */
#define CNN_START LED_On(1)
#define CNN_COMPLETE LED_Off(1)
#define SYS_START LED_On(0)
#define SYS_COMPLETE LED_Off(0)
/* Run software SoftMax on unloaded data */
void softmax_q17p14_q15(const q31_t *vec_in, const uint16_t dim_vec, q15_t *p_out);
/* Shift the input, then calculate SoftMax */
void softmax_shift_q17p14_q15(q31_t *vec_in, const uint16_t dim_vec, uint8_t in_shift,
q15_t *p_out);
/* Stopwatch - holds the runtime when accelerator finishes */
extern volatile uint32_t cnn_time;
/* Custom memcopy routines used for weights and data */
void memcpy32(uint32_t *dst, const uint32_t *src, int n);
void memcpy32_const(uint32_t *dst, int n);
/* Enable clocks and power to accelerator, enable interrupt */
int cnn_enable(uint32_t clock_source, uint32_t clock_divider);
/* Disable clocks and power to accelerator */
int cnn_disable(void);
/* Perform minimum accelerator initialization so it can be configured */
int cnn_init(void);
/* Configure accelerator for the given network */
int cnn_configure(void);
/* Load accelerator weights */
int cnn_load_weights(void);
/* Verify accelerator weights (debug only) */
int cnn_verify_weights(void);
/* Load accelerator bias values (if needed) */
int cnn_load_bias(void);
/* Start accelerator processing */
int cnn_start(void);
/* Force stop accelerator */
int cnn_stop(void);
/* Continue accelerator after stop */
int cnn_continue(void);
/* Unload results from accelerator */
int cnn_unload(uint32_t *out_buf);
/* Turn on the boost circuit */
int cnn_boost_enable(mxc_gpio_regs_t *port, uint32_t pin);
/* Turn off the boost circuit */
int cnn_boost_disable(mxc_gpio_regs_t *port, uint32_t pin);
#endif // __CNN_H__