Nux is the C API library of the NPU Engine. Nux provides the two kinds of execution ways to run inference tasks through NPU. The followings demonstrate the examples of two execution ways. If you want to see more details about API types and functions, please refer to nux.h.
Sync Model
The sync model provides APIs to run a single inference task with a single input batch at a time.
Example of Sync Model
const char *enf_path = "<a path of ENF file>";
struct stat st;
stat(enf_path, &st);
size_t enf_size = st.st_size;
void *enf_buf = malloc(enf_size);
FILE *enf_file = fopen(enf_path, "rb");
size_t read_item = fread(enf_buf, enf_size, 1, enf_file);
assert(read_item == 1);
fclose(enf_file);
uint8_t input_buf [784] = {[0 ... 783] = 1};
uint8_t *output_buf = NULL;
uintptr_t output_len = NULL;
Task Model
The task model provides APIs to run multiple inference tasks asynchronously and simultaneously. The callback functions defined by users will be called when each task is completed. When a user creates a task model, the user can configure the concurrency of running tasks depending on HW capacity.
Example of Task Model
}
}
}
void run() {
const char *enf_path = "<a path of ENF file>";
struct stat st;
stat(enf_path, &st);
size_t enf_size = st.st_size;
void *enf_buf = malloc(enf_size);
FILE *enf_file = fopen(enf_path, "rb");
size_t read_item = fread(enf_buf, enf_size, 1, enf_file);
assert(read_item == 1);
fclose(enf_file);
const uint32_t max_concurrency = 3;
const uintptr_t INPUT_SIZE = 784;
uint8_t input_buf [784] = {[0 ... 783] = 1};
memcpy(buf, input_buf, INPUT_SIZE);
sleep(1);
}
free(enf_buf);
}
How to build source codes with Nux
To build your source code with Nux, please follow:
export NPU_TOOLS_DIR="<npu-tools src dir>"
export NUX_DIR=${NPU_TOOLS_DIR}/crates/nux
cargo build --release --target x86_64-unknown-linux-gnu
cc sync_example.c -I${NUX_DIR}/include -L${NPU_TOOLS_DIR}/target/x86_64-unknown-linux-gnu/release -lnux
How to generate Doxygen
The following commands will generate a Doxygen document at $NUX_TOOLS_DIR/target/doxygen/html
.
cd <nux src root>
doxygen crates/nux/Doxyfile