1
+ //#Copyright 2019 Micron Technology, Inc. All Rights Reserved. This software contains confidential information and trade secrets of Micron Technology, Inc. Use, disclosure, or reproduction is prohibited without the prior express written permission of Micron Technology, Inc
1
2
/// @file
2
- /// @brief FWDNXT C api
3
+ /// @brief Micron DLA C api
3
4
#ifndef _IE_API_H_INCLUDED_
4
5
#define _IE_API_H_INCLUDED_
5
6
6
- static const char * fwdnxt_version = "v0.3.16 " ;
7
+ static const char * microndla_version = "2020.1 " ;
7
8
#include <stdint.h>
8
9
#include <stdio.h>
9
10
#include <string.h>
10
11
#ifdef __cplusplus
11
12
extern "C" {
12
13
#endif
13
14
15
+ typedef int16_t SF_INT ;
16
+
14
17
/*!
15
18
create a context object
16
19
*/
17
20
void * ie_create ();
18
21
22
+ /*
23
+ All-in-one: Compile a network, Init FPGA and Run accelerator
24
+ @param cmemo context object, can be null
25
+ @param image image file or image size in the format WxHxP or WxHxPxB or WxHxDxPxB, multiple inputs separated by semi-colon
26
+ @param modelpath path to the onnx file
27
+ @param fbitfile path to bitfile with FPGA code (part of the SDK)
28
+ @param numcard number of FPGAs to use
29
+ @param numclus number of clusters to use
30
+ @param input input data in [P, H, W] order, one pointer per input (in case of multiple inputs)
31
+ @param output output data in [P, H, W] order, one pointer per input
32
+ @return -1 (error), 0 (pass)
33
+ */
34
+ int ie_go (void * cmemo , const char * image , const char * modelpath , const char * fbitfile , int numcard , int numclus , const float * const * input , float * * output );
35
+
36
+ /*
37
+ Run static quatization of inputs, weight and outputs over a calibration dataset
38
+ @param cmemo context object, can be null
39
+ @param image image file or image size in the format WxHxP or WxHxPxB or WxHxDxPxB, multiple inputs separated by semi-colon
40
+ @param modelpath path to the onnx file
41
+ @param outbin path to output .bin file
42
+ @param swoutsize output size (including the layers run in software) assuming batch 1, in number of elements, one per output
43
+ @param noutputs number of returned output arrays
44
+ @param numcard number of FPGAs to use
45
+ @param numclus number of clusters to use
46
+ @param input input data in [P, H, W] order, one pointer per input (in case of multiple inputs)
47
+ @param num_inputs number of inputs in the calibration dataset
48
+ @param output output data in [P, H, W] order, one pointer per input
49
+ @return -1 (error), 0 (pass)
50
+ */
51
+ void * ie_quantize (void * cmemo , const char * image , const char * modelpath , const char * outbin ,
52
+ uint64_t * swoutsize , int * noutputs , int numcard , int numclus , float * * input , int num_inputs );
53
+
19
54
/*!
20
55
Compile a network and produce a .bin file with everything that is needed to execute in hardware.
21
56
If the model contains some layers that cannot be run in hardware, they will be run in software.
@@ -47,7 +82,7 @@ Load a .bin file into the hardware and initialize it
47
82
void * ie_init (void * cmemo , const char * fbitfile , const char * inbin , uint64_t * outsize , int * noutputs , void * cmemp );
48
83
49
84
/*!
50
- Run inference engine
85
+ Run hardware
51
86
It does the steps sequentially. putInput, compute, getResult
52
87
@param cmemo context object
53
88
@param input input data in [P, H, W] order, one pointer per input (in case of multiple inputs)
@@ -59,7 +94,8 @@ It does the steps sequentially. putInput, compute, getResult
59
94
int ie_run (void * cmemo , const float * const * input , const uint64_t * input_elements , float * * output , uint64_t * output_elements );
60
95
61
96
/*!
62
- Send input to the inference engine and start FWDNXT hardware
97
+ Send input to the hardware and start Micron DLA hardware
98
+ @param cmemo context object
63
99
@param input input data in [P, H, W] order, one pointer per input (in case of multiple inputs)
64
100
@param input_elements size of the input in number of elements, one per input
65
101
@param userparam user defined parameter useful to associate inputs and outputs
@@ -68,7 +104,7 @@ Send input to the inference engine and start FWDNXT hardware
68
104
int ie_putinput (void * cmemo , const float * const * input , const uint64_t * input_elements , void * userparam );
69
105
70
106
/*!
71
- Get an output from the inference engine . If opt_blocking was set then it will wait for FWDNXT hardware to finish, otherwise it will return -1
107
+ Get an output from the hardware . If opt_blocking was set then it will wait for Micron DLA hardware to finish, otherwise it will return -1
72
108
in case the output is not ready
73
109
@param cmemo context object
74
110
@param output output data in [P, H, W] order, one pointer per input
@@ -88,7 +124,7 @@ Set flags for the compiler
88
124
int ie_setflag (void * cmemo , const char * name , const char * value );
89
125
90
126
/*!
91
- Get various info about the inference engine
127
+ Get various info about the hardware
92
128
@param cmemo context object
93
129
@param name name of the info to fetch
94
130
@param value pointer to the returned value
@@ -97,7 +133,7 @@ Get various info about the inference engine
97
133
int ie_getinfo (void * cmemo , const char * name , void * value );
98
134
99
135
/*!
100
- Run software inference engine emulator
136
+ Run software Micron DLA emulator
101
137
This runs the model in software using the same data precision of the accelerator
102
138
@param cmemo context object
103
139
@param input input data in [P, H, W] order, one pointer per input (in case of multiple inputs)
@@ -129,7 +165,7 @@ void ie_free(void* cmemo);
129
165
130
166
/*!
131
167
Read data from an address in shared memory.
132
- @param cmemo context objject
168
+ @param cmemo context object
133
169
@param address shared memory address where to fetch the data from
134
170
@param data pointer to the buffer that will be filled with the returned data
135
171
@param nelements number of bytes to transfer
@@ -139,7 +175,7 @@ void ie_read_data(void *cmemo, uint64_t address, void *data, uint64_t nelements,
139
175
140
176
/*!
141
177
write data to an address in shared memory.
142
- @param cmemo context objject
178
+ @param cmemo context object
143
179
@param address shared memory address where to write the data
144
180
@param data pointer to the data to write
145
181
@param nelements number of bytes to transfer
@@ -149,10 +185,57 @@ void ie_write_data(void *cmemo, uint64_t address, const void *data, uint64_t nel
149
185
150
186
void ie_write_weights (void * cmemo , float * weight , int wsize , int nid );
151
187
188
+ /*!
189
+ create a MainMem for a FPGA card and initializes the FPGA (pico obj).
190
+ @param cmemo context object
191
+ @param nfpga set number of FPGAs to use and initialize
192
+ @param nclus set number of cluster to use
193
+ @param fbitfile bitfile path to load into FPGA
194
+ */
195
+ void ie_create_memcard (void * cmemo , int nfpga , int nclus , const char * fbitfile );
196
+
197
+ /*!
198
+ return an array with nonlinear coefficients (can be freed with free)
199
+ @param cmemo context object
200
+ @param type coefficient type (one of SFT_RELU, SFT_SIGMOUID...)
201
+ */
202
+ SF_INT * ie_get_nonlin_coefs (void * cmemo , int type );
203
+
204
+ /*!
205
+ create MemData, add to cmem, return its address: use address to read/write data to memory
206
+ @param cmemo context object
207
+ @param len number of words
208
+ @param type sizeof the word
209
+ @param card FPGA card id. select which FPGA to allocate memory for
210
+ @param comment comment for allocation, can be used in ASM code, prefixed with @
211
+ */
212
+ uint64_t ie_malloc (void * cmemo , unsigned len , size_t type , int card , const char * comment );
213
+
214
+ /*!
215
+ read code from text file, generate assembly and return assembly
216
+ @param cmemo context object
217
+ @param fname text file path with program
218
+ @param instr_addr memory address of instructions
219
+ @param programlen the generated program length in bytes will be returned here
220
+ @return buffer with machine code instructions, to be freed with free
221
+ */
222
+ uint32_t * ie_readcode (void * cmemo , const char * fname , uint64_t instr_addr , uint64_t * programlen );
223
+
224
+ /*!
225
+ set initial instructions, and start hw and poll/wait, return error or success
226
+ @param cmemo context object
227
+ @param instr_addr memory address of instructions
228
+ @param hwtime returns amount of time to run the accelerator
229
+ @param mvdata returns amount of data transferred to accelerator
230
+ @param outsize wait for this amount of data to return from accelerator. if 0 then wait for 2 sec
231
+ */
232
+ void ie_hwrun (void * cmemo , uint64_t instr_addr , double * hwtime , double * mvdata , int outsize );
233
+
152
234
/*!
153
235
Just load multiple bin files without initializing hardware
154
- @param inbins array of bin filenames
155
- @param count number of bin files to load
236
+ @param cmemo context object
237
+ @param inbins array of bin filenames
238
+ @param count number of bin files to load
156
239
@return a context obj to pass to ie_init
157
240
*/
158
241
void * ie_loadmulti (void * cmemo , const char * const * inbins , unsigned count );
@@ -240,12 +323,12 @@ static inline void *ie_safecreate()
240
323
241
324
if (ie_getinfo (cmemo , "version" , version ))
242
325
{
243
- fprintf (stderr , "Wrong libfwdnxt .so version\n" );
326
+ fprintf (stderr , "Wrong libmicrondla .so version\n" );
244
327
exit (-1 );
245
328
}
246
- if (strcmp (version , fwdnxt_version ))
329
+ if (strcmp (version , microndla_version ))
247
330
{
248
- fprintf (stderr , "Wrong libfwdnxt .so version, expecting %s, found %s\n" , fwdnxt_version , version );
331
+ fprintf (stderr , "Wrong libmicrondla .so version, expecting %s, found %s\n" , microndla_version , version );
249
332
exit (-1 );
250
333
}
251
334
return cmemo ;
0 commit comments