mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-23 01:36:33 +00:00
Enables use of multiple TPUs in OPI5
This commit is contained in:
@@ -12,13 +12,19 @@ AiEngineInferenceOpi5::AiEngineInferenceOpi5(QString modelPath, QObject *parent)
|
||||
: AiEngineInference{modelPath, parent}
|
||||
{
|
||||
qDebug() << "AiEngineInferenceOpi5() test mModelPath=" << mModelPath;
|
||||
}
|
||||
|
||||
memset(&mRrknnAppCtx, 0, sizeof(rknn_app_context_t));
|
||||
|
||||
void AiEngineInferenceOpi5::initialize(int number)
|
||||
{
|
||||
mNumber = number;
|
||||
|
||||
memset(&mRrknnAppCtx0, 0, sizeof(rknn_app_context_t));
|
||||
init_post_process();
|
||||
|
||||
int ret = init_yolov8_model(modelPath.toLocal8Bit(), &mRrknnAppCtx);
|
||||
int ret = init_yolov8_model(mModelPath.toLocal8Bit(), &mRrknnAppCtx0);
|
||||
if (ret != 0) {
|
||||
qDebug() << "init_yolov8_model() failure! ret: " << ret << "modelPath = " << modelPath;
|
||||
qDebug() << "init_yolov8_model() failure! ret: " << ret << "modelPath = " << mModelPath << "number:" << number;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -27,7 +33,7 @@ AiEngineInferenceOpi5::AiEngineInferenceOpi5(QString modelPath, QObject *parent)
|
||||
AiEngineInferenceOpi5::~AiEngineInferenceOpi5()
|
||||
{
|
||||
deinit_post_process();
|
||||
release_yolov8_model(&mRrknnAppCtx);
|
||||
release_yolov8_model(&mRrknnAppCtx0);
|
||||
}
|
||||
|
||||
|
||||
@@ -110,7 +116,7 @@ void AiEngineInferenceOpi5::performInferenceSlot(cv::Mat frame)
|
||||
image_buffer_t imgBuffer = convertCV2FrameToImageBuffer(scaledFrame);
|
||||
|
||||
object_detect_result_list od_results;
|
||||
int ret = inference_yolov8_model(&mRrknnAppCtx, &imgBuffer, &od_results);
|
||||
int ret = inference_yolov8_model(&mRrknnAppCtx0, &imgBuffer, &od_results, mNumber);
|
||||
if (ret != 0) {
|
||||
qDebug() << "inference_yolov8_model() failure! ret: " << ret;
|
||||
return;
|
||||
|
||||
@@ -11,6 +11,7 @@ class AiEngineInferenceOpi5 : public AiEngineInference
|
||||
public:
|
||||
explicit AiEngineInferenceOpi5(QString modelPath, QObject *parent = nullptr);
|
||||
~AiEngineInferenceOpi5();
|
||||
void initialize(int number) override;
|
||||
|
||||
public slots:
|
||||
void performInferenceSlot(cv::Mat frame) override;
|
||||
@@ -21,5 +22,5 @@ private:
|
||||
cv::Mat resizeToHalfAndAssigntoTopLeft640x640(const cv::Mat& inputFrame);
|
||||
void drawObjects(cv::Mat& image, const object_detect_result_list& result_list);
|
||||
|
||||
rknn_app_context_t mRrknnAppCtx;
|
||||
rknn_app_context_t mRrknnAppCtx0;
|
||||
};
|
||||
|
||||
@@ -155,7 +155,7 @@ int release_yolov8_model(rknn_app_context_t *app_ctx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int inference_yolov8_model(rknn_app_context_t *app_ctx, image_buffer_t *img, object_detect_result_list *od_results)
|
||||
int inference_yolov8_model(rknn_app_context_t *app_ctx, image_buffer_t *img, object_detect_result_list *od_results, int core)
|
||||
{
|
||||
int ret;
|
||||
image_buffer_t dst_img;
|
||||
@@ -211,6 +211,29 @@ int inference_yolov8_model(rknn_app_context_t *app_ctx, image_buffer_t *img, obj
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (core == 1) {
|
||||
ret = rknn_set_core_mask(app_ctx->rknn_ctx, RKNN_NPU_CORE_0);
|
||||
//ret = rknn_set_core_mask(app_ctx->rknn_ctx, RKNN_NPU_CORE_0_1_2);
|
||||
if (ret < 0) {
|
||||
printf("rknn_set_core_mask(RKNN_NPU_CORE_0) fail! ret=%d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (core == 2) {
|
||||
ret = rknn_set_core_mask(app_ctx->rknn_ctx, RKNN_NPU_CORE_1);
|
||||
if (ret < 0) {
|
||||
printf("rknn_set_core_mask(RKNN_NPU_CORE_1) fail! ret=%d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (core == 3) {
|
||||
ret = rknn_set_core_mask(app_ctx->rknn_ctx, RKNN_NPU_CORE_2);
|
||||
if (ret < 0) {
|
||||
printf("rknn_set_core_mask(RKNN_NPU_CORE_1) fail! ret=%d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// Run
|
||||
printf("rknn_run\n");
|
||||
ret = rknn_run(app_ctx->rknn_ctx, nullptr);
|
||||
@@ -247,4 +270,4 @@ out:
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,6 @@ int init_yolov8_model(const char* model_path, rknn_app_context_t* app_ctx);
|
||||
|
||||
int release_yolov8_model(rknn_app_context_t* app_ctx);
|
||||
|
||||
int inference_yolov8_model(rknn_app_context_t* app_ctx, image_buffer_t* img, object_detect_result_list* od_results);
|
||||
int inference_yolov8_model(rknn_app_context_t* app_ctx, image_buffer_t* img, object_detect_result_list* od_results, int core);
|
||||
|
||||
#endif //_RKNN_DEMO_YOLOV8_H_
|
||||
#endif //_RKNN_DEMO_YOLOV8_H_
|
||||
|
||||
Reference in New Issue
Block a user