Skip to content

Commit 37be39b

Browse files
alisonwhroman-janik-nxp
authored andcommitted
Update Neutron software to v1.2.0+0X1b86b19d
Signed-off-by: Alison Wang <[email protected]>
1 parent 61dff96 commit 37be39b

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed

backends/nxp/runtime/NeutronDriver.h

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 NXP
2+
* Copyright 2022-2024 NXP
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*
@@ -54,21 +54,21 @@ typedef void *NeutronModelHandle;
5454
typedef struct {
5555
/// Neutron microcode buffer address.
5656
/// The Neutron microcode is generated by the Neutron converter tool.
57-
/// The microcode buffer is allocated and initialized by the application or ML framework.
57+
/// The microcode buffer, 16 bytes aligned, is allocated and initialized by the application or ML framework.
5858
/// The microcode buffer is passed by reference to the Neutron firmware.
5959
/// The microcode buffer is specific for a given ML model.
6060
const void *microcode;
6161

6262
/// Neutron weights buffer address.
6363
/// The Neutron weights is generated by the Neutron converter tool.
64-
/// The weights buffer is allocated and initialized by the application or ML framework.
64+
/// The weights buffer, 16 bytes aligned, is allocated and initialized by the application or ML framework.
6565
/// The weights buffer address is passed by reference to the Neutron-firmware.
6666
/// The weights buffer is specific for a given ML model.
6767
const void *weights;
6868

6969
/// Neutron kernels buffer address.
7070
/// The Neutron kernels are generated by the Neutron converter tool.
71-
/// The kernels buffer is allocated and initialized by the application or ML framework.
71+
/// The kernels buffer, 16 bytes aligned, is allocated and initialized by the application or ML framework.
7272
/// The kernels buffer address is passed by reference to the Neutron-firmware.
7373
/// The kernels buffer is specific for a given ML model.
7474
const void *kernels;
@@ -137,6 +137,15 @@ NeutronError neutronInit();
137137
/// - Deinitialize the Neutron Driver library, releasing any resources aquired by neutronInit
138138
NeutronError neutronDeinit();
139139

140+
/// - Prepare Neutron execution for a model with custom firmware.
141+
/// - This function is only available for Neutron-S.
142+
NeutronError neutronCustomPrepare(uint32_t *inputSize, int32_t numInputs, uint32_t *outputSize, int32_t numOutputs,
143+
const void *firmware, size_t firmwareSize, NeutronModelHandle *hdl);
144+
145+
/// - Run Neutron custom firmware and get the results.
146+
/// - This function is only available for Neutron-S.
147+
NeutronError neutronCustomExec(NeutronModelHandle hdl, const NeutronDataConfig *neutron_dcfg);
148+
140149
/// - Prepare Neutron execution for a model with the given configuration.
141150
/// - This function only prepares the execution by transferring the parameters to the firmware.
142151
/// - This function allows caching a model and then running the same model but with different
@@ -188,6 +197,17 @@ NeutronError neutronSetConfig(NeutronConfig *config);
188197
/// - Used to get NeutronContext size.
189198
size_t neutronGetModelContextSize();
190199

200+
/// - Allocates size bytes and returns a pointer to the allocated memory.
201+
/// The returned pointer address will be a multiple of the alignment.
202+
/// Returns NULL on failure.
203+
/// - alignment: Set to 0 if unsure of alignment requirements.
204+
/// - This function is only available for Neutron-S in the Linux environment.
205+
void *neutronMemAlloc(size_t alignment, size_t size);
206+
207+
/// - Frees the memory buffer pointed to by ptr.
208+
/// - This function is only available for Neutron-S in the Linux environment.
209+
void neutronMemFree(void *ptr);
210+
191211
/// Other functions to control the state of driver/firmware.
192212
#ifdef __cplusplus
193213
}

backends/nxp/runtime/NeutronErrors.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2024 NXP
2+
* Copyright 2022-2024 NXP
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*
@@ -13,6 +13,40 @@
1313

1414
typedef int32_t NeutronError;
1515

16+
/*
17+
Generate error code.
18+
A code is composed of (from least to most significant bit):
19+
3 bits = component id
20+
5 bits = category id
21+
23 bits = code
22+
1 bit = sign
23+
*/
24+
#define GEN_NEUTRON_ERROR(component, category, code) ((NeutronError)( \
25+
((component & 0xF) << 0) | \
26+
((category & 0xF) << 3) | \
27+
((code & 0x7FFFFF) << 8) \
28+
))
29+
1630
#define ENONE 0
1731

32+
#define GET_ERROR_COMPONENT(e) ((e >> 0) & 0x00000007)
33+
#define GET_ERROR_CATEGORY(e) ((e >> 3) & 0x0000001F)
34+
#define GET_ERROR_CODE(e) ((e >> 8) & 0x007FFFFF)
35+
36+
37+
/* Components ids*/
38+
// DO NOT USE 0x0 as component magic number!
39+
typedef enum ERROR_COMPONENT_ID {
40+
ERROR_COMPONENT_LIBRARY = 0x1,
41+
ERROR_COMPONENT_FIRMWARE = 0x2,
42+
ERROR_COMPONENT_DRIVER = 0x3
43+
} ERROR_COMPONENT_ID;
44+
45+
46+
/// Retrieve component name as string from NeutronError code.
47+
char *getNeutronErrorComponent(NeutronError ne);
48+
49+
/// Retrieve catefory as string from NeutronError code.
50+
char *getNeutronErrorCategory(NeutronError ne);
51+
1852
#endif // NEUTRON_ERRORS_H

0 commit comments

Comments
 (0)