Skip to content
This repository was archived by the owner on Oct 21, 2023. It is now read-only.

Commit 3d06d46

Browse files
authored
Merge pull request #3 from FWDNXT/v1.0
V1.0
2 parents 4eca9f2 + c1ebce2 commit 3d06d46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1322
-478
lines changed

README.md

+183-205
Large diffs are not rendered by default.

api.h

+97-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,56 @@
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
12
/// @file
2-
/// @brief FWDNXT C api
3+
/// @brief Micron DLA C api
34
#ifndef _IE_API_H_INCLUDED_
45
#define _IE_API_H_INCLUDED_
56

6-
static const char *fwdnxt_version = "v0.3.16";
7+
static const char *microndla_version = "2020.1";
78
#include <stdint.h>
89
#include <stdio.h>
910
#include <string.h>
1011
#ifdef __cplusplus
1112
extern "C" {
1213
#endif
1314

15+
typedef int16_t SF_INT;
16+
1417
/*!
1518
create a context object
1619
*/
1720
void *ie_create();
1821

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+
1954
/*!
2055
Compile a network and produce a .bin file with everything that is needed to execute in hardware.
2156
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
4782
void *ie_init(void *cmemo, const char *fbitfile, const char *inbin, uint64_t *outsize, int *noutputs, void *cmemp);
4883

4984
/*!
50-
Run inference engine
85+
Run hardware
5186
It does the steps sequentially. putInput, compute, getResult
5287
@param cmemo context object
5388
@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
5994
int ie_run(void *cmemo, const float * const *input, const uint64_t *input_elements, float **output, uint64_t *output_elements);
6095

6196
/*!
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
6399
@param input input data in [P, H, W] order, one pointer per input (in case of multiple inputs)
64100
@param input_elements size of the input in number of elements, one per input
65101
@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
68104
int ie_putinput(void *cmemo, const float * const *input, const uint64_t *input_elements, void *userparam);
69105

70106
/*!
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
72108
in case the output is not ready
73109
@param cmemo context object
74110
@param output output data in [P, H, W] order, one pointer per input
@@ -88,7 +124,7 @@ Set flags for the compiler
88124
int ie_setflag(void *cmemo, const char *name, const char *value);
89125

90126
/*!
91-
Get various info about the inference engine
127+
Get various info about the hardware
92128
@param cmemo context object
93129
@param name name of the info to fetch
94130
@param value pointer to the returned value
@@ -97,7 +133,7 @@ Get various info about the inference engine
97133
int ie_getinfo(void *cmemo, const char *name, void *value);
98134

99135
/*!
100-
Run software inference engine emulator
136+
Run software Micron DLA emulator
101137
This runs the model in software using the same data precision of the accelerator
102138
@param cmemo context object
103139
@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);
129165

130166
/*!
131167
Read data from an address in shared memory.
132-
@param cmemo context objject
168+
@param cmemo context object
133169
@param address shared memory address where to fetch the data from
134170
@param data pointer to the buffer that will be filled with the returned data
135171
@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,
139175

140176
/*!
141177
write data to an address in shared memory.
142-
@param cmemo context objject
178+
@param cmemo context object
143179
@param address shared memory address where to write the data
144180
@param data pointer to the data to write
145181
@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
149185

150186
void ie_write_weights(void *cmemo, float *weight, int wsize, int nid);
151187

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+
152234
/*!
153235
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
156239
@return a context obj to pass to ie_init
157240
*/
158241
void *ie_loadmulti(void *cmemo, const char * const *inbins, unsigned count);
@@ -240,12 +323,12 @@ static inline void *ie_safecreate()
240323

241324
if(ie_getinfo(cmemo, "version", version))
242325
{
243-
fprintf(stderr, "Wrong libfwdnxt.so version\n");
326+
fprintf(stderr, "Wrong libmicrondla.so version\n");
244327
exit(-1);
245328
}
246-
if(strcmp(version, fwdnxt_version))
329+
if(strcmp(version, microndla_version))
247330
{
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);
249332
exit(-1);
250333
}
251334
return cmemo;

0 commit comments

Comments
 (0)