NPU Code Deployment*
1 Overview*
After generating the model file using the compiler, you can deploy and test the model on the SDK. This document is based on the SDK code example dsp/vpa/sed/vpa_algorithm.c
- The example model implements cry detection, with build configuration
configs/sed/sed_demo_8008_WUKONG_V1.0.config
- 8008c does not have NPU, not supported
2 NPU API Call Flow*
2.1 NPU Task Configuration*
int SedInitSnpuTask(SNPU_TASK *snpu_task)
{
snpu_task->module_id = 886;
snpu_task->ops = (void *)ops_content;
snpu_task->data = (void *)cpu_content;
snpu_task->cmd = (void *)npu_content;
snpu_task->tmp_mem = (void *)tmp_content;
return 0;
}
SedInitSnpuTask(&s_snpu_task);
s_snpu_task.input = SedGetSnpuFeatsBuffer(prev_context->snpu_buffer);
s_snpu_task.output = SedGetSnpuStateBuffer(curr_context->snpu_buffer);
2.2 NPU Execution*
SnpuRunTask(&s_snpu_task, (void *)curr_context);
2.3 NPU Processing Callback*
After NPU
execution is completed, the callback function VpaSedModelCallback
will be triggered, where you can get the processing results:
int VpaSedModelCallback(unsigned int module_id, unsigned int state, void *private_data)
{
VSP_CONTEXT *context = (VSP_CONTEXT *)private_data;
// Get output results
unsigned short *proOut = SedGetSnpuOutBuffer(context->snpu_buffer);
unsigned int proOut_int = VspFloat16toFloat32(proOut[0]);
g_prob_out = *((float*)&proOut_int);
return 0;
}
3 Notes*
3.1 Data Management*
// Invalidate data, reload from memory
xthal_dcache_region_invalidate(buffer, size);
// Write back cache to memory
xthal_dcache_region_writeback(buffer, size);
3.2 Data Conversion*
NPU input and output only support float16 format
VspFloat32ToFloat16() // float32 to float16 conversion
VspFloat16toFloat32() // float16 to float32 conversion