From 7662674a240c1e51e8b9a25342ecf12bdc1c78c9 Mon Sep 17 00:00:00 2001 From: Ahmed Taha ELthakeb Date: Thu, 3 Nov 2022 23:52:58 -0700 Subject: [PATCH 1/3] submission_v2.1_samsung update --- mobile_back_samsung/BUILD | 5 +- mobile_back_samsung/README.md | 17 + .../cpp/eden_mlperf_c_backend/jni/edenai.cc | 1562 ----------------- .../jni/eden_sdk/include/sbe1200.hpp | 134 -- .../cpp/sbe_backend/jni/eden_sdk/sbe1200.cc | 557 ------ .../jni/enn_sdk/include/sbe2200.hpp | 127 -- .../cpp/sbe_backend/jni/enn_sdk/sbe2200.cc | 538 ------ .../cpp/sbe_backend/jni/include/backend_c.h | 82 - .../sbe_backend/jni/include/sbe_config.hpp | 434 +---- .../cpp/sbe_backend/jni/include/sbe_core.hpp | 128 -- .../cpp/sbe_backend/jni/sbe/sbe_core.cc | 163 -- .../cpp/sbe_backend/jni/sbe/sbe_helper.cc | 111 -- .../{samsung_backend => samsung}/lib/BUILD | 0 .../lib/backend_c.h | 0 .../samsung/lib/sbe_config.hpp | 560 ++++++ .../lib/sbe_core.cc | 0 .../lib/sbe_core.hpp | 0 .../lib/sbe_helper.cc | 0 .../include => samsung/lib}/sbe_helper.hpp | 0 .../include => samsung/lib}/sbe_loader.hpp | 0 .../lib}/sbe_model_container.hpp | 0 .../jni/include => samsung/lib}/sbe_utils.hpp | 0 .../jni/include => samsung/lib}/type.h | 0 mobile_back_samsung/samsung_backend.mk | 9 +- mobile_back_samsung/samsung_backend/README.md | 9 - .../samsung_backend/lib/sbe_config.hpp | 282 --- .../samsung_backend/lib/sbe_helper.hpp | 43 - .../samsung_backend/lib/sbe_loader.hpp | 49 - .../lib/sbe_model_container.hpp | 404 ----- .../samsung_backend/lib/sbe_utils.hpp | 61 - .../samsung_backend/lib/type.h | 65 - 31 files changed, 679 insertions(+), 4661 deletions(-) create mode 100644 mobile_back_samsung/README.md delete mode 100644 mobile_back_samsung/cpp/eden_mlperf_c_backend/jni/edenai.cc delete mode 100644 mobile_back_samsung/cpp/sbe_backend/jni/eden_sdk/include/sbe1200.hpp delete mode 100644 mobile_back_samsung/cpp/sbe_backend/jni/eden_sdk/sbe1200.cc delete mode 100644 mobile_back_samsung/cpp/sbe_backend/jni/enn_sdk/include/sbe2200.hpp delete mode 100644 mobile_back_samsung/cpp/sbe_backend/jni/enn_sdk/sbe2200.cc delete mode 100644 mobile_back_samsung/cpp/sbe_backend/jni/include/backend_c.h delete mode 100644 mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_core.hpp delete mode 100644 mobile_back_samsung/cpp/sbe_backend/jni/sbe/sbe_core.cc delete mode 100644 mobile_back_samsung/cpp/sbe_backend/jni/sbe/sbe_helper.cc rename mobile_back_samsung/{samsung_backend => samsung}/lib/BUILD (100%) rename mobile_back_samsung/{samsung_backend => samsung}/lib/backend_c.h (100%) create mode 100644 mobile_back_samsung/samsung/lib/sbe_config.hpp rename mobile_back_samsung/{samsung_backend => samsung}/lib/sbe_core.cc (100%) rename mobile_back_samsung/{samsung_backend => samsung}/lib/sbe_core.hpp (100%) rename mobile_back_samsung/{samsung_backend => samsung}/lib/sbe_helper.cc (100%) rename mobile_back_samsung/{cpp/sbe_backend/jni/include => samsung/lib}/sbe_helper.hpp (100%) rename mobile_back_samsung/{cpp/sbe_backend/jni/include => samsung/lib}/sbe_loader.hpp (100%) rename mobile_back_samsung/{cpp/sbe_backend/jni/include => samsung/lib}/sbe_model_container.hpp (100%) rename mobile_back_samsung/{cpp/sbe_backend/jni/include => samsung/lib}/sbe_utils.hpp (100%) rename mobile_back_samsung/{cpp/sbe_backend/jni/include => samsung/lib}/type.h (100%) mode change 100755 => 100644 delete mode 100644 mobile_back_samsung/samsung_backend/README.md delete mode 100644 mobile_back_samsung/samsung_backend/lib/sbe_config.hpp delete mode 100644 mobile_back_samsung/samsung_backend/lib/sbe_helper.hpp delete mode 100644 mobile_back_samsung/samsung_backend/lib/sbe_loader.hpp delete mode 100644 mobile_back_samsung/samsung_backend/lib/sbe_model_container.hpp delete mode 100644 mobile_back_samsung/samsung_backend/lib/sbe_utils.hpp delete mode 100644 mobile_back_samsung/samsung_backend/lib/type.h diff --git a/mobile_back_samsung/BUILD b/mobile_back_samsung/BUILD index 4ac012e6a..479d50a3c 100644 --- a/mobile_back_samsung/BUILD +++ b/mobile_back_samsung/BUILD @@ -1,5 +1,3 @@ -# Link to .so libs -# https://github.com/mlcommons/mobile_back_samsung/tree/merge-submission-v2.0-into-master_samsung-backend/mobile_back_samsung/samsung/lib package( default_visibility = ["//visibility:public"], licenses = ["notice"], # Apache 2.0 @@ -17,8 +15,9 @@ cc_library( ] + select({ "android_arm64": [ "samsung_backend/lib/libenn_public_api_cpp.so", - "samsung_backend/lib/libsbe2200_core.so", "samsung_backend/lib/libsbe1200_core.so", + "samsung_backend/lib/libsbe2200_core.so", + "samsung_backend/lib/libsbe2300_core.so", "samsung_backend/lib/libc++.so", "samsung_backend/lib/libeden_nn_on_system.so", ], diff --git a/mobile_back_samsung/README.md b/mobile_back_samsung/README.md new file mode 100644 index 000000000..2cacbb2b0 --- /dev/null +++ b/mobile_back_samsung/README.md @@ -0,0 +1,17 @@ +# Building MLPerf Open app with Samsung backend + + +1. Update the "lib" folder at 'mobile_app_open/mobile_back_samsung/samsung/lib' by copying it from [here](https://github.com/mlcommons/mobile_back_samsung/tree/submission_v2.1_samsung_backend/samsung_libs/mobile_back_samsung/samsung). Here are the .so libs hashes: +``` +5aceeaf47af8c3c1847906a12a7b5de70260e5cbd36a70ab2d163c08682399eb libsamsungbackend.so +2104ff038a520180ac4eb6ca5797fa4bd93f1a50943a4412de9bb783947b3194 libsbe1200_core.so +9333a90f065f65610e0ddc788003b33b55c9940f73e665b3d6a0282de11c046c libsbe2100_core.so +959e772790516649eb5454fd17c4219e3778e35af620061e5c62c6c4a88e1d67 libsbe2200_core.so +d5a475d949018179c8e6aa18a5e524c79197a55e07092d5a63e04d5da10d281c libsbe2300_core.so +``` +2. Change directory to the main path (mobile_app_open) +3. Run the build command + +```bash +make WITH_SAMSUNG=1 OFFICIAL_BUILD=false FLUTTER_BUILD_NUMBER=0 docker/flutter/android/release +``` diff --git a/mobile_back_samsung/cpp/eden_mlperf_c_backend/jni/edenai.cc b/mobile_back_samsung/cpp/eden_mlperf_c_backend/jni/edenai.cc deleted file mode 100644 index 3c93a6c3f..000000000 --- a/mobile_back_samsung/cpp/eden_mlperf_c_backend/jni/edenai.cc +++ /dev/null @@ -1,1562 +0,0 @@ -/* Copyright (c) 2020-2021 Samsung Electronics Co., Ltd. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ -#include "edenai.h" - -#include - -#include -#include -#include -#include -#include -#include - -#define LOG_TAG "EdenAI" - -#include -#include - -#include "backend_c.h" -#include "exynos_ofi_wrapper.h" -#include "samsung_settings.h" - -#define NUM_MIXED_MODEL_FILES 16 -#define NUM_OF_INIT_DSP_BATCH 2 -#define NUM_OF_DSP_BATCH 128 - -void* LoadFunction(void* dl_handle, const char* name) { - auto func_pt = dlsym(dl_handle, name); - return func_pt; -} - -#define LOAD_FUNCTION(dl_handle, method_name) \ - method_name##Func = reinterpret_cast( \ - LoadFunction(dl_handle, #method_name)) - -namespace EdenAI { - -const uint32_t EDEN_NN_TIMEOUT = UINT32_MAX; - -int makeBufferCount = 0; - -uint32_t ModelId0 = INVALID_MODEL_ID; -EdenBuffer* inputBuffers0[NUM_OF_BUFF_MAX]; -EdenBuffer* outputBuffers0[NUM_OF_BUFF_MAX]; - -uint32_t ModelId1 = INVALID_MODEL_ID; -EdenBuffer* inputBuffers1[NUM_OF_BUFF_MAX]; -EdenBuffer* outputBuffers1[NUM_OF_BUFF_MAX]; - -uint32_t ModelId2 = INVALID_MODEL_ID; -EdenBuffer* inputBuffers2[NUM_OF_BUFF_MAX]; -EdenBuffer* outputBuffers2[NUM_OF_BUFF_MAX]; - -uint32_t ModelIdDsp = INVALID_MODEL_ID; -EdenBuffer* inputBuffers3[NUM_OF_INIT_DSP_BATCH]; -EdenBuffer* outputBuffers3[NUM_OF_INIT_DSP_BATCH]; -int inputSize = 0; -int outputSize = 0; - -bool MULTI_NPU_ENABLED = false; -EdenPreference preference; -HwPreference hwPreference = NPU_ONLY; -RequestMode requestMode = RequestMode::BLOCK; -ModePreference modePreference = BOOST_MODE; -bool gIsOfflineModel = false; -MLPERF_MODEL_TYPE gTestModelType = MLPERF_MODEL_TYPE_NONE; -const char* dspModelPath = "/sdcard/MLPerf_sideload/mobilenet_edgetpu_out.cgo"; - -std::vector vecOutputSize; - -inline void _fillRequest(EdenRequest* request, uint32_t modelId, - EdenBuffer* inputBuffer, EdenBuffer* outputBuffer) { - request->modelId = modelId; - request->inputBuffers = inputBuffer; - request->outputBuffers = outputBuffer; -} - -inline int fillRequest(EdenRequest* request, uint32_t modelId, - EdenBuffer* inputBuffer, EdenBuffer* outputBuffer, - char* src, size_t size, IMAGE_FORMAT image_format) { - memcpy(inputBuffer->addr, src, size); - _fillRequest(request, modelId, inputBuffer, outputBuffer); - return RET_OK; -} - -inline int fillDspRequest(EdenRequest* request, uint32_t modelId, - EdenBuffer* inputBuffer, EdenBuffer* outputBuffer, - char* src, size_t size, IMAGE_FORMAT image_format) { - if (ExynosOFI_CopyToBuffer(inputBuffer, 0, src, size, image_format) != - RET_OK) { - MLOGE("load input failed"); - return RET_ERROR_ON_RT_LOAD_BUFFERS; - } - _fillRequest(request, modelId, inputBuffer, outputBuffer); - return RET_OK; -} - -bool dspOpenModel(uint32_t& modelId, const char* path, - EdenBuffer** inputBuffers, EdenBuffer** outputBuffers, - const int num_buffers) { - EdenModelFile modelFile = makeModel(path); - int ret = ExynosOFI_OpenModel(&modelFile, &modelId, preference); - if (ret != RET_OK) { - MLOGE("open dsp model failed"); - return false; - } - for (int i = 0; i < num_buffers; i++) { - int32_t tempNumber = 0; - ret = - ExynosOFI_AllocateInputBuffers(modelId, &inputBuffers[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate input buffer, ret = %d", ret); - return false; - } - ret = ExynosOFI_AllocateOutputBuffers(modelId, &outputBuffers[i], - &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate output buffer, ret = %d", ret); - return false; - } - } - return true; -} - -bool dspOpenModelFromMemory(uint32_t& modelId, char* va, size_t size, - EdenBuffer** inputBuffers, - EdenBuffer** outputBuffers, const int num_buffers) { - int ret; - EdenModelOptions dummy_options; - ret = ExynosOFI_OpenEdenModelFromMemory(MODEL_TYPE_IN_MEMORY_TFLITE, - reinterpret_cast(va), size, - false, &modelId, dummy_options); - if (ret != RET_OK) { - MLOGE("Open DSP model from memory failed."); - return false; - } - for (int i = 0; i < num_buffers; i++) { - int32_t dummy = 0; - ret = ExynosOFI_AllocateInputBuffers(modelId, &inputBuffers[i], &dummy); - if (ret != RET_OK) { - MLOGE("Fail to Allocate input buffer, ret = %d", ret); - return false; - } - ret = ExynosOFI_AllocateOutputBuffers(modelId, &outputBuffers[i], &dummy); - if (ret != RET_OK) { - MLOGE("Fail to Allocate output buffer, ret = %d", ret); - return false; - } - } - return true; -} - -void setHwPreference(int hp) { hwPreference = (HwPreference)hp; } - -uint32_t getInputSize() { - int32_t w, h, c, n; - GetInputBufferShapeFunc(ModelId0, 0, &w, &h, &c, &n); - return w * h * c * n; -} - -uint32_t getOutputSize() { - int32_t w, h, c, n; - GetOutputBufferShapeFunc(ModelId0, 0, &w, &h, &c, &n); - if (GetOutputBufferShapeFunc == ExynosOFI_GetOutputBufferShape) { - w /= 4; - } - return w * h * c * n; -} - -void setInputSize(int size) { inputSize = size; } - -void setOutputSize(int size) { outputSize = size; } - -void edenNotify(addr_t* addr, addr_t value) { *addr = value; } - -int32_t edenWaitFor(addr_t* addr, uint32_t value, uint32_t timeout) { - while (timeout--) { - usleep(1); - if (*addr != INVALID_REQUEST_ID) break; - } - if (timeout == 0) { - return -1; - } - return RET_OK; -} - -int32_t edenWaitForAll(EdenCallback* callbacks, uint32_t timeout, - uint32_t batch, char* output, EdenRequest* requests, - int oneFrameSize, int outputFrameSize, addr_t* requestId, - Backend* ptr) { - bool all_done, all_dsp_done; - const int COPIED = 1; - const int NOT_COPIED = 0; - const int dsp_batch = (ModelIdDsp != INVALID_MODEL_ID) ? NUM_OF_DSP_BATCH : 0; - const int dsp_init_batch = - (ModelIdDsp != INVALID_MODEL_ID) ? NUM_OF_INIT_DSP_BATCH : 0; - int dsp_idx = batch + dsp_init_batch; - int dsp_idx_end = batch + dsp_batch; - - int scoreBoard[batch + dsp_batch]; - for (int i = 0; i < batch + dsp_batch; i++) { - scoreBoard[i] = NOT_COPIED; - } - - int idx = NUM_OF_BUFF_MAX * 3; - int offset; - - EdenPreference pref; - pref.mode = modePreference; - pref.hw = hwPreference; - - EdenRequestOptions options; - options.userPreference = pref; - options.requestMode = requestMode; - options.reserved[0] = { - 0, - }; - - int i = 0; - while (timeout--) { - usleep(1); - all_done = true; - all_dsp_done = true; - for (; i < batch; i++) { - if (callbacks[i].requestId != INVALID_REQUEST_ID && - scoreBoard[i] == NOT_COPIED) { - offset = i * outputFrameSize; - vecOutputSize.push_back(requests[i].outputBuffers->size); - memcpy(output + offset, requests[i].outputBuffers->addr, - requests[i].outputBuffers->size); - scoreBoard[i] = COPIED; - if (idx < batch) { - if (fillRequest(&requests[idx], requests[i].modelId, - requests[i].inputBuffers, requests[i].outputBuffers, - (char*)ptr->input_conv->at(idx), oneFrameSize, - IMAGE_FORMAT_BGRC) == RET_OK && - ExecuteEdenModel(&requests[idx], &requestId[idx], options) == - RET_OK) { - idx++; - } else { - MLOGE("edenWaitForAll ExecuteModel() failed "); - } - } - } - all_done = all_done && (callbacks[i].requestId != INVALID_REQUEST_ID); - } - for (; ModelIdDsp && i < dsp_idx_end; i++) { - auto req = reinterpret_cast(&requests[i]); - if (scoreBoard[i] == NOT_COPIED && req->result != (int32_t)0xffffffff) { - ExynosOFI_CopyFromBuffer(output + i * outputFrameSize, - requests[i].outputBuffers, outputFrameSize); - scoreBoard[i] = COPIED; - if (dsp_idx < dsp_idx_end) { - if (fillDspRequest(&requests[dsp_idx], requests[i].modelId, - requests[i].inputBuffers, - requests[i].outputBuffers, - (char*)ptr->input_conv->at(dsp_idx), oneFrameSize, - IMAGE_FORMAT_BGRC) == RET_OK && - ExynosOFI_ExecuteEdenModel( - &requests[dsp_idx], &requestId[dsp_idx], options) == RET_OK) { - dsp_idx++; - } else { - MLOGE("execute dsp failed "); - } - } - } - all_dsp_done = all_dsp_done && (req->result != (int32_t)0xffffffff); - } - if (all_done && all_dsp_done) { - break; - } - i = 0; - if (all_done) { - // skip NPU check in next iteration - i = batch; - } - if (all_dsp_done) { - // skip DSP check in next iteration - dsp_idx_end = batch; - } - } - if (timeout == 0) { - MLOGE("edenWaitForAll timeout"); - return -1; - } - return RET_OK; -} - -EdenModelFile makeModel(const char* pathToModelFile) { - EdenModelFile modelFile; - modelFile.modelFileFormat = TFLITE; - modelFile.pathToModelFile = (int8_t*)pathToModelFile; - modelFile.lengthOfPath = strlen(pathToModelFile) + 1; - modelFile.pathToWeightBiasFile = nullptr; - modelFile.lengthOfWeightBias = 0; - return modelFile; -} - -bool jni_Initialize() { - int ret = 0; - - ret = InitializeFunc(); - if (ret != RET_OK) { - MLOGE("jni_Initialize false"); - return false; - } - MLOGD("jni_Initialize true"); - ExynosOFI_Initialize(); - return true; -} - -bool jni_OpenModelFromMemory(char* bufferMain, int lengthMain, - char* bufferOther, int lengthOther, int device, - int batch) { - MLOGD("(+)"); - int ret = 0; - - EdenModelOptions options; - options.modelPreference = { - {(HwPreference)device, modePreference, {false, false}}, EDEN_NN_API}; - options.priority = P_DEFAULT; - options.boundCore = NPU_UNBOUND; - - ModelId0 = INVALID_MODEL_ID; - ModelId1 = INVALID_MODEL_ID; - ModelId2 = INVALID_MODEL_ID; - ModelIdDsp = INVALID_MODEL_ID; - - if (options.modelPreference.userPreference.hw == NPU_ONLY) { - // OpenModel for 3 Core - ret = OpenEdenModelFromMemory(MODEL_TYPE_IN_MEMORY_TFLITE, - reinterpret_cast(bufferMain), - lengthMain, false, &ModelId0, options); - - if (ret != RET_OK) { - MLOGE("Fail to OpenModel0!, ret = %d", ret); - return false; - } - - if (batch > 1) { - ret = OpenEdenModelFromMemory(MODEL_TYPE_IN_MEMORY_TFLITE, - reinterpret_cast(bufferMain), - lengthMain, false, &ModelId1, options); - if (ret != RET_OK) { - MLOGE("Fail to OpenModel1!, ret = %d", ret); - return false; - } - - ret = OpenEdenModelFromMemory(MODEL_TYPE_IN_MEMORY_TFLITE, - reinterpret_cast(bufferMain), - lengthMain, false, &ModelId2, options); - if (ret != RET_OK) { - MLOGE("Fail to OpenModel2!, ret = %d", ret); - return false; - } - - if (bufferOther && lengthOther) { - if (!dspOpenModelFromMemory(ModelIdDsp, bufferOther, lengthOther, - inputBuffers3, outputBuffers3, - NUM_OF_INIT_DSP_BATCH)) { - MLOGE("Fail to OpenModel3!, ret = %d", ret); - return false; - } - } - - MULTI_NPU_ENABLED = true; - } - - } else if (options.modelPreference.userPreference.hw == GPU_ONLY) { - // OpenModel for GPU - ret = OpenEdenModelFromMemoryFunc(MODEL_TYPE_IN_MEMORY_TFLITE, - reinterpret_cast(bufferMain), - lengthMain, false, &ModelId0, options); - if (ret != RET_OK) { - MLOGE("Fail to OpenModel0() GPU!, ret = %d", ret); - return false; - } - MULTI_NPU_ENABLED = false; - } else if (options.modelPreference.userPreference.hw == DSP_ONLY) { - return false; - } - for (int32_t i = 0; i < NUM_OF_BUFF_MAX; i++) { - int32_t tempNumber = 0; - if (ModelId0 != INVALID_MODEL_ID) { - ret = AllocateInputBuffersFunc(ModelId0, &inputBuffers0[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate input buffer NPU0, ret = %d", ret); - return false; - } - ret = - AllocateOutputBuffersFunc(ModelId0, &outputBuffers0[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate output buffer NPU0, ret = %d", ret); - return false; - } - } - if (ModelId1 != INVALID_MODEL_ID) { - ret = AllocateInputBuffers(ModelId1, &inputBuffers1[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate input buffer NPU1, ret = %d", ret); - return false; - } - ret = AllocateOutputBuffers(ModelId1, &outputBuffers1[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate output buffer NPU1, ret = %d", ret); - return false; - } - } - if (ModelId2 != INVALID_MODEL_ID) { - ret = AllocateInputBuffers(ModelId2, &inputBuffers2[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate input buffer NPU2, ret = %d", ret); - return false; - } - ret = AllocateOutputBuffers(ModelId2, &outputBuffers2[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate output buffer NPU2, ret = %d", ret); - return false; - } - } - } - return true; -} - -bool jni_OpenModel(const char* pathToModelFile, int device, int batch) { - int ret = 0; - - preference.hw = (HwPreference)device; - preference.mode = modePreference; - - preference.inputBufferMode.enable = false; - preference.inputBufferMode.setInputAsFloat = false; - - EdenModelFile modelFile = makeModel(pathToModelFile); - ModelId0 = INVALID_MODEL_ID; - ModelId1 = INVALID_MODEL_ID; - ModelId2 = INVALID_MODEL_ID; - ModelIdDsp = INVALID_MODEL_ID; - - MLOGD("pathToModelFile=%s", pathToModelFile); - if (preference.hw == NPU_ONLY) { - ret = OpenModel(&modelFile, &ModelId0, preference); - if (ret != RET_OK) { - return false; - } - - if (batch > 1) { - ret = OpenModel(&modelFile, &ModelId1, preference); - if (ret != RET_OK) { - return false; - } - ret = OpenModel(&modelFile, &ModelId2, preference); - if (ret != RET_OK) { - return false; - } - - if (!dspOpenModel(ModelIdDsp, dspModelPath, inputBuffers3, outputBuffers3, - NUM_OF_INIT_DSP_BATCH)) { - return false; - } - - MULTI_NPU_ENABLED = true; - } - - } else if (preference.hw == GPU_ONLY) { - ret = OpenModelFunc(&modelFile, &ModelId0, preference); - if (ret != RET_OK) { - return false; - } - MULTI_NPU_ENABLED = false; - } else if (preference.hw == DSP_ONLY) { - MULTI_NPU_ENABLED = false; - return dspOpenModel(ModelId0, pathToModelFile, inputBuffers0, - outputBuffers0, NUM_OF_BUFF_MAX); - } - - for (int32_t i = 0; i < NUM_OF_BUFF_MAX; i++) { - int32_t tempNumber = 0; - if (ModelId0 != INVALID_MODEL_ID) { - ret = AllocateInputBuffersFunc(ModelId0, &inputBuffers0[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate input buffer NPU0, ret = %d", ret); - return false; - } - ret = - AllocateOutputBuffersFunc(ModelId0, &outputBuffers0[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate output buffer NPU0, ret = %d", ret); - return false; - } - } - if (ModelId1 != INVALID_MODEL_ID) { - ret = AllocateInputBuffers(ModelId1, &inputBuffers1[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate input buffer NPU1, ret = %d", ret); - return false; - } - ret = AllocateOutputBuffers(ModelId1, &outputBuffers1[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate output buffer NPU1, ret = %d", ret); - return false; - } - } - if (ModelId2 != INVALID_MODEL_ID) { - ret = AllocateInputBuffers(ModelId2, &inputBuffers2[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate input buffer NPU2, ret = %d", ret); - return false; - } - ret = AllocateOutputBuffers(ModelId2, &outputBuffers2[i], &tempNumber); - if (ret != RET_OK) { - MLOGE("Fail to Allocate output buffer NPU2, ret = %d", ret); - return false; - } - } - } - return true; -} - -int sample_notify_callback(int num_param, void** params) { - if (num_param != 1) { - MLOGE("Wrong params. num_param(%d != 1)\n", num_param); - } - // MLOGD("User notify callback-ed! req=%p", params[0]); - return 0; -} - -/* OFI Test */ -int sample_user_wait_for(exynos_nn_request_t* req) { - while (req->result == (int32_t)0xffffffff) { - // MLOGD("User waiting.. result(0x%x) addr:%p", req->result, req); - usleep(1000); - } - if (req->result != RET_OK) { - MLOGE("Execute done but failed."); - return req->result; - } - return 0; -} - -bool jni_ExecuteModelBatch(char* input, char* output, bool isMobileBert, - Backend* ptr) { - int ret = RET_OK; - vecOutputSize.clear(); - - int batch = ptr->batch; - int dsp_batch = 0; - int dsp_init_batch = 0; - std::unique_ptr cb_param_ptr; - auto dsp_callbacks = - std::make_unique(batch + dsp_batch); - - if (ModelIdDsp != INVALID_MODEL_ID) { - dsp_batch = NUM_OF_DSP_BATCH; - dsp_init_batch = NUM_OF_INIT_DSP_BATCH; - cb_param_ptr = std::make_unique(batch + dsp_batch); - } - batch -= dsp_batch; - - EdenRequest* requests = new EdenRequest[batch + dsp_batch]; - EdenCallback* callbacks = new EdenCallback[batch + dsp_batch]; - addr_t* requestId = new addr_t[batch + dsp_batch]; - - EdenPreference pref; - pref.mode = modePreference; - pref.hw = hwPreference; - - EdenRequestOptions options; - options.userPreference = pref; - options.requestMode = requestMode; - options.reserved[0] = { - 0, - }; - - if (hwPreference != DSP_ONLY) { - for (int i = 0; i < batch; i++) { - callbacks[i].notify = edenNotify; - callbacks[i].waitFor = edenWaitFor; - callbacks[i].requestId = INVALID_REQUEST_ID; - callbacks[i].executionResult.inference.retCode = RET_OK; - - requestId[i] = INVALID_REQUEST_ID; - requests[i].callback = &callbacks[i]; - requests[i].hw = hwPreference; - } - } else { - for (int i = 0; i < batch; i++) { - /* set callback_func param. */ - cb_param_ptr[i] = reinterpret_cast(&requests[i]); - dsp_callbacks.get()[i].num_param = 1; - dsp_callbacks.get()[i].param = &cb_param_ptr[i]; - dsp_callbacks.get()[i].notify = sample_notify_callback; - - requestId[i] = INVALID_REQUEST_ID; - requests[i].callback = - reinterpret_cast(&dsp_callbacks.get()[i]); - reinterpret_cast(&requests[i])->result = 0xffffffff; - } - } - for (int i = batch; i < batch + dsp_batch; i++) { - cb_param_ptr[i] = reinterpret_cast(&requests[i]); - dsp_callbacks.get()[i].num_param = 1; - dsp_callbacks.get()[i].param = &cb_param_ptr[i]; - dsp_callbacks.get()[i].notify = sample_notify_callback; - requestId[i] = INVALID_REQUEST_ID; - requests[i].callback = - reinterpret_cast(&dsp_callbacks.get()[i]); - reinterpret_cast(&requests[i])->result = 0xffffffff; - } - - const int OCCUPIED = 1; - const int AVAILABLE = 0; - - int checkBufferBoard0[NUM_OF_BUFF_MAX] = { - AVAILABLE, - }; - - int checkBufferBoard1[NUM_OF_BUFF_MAX] = { - AVAILABLE, - }; - - int checkBufferBoard2[NUM_OF_BUFF_MAX] = { - AVAILABLE, - }; - - int executedCount = 0; - int oneFrameSize = inputSize / (batch + dsp_batch); - int outputFrameSize = outputSize / (batch + dsp_batch); - for (int i = 0; i < NUM_OF_BUFF_MAX; i++) { - if (checkBufferBoard0[i] == AVAILABLE && ModelId0 != INVALID_MODEL_ID) { - if (hwPreference == DSP_ONLY) { - fillDspRequest(&requests[executedCount], ModelId0, inputBuffers0[i], - outputBuffers0[i], - (char*)ptr->input_conv->at(executedCount), oneFrameSize, - IMAGE_FORMAT_BGR); - } else { - if (isMobileBert) { - memcpy((inputBuffers0[i] + 0)->addr, input + inputSize * 4 * 0, - inputSize * 4); - memcpy((inputBuffers0[i] + 1)->addr, input + inputSize * 4 * 1, - inputSize * 4); - memcpy((inputBuffers0[i] + 2)->addr, input + inputSize * 4 * 2, - inputSize * 4); - requests[executedCount].modelId = ModelId0; - requests[executedCount].inputBuffers = inputBuffers0[i]; - requests[executedCount].outputBuffers = outputBuffers0[i]; - GPUBoost::apply_GPU_boost(); - } else { - fillRequest(&requests[executedCount], ModelId0, inputBuffers0[i], - outputBuffers0[i], - (char*)ptr->input_conv->at(executedCount), oneFrameSize, - IMAGE_FORMAT_BGRC); - } - } - if (ExecuteEdenModelFunc(&requests[executedCount], - &requestId[executedCount], options) != RET_OK) { - MLOGE("execute model failed"); - } else { - executedCount++; - } - checkBufferBoard0[i] = OCCUPIED; - if (executedCount >= batch) { - break; - } - } - - if (MULTI_NPU_ENABLED) { - if (checkBufferBoard1[i] == AVAILABLE && ModelId1 != INVALID_MODEL_ID) { - memcpy(inputBuffers1[i]->addr, - (char*)ptr->input_conv->at(executedCount), oneFrameSize); - requests[executedCount].modelId = ModelId1; - requests[executedCount].inputBuffers = inputBuffers1[i]; - requests[executedCount].outputBuffers = outputBuffers1[i]; - - ret = ExecuteEdenModel(&requests[executedCount], - &requestId[executedCount], options); - if (ret != RET_OK) { - MLOGE("execute model failed"); - } else { - executedCount++; - } - checkBufferBoard1[i] = OCCUPIED; - if (executedCount >= batch) { - break; - } - } - - if (checkBufferBoard2[i] == AVAILABLE && ModelId2 != INVALID_MODEL_ID) { - memcpy(inputBuffers2[i]->addr, - (char*)ptr->input_conv->at(executedCount), oneFrameSize); - requests[executedCount].modelId = ModelId2; - requests[executedCount].inputBuffers = inputBuffers2[i]; - requests[executedCount].outputBuffers = outputBuffers2[i]; - - ret = ExecuteEdenModel(&requests[executedCount], - &requestId[executedCount], options); - if (ret != RET_OK) { - } else { - executedCount++; - } - - checkBufferBoard2[i] = OCCUPIED; - if (executedCount >= batch) { - break; - } - } - } - } - if (ModelIdDsp != INVALID_MODEL_ID) { - for (int i = 0; i < dsp_init_batch; ++i) { - if (fillDspRequest(&requests[batch + i], ModelIdDsp, inputBuffers3[i], - outputBuffers3[i], - (char*)ptr->input_conv->at(batch + i), oneFrameSize, - IMAGE_FORMAT_BGRC) != RET_OK || - ExynosOFI_ExecuteEdenModel( - &requests[batch + i], &requestId[batch + i], options) != RET_OK) { - MLOGE("dsp model execution failed"); - } - } - } - - if (batch == 1) { - do { - if (hwPreference == DSP_ONLY && requestMode == RequestMode::NONBLOCK) { - for (int i = 0; i < batch; i++) { - if (sample_user_wait_for(reinterpret_cast( - &requests[i])) != RET_OK) { - MLOGE("callback error"); - } - } - ExynosOFI_CopyFromBuffer(output, requests[0].outputBuffers, - outputFrameSize); - } else if (requestMode == RequestMode::NONBLOCK && - callbacks[0].waitFor(&callbacks[0].requestId, requestId[0], - EDEN_NN_TIMEOUT) < 0) { - ret = RET_ERROR_ON_RT_EXECUTE_MODEL; - MLOGE("callbackThread RET_ERROR_ON_RT_EXECUTE_MODEL"); - break; - } - vecOutputSize.push_back(requests[0].outputBuffers->size); - - if (isMobileBert) { - memcpy(output + outputSize * 0, (requests[0].outputBuffers + 0)->addr, - outputSize * 4); - memcpy(output + outputSize * 4, (requests[0].outputBuffers + 1)->addr, - outputSize * 4); - } else { - memcpy(output, requests[0].outputBuffers->addr, - requests[0].outputBuffers->size); - } - - if (requests[executedCount].modelId == ModelId0 && - ModelId0 != INVALID_MODEL_ID) { - checkBufferBoard0[0] = AVAILABLE; - } - } while (0); - } else { - do { - if (hwPreference == DSP_ONLY && requestMode == RequestMode::NONBLOCK) { - int idx = NUM_OF_BUFF_MAX; - for (int i = 0; i < batch; i++) { - if (sample_user_wait_for(reinterpret_cast( - &requests[i])) != RET_OK) { - MLOGE("callback error"); - } - int offset = i * outputFrameSize; - auto mem = - reinterpret_cast(requests[i].outputBuffers); - memcpy(output + offset, mem->address, mem->size); - if (idx < batch) { - if (fillDspRequest(&requests[idx], requests[i].modelId, - requests[i].inputBuffers, - requests[i].outputBuffers, - (char*)ptr->input_conv->at(idx), oneFrameSize, - IMAGE_FORMAT_BGR) == RET_OK && - ExecuteEdenModelFunc(&requests[idx], &requestId[idx], - options) == RET_OK) { - idx++; - } else { - MLOGE("edenWaitForAll ExecuteModel() failed"); - } - } - } - } else if (requestMode == RequestMode::NONBLOCK && - edenWaitForAll(callbacks, EDEN_NN_TIMEOUT, batch, output, - requests, oneFrameSize, outputFrameSize, - requestId, ptr) < 0) { - ret = RET_ERROR_ON_RT_EXECUTE_MODEL; - MLOGE("callbackThread RET_ERROR_ON_RT_EXECUTE_MODEL"); - break; - } - for (int i = 0; i < NUM_OF_BUFF_MAX; i++) { - checkBufferBoard0[i] = AVAILABLE; - checkBufferBoard1[i] = AVAILABLE; - checkBufferBoard2[i] = AVAILABLE; - } - } while (0); - } - - delete[] requests; - delete[] callbacks; - delete[] requestId; - return true; -} - -bool jni_CloseModel() { - int ret = RET_OK; - for (int32_t i = 0; i < NUM_OF_BUFF_MAX; i++) { - if (ModelId0 != INVALID_MODEL_ID) { - ret = FreeBuffersFunc(ModelId0, inputBuffers0[i]); - ret = FreeBuffersFunc(ModelId0, outputBuffers0[i]); - if (ret != RET_OK) { - MLOGE("FreeBuffers failed ModelId0"); - } - MLOGD("FreeBuffers ModelId0"); - } - - if (ModelId1 != INVALID_MODEL_ID) { - ret = FreeBuffers(ModelId1, inputBuffers1[i]); - ret = FreeBuffers(ModelId1, outputBuffers1[i]); - if (ret != RET_OK) { - MLOGE("FreeBuffers failed ModelId1"); - } - MLOGD("FreeBuffers ModelId1"); - } - - if (ModelId2 != INVALID_MODEL_ID) { - ret = FreeBuffers(ModelId2, inputBuffers2[i]); - ret = FreeBuffers(ModelId2, outputBuffers2[i]); - if (ret != RET_OK) { - MLOGE("FreeBuffers failed ModelId2"); - } - MLOGD("FreeBuffers ModelId2"); - } - } - if (ModelIdDsp != INVALID_MODEL_ID) { - for (int32_t i = 0; i < NUM_OF_INIT_DSP_BATCH; i++) { - ExynosOFI_FreeBuffers(ModelIdDsp, inputBuffers3[i]); - ExynosOFI_FreeBuffers(ModelIdDsp, outputBuffers3[i]); - } - } - - if (ModelId0 != INVALID_MODEL_ID) { - ret = CloseModelFunc(ModelId0); - if (ret != RET_OK) { - MLOGE("CloseModel failed ModelId0"); - } - ModelId0 = INVALID_MODEL_ID; - MLOGD("CloseModel ModelId0"); - } - if (ModelId1 != INVALID_MODEL_ID) { - ret = CloseModel(ModelId1); - if (ret != RET_OK) { - MLOGE("CloseModel failed ModelId1"); - } - ModelId1 = INVALID_MODEL_ID; - MLOGD("CloseModel ModelId1"); - } - - if (ModelId2 != INVALID_MODEL_ID) { - ret = CloseModel(ModelId2); - if (ret != RET_OK) { - MLOGE("CloseModel failed ModelId2"); - } - ModelId2 = INVALID_MODEL_ID; - MLOGD("CloseModel ModelId2"); - } - - if (ModelIdDsp != INVALID_MODEL_ID) { - ret = ExynosOFI_CloseModel(ModelIdDsp); - if (ret != RET_OK) { - MLOGE("CloseModel failed ModelIdDsp"); - } - ModelIdDsp = INVALID_MODEL_ID; - } - return true; -} - -bool jni_Shutdown() { - int ret = ShutdownFunc(); - if (ret != RET_OK) { - MLOGE("Shutdown failed"); - } - - if (ShutdownFunc != ExynosOFI_Shutdown) { - ExynosOFI_Shutdown(); - } - - MLOGV("Shutdown"); - return true; -} - -bool jni_GetEdenVersion(uint32_t modelId, int32_t* versions) { - int ret = GetEdenVersion(modelId, versions); - if (ret != RET_OK) { - MLOGE("GetEdenVersion failed"); - } - return true; -} - -} // namespace EdenAI - -// Should return true if current hardware is supported. -bool mlperf_backend_matches_hardware(const char** not_allowed_message, - const char** settings, - mlperf_device_info_t* device_info) { - MLOGD("Check for support manufacturer: %s model: %s", - device_info->manufacturer, device_info->model); - - *not_allowed_message = nullptr; - *settings = samsung_settings.c_str(); - - char* isSamsung1 = NULL; - isSamsung1 = strstr((char*)device_info->manufacturer, "samsung"); - char* isSamsung2 = NULL; - isSamsung2 = strstr((char*)device_info->manufacturer, "Samsung"); - if (isSamsung1 || isSamsung2) { // Samsung device - MLOGD("This is Samsung device"); - - char* isG998N = NULL; - isG998N = strstr((char*)device_info->model, "SM-G998N"); - char* isG998B = NULL; - isG998B = strstr((char*)device_info->model, "SM-G998B"); - char* isG996N = NULL; - isG996N = strstr((char*)device_info->model, "SM-G996N"); - char* isG996B = NULL; - isG996B = strstr((char*)device_info->model, "SM-G996B"); - char* isG991N = NULL; - isG991N = strstr((char*)device_info->model, "SM-G991N"); - char* isG991B = NULL; - isG991B = strstr((char*)device_info->model, "SM-G991B"); - if (isG998N || isG998B || isG996N || isG996B || isG991N || - isG991B) { // S21, S21 ultra or Olympus engineering device - MLOGD("This is S21 device"); - std::array buffer; - std::string result; - std::unique_ptr pipe( - popen("getprop | grep ro.hardware.chipname", "r"), pclose); - if (!pipe) { - throw std::runtime_error("popen() failed!"); - } - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { - result += buffer.data(); - } - if (result.find("exynos2100") != std::string::npos) { - MLOGD("This hardware is supported"); - return true; - } else { // S21 but not using exynos2100, unsuported, should stop search - // for next backend, report unsupported - MLOGD("This hardware is unsupported"); - *not_allowed_message = "Unsupported"; - return true; - } - } else { // Samsung but not s21 - MLOGD("This hardware is unsupported"); - *not_allowed_message = "Unsupported"; - return true; - } - } else { // not Samsung - MLOGD("Soc Not supported. Trying next backend"); - *not_allowed_message = "UnsupportedSoc"; - return true; - } -} -void mlperf_backend_clear(mlperf_backend_ptr_t backend_ptr) { - MLOGD("mlperf_backend_clear"); - Backend* samsung_backend = (Backend*)backend_ptr; - samsung_backend->input_format_.clear(); - samsung_backend->input_format_.shrink_to_fit(); - - samsung_backend->output_format_.clear(); - samsung_backend->output_format_.shrink_to_fit(); - - if (samsung_backend->outputs_buffer != nullptr) { - samsung_backend->outputs_buffer->clear(); - samsung_backend->outputs_buffer->shrink_to_fit(); - delete samsung_backend->outputs_buffer; - samsung_backend->outputs_buffer = nullptr; - } - - if (samsung_backend->model_buffer != nullptr) { - samsung_backend->model_buffer->clear(); - samsung_backend->model_buffer->shrink_to_fit(); - delete samsung_backend->model_buffer; - samsung_backend->model_buffer = nullptr; - } - - if (samsung_backend->input_conv != nullptr) { - samsung_backend->input_conv->clear(); - samsung_backend->input_conv->shrink_to_fit(); - delete samsung_backend->input_conv; - samsung_backend->input_conv = nullptr; - } - - if (samsung_backend->detected_label_boxes != nullptr) { - samsung_backend->detected_label_boxes->clear(); - samsung_backend->detected_label_boxes->shrink_to_fit(); - delete samsung_backend->detected_label_boxes; - samsung_backend->detected_label_boxes = nullptr; - } - - if (samsung_backend->detected_label_indices != nullptr) { - samsung_backend->detected_label_indices->clear(); - samsung_backend->detected_label_indices->shrink_to_fit(); - delete samsung_backend->detected_label_indices; - samsung_backend->detected_label_indices = nullptr; - } - - if (samsung_backend->detected_label_probabilities != nullptr) { - samsung_backend->detected_label_probabilities->clear(); - samsung_backend->detected_label_probabilities->shrink_to_fit(); - delete samsung_backend->detected_label_probabilities; - samsung_backend->detected_label_probabilities = nullptr; - } - - if (samsung_backend->num_detections != nullptr) { - samsung_backend->num_detections->clear(); - samsung_backend->num_detections->shrink_to_fit(); - delete samsung_backend->num_detections; - samsung_backend->num_detections = nullptr; - } - - samsung_backend->input_size = 0; - samsung_backend->output_size = 0; - samsung_backend->batch = 0; - - // for mobile bert - samsung_backend->isMobileBertModel_ = false; - samsung_backend->m_inputs_.clear(); - samsung_backend->m_inputs_.shrink_to_fit(); - samsung_backend->m_outputs_.clear(); - samsung_backend->m_outputs_.shrink_to_fit(); - samsung_backend->out0_.clear(); - samsung_backend->out0_.shrink_to_fit(); - samsung_backend->out1_.clear(); - samsung_backend->out1_.shrink_to_fit(); - - EdenAI::jni_CloseModel(); - EdenAI::jni_Shutdown(); - libeden_nn_on_direct = nullptr; -} - -Backend ss_backend; - -// Create a new backend and return the pointer to it. -mlperf_backend_ptr_t mlperf_backend_create( - const char* model_path, mlperf_backend_configuration_t* configs, - const char* native_lib_path) { - Backend* samsung_backend = &ss_backend; - if (samsung_backend->created) { - mlperf_backend_clear(samsung_backend); - } - - std::array buffer_kill; - std::string result_kill; - std::unique_ptr pipe_kill( - popen("killall android.hardware.neuralnetworks@1.3-service.eden-drv", - "r"), - pclose); - if (!pipe_kill) { - throw std::runtime_error("popen() failed!"); - } - while (fgets(buffer_kill.data(), buffer_kill.size(), pipe_kill.get()) != - nullptr) { - result_kill += buffer_kill.data(); - } - MLOGD("killed eden drv"); - - std::array buffer_kill2; - std::string result_kill2; - std::unique_ptr pipe_kill2( - popen("killall vendor.samsung_slsi.hardware.eden_runtime@1.0-service", - "r"), - pclose); - if (!pipe_kill2) { - throw std::runtime_error("popen() failed!"); - } - while (fgets(buffer_kill2.data(), buffer_kill2.size(), pipe_kill2.get()) != - nullptr) { - result_kill2 += buffer_kill2.data(); - } - MLOGD("killed eden service"); - cpu_set_t mask; - long nproc, i; - pid_t tid = gettid(); - CPU_ZERO(&mask); - CPU_SET(4, &mask); - CPU_SET(5, &mask); - CPU_SET(6, &mask); - if (sched_setaffinity(tid, sizeof(mask), &mask) || - sched_getaffinity(tid, sizeof(cpu_set_t), &mask)) { - MLOGE("Error setting up cpu affinity. tid: %d", tid); - } else { - nproc = sysconf(_SC_NPROCESSORS_ONLN); - MLOGD("sched_getaffinity tid: %d", tid); - for (i = 0; i < nproc; i++) { - MLOGD("CPU(%ld): %d", i, CPU_ISSET(i, &mask)); - } - } - - samsung_backend->created = true; - - mlperf_data_t v; - bool isMixedModel = false; - samsung_backend->model_path = model_path; - EdenAI::requestMode = RequestMode::BLOCK; - EdenAI::modePreference = BOOST_MODE; - samsung_backend->batch = 1; - EdenAI::gIsOfflineModel = false; - if (configs->batch_size > 1) { - samsung_backend->batch = configs->batch_size; - MLOGD("mlperf_backend_create samsung_backend->batch: %d", - samsung_backend->batch); - EdenAI::requestMode = RequestMode::NONBLOCK; - EdenAI::modePreference = BOOST_MODE; - EdenAI::gIsOfflineModel = true; - } - - libeden_nn_on_direct = nullptr; - if (strstr(model_path, "lu") != NULL) { - samsung_backend->isMobileBertModel_ = true; - std::string direct_lib_path = - std::string(native_lib_path) + std::string("/libeden_nn.so"); - libeden_nn_on_direct = - dlopen(direct_lib_path.c_str(), RTLD_LAZY | RTLD_LOCAL); - if (libeden_nn_on_direct != nullptr) { - MLOGD("libeden_nn_on_direct != nullptr"); - } else { - MLOGD("libeden_nn_on_direct == nullptr"); - } - MLOGD("EDEN Direct NN lib path = %s; dlerror = %s\n", - direct_lib_path.c_str(), dlerror()); - } else { - samsung_backend->isMobileBertModel_ = false; - } - - if (libeden_nn_on_direct != nullptr) { - LOAD_FUNCTION(libeden_nn_on_direct, Initialize); - LOAD_FUNCTION(libeden_nn_on_direct, OpenModel); - LOAD_FUNCTION(libeden_nn_on_direct, OpenEdenModelFromMemory); - LOAD_FUNCTION(libeden_nn_on_direct, AllocateInputBuffers); - LOAD_FUNCTION(libeden_nn_on_direct, AllocateOutputBuffers); - LOAD_FUNCTION(libeden_nn_on_direct, ExecuteModel); - LOAD_FUNCTION(libeden_nn_on_direct, ExecuteEdenModel); - LOAD_FUNCTION(libeden_nn_on_direct, FreeBuffers); - LOAD_FUNCTION(libeden_nn_on_direct, CloseModel); - LOAD_FUNCTION(libeden_nn_on_direct, Shutdown); - GetInputBufferShapeFunc = GetInputBufferShape; - GetOutputBufferShapeFunc = GetOutputBufferShape; - EdenAI::setHwPreference(GPU_ONLY); - } else if (strstr(model_path, "mobilenet_edgetpu_out.cgo") != NULL) { - InitializeFunc = ExynosOFI_Initialize; - OpenModelFunc = ExynosOFI_OpenModel; - OpenEdenModelFromMemoryFunc = ExynosOFI_OpenEdenModelFromMemory; - AllocateInputBuffersFunc = ExynosOFI_AllocateInputBuffers; - AllocateOutputBuffersFunc = ExynosOFI_AllocateOutputBuffers; - ExecuteModelFunc = ExynosOFI_ExecuteModel; - ExecuteEdenModelFunc = ExynosOFI_ExecuteEdenModel; - GetInputBufferShapeFunc = ExynosOFI_GetInputBufferShape; - GetOutputBufferShapeFunc = ExynosOFI_GetOutputBufferShape; - FreeBuffersFunc = ExynosOFI_FreeBuffers; - CloseModelFunc = ExynosOFI_CloseModel; - ShutdownFunc = ExynosOFI_Shutdown; - EdenAI::requestMode = RequestMode::NONBLOCK; - EdenAI::setHwPreference(DSP_ONLY); - } else { - InitializeFunc = Initialize; - OpenModelFunc = OpenModel; - OpenEdenModelFromMemoryFunc = OpenEdenModelFromMemory; - AllocateInputBuffersFunc = AllocateInputBuffers; - AllocateOutputBuffersFunc = AllocateOutputBuffers; - ExecuteModelFunc = ExecuteModel; - ExecuteEdenModelFunc = ExecuteEdenModel; - GetInputBufferShapeFunc = GetInputBufferShape; - GetOutputBufferShapeFunc = GetOutputBufferShape; - FreeBuffersFunc = FreeBuffers; - CloseModelFunc = CloseModel; - ShutdownFunc = Shutdown; - EdenAI::setHwPreference(NPU_ONLY); - } - - if (EdenAI::jni_Initialize() != true) { - MLOGE("init fail\n"); - } else { - MLOGD("jni_Initialize() succeed\n"); - } - if (strstr(model_path, ".nncgo")) { - isMixedModel = true; - } - - size_t length = 0; - size_t length_others = 0; - std::ifstream infile; - if (isMixedModel && EdenAI::gIsOfflineModel) { - /* TODO: need sophisticated header to better describe mixed models */ - struct MixedModelHeader { - int64_t file_sizes[NUM_MIXED_MODEL_FILES]; - } header; - infile.open(model_path); - infile.read(reinterpret_cast(&header), sizeof(header)); - length = header.file_sizes[0]; - for (int i = 1; - i < sizeof(header.file_sizes) / sizeof(header.file_sizes[0]); ++i) { - length_others += header.file_sizes[i]; - } - } else { - // open file - infile.open(model_path); - infile.seekg(0, infile.end); - length = infile.tellg(); - infile.seekg(0, infile.beg); - } - - // read file - if (length + length_others) { - samsung_backend->model_buffer = - new std::vector(length + length_others); - infile.read(samsung_backend->model_buffer->data(), length + length_others); - } else { - MLOGE("error reading model file: %s", model_path); - } - - if (samsung_backend->isMobileBertModel_) { - samsung_backend->batch = 1; - if (EdenAI::jni_OpenModelFromMemory(samsung_backend->model_buffer->data(), - length, nullptr, 0, GPU_ONLY, - samsung_backend->batch) != true) { - MLOGE("jni_OpenModelFromMemory GPU failed"); - } else { - MLOGD("jni_OpenModelFromMemory GPU success"); - } - } else if (EdenAI::hwPreference == DSP_ONLY) { - if (EdenAI::jni_OpenModel(samsung_backend->model_path.c_str(), DSP_ONLY, - samsung_backend->batch) != true) { - MLOGE("jni_OpenModel() failed\n"); - return nullptr; - } - } else { - if (EdenAI::jni_OpenModelFromMemory( - samsung_backend->model_buffer->data(), length, - samsung_backend->model_buffer->data() + length, length_others, - NPU_ONLY, samsung_backend->batch) != true) { - MLOGE("jni_OpenModelFromMemory failed"); - } else { - MLOGD("jni_OpenModelFromMemory success"); - } - } - - MLOGD("requestMode = %d", EdenAI::requestMode); - if (samsung_backend->isMobileBertModel_) { - samsung_backend->m_inputs_.resize(384 * 3); - samsung_backend->m_outputs_.resize(384 * 2 * 4); - - samsung_backend->out0_.resize(384); - samsung_backend->out1_.resize(384); - - v.type = mlperf_data_t::Int32; - v.size = 384; - samsung_backend->input_format_.push_back(v); - samsung_backend->input_format_.push_back(v); - samsung_backend->input_format_.push_back(v); - v.type = mlperf_data_t::Float32; - v.size = 384; - samsung_backend->output_format_.push_back(v); - samsung_backend->output_format_.push_back(v); - - samsung_backend->output_size = 384; - samsung_backend->input_size = 384; - } else { - samsung_backend->output_size = EdenAI::getOutputSize() * 4; - samsung_backend->input_size = EdenAI::getInputSize(); - - if (samsung_backend->input_size == 150528) { - samsung_backend->model = "classification"; - } else if (samsung_backend->input_size == 270000 || - samsung_backend->input_size == 307200) { - samsung_backend->model = "object_detection"; - MLOGD( - "object_detection samsung_backend->output_size %d " - "samsung_backend->input_size %d", - samsung_backend->output_size, samsung_backend->input_size); - } else { - samsung_backend->model = "segmentation"; - samsung_backend->output_size = EdenAI::getOutputSize(); - MLOGD("output_size %d", samsung_backend->output_size); - } - - if (samsung_backend->model == "object_detection") { - samsung_backend->outputs_buffer = new std::vector( - samsung_backend->output_size * samsung_backend->batch); - samsung_backend->input_conv = - new std::vector(samsung_backend->batch); - samsung_backend->detected_label_boxes = - new std::vector(samsung_backend->output_size / 7); - samsung_backend->detected_label_indices = - new std::vector(samsung_backend->output_size / 28); - samsung_backend->detected_label_probabilities = - new std::vector(samsung_backend->output_size / 28); - samsung_backend->num_detections = new std::vector(1); - - v.type = mlperf_data_t::Uint8; - v.size = samsung_backend->input_size; - samsung_backend->input_format_.push_back(v); - - v.type = mlperf_data_t::Float32; - v.size = samsung_backend->output_size / 7; - samsung_backend->output_format_.push_back(v); - - v.type = mlperf_data_t::Float32; - v.size = samsung_backend->output_size / 28; - samsung_backend->output_format_.push_back(v); - - v.type = mlperf_data_t::Float32; - v.size = samsung_backend->output_size / 28; - samsung_backend->output_format_.push_back(v); - - v.type = mlperf_data_t::Float32; - v.size = 1; - samsung_backend->output_format_.push_back(v); - - } else { - samsung_backend->outputs_buffer = new std::vector( - samsung_backend->output_size * samsung_backend->batch); - samsung_backend->input_conv = - new std::vector(samsung_backend->batch); - - v.type = mlperf_data_t::Uint8; - v.size = samsung_backend->input_size; - samsung_backend->input_format_.push_back(v); - if (samsung_backend->model == "classification") { - v.type = mlperf_data_t::Float32; - v.size = samsung_backend->output_size / 4; - samsung_backend->output_format_.push_back(v); - } else { - v.type = mlperf_data_t::Uint8; - v.size = samsung_backend->output_size; - samsung_backend->output_format_.push_back(v); - } - } - } - MLOGD("mlperf_backend_create backend_ptr: %p", samsung_backend); - return (mlperf_backend_ptr_t)(samsung_backend); -} - -// Vendor name who create this backend. -const char* mlperf_backend_vendor_name(mlperf_backend_ptr_t backend_ptr) { - static const char name[] = "samsung"; - return name; -} - -// TODO: Return the name of the accelerator. -const char* mlperf_backend_accelerator_name(mlperf_backend_ptr_t backend_ptr) { - return "ACCELERATOR_NAME"; -} - -const char* mlperf_backend_name(mlperf_backend_ptr_t backend_ptr) { - static const char name[] = "samsung"; - return name; -} - -int32_t mlperf_backend_get_input_count(mlperf_backend_ptr_t backend_ptr) { - return ((Backend*)backend_ptr)->input_format_.size(); -} - -// Return the type of the ith input. -mlperf_data_t mlperf_backend_get_input_type(mlperf_backend_ptr_t backend_ptr, - int32_t i) { - return ((Backend*)backend_ptr)->input_format_.at(i); -} - -mlperf_status_t mlperf_backend_set_input(mlperf_backend_ptr_t backend_ptr, - int32_t batchIndex, int32_t i, - void* data) { - Backend* ptr = (Backend*)backend_ptr; - - if (ptr->isMobileBertModel_) { - int32_t* pInputs = ptr->m_inputs_.data(); - int32_t* input_data = (int32_t*)data; - for (int j = 0; j < 384; ++j) { - *(pInputs + 384 * i + j) = input_data[j]; - } - } else { - (ptr->input_conv)->at(batchIndex) = static_cast(data); - } - return MLPERF_SUCCESS; -} - -// Return the number of outputs from the model. -int32_t mlperf_backend_get_output_count(mlperf_backend_ptr_t backend_ptr) { - return ((Backend*)backend_ptr)->output_format_.size(); -} -// Return the type of ith output. -mlperf_data_t mlperf_backend_get_output_type(mlperf_backend_ptr_t backend_ptr, - int32_t i) { - return ((Backend*)backend_ptr)->output_format_.at(i); -} - -// Run the inference for a sample. -mlperf_status_t mlperf_backend_issue_query(mlperf_backend_ptr_t backend_ptr) { - Backend* ptr = (Backend*)backend_ptr; - if (ptr->isMobileBertModel_) { - EdenAI::setInputSize(ptr->input_size); - EdenAI::setOutputSize(ptr->output_size); - if (EdenAI::jni_ExecuteModelBatch((char*)(ptr->m_inputs_.data()), - (char*)(ptr->m_outputs_.data()), true, - ptr)) { - return MLPERF_SUCCESS; - } else { - return MLPERF_FAILURE; - } - } else { - EdenAI::setInputSize(ptr->input_size * ptr->batch); - EdenAI::setOutputSize(ptr->output_size * ptr->batch); - if (EdenAI::jni_ExecuteModelBatch((char*)((ptr->input_conv)->at(0)), - (char*)(ptr->outputs_buffer->data()), - false, ptr)) { - return MLPERF_SUCCESS; - } else { - return MLPERF_FAILURE; - } - } -} - -mlperf_status_t mlperf_backend_get_output(mlperf_backend_ptr_t backend_ptr, - uint32_t batchIndex, int32_t i, - void** data) { - Backend* ptr = (Backend*)backend_ptr; - if (ptr->isMobileBertModel_ == true) { - int8_t* pOut = ptr->m_outputs_.data(); - - if (i == 1) { - float* pOut0 = ptr->out0_.data(); - for (int i = 0; i < 384; ++i) { - memcpy(pOut0 + i, pOut + 384 * 0 + i * 4, sizeof(float)); - } - *data = (void*)(pOut0); - } else if (i == 0) { - float* pOut1 = ptr->out1_.data(); - for (int i = 0; i < 384; ++i) { - memcpy(pOut1 + i, pOut + 384 * 4 + i * 4, sizeof(float)); - } - *data = (void*)(pOut1); - } - - } else { - if (ptr->model == "object_detection") { - uint8_t* b = 0; - b = ptr->outputs_buffer->data() + ptr->output_size * batchIndex; - float num_d = 0.0; - float* detected_label_probabilities_p = - ptr->detected_label_probabilities->data(); - float* detected_label_boxes_p = ptr->detected_label_boxes->data(); - float* detected_label_indices_p = ptr->detected_label_indices->data(); - float* num_detections_p = ptr->num_detections->data(); - float curr_detected_idx = 0.0; - for (int j = 0; j < 11; j++) { - curr_detected_idx = (*((float*)(b + j * 28 + 4))); - if (curr_detected_idx > 0) { - switch (i) { - case 0: - memcpy(detected_label_boxes_p, b + j * 28 + 16, sizeof(float)); - detected_label_boxes_p++; - memcpy(detected_label_boxes_p, b + j * 28 + 12, sizeof(float)); - detected_label_boxes_p++; - memcpy(detected_label_boxes_p, b + j * 28 + 24, sizeof(float)); - detected_label_boxes_p++; - memcpy(detected_label_boxes_p, b + j * 28 + 20, sizeof(float)); - detected_label_boxes_p++; - break; - case 1: - curr_detected_idx = curr_detected_idx - 1; - memcpy(detected_label_indices_p, &curr_detected_idx, - sizeof(float)); - detected_label_indices_p++; - break; - case 2: - memcpy(detected_label_probabilities_p, b + j * 28 + 8, - sizeof(float)); - detected_label_probabilities_p++; - break; - case 3: - num_d++; - break; - default: - break; - } - } - } - - switch (i) { - case 0: - *data = (void*)(ptr->detected_label_boxes->data()); - break; - case 1: - *data = (void*)(ptr->detected_label_indices->data()); - break; - case 2: - *data = (void*)(ptr->detected_label_probabilities->data()); - break; - case 3: - memcpy(num_detections_p, &num_d, sizeof(float)); - *data = (void*)(num_detections_p); - memset(b, 0, sizeof(uint8_t) * 28 * num_d); - break; - default: - break; - } - } else if (ptr->model == "classification" || ptr->model == "segmentation") { - *data = - (void*)(ptr->outputs_buffer->data() + ptr->output_size * batchIndex); - } - } - return MLPERF_SUCCESS; -} - -// Flush the staged queries immediately. -mlperf_status_t mlperf_backend_flush_queries(mlperf_backend_ptr_t backend_ptr) { - return MLPERF_SUCCESS; -} - -// Destroy the backend pointer and its data. -void mlperf_backend_delete(mlperf_backend_ptr_t backend_ptr) { - mlperf_backend_clear(backend_ptr); -} - -void mlperf_backend_convert_inputs(mlperf_backend_ptr_t backend_ptr, int bytes, - int width, int height, uint8_t* data) { - // MLOGE("mlperf_backend_convert_inputs called width: %d height: %d", width, - // height); - std::vector* data_uint8_conv = new std::vector(bytes); - int blueOffset = 0; - int greenOffset = width * height; - int redOffset = width * height * 2; - int idx = 0; - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - (*data_uint8_conv)[redOffset] = data[idx]; - (*data_uint8_conv)[greenOffset] = data[idx + 1]; - (*data_uint8_conv)[blueOffset] = data[idx + 2]; - redOffset++; - greenOffset++; - blueOffset++; - idx = idx + 3; - } - } - memcpy(data, data_uint8_conv->data(), sizeof(uint8_t) * bytes); - data_uint8_conv->clear(); - data_uint8_conv->shrink_to_fit(); - delete data_uint8_conv; -} diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/eden_sdk/include/sbe1200.hpp b/mobile_back_samsung/cpp/sbe_backend/jni/eden_sdk/include/sbe1200.hpp deleted file mode 100644 index ab8469612..000000000 --- a/mobile_back_samsung/cpp/sbe_backend/jni/eden_sdk/include/sbe1200.hpp +++ /dev/null @@ -1,134 +0,0 @@ -/* Copyright 2020-2022 Samsung Electronics Co. LTD All Rights Reserved. -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ -#ifndef SBE1200_H_ -#define SBE1200_H_ - -/** - * @file sbe1200.hpp - * @brief samsung backend for 1200. - * @date 2022-01-04 - * @author soobong Huh (soobong.huh@samsung.com) - */ - -#include - -#include -#include -#include -#include -#include - -#include "client/eden_nn_api.h" -#include "client/eden_types.h" -#include "sbe_model_container.hpp" -#include "sbe_utils.hpp" -#include "type.h" -namespace sbe { -class sbe1200 { - public: - const std::string name_ = "sbe1200"; - int m_batch_size; - - /* common buf */ - void *m_mdl_buf; - size_t m_mdl_buf_len; - HwPreference pref_hw = NPU_ONLY; - - std::vector det_lbl_boxes; - std::vector det_lbl_indices; - std::vector det_lbl_prob; - std::vector det_num; - - uint32_t mdl_id[MAX_INSTANCE]; - std::vector m_mdl_inbuf; - std::vector m_mdl_outbuf; - - void *m_batch_buf; - - /* create request */ - EdenRequest *requests; - EdenCallback *callbacks; - addr_t *requestId; - EdenPreference pref; - EdenModelOptions options; - - bool m_created; - - model_container *mdl_container; - - std::queue> task_pool; - std::unordered_map heap_mem; - - std::condition_variable inferece_start_cond[MAX_INSTANCE]; - std::condition_variable inferece_done_cond; - std::mutex inference_start_mtx[MAX_INSTANCE]; - std::mutex inference_done_mtx; - std::mutex task_deque_mtx; - - std::atomic force_thread_done{true}; - std::atomic inference_done_count{0}; - std::thread task_thread_executor[MAX_INSTANCE]; - - /* common API */ - bool impl_closeModel(); - bool impl_shutdown(); - void clear(); - bool inference(); - void *allocate_buf(size_t); - void release_buf(void *); - - void set_inbuf(void *, int, int); - void config_request(); - void impl_config_batch(); - bool initialize(mlperf_backend_configuration_t *); - - /* common external api */ - void attach_model_container(); - void impl_parse_mdl_attribute(); - void impl_parse_ext_attribute(mlperf_backend_configuration_t *); - - /* batch execution */ - void impl_inference_thread(int); - bool task_deque(int mdl_idx, std::pair &node); - - /* target specific */ - bool open_model(const char *, const char *); - void impl_load_model(const char *); - bool set_model_buf(); - - sbe1200() : m_batch_size(0), m_mdl_buf(nullptr), m_created(false) {} -}; // sbe1200 - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -bool backend_create(const char *, mlperf_backend_configuration_t *, - const char *); -mlperf_status_t backend_get_output(uint32_t, int32_t, void **); -int32_t backend_get_input_count(); -mlperf_data_t backend_get_input_type(int32_t); -mlperf_status_t backend_set_input(int32_t, int32_t, void *); -int32_t backend_get_output_count(); -mlperf_data_t backend_get_output_type(int32_t); -mlperf_status_t backend_issue_query(); -void backend_convert_inputs(int, int, int, uint8_t *); -void backend_delete(); -void *backend_get_buffer(size_t); -void backend_release_buffer(void *); - -#ifdef __cplusplus -} -#endif // __cplusplus - -} // namespace sbe -#endif \ No newline at end of file diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/eden_sdk/sbe1200.cc b/mobile_back_samsung/cpp/sbe_backend/jni/eden_sdk/sbe1200.cc deleted file mode 100644 index e23862c93..000000000 --- a/mobile_back_samsung/cpp/sbe_backend/jni/eden_sdk/sbe1200.cc +++ /dev/null @@ -1,557 +0,0 @@ -#include "sbe1200.hpp" - -namespace sbe { -using namespace sbeID1200; -static sbe1200 sbe_obj; - -void notify_f(addr_t *addr, addr_t value) { *addr = value; } - -int32_t wait_f(addr_t *addr, uint32_t value, uint32_t timeout) { - MLOGD("wait done with addr[%d]", *addr); - while (timeout--) { - usleep(1); - if (*addr != INVALID_REQUEST_ID) { - MLOGD("changed callback done with addr[%d]", *addr); - *addr = INVALID_REQUEST_ID; - break; - } - } - if (timeout == 0) { - return -1; - } - return RET_OK; -} - -void sbe1200::impl_load_model(const char *model_path) { - std::ifstream infile(model_path); - infile.seekg(0, infile.end); - m_mdl_buf_len = infile.tellg(); - infile.seekg(0, infile.beg); - if (m_mdl_buf_len > 0) { - m_mdl_buf = allocate_buf(m_mdl_buf_len); - ; - infile.read((char *)m_mdl_buf, m_mdl_buf_len); - } -} - -bool sbe1200::task_deque(int mdl_idx, std::pair &node) { - std::unique_lock lock(task_deque_mtx); - if (task_pool.size() == 0) return false; - MLOGD("remained node[%lu]", task_pool.size()); - node = task_pool.front(); - MLOGD("mdl[%d] taken node[%p, %p]", mdl_idx, node.first, node.second); - task_pool.pop(); - return true; -} - -void sbe1200::impl_inference_thread(int mdl_idx) { - MLOGD("inference_thread with mdl[%d]", mdl_idx); - int inbuf_size = mdl_container->m_inbuf_size; - int outbuf_size = mdl_container->m_outbuf_size; - - while (true) { - std::unique_lock lock(inference_start_mtx[mdl_idx]); - inferece_start_cond[mdl_idx].wait( - lock, [this] { return (!task_pool.empty() || force_thread_done); }); - MLOGD("thread unlock with mdl[%d]", mdl_idx); - if (force_thread_done) return; - - std::pair buf; - while (task_deque(mdl_idx, buf)) { - MLOGD("mdl_idx[%d], m_mdl_inbuf[%x], m_mdl_outbuf[%x]", mdl_idx, - m_mdl_inbuf[mdl_idx], m_mdl_outbuf[mdl_idx]); - MLOGD("m_mdl_inbuf[%d]->addr[%x], buf[%x]", mdl_idx, - m_mdl_inbuf[mdl_idx]->addr, buf.first); - memcpy(m_mdl_inbuf[mdl_idx]->addr, buf.first, inbuf_size); - requests[mdl_idx].modelId = mdl_id[mdl_idx]; - requests[mdl_idx].inputBuffers = m_mdl_inbuf[mdl_idx]; - requests[mdl_idx].outputBuffers = m_mdl_outbuf[mdl_idx]; - - int ret = ExecuteModel(&requests[mdl_idx], &requestId[mdl_idx], pref); - if (ret != RET_OK) { - MLOGE("request an inference fail ret[%d]", ret); - } else { - if (callbacks[mdl_idx].waitFor(&callbacks[mdl_idx].requestId, - requestId[mdl_idx], - EDEN_NN_TIMEOUT) < 0) { - MLOGE("inference callback fail - timeout"); - break; - } - } - memcpy(buf.second, m_mdl_outbuf[mdl_idx]->addr, outbuf_size); - } - inference_done_count++; - if (inference_done_count == MAX_INSTANCE) { - inferece_done_cond.notify_one(); - } - } -} - -bool sbe1200::impl_closeModel() { - int ret = RET_OK; - for (int mdl_idx = 0; mdl_idx < MAX_INSTANCE && mdl_idx < m_batch_size; - mdl_idx++) { - for (int idx = 0; idx < mdl_container->m_in_cnt; idx++) { - ret = FreeBuffers(mdl_id[mdl_idx], m_mdl_inbuf[idx]); - MLOGD("free batch_inbuf mdl_idx[%d], ret[%d]", mdl_idx, ret); - } - - for (int idx = 0; idx < mdl_container->m_out_cnt; idx++) { - ret = FreeBuffers(mdl_id[mdl_idx], m_mdl_outbuf[idx]); - MLOGD("free batch_outbuf mdl_idx[%d], ret[%d]", mdl_idx, ret); - } - - ret = CloseModel(mdl_id[mdl_idx]); - mdl_id[mdl_idx] = INVALID_MODEL_ID; - MLOGD("close mdl_idx[%d], ret[%d]", mdl_idx, ret); - } - - if (force_thread_done == false) { - force_thread_done = true; - for (int i = 0; i < MAX_INSTANCE; i++) { - inferece_start_cond[i].notify_one(); - task_thread_executor[i].join(); - } - } - - MLOGD("Close done"); - return true; -} - -bool sbe1200::impl_shutdown() { - int ret = Shutdown(); - if (ret != RET_OK) { - MLOGE("fail to Shutdown"); - } - MLOGD("Shutdown done"); - return true; -} - -bool sbe1200::initialize(mlperf_backend_configuration_t *configs) { - int ret = Initialize(); - if (ret != RET_OK) { - return false; - } - - impl_parse_ext_attribute(configs); - return true; -} - -bool sbe1200::open_model(const char *model_path, const char *accelerator) { - int ret = 0; - pref_hw = (HwPreference)NPU_ONLY; - options.modelPreference = {{pref_hw, BOOST_MODE, {false, false}}, - EDEN_NN_API}; - options.priority = P_DEFAULT; - options.boundCore = NPU_UNBOUND; - /* for execution */ - pref.mode = BOOST_MODE; - pref.hw = pref_hw; - for (int i = 0; i < MAX_INSTANCE; i++) { - mdl_id[i] = INVALID_MODEL_ID; - } - - impl_load_model(model_path); - for (int mdl_idx = 0; mdl_idx < MAX_INSTANCE && mdl_idx < m_batch_size; - mdl_idx++) { - MLOGD("mdl_idx[%d], m_batch_size[%d]", mdl_idx, m_batch_size); - - ret = OpenEdenModelFromMemory( - MODEL_TYPE_IN_MEMORY_TFLITE, reinterpret_cast(m_mdl_buf), - m_mdl_buf_len, false, &mdl_id[mdl_idx], options); - if (ret != RET_OK) { - MLOGE("fail to open_model. ret = %d", ret); - return false; - } - } - return true; -} - -bool sbe1200::set_model_buf() { - int32_t buf_cnt = 0; - int ret = 0; - int inbuf_size = m_batch_size > 1 ? MAX_INSTANCE : mdl_container->m_in_cnt; - int outbuf_size = m_batch_size > 1 ? MAX_INSTANCE : mdl_container->m_out_cnt; - - MLOGD("inbuf size[%d], outbuf size[%d]", inbuf_size, outbuf_size); - - m_mdl_inbuf.resize(inbuf_size); - m_mdl_outbuf.resize(outbuf_size); - - for (int32_t mdl_idx = 0; mdl_idx < MAX_INSTANCE && mdl_idx < m_batch_size; - mdl_idx++) { - for (int idx = 0; idx < mdl_container->m_in_cnt; idx++) { - ret = AllocateInputBuffers( - mdl_id[mdl_idx], - &m_mdl_inbuf[mdl_container->m_in_cnt * mdl_idx + idx], &buf_cnt); - if (ret != RET_OK) { - MLOGE("fail to alloc inbuf mdl_idx[%d], ret = %d", 0, ret); - return false; - } - MLOGD("m_mdl_inbuf[idx]->addr[%x], size[%d]", - m_mdl_inbuf[mdl_container->m_in_cnt * mdl_idx + idx]->addr, - m_mdl_inbuf[mdl_container->m_in_cnt * mdl_idx + idx]->size); - } - for (int idx = 0; idx < mdl_container->m_out_cnt; idx++) { - ret = AllocateOutputBuffers( - mdl_id[mdl_idx], - &m_mdl_outbuf[mdl_container->m_out_cnt * mdl_idx + idx], &buf_cnt); - if (ret != RET_OK) { - MLOGE("fail to alloc outbuf mdl_idx[%d], ret = %d", 0, ret); - return false; - } - MLOGD("m_mdl_outbuf[idx]->addr[%x], size[%d]", - m_mdl_outbuf[mdl_container->m_out_cnt * mdl_idx + idx]->addr, - m_mdl_outbuf[mdl_container->m_out_cnt * mdl_idx + idx]->size); - } - } - - MLOGD("m_mdl_inbuf.size[%d], m_mdl_outbuf.size[%d]", m_mdl_inbuf.size(), - m_mdl_outbuf.size()); - return true; -} - -bool sbe1200::inference() { - int ret = RET_OK; - if (m_batch_size == 1) { - requests[0].modelId = mdl_id[0]; - requests[0].inputBuffers = m_mdl_inbuf[0]; - requests[0].outputBuffers = m_mdl_outbuf[0]; - - ret = ExecuteModel(&requests[0], &requestId[0], pref); - if (callbacks[0].waitFor(&callbacks[0].requestId, requestId[0], - EDEN_NN_TIMEOUT) < 0) { - ret = RET_ERROR_ON_RT_EXECUTE_MODEL; - MLOGE("fail to inference with ret[%d]", ret); - } - } else { - for (int mdl_idx = 0; mdl_idx < MAX_INSTANCE; mdl_idx++) { - inferece_start_cond[mdl_idx].notify_one(); - } - - std::unique_lock lock(inference_done_mtx); - inferece_done_cond.wait(lock); - inference_done_count = 0; - } - return true; -} - -void sbe1200::impl_config_batch() { - force_thread_done = false; - for (int mdl_idx = 0; mdl_idx < MAX_INSTANCE && mdl_idx < m_batch_size; - mdl_idx++) { - task_thread_executor[mdl_idx] = - std::thread(&sbe1200::impl_inference_thread, this, mdl_idx); - } - m_batch_buf = allocate_buf(mdl_container->m_outbuf_size * m_batch_size); -} - -void sbe1200::config_request() { - requests = new EdenRequest[MAX_INSTANCE]; - callbacks = new EdenCallback[MAX_INSTANCE]; - requestId = new addr_t[MAX_INSTANCE]; - - for (int idx = 0; idx < MAX_INSTANCE && idx < m_batch_size; idx++) { - callbacks[idx].notify = notify_f; - callbacks[idx].waitFor = wait_f; - callbacks[idx].requestId = INVALID_REQUEST_ID; - callbacks[idx].executionResult.inference.retCode = RET_OK; - requestId[idx] = INVALID_REQUEST_ID; - requests[idx].callback = &callbacks[idx]; - requests[idx].hw = pref_hw; - } - - if (m_batch_size > 1) { - impl_config_batch(); - } -} - -void sbe1200::set_inbuf(void *p, int batch_idx, int idx) { - if (m_batch_size == 1) { - memcpy(m_mdl_inbuf[idx]->addr, p, mdl_container->m_inbuf_size); - } else { - task_pool.push( - {p, (char *)(m_batch_buf) + batch_idx * mdl_container->m_outbuf_size}); - } -} - -void *sbe1200::allocate_buf(size_t size) { - if (!size) return nullptr; - - void *ptr = std::malloc(size); - heap_mem[ptr] = ptr; - return ptr; -} - -void sbe1200::release_buf(void *p) { - if (heap_mem.find(p) != heap_mem.end()) { - heap_mem.erase(p); - } - std::free(p); - p = nullptr; -} - -void sbe1200::clear() { - impl_closeModel(); - impl_shutdown(); - - m_mdl_buf_len = 0; - det_lbl_boxes.clear(); - det_lbl_indices.clear(); - det_lbl_prob.clear(); - det_num.clear(); - det_lbl_boxes.shrink_to_fit(); - det_lbl_indices.shrink_to_fit(); - det_lbl_prob.shrink_to_fit(); - det_num.shrink_to_fit(); - - m_batch_size = 0; - m_created = false; - - while (!task_pool.empty()) { - task_pool.pop(); - } - - for (auto elem : heap_mem) { - free(elem.second); - } - heap_mem.clear(); - - m_mdl_inbuf.clear(); - m_mdl_inbuf.shrink_to_fit(); - - m_mdl_outbuf.clear(); - m_mdl_outbuf.shrink_to_fit(); - - mdl_container->deinit(); - mdl_container = nullptr; - - delete[] requests; - delete[] callbacks; - delete[] requestId; -} - -void sbe1200::impl_parse_ext_attribute( - mlperf_backend_configuration_t *configs) { - if (configs->batch_size > 1) { - m_batch_size = configs->batch_size; - } - - for (int i = 0; i < configs->count; ++i) { - if (strcmp(configs->keys[i], "i_type") == 0) { - if (strcmp(configs->values[i], "Int32") == 0) { - mdl_attr.m_inbuf_type = mlperf_data_t::Int32; - } else { - mdl_attr.m_inbuf_type = mlperf_data_t::Uint8; - } - } else if (strcmp(configs->keys[i], "o_type") == 0) { - if (strcmp(configs->values[i], "Float32") == 0) { - mdl_attr.m_outbuf_type = mlperf_data_t::Float32; - } else { - mdl_attr.m_outbuf_type = mlperf_data_t::Uint8; - } - } - } -} - -void sbe1200::impl_parse_mdl_attribute() { - int32_t in_w, in_h, in_c, in_n; - GetInputBufferShape(mdl_id[0], 0, &in_w, &in_h, &in_c, &in_n); - - int32_t out_w, out_h, out_c, out_n; - GetOutputBufferShape(mdl_id[0], 0, &out_w, &out_h, &out_c, &out_n); - - mdl_attr.m_channel = in_c; - mdl_attr.m_width = in_w; - mdl_attr.m_height = in_h; - - mdl_attr.m_inbuf_size = in_w * in_h * in_c * in_n; - mdl_attr.m_outbuf_size = - out_w * out_h * out_c * out_n * mdl_attr.get_byte(mdl_attr.m_outbuf_type); -} - -void sbe1200::attach_model_container() { - impl_parse_mdl_attribute(); - - if (mdl_attr.m_inbuf_size == obj_od.get_buf_size()) { - mdl_container = &obj_od; - det_lbl_boxes = std::vector(mdl_attr.m_outbuf_size / 7); - det_lbl_indices = std::vector(mdl_attr.m_outbuf_size / 28); - det_lbl_prob = std::vector(mdl_attr.m_outbuf_size / 28); - det_num = std::vector(1); - } else if (mdl_attr.m_inbuf_size == obj_ic.get_buf_size()) { - mdl_container = &obj_ic; - } else { - mdl_container = &obj_is; - } - - mdl_attr.m_in_cnt = mdl_container->m_in_cnt; - mdl_attr.m_out_cnt = mdl_container->m_out_cnt; - - mdl_attr.update(mdl_container); - mdl_attr.show(); - - mdl_container->init(); -} -} // namespace sbe - -using namespace sbe; - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -bool backend_create(const char *model_path, - mlperf_backend_configuration_t *configs, - const char *native_lib_path) { - if (sbe_obj.m_created) { - sbe_obj.clear(); - } - sbe_obj.m_mdl_buf_len = 0; - sbe_obj.m_created = true; - sbe_obj.m_batch_size = 1; - - if (sbe_obj.initialize(configs) != true) { - return false; - } - if (sbe_obj.open_model(model_path, configs->accelerator) != true) { - return false; - } - - sbe_obj.attach_model_container(); - sbe_obj.set_model_buf(); - sbe_obj.config_request(); - return true; -} - -int32_t backend_get_input_count() { - return sbe_obj.mdl_container->get_input_size(); -} - -mlperf_data_t backend_get_input_type(int32_t i) { - return sbe_obj.mdl_container->get_input_type(i); -} - -mlperf_status_t backend_set_input(int32_t batchIndex, int32_t i, void *data) { - sbe_obj.set_inbuf(data, batchIndex, i); - return MLPERF_SUCCESS; -} - -int32_t backend_get_output_count() { - return sbe_obj.mdl_container->get_output_size(); -} - -mlperf_data_t backend_get_output_type(int32_t i) { - return sbe_obj.mdl_container->get_output_type(i); -} - -mlperf_status_t backend_issue_query() { - if (sbe_obj.inference()) { - return MLPERF_SUCCESS; - } - return MLPERF_FAILURE; -} - -mlperf_status_t backend_get_output(uint32_t batch_idx, int32_t idx, - void **data) { - if (sbe_obj.mdl_container->m_model_id == MOBILE_BERT) { - if (idx == 1) { - *data = sbe_obj.m_mdl_outbuf[0]->addr; - } else if (idx == 0) { - *data = sbe_obj.m_mdl_outbuf[1]->addr; - } - } else { - if (sbe_obj.mdl_container->m_model_id == OBJECT_DETECTION) { - float *buf = (float *)(sbe_obj.m_mdl_outbuf[0]->addr); - float det_idx = 0.0; - int det_cnt = 0; - int block_cnt = ((detection *)(sbe_obj.mdl_container))->det_block_cnt; - int block_size = ((detection *)(sbe_obj.mdl_container))->det_block_size; - - for (int i = 0, j = 0; j < block_cnt; j++) { - det_idx = buf[j * block_size + 1]; - if (det_idx > 0) { - switch (idx) { - case 0: - sbe_obj.det_lbl_boxes[i++] = buf[j * block_size + 4]; - sbe_obj.det_lbl_boxes[i++] = buf[j * block_size + 3]; - sbe_obj.det_lbl_boxes[i++] = buf[j * block_size + 6]; - sbe_obj.det_lbl_boxes[i++] = buf[j * block_size + 5]; - break; - case 1: - sbe_obj.det_lbl_indices[j] = det_idx - 1; - case 2: - sbe_obj.det_lbl_prob[j] = buf[j * block_size + 2]; - case 3: - det_cnt++; - default: - break; - } - } - } - - switch (idx) { - case 0: - *data = (void *)(sbe_obj.det_lbl_boxes.data()); - break; - case 1: - *data = (void *)(sbe_obj.det_lbl_indices.data()); - break; - case 2: - *data = (void *)(sbe_obj.det_lbl_prob.data()); - break; - case 3: - sbe_obj.det_num[0] = det_cnt; - *data = (void *)(sbe_obj.det_num.data()); - memset(buf, 0, sizeof(float) * block_size * block_cnt); - break; - default: - break; - } - } else if (sbe_obj.mdl_container->m_model_id == IMAGE_SEGMENTATION) { - *data = (void *)(sbe_obj.m_mdl_outbuf[0]->addr); - } else if (sbe_obj.mdl_container->m_model_id == IMAGE_CLASSIFICATION) { - uint8_t *buf; - if (sbe_obj.m_batch_size > 1) - buf = (uint8_t *)(sbe_obj.m_batch_buf); - else - buf = (uint8_t *)(sbe_obj.m_mdl_outbuf[0]->addr); - *data = (void *)(buf + sbe_obj.mdl_container->m_outbuf_size * batch_idx); - } - } - return MLPERF_SUCCESS; -} - -void backend_convert_inputs(int bytes, int width, int height, uint8_t *data) { - std::vector *data_uint8 = new std::vector(bytes); - int blueOffset = 0; - int greenOffset = width * height; - int redOffset = width * height * 2; - int idx = 0; - - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - (*data_uint8)[redOffset] = data[idx]; - (*data_uint8)[greenOffset] = data[idx + 1]; - (*data_uint8)[blueOffset] = data[idx + 2]; - redOffset++; - greenOffset++; - blueOffset++; - idx = idx + 3; - } - } - memcpy(data, data_uint8->data(), sizeof(uint8_t) * bytes); - data_uint8->clear(); - data_uint8->shrink_to_fit(); - delete data_uint8; -} - -void backend_delete() { sbe_obj.clear(); } - -void *backend_get_buffer(size_t size) { return sbe_obj.allocate_buf(size); } - -void backend_release_buffer(void *p) { sbe_obj.release_buf(p); } - -#ifdef __cplusplus -} -#endif // __cplusplus \ No newline at end of file diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/enn_sdk/include/sbe2200.hpp b/mobile_back_samsung/cpp/sbe_backend/jni/enn_sdk/include/sbe2200.hpp deleted file mode 100644 index 3859868e7..000000000 --- a/mobile_back_samsung/cpp/sbe_backend/jni/enn_sdk/include/sbe2200.hpp +++ /dev/null @@ -1,127 +0,0 @@ -/* Copyright 2020 The MLPerf Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ - -#ifndef SBE2200_H_ -#define SBE2200_H_ - -/** - * @file sbe2200.hpp - * @brief samsung backend for exynos 2200. - * @date 2022-01-04 - * @author soobong Huh (soobong.huh@samsung.com) - */ - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "client/enn_api-public.hpp" -#include "client/enn_api-type.h" -#include "sbe_model_container.hpp" -#include "sbe_utils.hpp" -#include "type.h" - -namespace sbe { -using namespace enn::api; -class sbe2200 { - public: - const std::string name = "sbe2200"; - int m_batch_size; - - /* declaration of buffers for model */ - std::vector m_inbuf; - std::vector m_outbuf; - std::vector m_batch_buf; - - std::vector det_lbl_boxes; - std::vector det_lbl_indices; - std::vector det_lbl_prob; - std::vector det_num; - - bool m_created; - model_container *mdl_container; - - std::queue> task_pool; - std::unordered_map mapped_mem; - - void impl_set_buffer(int, void *, enn_buf_dir_e, int); - void impl_commit_buffer(int); - - EnnBufferPtr impl_get_memobj(void *); - bool impl_closeModel(); - bool impl_shutdown(); - - /* external method */ - void attach_model_container(); - void impl_parse_mdl_attribute(); - void impl_parse_ext_attribute(mlperf_backend_configuration_t *); - - bool initialize(mlperf_backend_configuration_t *); - bool open_model(const char *); - bool inference(); - - void clear(); - void *allocate_buf(size_t); - void release_buf(void *); - - void config_instance(); - void impl_config_batch(); - void set_inbuf(void *, int, int); - - bool task_deque(int idx, std::pair &); - void impl_inference_thread(int); - - sbe2200() : m_batch_size(0), m_created(false) {} - -}; // sbe2200 - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -bool backend_create(const char *, mlperf_backend_configuration_t *, - const char *); -mlperf_status_t backend_get_output(uint32_t, int32_t, void **); -int32_t backend_get_input_count(); -mlperf_data_t backend_get_input_type(int32_t); -mlperf_status_t backend_set_input(int32_t, int32_t, void *); -int32_t backend_get_output_count(); -mlperf_data_t backend_get_output_type(int32_t); -mlperf_status_t backend_issue_query(); -void backend_convert_inputs(int, int, int, uint8_t *); -void backend_delete(); -void *backend_get_buffer(size_t); -void backend_release_buffer(void *); - -#ifdef __cplusplus -} -#endif // __cplusplus - -} // namespace sbe -#endif diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/enn_sdk/sbe2200.cc b/mobile_back_samsung/cpp/sbe_backend/jni/enn_sdk/sbe2200.cc deleted file mode 100644 index 8448a3034..000000000 --- a/mobile_back_samsung/cpp/sbe_backend/jni/enn_sdk/sbe2200.cc +++ /dev/null @@ -1,538 +0,0 @@ -#include "sbe2200.hpp" - -namespace sbe { -using namespace sbeID2200; -static sbe2200 sbe_obj; - -std::condition_variable inferece_start_cond[MAX_INSTANCE]; -std::condition_variable inferece_done_cond; -std::mutex inference_start_mtx[MAX_INSTANCE]; -std::mutex inference_done_mtx; -std::mutex task_deque_mtx; - -std::atomic force_thread_done{true}; -std::atomic inference_done_count{0}; -std::thread task_thread_executor[MAX_INSTANCE]; -EnnModelId mdl_id[MAX_INSTANCE] = { - INVALID_MDL, -}; - -bool sbe2200::task_deque(int mdl_idx, std::pair &node) { - std::unique_lock lock(task_deque_mtx); - if (task_pool.size() == 0) return false; - MLOGD("remained node[%lu]", task_pool.size()); - node = task_pool.front(); - MLOGD("mld[%d] taken node[%p, %p]", mdl_idx, node.first, node.second); - task_pool.pop(); - return true; -} - -void sbe2200::impl_inference_thread(int mdl_idx) { - if (EnnSetExecMsgAlwaysOff() != ENN_RET_SUCCESS) { - MLOGD("fail to turn off execute log for thread"); - } - int inbuf_size = mdl_container->m_inbuf_size; - int outbuf_size = mdl_container->m_outbuf_size; - - while (true) { - std::unique_lock lock(inference_start_mtx[mdl_idx]); - inferece_start_cond[mdl_idx].wait( - lock, [this] { return (!task_pool.empty() || force_thread_done); }); - if (force_thread_done) return; - - std::pair buf; - while (task_deque(mdl_idx, buf)) { - memcpy(m_inbuf[mdl_idx], buf.first, inbuf_size); - EnnReturn ret = EnnExecuteModel(mdl_id[mdl_idx]); - if (ret != ENN_RET_SUCCESS) { - MLOGE("fail to execute model"); - } - memcpy(buf.second, m_batch_buf[mdl_idx], outbuf_size); - } - inference_done_count++; - if (inference_done_count == MAX_INSTANCE) { - inferece_done_cond.notify_one(); - } - } -} - -bool sbe2200::impl_closeModel() { - EnnReturn ret = ENN_RET_SUCCESS; - for (int i = 0; i < MAX_INSTANCE; i++) { - if (mdl_id[i] == INVALID_MDL) continue; - - ret = EnnCloseModel(mdl_id[i]); - if (ret != ENN_RET_SUCCESS) { - MLOGE("fail to Close model #%d", i); - } - - mdl_id[i] = INVALID_MDL; - } - - if (force_thread_done == false) { - force_thread_done = true; - for (int i = 0; i < MAX_INSTANCE; i++) { - inferece_start_cond[i].notify_one(); - task_thread_executor[i].join(); // wait thread done - } - } - - if (mdl_container->b_enable_fpc) { - ret = EnnUnsetFastIpc(); - } - return ret; -} - -bool sbe2200::impl_shutdown() { - EnnReturn ret = EnnDeinitialize(); - if (ret != ENN_RET_SUCCESS) { - MLOGE("fail to Deinitialize"); - } - return true; -} - -void sbe2200::impl_set_buffer(int mdl_idx, void *buf, enn_buf_dir_e dir, - int idx) { - EnnBufferPtr p_memobj = impl_get_memobj(buf); - EnnSetBufferByIndex(mdl_id[mdl_idx], dir, idx, p_memobj); -} - -void sbe2200::impl_commit_buffer(int mdl_idx) { - if (!mdl_container->b_enable_lazy) { - EnnBufferCommit(mdl_id[mdl_idx]); - } -} - -EnnBufferPtr sbe2200::impl_get_memobj(void *p) { return mapped_mem[p]; } - -bool sbe2200::initialize(mlperf_backend_configuration_t *configs) { - EnnReturn ret = EnnInitialize(); - if (ret != ENN_RET_SUCCESS) { - MLOGE("fail to EnnInitialize"); - return false; - } - - impl_parse_ext_attribute(configs); - return true; -} - -bool sbe2200::open_model(const char *model_path) { - EnnReturn ret = ENN_RET_SUCCESS; - for (int i = 0; i < MAX_INSTANCE; i++) { - mdl_id[i] = INVALID_MDL; - } - - ret = EnnSetPreferencePerfMode(ENN_PREF_MODE_CUSTOM); - if (ret != ENN_RET_SUCCESS) { - MLOGE("fail to set perf mode. But test continues"); - } - ret = EnnSetPreferencePresetId(mdl_attr.m_preset_id); - if (ret != ENN_RET_SUCCESS) { - MLOGE("fail to set preset id. But test continues"); - } - ret = EnnSetExecMsgAlwaysOff(); - if (ret != ENN_RET_SUCCESS) { - MLOGE("fail to turn of execute log. But test continues"); - } - for (int mdl_idx = 0; mdl_idx < MAX_INSTANCE && mdl_idx < m_batch_size; - mdl_idx++) { - ret = EnnOpenModel(model_path, &mdl_id[mdl_idx]); - if (ret != ENN_RET_SUCCESS) { - MLOGE("fail to Open model #%d", mdl_idx); - return false; - } - } - return true; -} - -bool sbe2200::inference() { - if (mdl_container->b_enable_lazy) { - for (int mdl_idx = 0; mdl_idx < MAX_INSTANCE && mdl_idx < m_batch_size; - mdl_idx++) { - EnnBufferCommit(mdl_id[mdl_idx]); - } - mdl_container->unset_lazy(); - } - - EnnReturn ret = ENN_RET_SUCCESS; - if (m_batch_size == 1) { - if (mdl_container->b_enable_fpc) { - ret = EnnExecuteModelFastIpc(mdl_id[0], mdl_container->m_freeze); - } else { - ret = EnnExecuteModel(mdl_id[0]); - } - MLOGD("Enn execute model with ret[%d]", ret); - if (ret != ENN_RET_SUCCESS) { - MLOGE("fail to Execute model for single batch"); - return false; - } - return true; - } else { - for (int mdl_idx = 0; mdl_idx < MAX_INSTANCE; mdl_idx++) { - inferece_start_cond[mdl_idx].notify_one(); - } - std::unique_lock lock(inference_done_mtx); - inferece_done_cond.wait(lock); - inference_done_count = 0; - } - return true; -} - -void sbe2200::impl_config_batch() { - force_thread_done = false; - for (int mdl_idx = 0; mdl_idx < MAX_INSTANCE && mdl_idx < m_batch_size; - mdl_idx++) { - task_thread_executor[mdl_idx] = - std::thread(&sbe2200::impl_inference_thread, this, mdl_idx); - } - void *ptr = allocate_buf(mdl_container->m_outbuf_size * m_batch_size); - m_outbuf.push_back(ptr); -} - -void sbe2200::config_instance() { - void *ptr = nullptr; - for (int32_t mdl_idx = 0; mdl_idx < MAX_INSTANCE && mdl_idx < m_batch_size; - mdl_idx++) { - for (int idx = 0; idx < mdl_container->m_in_cnt; idx++) { - ptr = allocate_buf(mdl_container->m_inbuf_size); - m_inbuf.push_back(ptr); - impl_set_buffer(mdl_idx, ptr, ENN_DIR_IN, idx); - } - for (int idx = 0; idx < mdl_container->m_out_cnt; idx++) { - ptr = allocate_buf(mdl_container->m_outbuf_size); - if (m_batch_size > 1) - m_batch_buf.push_back(ptr); - else - m_outbuf.push_back(ptr); - impl_set_buffer(mdl_idx, ptr, ENN_DIR_OUT, idx); - } - impl_commit_buffer(mdl_idx); - } - if (m_batch_size > 1) { - impl_config_batch(); - } -} - -void sbe2200::set_inbuf(void *p, int batch_idx, int idx) { - if (m_batch_size == 1) { - memcpy(m_inbuf[idx], p, mdl_container->m_inbuf_size); - } else { - task_pool.push( - {p, (char *)m_outbuf[0] + batch_idx * mdl_container->m_outbuf_size}); - } -} - -void *sbe2200::allocate_buf(size_t size) { - if (!size) return nullptr; - - EnnBufferPtr ptr; - EnnReturn ret = EnnCreateBuffer(&ptr, size); - if (ret != ENN_RET_SUCCESS) { - MLOGE("fail to alloc buf"); - } - mapped_mem[ptr->va] = ptr; - return ptr->va; -} - -void sbe2200::release_buf(void *p) { - /* release heap buffer */ - if (mapped_mem.find(p) == mapped_mem.end()) { - std::free(p); - p = nullptr; - } else { - /* release ion buffer */ - EnnReleaseBuffer(mapped_mem[p]); - mapped_mem.erase(p); - } -} - -void sbe2200::clear() { - impl_closeModel(); - impl_shutdown(); - - det_lbl_boxes.clear(); - det_lbl_indices.clear(); - det_lbl_prob.clear(); - det_num.clear(); - det_lbl_boxes.shrink_to_fit(); - det_lbl_indices.shrink_to_fit(); - det_lbl_prob.shrink_to_fit(); - det_num.shrink_to_fit(); - - m_batch_size = 0; - m_created = false; - - while (!task_pool.empty()) { - task_pool.pop(); - } - - for (auto elem : mapped_mem) { - EnnReleaseBuffer(elem.second); - } - mapped_mem.clear(); - - m_inbuf.clear(); - m_inbuf.shrink_to_fit(); - m_outbuf.clear(); - m_outbuf.shrink_to_fit(); - m_batch_buf.clear(); - m_batch_buf.shrink_to_fit(); - - mdl_container->deinit(); - mdl_container = nullptr; -} - -void sbe2200::impl_parse_ext_attribute( - mlperf_backend_configuration_t *configs) { - if (configs->batch_size > 1) { - m_batch_size = configs->batch_size; - } - for (int i = 0; i < configs->count; ++i) { - if (strcmp(configs->keys[i], "preset") == 0) { - mdl_attr.m_preset_id = std::stoul(configs->values[i]); - } else if (strcmp(configs->keys[i], "i_type") == 0) { - if (strcmp(configs->values[i], "Int32") == 0) { - mdl_attr.m_inbuf_type = mlperf_data_t::Int32; - } else { - mdl_attr.m_inbuf_type = mlperf_data_t::Uint8; - } - } else if (strcmp(configs->keys[i], "o_type") == 0) { - if (strcmp(configs->values[i], "Float32") == 0) { - mdl_attr.m_outbuf_type = mlperf_data_t::Float32; - } else { - mdl_attr.m_outbuf_type = mlperf_data_t::Uint8; - } - } else if (strcmp(configs->keys[i], "fpc_mode") == 0) { - if (strcmp(configs->values[i], "true") == 0) { - mdl_attr.b_enable_fpc = true; - } else { - mdl_attr.b_enable_fpc = false; - } - } else if (strcmp(configs->keys[i], "freezing") == 0) { - mdl_attr.m_freeze = std::stoul(configs->values[i]); - } else if (strcmp(configs->keys[i], "lazy_mode") == 0) { - if (strcmp(configs->values[i], "true") == 0) { - mdl_attr.b_enable_lazy = true; - } else { - mdl_attr.b_enable_lazy = false; - } - } - } -} - -void sbe2200::impl_parse_mdl_attribute() { - NumberOfBuffersInfo buf_info; - EnnGetBuffersInfo(&buf_info, mdl_id[0]); - - mdl_attr.m_in_cnt = buf_info.n_in_buf; - mdl_attr.m_out_cnt = buf_info.n_out_buf; - - EnnBufferInfo in_buf_info, out_buf_info; - EnnGetBufferInfoByIndex(&in_buf_info, mdl_id[0], ENN_DIR_IN, 0); - EnnGetBufferInfoByIndex(&out_buf_info, mdl_id[0], ENN_DIR_OUT, 0); - - mdl_attr.m_channel = in_buf_info.channel; - mdl_attr.m_width = in_buf_info.width; - mdl_attr.m_height = in_buf_info.height; - - mdl_attr.m_inbuf_size = in_buf_info.size; - mdl_attr.m_outbuf_size = out_buf_info.size; -} - -void sbe2200::attach_model_container() { - impl_parse_mdl_attribute(); - - if (mdl_attr.m_inbuf_size == obj_od.get_buf_size()) { - mdl_container = &obj_od; - det_lbl_boxes = std::vector(mdl_attr.m_outbuf_size / 7); - det_lbl_indices = std::vector(mdl_attr.m_outbuf_size / 28); - det_lbl_prob = std::vector(mdl_attr.m_outbuf_size / 28); - det_num = std::vector(1); - } else if (mdl_attr.m_inbuf_size == obj_ic.get_buf_size()) { - if (m_batch_size > 1) { - mdl_container = &obj_ic_offline; - } else { - mdl_container = &obj_ic; - } - } else if (mdl_attr.m_inbuf_size == obj_is.get_buf_size()) { - mdl_container = &obj_is; - } else { - mdl_container = &obj_bert; - } - - mdl_attr.update(mdl_container); - mdl_attr.show(); - - mdl_container->init(); - if (mdl_container->b_enable_fpc) { - EnnReturn ret = EnnSetFastIpc(); - MLOGD("Enable Fast IPC mode with ret[%d]", ret); - } -} -} // namespace sbe - -using namespace sbe; - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -bool backend_create(const char *model_path, - mlperf_backend_configuration_t *configs, - const char *native_lib_path) { - if (sbe_obj.m_created) { - sbe_obj.clear(); - } - sbe_obj.m_created = true; - sbe_obj.m_batch_size = 1; - - if (sbe_obj.initialize(configs) != true) { - return false; - } - - if (sbe_obj.open_model(model_path) != true) { - return false; - } - - sbe_obj.attach_model_container(); - sbe_obj.config_instance(); - usleep(1000000); - return true; -} - -int32_t backend_get_input_count() { - return sbe_obj.mdl_container->get_input_size(); -} - -mlperf_data_t backend_get_input_type(int32_t i) { - return sbe_obj.mdl_container->get_input_type(i); -} - -mlperf_status_t backend_set_input(int32_t batchIndex, int32_t i, void *data) { - sbe_obj.set_inbuf(data, batchIndex, i); - return MLPERF_SUCCESS; -} - -int32_t backend_get_output_count() { - return sbe_obj.mdl_container->get_output_size(); -} - -mlperf_data_t backend_get_output_type(int32_t i) { - return sbe_obj.mdl_container->get_output_type(i); -} - -mlperf_status_t backend_issue_query() { - if (sbe_obj.inference()) { - return MLPERF_SUCCESS; - } - return MLPERF_FAILURE; -} - -mlperf_status_t backend_get_output(uint32_t batch_idx, int32_t idx, - void **data) { - if (sbe_obj.mdl_container->m_model_id == MOBILE_BERT) { - if (idx == 1) { - *data = sbe_obj.m_outbuf[0]; - } else if (idx == 0) { - *data = (void *)(sbe_obj.m_outbuf[1]); - } - } else if (sbe_obj.mdl_container->m_model_id == OBJECT_DETECTION) { - float *buf = (float *)(sbe_obj.m_outbuf[0]); - float det_idx = 0.0; - int det_cnt = 0; - int block_cnt = ((detection *)(sbe_obj.mdl_container))->det_block_cnt; - int block_size = ((detection *)(sbe_obj.mdl_container))->det_block_size; - - for (int i = 0, j = 0; j < block_cnt; j++) { - det_idx = buf[j * block_size + 1]; - if (det_idx > 0) { - switch (idx) { - case 0: - sbe_obj.det_lbl_boxes[i++] = buf[j * block_size + 4]; - sbe_obj.det_lbl_boxes[i++] = buf[j * block_size + 3]; - sbe_obj.det_lbl_boxes[i++] = buf[j * block_size + 6]; - sbe_obj.det_lbl_boxes[i++] = buf[j * block_size + 5]; - break; - case 1: - sbe_obj.det_lbl_indices[j] = det_idx - 1; - case 2: - sbe_obj.det_lbl_prob[j] = buf[j * block_size + 2]; - case 3: - det_cnt++; - default: - break; - } - } - } - - switch (idx) { - case 0: - *data = (void *)(sbe_obj.det_lbl_boxes.data()); - break; - case 1: - *data = (void *)(sbe_obj.det_lbl_indices.data()); - break; - case 2: - *data = (void *)(sbe_obj.det_lbl_prob.data()); - break; - case 3: - sbe_obj.det_num[0] = det_cnt; - *data = (void *)(sbe_obj.det_num.data()); - memset(buf, 0, sizeof(float) * block_size * block_cnt); - break; - default: - break; - } - } else if (sbe_obj.mdl_container->m_model_id == IMAGE_SEGMENTATION) { - *data = (void *)(sbe_obj.m_outbuf[0]); - } else if (sbe_obj.mdl_container->m_model_id == IMAGE_CLASSIFICATION) { - uint8_t *buf = (uint8_t *)(sbe_obj.m_outbuf[0]); - *data = (void *)(buf + sbe_obj.mdl_container->m_outbuf_size * batch_idx); - } - return MLPERF_SUCCESS; -} - -void backend_convert_inputs(int bytes, int width, int height, uint8_t *data) { - std::vector *data_uint8 = new std::vector(bytes); - int blueOffset = 0; - int greenOffset = 0; - int redOffset = 0; - int idx = 0; - - if (sbe_obj.mdl_container->m_model_id == IMAGE_SEGMENTATION) { - redOffset = 0; - greenOffset = width * height; - blueOffset = width * height * 2; - } else { - blueOffset = 0; - greenOffset = width * height; - redOffset = width * height * 2; - } - - for (int i = 0; i < height; i++) { - for (int j = 0; j < width; j++) { - (*data_uint8)[redOffset] = data[idx]; - (*data_uint8)[greenOffset] = data[idx + 1]; - (*data_uint8)[blueOffset] = data[idx + 2]; - redOffset++; - greenOffset++; - blueOffset++; - idx = idx + 3; - } - } - - memcpy(data, data_uint8->data(), sizeof(uint8_t) * bytes); - data_uint8->clear(); - data_uint8->shrink_to_fit(); - delete data_uint8; -} - -void backend_delete() { sbe_obj.clear(); } - -void *backend_get_buffer(size_t size) { return sbe_obj.allocate_buf(size); } - -void backend_release_buffer(void *p) { sbe_obj.release_buf(p); } - -#ifdef __cplusplus -} -#endif // __cplusplus \ No newline at end of file diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/include/backend_c.h b/mobile_back_samsung/cpp/sbe_backend/jni/include/backend_c.h deleted file mode 100644 index df8e44823..000000000 --- a/mobile_back_samsung/cpp/sbe_backend/jni/include/backend_c.h +++ /dev/null @@ -1,82 +0,0 @@ -/* Copyright 2020 The MLPerf Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ -#ifndef MLPERF_C_BACKEND_C_H_ -#define MLPERF_C_BACKEND_C_H_ - -#include - -#include "type.h" - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -// Should return true if current hardware is supported. -bool mlperf_backend_matches_hardware(const char** not_allowed_message, - const char** settings, - const mlperf_device_info_t* device_info); - -// Create a new backend and return the pointer to it. -mlperf_backend_ptr_t mlperf_backend_create( - const char* model_path, mlperf_backend_configuration_t* configs, - const char* native_lib_path); - -// Vendor name who create this backend. -const char* mlperf_backend_vendor_name(mlperf_backend_ptr_t backend_ptr); - -// Return the name of this backend. -const char* mlperf_backend_name(mlperf_backend_ptr_t backend_ptr); - -// Destroy the backend pointer and its data. -void mlperf_backend_delete(mlperf_backend_ptr_t backend_ptr); - -// Run the inference for a sample. -mlperf_status_t mlperf_backend_issue_query(mlperf_backend_ptr_t backend_ptr); -// Flush the staged queries immediately. -mlperf_status_t mlperf_backend_flush_queries(mlperf_backend_ptr_t backend_ptr); - -// Return the number of inputs of the model. -int32_t mlperf_backend_get_input_count(mlperf_backend_ptr_t backend_ptr); -// Return the type of the ith input. -mlperf_data_t mlperf_backend_get_input_type(mlperf_backend_ptr_t backend_ptr, - int32_t i); -// Set the data for ith input, of batchIndex'th batch -mlperf_status_t mlperf_backend_set_input(mlperf_backend_ptr_t backend_ptr, - int32_t batchIndex, int32_t i, - void* data); - -// Return the number of outputs from the model. -int32_t mlperf_backend_get_output_count(mlperf_backend_ptr_t backend_ptr); -// Return the type of ith output. -mlperf_data_t mlperf_backend_get_output_type(mlperf_backend_ptr_t backend_ptr, - int32_t i); -// Get the data from ith output. -mlperf_status_t mlperf_backend_get_output(mlperf_backend_ptr_t backend_ptr, - uint32_t batchIndex, int32_t i, - void** data); - -// Optional functions -void mlperf_backend_convert_inputs(mlperf_backend_ptr_t backend_ptr, int bytes, - int width, int height, uint8_t* data); - -void* mlperf_backend_get_buffer(size_t size); - -void mlperf_backend_release_buffer(void* p); - -#ifdef __cplusplus -} -#endif // __cplusplus - -#endif // MLPERF_C_BACKEND_C_H_ diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_config.hpp b/mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_config.hpp index 896c0d84f..5768a3fe4 100644 --- a/mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_config.hpp +++ b/mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_config.hpp @@ -25,8 +25,7 @@ limitations under the License. */ namespace sbe { - -const std::string sbe2200_flutter_config = R"SETTINGS( +const std::string sbe2300_config = R"SETTINGS( benchmark_setting { benchmark_id: "IC_tpu_uint8" accelerator: "samsung npu" @@ -38,7 +37,7 @@ benchmark_setting { } custom_setting { id: "preset" - value: "1001" + value: "1009" } custom_setting { id: "i_type" @@ -49,58 +48,16 @@ benchmark_setting { value: "Float32" } custom_setting { - id: "fpc_mode" + id: "extension" value: "true" } - custom_setting { - id: "freezing" - value: "300" - } custom_setting { id: "lazy_mode" - value: "false" - } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_single.nnc" - md5_checksum: "a49175f3f4f37f59780995cec540dbf2" - single_stream_expected_latency_ns: 900000 -} - -benchmark_setting { - benchmark_id: "IS_uint8" - accelerator: "samsung npu" - accelerator_desc: "NPU" - configuration: "Samsung Exynos" - custom_setting { - id: "mode" - value: "3" - } - custom_setting { - id: "preset" - value: "1004" - } - custom_setting { - id: "i_type" - value: "Uint8" - } - custom_setting { - id: "o_type" - value: "Uint8" - } - custom_setting { - id: "fpc_mode" - value: "false" - } - custom_setting { - id: "freezing" - value: "0" - } - custom_setting { - id: "lazy_mode" - value: "false" + value: "true" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/is.nnc" - md5_checksum: "d7cbd596179beb3c0fe51b745769fc69" - single_stream_expected_latency_ns: 1000000 + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_1/Samsung/ic_single_fence.nnc" + md5_checksum: "a451da1f48b1fad01c17fb7a49e5822e" + single_stream_expected_latency_ns: 500000 } benchmark_setting { @@ -114,7 +71,7 @@ benchmark_setting { } custom_setting { id: "preset" - value: "1004" + value: "1009" } custom_setting { id: "i_type" @@ -125,19 +82,15 @@ benchmark_setting { value: "Uint8" } custom_setting { - id: "fpc_mode" - value: "false" - } - custom_setting { - id: "freezing" - value: "0" + id: "extension" + value: "true" } custom_setting { id: "lazy_mode" - value: "false" + value: "true" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/sm_uint8.nnc" - md5_checksum: "f715f55818863f371336ad29ecba1183" + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_1/Samsung/sm_uint8_fence.nnc" + md5_checksum: "08fa7b354f82140a8863fed57c2d499b" single_stream_expected_latency_ns: 1000000 } @@ -152,7 +105,7 @@ benchmark_setting { } custom_setting { id: "preset" - value: "1003" + value: "1009" } custom_setting { id: "i_type" @@ -163,26 +116,22 @@ benchmark_setting { value: "Float32" } custom_setting { - id: "fpc_mode" + id: "extension" value: "true" } - custom_setting { - id: "freezing" - value: "200" - } custom_setting { id: "lazy_mode" - value: "false" + value: "true" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/od.nnc" - md5_checksum: "6b34201b6696fa75311d0d43820e03d2" + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_1/Samsung/od_fence.nnc" + md5_checksum: "8a7e1808446072545c990f3d219255c6" single_stream_expected_latency_ns: 1000000 } benchmark_setting { benchmark_id: "LU_gpu_float32" - accelerator: "gpu" - accelerator_desc: "gpu" + accelerator: "npu" + accelerator_desc: "npu" configuration: "Samsung Exynos" custom_setting { id: "mode" @@ -190,7 +139,7 @@ benchmark_setting { } custom_setting { id: "preset" - value: "1000" + value: "1009" } custom_setting { id: "i_type" @@ -201,19 +150,15 @@ benchmark_setting { value: "Float32" } custom_setting { - id: "fpc_mode" - value: "false" - } - custom_setting { - id: "freezing" - value: "0" + id: "extension" + value: "true" } custom_setting { id: "lazy_mode" - value: "false" + value: "true" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/mobile_bert_gpu.nnc" - md5_checksum: "d98dfcc37ad33fa7081d6fbb5bc6ddd1" + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_1/Samsung/mobile_bert_fence.nnc" + md5_checksum: "5fb666b684a9bd0b68d497128b990137" single_stream_expected_latency_ns: 1000000 } @@ -244,23 +189,19 @@ benchmark_setting { value: "Float32" } custom_setting { - id: "fpc_mode" + id: "extension" value: "false" } - custom_setting { - id: "freezing" - value: "0" - } custom_setting { id: "lazy_mode" value: "false" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_offline.nnc" - md5_checksum: "8832370c770fa820dfde83e039e3243c" + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_1/Samsung/ic_offline.nnc" + md5_checksum: "6885f281a3d7a7ec3549d629dff8c8ac" single_stream_expected_latency_ns: 1000000 })SETTINGS"; -const std::string sbe2200_config_fence_off = R"SETTINGS( +const std::string sbe2200_config = R"SETTINGS( benchmark_setting { benchmark_id: "IC_tpu_uint8" accelerator: "samsung npu" @@ -283,13 +224,9 @@ benchmark_setting { value: "Float32" } custom_setting { - id: "fpc_mode" + id: "extension" value: "true" } - custom_setting { - id: "freezing" - value: "300" - } custom_setting { id: "lazy_mode" value: "false" @@ -298,45 +235,6 @@ benchmark_setting { md5_checksum: "a49175f3f4f37f59780995cec540dbf2" single_stream_expected_latency_ns: 900000 } - -benchmark_setting { - benchmark_id: "IS_uint8" - accelerator: "samsung npu" - accelerator_desc: "NPU" - configuration: "Samsung Exynos" - custom_setting { - id: "mode" - value: "3" - } - custom_setting { - id: "preset" - value: "1004" - } - custom_setting { - id: "i_type" - value: "Uint8" - } - custom_setting { - id: "o_type" - value: "Uint8" - } - custom_setting { - id: "fpc_mode" - value: "false" - } - custom_setting { - id: "freezing" - value: "0" - } - custom_setting { - id: "lazy_mode" - value: "false" - } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/is.nnc" - md5_checksum: "d7cbd596179beb3c0fe51b745769fc69" - single_stream_expected_latency_ns: 1000000 -} - benchmark_setting { benchmark_id: "IS_uint8_mosaic" accelerator: "samsung npu" @@ -359,13 +257,9 @@ benchmark_setting { value: "Uint8" } custom_setting { - id: "fpc_mode" + id: "extension" value: "false" } - custom_setting { - id: "freezing" - value: "0" - } custom_setting { id: "lazy_mode" value: "false" @@ -374,7 +268,6 @@ benchmark_setting { md5_checksum: "f715f55818863f371336ad29ecba1183" single_stream_expected_latency_ns: 1000000 } - benchmark_setting { benchmark_id: "OD_uint8" accelerator: "samsung npu" @@ -397,13 +290,9 @@ benchmark_setting { value: "Float32" } custom_setting { - id: "fpc_mode" + id: "extension" value: "true" } - custom_setting { - id: "freezing" - value: "200" - } custom_setting { id: "lazy_mode" value: "false" @@ -412,7 +301,6 @@ benchmark_setting { md5_checksum: "6b34201b6696fa75311d0d43820e03d2" single_stream_expected_latency_ns: 1000000 } - benchmark_setting { benchmark_id: "LU_gpu_float32" accelerator: "gpu" @@ -435,13 +323,9 @@ benchmark_setting { value: "Float32" } custom_setting { - id: "fpc_mode" + id: "extension" value: "false" } - custom_setting { - id: "freezing" - value: "0" - } custom_setting { id: "lazy_mode" value: "false" @@ -450,7 +334,6 @@ benchmark_setting { md5_checksum: "d98dfcc37ad33fa7081d6fbb5bc6ddd1" single_stream_expected_latency_ns: 1000000 } - benchmark_setting { benchmark_id: "IC_tpu_uint8_offline" accelerator: "samsung npu" @@ -478,13 +361,9 @@ benchmark_setting { value: "Float32" } custom_setting { - id: "fpc_mode" + id: "extension" value: "false" } - custom_setting { - id: "freezing" - value: "0" - } custom_setting { id: "lazy_mode" value: "false" @@ -494,134 +373,66 @@ benchmark_setting { single_stream_expected_latency_ns: 1000000 })SETTINGS"; -const std::string sbe2200_config = R"SETTINGS( +const std::string sbe1200_config = R"SETTINGS( benchmark_setting { - benchmark_id: "IC_tpu_uint8" - accelerator: "samsung npu" - accelerator_desc: "NPU" + benchmark_id: "IS_uint8_mosaic" + accelerator: "npu" + accelerator_desc: "npu" configuration: "Samsung Exynos" - custom_setting { - id: "mode" - value: "3" - } - custom_setting { - id: "preset" - value: "1007" - } custom_setting { id: "i_type" value: "Uint8" } custom_setting { id: "o_type" - value: "Float32" - } - custom_setting { - id: "fpc_mode" - value: "true" - } - custom_setting { - id: "freezing" - value: "200" - } - custom_setting { - id: "lazy_mode" - value: "true" + value: "Int32" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_single_fence.nnc" - md5_checksum: "81af8ea507065da2c04a89229a0e4c45" - single_stream_expected_latency_ns: 900000 + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/is.nnc" + md5_checksum: "d7cbd596179beb3c0fe51b745769fc69" + single_stream_expected_latency_ns: 1000000 } - benchmark_setting { - benchmark_id: "IS_uint8" - accelerator: "samsung npu" - accelerator_desc: "NPU" + benchmark_id: "IC_tpu_uint8" + accelerator: "npu" + accelerator_desc: "npu" configuration: "Samsung Exynos" - custom_setting { - id: "mode" - value: "3" - } - custom_setting { - id: "preset" - value: "1004" - } custom_setting { id: "i_type" value: "Uint8" } custom_setting { id: "o_type" - value: "Uint8" - } - custom_setting { - id: "fpc_mode" - value: "false" - } - custom_setting { - id: "freezing" - value: "0" - } - custom_setting { - id: "lazy_mode" - value: "false" + value: "Float32" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/is_fence.nnc" - md5_checksum: "a727276c80d7a93073266113fba9beec" - single_stream_expected_latency_ns: 1000000 + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_single.nnc" + md5_checksum: "a49175f3f4f37f59780995cec540dbf2" + single_stream_expected_latency_ns: 900000 } benchmark_setting { - benchmark_id: "IS_uint8_mosaic" - accelerator: "samsung npu" - accelerator_desc: "NPU" + benchmark_id: "OD_uint8" + accelerator: "npu" + accelerator_desc: "npu" configuration: "Samsung Exynos" - custom_setting { - id: "mode" - value: "3" - } - custom_setting { - id: "preset" - value: "1004" - } custom_setting { id: "i_type" value: "Uint8" } custom_setting { id: "o_type" - value: "Uint8" - } - custom_setting { - id: "fpc_mode" - value: "false" - } - custom_setting { - id: "freezing" - value: "0" - } - custom_setting { - id: "lazy_mode" - value: "false" + value: "Float32" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/sm_uint8_fence.nnc" - md5_checksum: "190169754dc4557725fbe456e31a238e" + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/od.nnc" + md5_checksum: "6b34201b6696fa75311d0d43820e03d2" single_stream_expected_latency_ns: 1000000 } benchmark_setting { - benchmark_id: "OD_uint8" - accelerator: "samsung npu" - accelerator_desc: "NPU" + benchmark_id: "IC_tpu_uint8_offline" + accelerator: "npu" + accelerator_desc: "npu" configuration: "Samsung Exynos" - custom_setting { - id: "mode" - value: "3" - } - custom_setting { - id: "preset" - value: "1008" - } + batch_size: 48 custom_setting { id: "i_type" value: "Uint8" @@ -630,107 +441,50 @@ benchmark_setting { id: "o_type" value: "Float32" } - custom_setting { - id: "fpc_mode" - value: "true" - } - custom_setting { - id: "freezing" - value: "200" - } - custom_setting { - id: "lazy_mode" - value: "true" - } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/od_fence.nnc" - md5_checksum: "e3760bd134eb93438345d7ddbf34ee48" + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_offline.nnc" + md5_checksum: "8832370c770fa820dfde83e039e3243c" single_stream_expected_latency_ns: 1000000 -} +})SETTINGS"; +const std::string sbe2100_config = R"SETTINGS( benchmark_setting { - benchmark_id: "LU_gpu_float32" - accelerator: "gpu" - accelerator_desc: "gpu" + benchmark_id: "IC_tpu_uint8" + accelerator: "npu" + accelerator_desc: "npu" configuration: "Samsung Exynos" - custom_setting { - id: "mode" - value: "3" - } - custom_setting { - id: "preset" - value: "1000" - } custom_setting { id: "i_type" - value: "Int32" + value: "Uint8" } custom_setting { id: "o_type" value: "Float32" } - custom_setting { - id: "fpc_mode" - value: "false" - } - custom_setting { - id: "freezing" - value: "0" - } - custom_setting { - id: "lazy_mode" - value: "false" - } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/mobile_bert_gpu.nnc" - md5_checksum: "d98dfcc37ad33fa7081d6fbb5bc6ddd1" - single_stream_expected_latency_ns: 1000000 + src: "https://github.com/mlcommons/mobile_models/raw/main/v1_0/Samsung/ic.nnc" + md5_checksum: "955ef2ac3c134820eab901f3dac9f732" + single_stream_expected_latency_ns: 900000 } benchmark_setting { - benchmark_id: "IC_tpu_uint8_offline" - accelerator: "samsung npu" + benchmark_id: "IS_uint8" + accelerator: "npu" accelerator_desc: "npu" configuration: "Samsung Exynos" - batch_size: 8192 - custom_setting { - id: "scenario" - value: "offline" - } - custom_setting { - id: "mode" - value: "1" - } - custom_setting { - id: "preset" - value: "1002" - } custom_setting { id: "i_type" value: "Uint8" } custom_setting { id: "o_type" - value: "Float32" - } - custom_setting { - id: "fpc_mode" - value: "false" - } - custom_setting { - id: "freezing" - value: "0" - } - custom_setting { - id: "lazy_mode" - value: "false" + value: "Uint8" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_offline.nnc" - md5_checksum: "8832370c770fa820dfde83e039e3243c" + src: "https://github.com/mlcommons/mobile_models/raw/main/v1_0/Samsung/is.nnc" + md5_checksum: "b501ed669da753b08a151639798af37e" single_stream_expected_latency_ns: 1000000 -})SETTINGS"; +} -const std::string sbe1200_config = R"SETTINGS( benchmark_setting { - benchmark_id: "IS_uint8" + benchmark_id: "IS_uint8_mosaic" accelerator: "npu" accelerator_desc: "npu" configuration: "Samsung Exynos" @@ -742,13 +496,13 @@ benchmark_setting { id: "o_type" value: "Uint8" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/is.nnc" - md5_checksum: "d7cbd596179beb3c0fe51b745769fc69" + src: "https://github.com/mlcommons/mobile_models/raw/main/v1_0/Samsung/sm_uint8.nnc" + md5_checksum: "483eee2df253ecc135a6e8701cc0c909" single_stream_expected_latency_ns: 1000000 } benchmark_setting { - benchmark_id: "IC_tpu_uint8" + benchmark_id: "OD_uint8" accelerator: "npu" accelerator_desc: "npu" configuration: "Samsung Exynos" @@ -760,35 +514,35 @@ benchmark_setting { id: "o_type" value: "Float32" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_single.nnc" - md5_checksum: "a49175f3f4f37f59780995cec540dbf2" + src: "https://github.com/mlcommons/mobile_models/raw/main/v1_0/Samsung/od.nnc" + md5_checksum: "a3c7b5e8d6b978c05807e8926584758c" single_stream_expected_latency_ns: 1000000 } benchmark_setting { - benchmark_id: "OD_uint8" - accelerator: "npu" - accelerator_desc: "npu" + benchmark_id: "LU_gpu_float32" + accelerator: "gpu" + accelerator_desc: "gpu" configuration: "Samsung Exynos" custom_setting { id: "i_type" - value: "Uint8" + value: "Int32" } custom_setting { id: "o_type" value: "Float32" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/od.nnc" - md5_checksum: "6b34201b6696fa75311d0d43820e03d2" + src: "https://github.com/mlcommons/mobile_models/raw/main/v1_0/Samsung/lu.nnc" + md5_checksum: "215ee3b9224d15dc50b30d56fa7b7396" single_stream_expected_latency_ns: 1000000 } benchmark_setting { benchmark_id: "IC_tpu_uint8_offline" - accelerator: "npu" + accelerator: "npudsp" accelerator_desc: "npu" configuration: "Samsung Exynos" - batch_size: 48 + batch_size: 8192 custom_setting { id: "i_type" value: "Uint8" @@ -797,10 +551,10 @@ benchmark_setting { id: "o_type" value: "Float32" } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_offline.nnc" - md5_checksum: "8832370c770fa820dfde83e039e3243c" + src: "https://github.com/mlcommons/mobile_models/raw/main/v1_0/Samsung/ic_offline.nncgo" + md5_checksum: "c38acf6c66ca32c525c14ce25ead823a" single_stream_expected_latency_ns: 1000000 })SETTINGS"; -} // namespace sbe +} // namespace sbe #endif diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_core.hpp b/mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_core.hpp deleted file mode 100644 index 58e70974f..000000000 --- a/mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_core.hpp +++ /dev/null @@ -1,128 +0,0 @@ - -/* Copyright 2020-2022 Samsung Electronics Co. LTD All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ -#ifndef SBE_CORE_H_ -#define SBE_CORE_H_ - -/** - * @file sbe_core.hpp - * @brief main core object for samsung backend - * @date 2022-01-03 - * @author soobong Huh (soobong.huh@samsung.com) - */ - -#include "backend_c.h" -#include "sbe_helper.hpp" -#include "sbe_loader.hpp" -#include "type.h" - -namespace sbe { -class sbe_core_holder { - public: - ~sbe_core_holder() { MLOGD("Destruct a sbe_core_holder object"); } - - using backend_create_t = std::add_pointer::type; - using backend_get_input_count_t = std::add_pointer::type; - using backend_get_input_type_t = - std::add_pointer::type; - using backend_set_input_t = - std::add_pointer::type; - using backend_get_output_count_t = std::add_pointer::type; - using backend_get_output_type_t = - std::add_pointer::type; - using backend_get_output_t = - std::add_pointer::type; - using backend_issue_query_t = std::add_pointer::type; - using backend_convert_inputs_t = - std::add_pointer::type; - using backend_delete_t = std::add_pointer::type; - using backend_get_buffer_t = std::add_pointer::type; - using backend_release_buffer_t = std::add_pointer::type; - - backend_create_t create_fp; - backend_delete_t delete_fp; - backend_issue_query_t issue_query_fp; - backend_get_input_count_t get_input_count_fp; - backend_get_input_type_t get_input_type_fp; - backend_set_input_t set_input_fp; - backend_get_output_count_t get_output_count_fp; - backend_get_output_type_t get_output_type_fp; - backend_get_output_t get_output_fp; - backend_convert_inputs_t convert_inputs_fp; - backend_get_buffer_t get_buffer_fp; - backend_release_buffer_t release_buffer_fp; - - bool load_core_library(const char *lib_path) { - char *error = nullptr; - /* load sbe core */ - int core_id = core_ctrl::get_core_id(); - MLOGD("acquired core id[%d]", core_id); - - if (core_id == CORE_INVALID) { - MLOGD("fail to get sbe core libarary. core_id[%d]", core_id); - return false; - } - - std::string core_lib_path = - std::string(lib_path) + "/" + sbe_core_libs[core_id]; - void *handle = dlopen(core_lib_path.c_str(), RTLD_NOW); - MLOGD("native library path[%s], handle[%p]", core_lib_path.c_str(), handle); - if (!handle) { - MLOGD("fail to get handle of shared library"); - if ((error = dlerror()) != NULL) { - MLOGD("dlopen error with %s\n", error); - } - return false; - } - - create_fp = link_symbol(handle, backend_create); - delete_fp = link_symbol(handle, backend_delete); - issue_query_fp = link_symbol(handle, backend_issue_query); - get_input_count_fp = link_symbol(handle, backend_get_input_count); - get_input_type_fp = link_symbol(handle, backend_get_input_type); - set_input_fp = link_symbol(handle, backend_set_input); - get_output_count_fp = link_symbol(handle, backend_get_output_count); - get_output_type_fp = link_symbol(handle, backend_get_output_type); - get_output_fp = link_symbol(handle, backend_get_output); - convert_inputs_fp = link_symbol(handle, backend_convert_inputs); - get_buffer_fp = link_symbol(handle, backend_get_buffer); - release_buffer_fp = link_symbol(handle, backend_release_buffer); - return true; - } - - void unload_core_library() { - /* TODO: to something */ - MLOGD("unload native library"); - } - - sbe_core_holder() - : create_fp(nullptr), - delete_fp(nullptr), - issue_query_fp(nullptr), - get_input_count_fp(nullptr), - get_input_type_fp(nullptr), - set_input_fp(nullptr), - get_output_count_fp(nullptr), - get_output_type_fp(nullptr), - get_output_fp(nullptr), - convert_inputs_fp(nullptr), - get_buffer_fp(nullptr), - release_buffer_fp(nullptr) { - MLOGD("Construct a sbe_core_holder object"); - } -}; -} // namespace sbe -#endif diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/sbe/sbe_core.cc b/mobile_back_samsung/cpp/sbe_backend/jni/sbe/sbe_core.cc deleted file mode 100644 index 4f98b170e..000000000 --- a/mobile_back_samsung/cpp/sbe_backend/jni/sbe/sbe_core.cc +++ /dev/null @@ -1,163 +0,0 @@ -/* Copyright 2020 The MLPerf Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ -#include "sbe_core.hpp" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "sbe_utils.hpp" - -using namespace sbe; - -static sbe_core_holder* sbe_core = nullptr; - -bool mlperf_backend_matches_hardware(const char** not_allowed_message, - const char** settings, - const mlperf_device_info_t* device_info) { - MLOGD("Check a support manufacturer: %s model: %s", - device_info->manufacturer, device_info->model); - MLOGD("+ mlperf_backend_matches_hardware"); - - *not_allowed_message = nullptr; - - int support = - core_ctrl::support_sbe(device_info->manufacturer, device_info->model); - if (support != CORE_INVALID && support != CORE_2100) { - MLOGD("backend core selected [%d]", support); - *settings = core_ctrl::get_benchmark_config(support); - return true; - } - - MLOGD("Soc Not supported. Trying next backend"); - *not_allowed_message = "UnsupportedSoc"; - return false; -} - -const char* mlperf_backend_vendor_name(mlperf_backend_ptr_t backend_ptr) { - static const char name[] = "samsung"; - return name; -} - -const char* mlperf_backend_name(mlperf_backend_ptr_t backend_ptr) { - static const char name[] = "samsung"; - return name; -} - -mlperf_status_t mlperf_backend_flush_queries(mlperf_backend_ptr_t backend_ptr) { - return MLPERF_SUCCESS; -} - -mlperf_backend_ptr_t mlperf_backend_create( - const char* model_path, mlperf_backend_configuration_t* configs, - const char* native_lib_path) { - MLOGD("mlperf_backend_create", "mlperf_backend_create"); - - if (sbe_core) { - MLOGD("sbe object exist."); - sbe_core->unload_core_library(); - } - - MLOGD("ready to load sbe library"); - sbe_core = new sbe_core_holder(); - bool ret = sbe_core->load_core_library(native_lib_path); - if (ret == false) return nullptr; - sbe_core->create_fp(model_path, configs, native_lib_path); - MLOGD("ptr of sbe_core[%p]", sbe_core); - return (mlperf_backend_ptr_t)sbe_core; -} - -int32_t mlperf_backend_get_input_count(mlperf_backend_ptr_t backend_ptr) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_get_input_count with ptr[%x]", ptr); - return ptr->get_input_count_fp(); -} - -mlperf_data_t mlperf_backend_get_input_type(mlperf_backend_ptr_t backend_ptr, - int32_t i) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_get_input_type with ptr[%p]", ptr); - return ptr->get_input_type_fp(i); -} - -mlperf_status_t mlperf_backend_set_input(mlperf_backend_ptr_t backend_ptr, - int32_t batchIndex, int32_t i, - void* data) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_set_input with ptr[%p]", ptr); - return ptr->set_input_fp(batchIndex, i, data); -} - -int32_t mlperf_backend_get_output_count(mlperf_backend_ptr_t backend_ptr) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_get_output_count with ptr[%p]", ptr); - return ptr->get_output_count_fp(); -} - -mlperf_data_t mlperf_backend_get_output_type(mlperf_backend_ptr_t backend_ptr, - int32_t i) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_get_output_type with ptr[%p]", ptr); - return ptr->get_output_type_fp(i); -} - -mlperf_status_t mlperf_backend_issue_query(mlperf_backend_ptr_t backend_ptr) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_issue_query with ptr[%p]", ptr); - return ptr->issue_query_fp(); -} - -mlperf_status_t mlperf_backend_get_output(mlperf_backend_ptr_t backend_ptr, - uint32_t batchIndex, int32_t i, - void** data) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_get_output with ptr[%p]", ptr); - return ptr->get_output_fp(batchIndex, i, data); -} - -void mlperf_backend_convert_inputs(void* backend_ptr, int bytes, int width, - int height, uint8_t* data) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_convert_inputs with ptr[%p]", ptr); - ptr->convert_inputs_fp(bytes, width, height, data); -} - -void mlperf_backend_delete(mlperf_backend_ptr_t backend_ptr) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_delete with ptr[%p]", ptr); - ptr->delete_fp(); - - delete (ptr); - ptr = nullptr; -} - -void* mlperf_backend_get_buffer(size_t size) { - MLOGD("+ mlperf_backend_get_buffer with size[%d]", size); - return sbe_core->get_buffer_fp(size); -} - -void mlperf_backend_release_buffer(void* p) { - MLOGD("+ mlperf_backend_release_buffer with ptr[%p]", p); - sbe_core->release_buffer_fp(p); -} \ No newline at end of file diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/sbe/sbe_helper.cc b/mobile_back_samsung/cpp/sbe_backend/jni/sbe/sbe_helper.cc deleted file mode 100644 index 6d4d09d5b..000000000 --- a/mobile_back_samsung/cpp/sbe_backend/jni/sbe/sbe_helper.cc +++ /dev/null @@ -1,111 +0,0 @@ -/* Copyright 2020-2022 Samsung Electronics Co. LTD All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ -#include "sbe_helper.hpp" - -#include - -#include - -namespace sbe { -static std::string get_core_info() { - std::array buffer; - std::string core_info; - - std::unique_ptr pipe( - popen("getprop | grep ro.hardware", "r"), pclose); - if (!pipe) { - __android_log_print(ANDROID_LOG_INFO, "TAG", - "Can not find Samsung specific information"); - return ""; - } - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { - core_info += buffer.data(); - } - MLOGD("completed hardware info [%s]", core_info.c_str()); - return core_info; -} - -static bool get_manufacturer(const char *manufacturer) { - MLOGD("Check for support manufacturer[%s]", manufacturer); - if (strstr((char *)manufacturer, "samsung") || - strstr((char *)manufacturer, "Samsung")) - return true; - return false; -} - -static int get_core_id_from_model(const char *model) { - MLOGD("Check for support model[%s]", model); - int core_id = CORE_INVALID; - - if (strstr((char *)model, "G998") || strstr((char *)model, "G996") || - strstr((char *)model, "G991") || strstr((char *)model, "UNIVERSAL2100")) - core_id = CORE_2100; - else if (strstr((char *)model, "ERD9925") || - strstr((char *)model, "S5E9925") || strstr((char *)model, "S906")) - core_id = CORE_2200; - else if (strstr((char *)model, "ERD8825")) - core_id = CORE_1200; - else - return CORE_INVALID; - return core_id; -} - -static int get_core_id_from_hardware(const char *hardware) { - MLOGD("Check for support hardware[%s]", hardware); - int core_id = CORE_INVALID; - - if (strstr((char *)hardware, "2100")) - core_id = CORE_INVALID; - else if (strstr((char *)hardware, "9925")) - core_id = CORE_2200; - else if (strstr((char *)hardware, "8825")) - core_id = CORE_1200; - else - return CORE_INVALID; - return core_id; -} - -int core_ctrl::support_sbe(const char *manufacturer, const char *model) { - bool is_samsung = get_manufacturer(manufacturer); - int core_id = get_core_id_from_model(model); - if (is_samsung && (core_id > CORE_INVALID)) { - return core_id; - } - return CORE_INVALID; -} - -const char *core_ctrl::get_benchmark_config(int core_id) { - const char *settings = nullptr; - ; - if (core_id == CORE_2100) { - MLOGE("Not supported"); - return settings; - } else if (core_id == CORE_1200) { - settings = sbe1200_config.c_str(); - } else if (core_id == CORE_2200) { - settings = sbe2200_config.c_str(); - } - return settings; -} - -// called mlperf_create -int core_ctrl::get_core_id() { - std::string temp = get_core_info(); - const char *core_model = temp.c_str(); - MLOGD("check system info. core[%s]", core_model); - if (!core_model) return CORE_INVALID; - return get_core_id_from_hardware(core_model); -} -} // namespace sbe \ No newline at end of file diff --git a/mobile_back_samsung/samsung_backend/lib/BUILD b/mobile_back_samsung/samsung/lib/BUILD similarity index 100% rename from mobile_back_samsung/samsung_backend/lib/BUILD rename to mobile_back_samsung/samsung/lib/BUILD diff --git a/mobile_back_samsung/samsung_backend/lib/backend_c.h b/mobile_back_samsung/samsung/lib/backend_c.h similarity index 100% rename from mobile_back_samsung/samsung_backend/lib/backend_c.h rename to mobile_back_samsung/samsung/lib/backend_c.h diff --git a/mobile_back_samsung/samsung/lib/sbe_config.hpp b/mobile_back_samsung/samsung/lib/sbe_config.hpp new file mode 100644 index 000000000..5768a3fe4 --- /dev/null +++ b/mobile_back_samsung/samsung/lib/sbe_config.hpp @@ -0,0 +1,560 @@ +/* Copyright 2020 The MLPerf Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ +#include + +#ifndef SBE_CONFIG_H +#define SBE_CONFIG_H + +/** + * @file sbe_config.hpp + * @brief description of benchmark_setting for samsung backend core + * @date 2022-01-04 + * @author soobong Huh (soobong.huh@samsung.com) + */ + +namespace sbe { +const std::string sbe2300_config = R"SETTINGS( +benchmark_setting { + benchmark_id: "IC_tpu_uint8" + accelerator: "samsung npu" + accelerator_desc: "NPU" + configuration: "Samsung Exynos" + custom_setting { + id: "mode" + value: "3" + } + custom_setting { + id: "preset" + value: "1009" + } + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Float32" + } + custom_setting { + id: "extension" + value: "true" + } + custom_setting { + id: "lazy_mode" + value: "true" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_1/Samsung/ic_single_fence.nnc" + md5_checksum: "a451da1f48b1fad01c17fb7a49e5822e" + single_stream_expected_latency_ns: 500000 +} + +benchmark_setting { + benchmark_id: "IS_uint8_mosaic" + accelerator: "samsung npu" + accelerator_desc: "NPU" + configuration: "Samsung Exynos" + custom_setting { + id: "mode" + value: "3" + } + custom_setting { + id: "preset" + value: "1009" + } + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Uint8" + } + custom_setting { + id: "extension" + value: "true" + } + custom_setting { + id: "lazy_mode" + value: "true" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_1/Samsung/sm_uint8_fence.nnc" + md5_checksum: "08fa7b354f82140a8863fed57c2d499b" + single_stream_expected_latency_ns: 1000000 +} + +benchmark_setting { + benchmark_id: "OD_uint8" + accelerator: "samsung npu" + accelerator_desc: "NPU" + configuration: "Samsung Exynos" + custom_setting { + id: "mode" + value: "3" + } + custom_setting { + id: "preset" + value: "1009" + } + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Float32" + } + custom_setting { + id: "extension" + value: "true" + } + custom_setting { + id: "lazy_mode" + value: "true" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_1/Samsung/od_fence.nnc" + md5_checksum: "8a7e1808446072545c990f3d219255c6" + single_stream_expected_latency_ns: 1000000 +} + +benchmark_setting { + benchmark_id: "LU_gpu_float32" + accelerator: "npu" + accelerator_desc: "npu" + configuration: "Samsung Exynos" + custom_setting { + id: "mode" + value: "3" + } + custom_setting { + id: "preset" + value: "1009" + } + custom_setting { + id: "i_type" + value: "Int32" + } + custom_setting { + id: "o_type" + value: "Float32" + } + custom_setting { + id: "extension" + value: "true" + } + custom_setting { + id: "lazy_mode" + value: "true" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_1/Samsung/mobile_bert_fence.nnc" + md5_checksum: "5fb666b684a9bd0b68d497128b990137" + single_stream_expected_latency_ns: 1000000 +} + +benchmark_setting { + benchmark_id: "IC_tpu_uint8_offline" + accelerator: "samsung npu" + accelerator_desc: "npu" + configuration: "Samsung Exynos" + batch_size: 8192 + custom_setting { + id: "scenario" + value: "offline" + } + custom_setting { + id: "mode" + value: "1" + } + custom_setting { + id: "preset" + value: "1002" + } + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Float32" + } + custom_setting { + id: "extension" + value: "false" + } + custom_setting { + id: "lazy_mode" + value: "false" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_1/Samsung/ic_offline.nnc" + md5_checksum: "6885f281a3d7a7ec3549d629dff8c8ac" + single_stream_expected_latency_ns: 1000000 +})SETTINGS"; + +const std::string sbe2200_config = R"SETTINGS( +benchmark_setting { + benchmark_id: "IC_tpu_uint8" + accelerator: "samsung npu" + accelerator_desc: "NPU" + configuration: "Samsung Exynos" + custom_setting { + id: "mode" + value: "3" + } + custom_setting { + id: "preset" + value: "1001" + } + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Float32" + } + custom_setting { + id: "extension" + value: "true" + } + custom_setting { + id: "lazy_mode" + value: "false" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_single.nnc" + md5_checksum: "a49175f3f4f37f59780995cec540dbf2" + single_stream_expected_latency_ns: 900000 +} +benchmark_setting { + benchmark_id: "IS_uint8_mosaic" + accelerator: "samsung npu" + accelerator_desc: "NPU" + configuration: "Samsung Exynos" + custom_setting { + id: "mode" + value: "3" + } + custom_setting { + id: "preset" + value: "1004" + } + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Uint8" + } + custom_setting { + id: "extension" + value: "false" + } + custom_setting { + id: "lazy_mode" + value: "false" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/sm_uint8.nnc" + md5_checksum: "f715f55818863f371336ad29ecba1183" + single_stream_expected_latency_ns: 1000000 +} +benchmark_setting { + benchmark_id: "OD_uint8" + accelerator: "samsung npu" + accelerator_desc: "NPU" + configuration: "Samsung Exynos" + custom_setting { + id: "mode" + value: "3" + } + custom_setting { + id: "preset" + value: "1003" + } + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Float32" + } + custom_setting { + id: "extension" + value: "true" + } + custom_setting { + id: "lazy_mode" + value: "false" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/od.nnc" + md5_checksum: "6b34201b6696fa75311d0d43820e03d2" + single_stream_expected_latency_ns: 1000000 +} +benchmark_setting { + benchmark_id: "LU_gpu_float32" + accelerator: "gpu" + accelerator_desc: "gpu" + configuration: "Samsung Exynos" + custom_setting { + id: "mode" + value: "3" + } + custom_setting { + id: "preset" + value: "1000" + } + custom_setting { + id: "i_type" + value: "Int32" + } + custom_setting { + id: "o_type" + value: "Float32" + } + custom_setting { + id: "extension" + value: "false" + } + custom_setting { + id: "lazy_mode" + value: "false" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/mobile_bert_gpu.nnc" + md5_checksum: "d98dfcc37ad33fa7081d6fbb5bc6ddd1" + single_stream_expected_latency_ns: 1000000 +} +benchmark_setting { + benchmark_id: "IC_tpu_uint8_offline" + accelerator: "samsung npu" + accelerator_desc: "npu" + configuration: "Samsung Exynos" + batch_size: 8192 + custom_setting { + id: "scenario" + value: "offline" + } + custom_setting { + id: "mode" + value: "1" + } + custom_setting { + id: "preset" + value: "1002" + } + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Float32" + } + custom_setting { + id: "extension" + value: "false" + } + custom_setting { + id: "lazy_mode" + value: "false" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_offline.nnc" + md5_checksum: "8832370c770fa820dfde83e039e3243c" + single_stream_expected_latency_ns: 1000000 +})SETTINGS"; + +const std::string sbe1200_config = R"SETTINGS( +benchmark_setting { + benchmark_id: "IS_uint8_mosaic" + accelerator: "npu" + accelerator_desc: "npu" + configuration: "Samsung Exynos" + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Int32" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/is.nnc" + md5_checksum: "d7cbd596179beb3c0fe51b745769fc69" + single_stream_expected_latency_ns: 1000000 +} +benchmark_setting { + benchmark_id: "IC_tpu_uint8" + accelerator: "npu" + accelerator_desc: "npu" + configuration: "Samsung Exynos" + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Float32" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_single.nnc" + md5_checksum: "a49175f3f4f37f59780995cec540dbf2" + single_stream_expected_latency_ns: 900000 +} + +benchmark_setting { + benchmark_id: "OD_uint8" + accelerator: "npu" + accelerator_desc: "npu" + configuration: "Samsung Exynos" + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Float32" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/od.nnc" + md5_checksum: "6b34201b6696fa75311d0d43820e03d2" + single_stream_expected_latency_ns: 1000000 +} + +benchmark_setting { + benchmark_id: "IC_tpu_uint8_offline" + accelerator: "npu" + accelerator_desc: "npu" + configuration: "Samsung Exynos" + batch_size: 48 + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Float32" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_offline.nnc" + md5_checksum: "8832370c770fa820dfde83e039e3243c" + single_stream_expected_latency_ns: 1000000 +})SETTINGS"; + +const std::string sbe2100_config = R"SETTINGS( +benchmark_setting { + benchmark_id: "IC_tpu_uint8" + accelerator: "npu" + accelerator_desc: "npu" + configuration: "Samsung Exynos" + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Float32" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v1_0/Samsung/ic.nnc" + md5_checksum: "955ef2ac3c134820eab901f3dac9f732" + single_stream_expected_latency_ns: 900000 +} + +benchmark_setting { + benchmark_id: "IS_uint8" + accelerator: "npu" + accelerator_desc: "npu" + configuration: "Samsung Exynos" + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Uint8" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v1_0/Samsung/is.nnc" + md5_checksum: "b501ed669da753b08a151639798af37e" + single_stream_expected_latency_ns: 1000000 +} + +benchmark_setting { + benchmark_id: "IS_uint8_mosaic" + accelerator: "npu" + accelerator_desc: "npu" + configuration: "Samsung Exynos" + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Uint8" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v1_0/Samsung/sm_uint8.nnc" + md5_checksum: "483eee2df253ecc135a6e8701cc0c909" + single_stream_expected_latency_ns: 1000000 +} + +benchmark_setting { + benchmark_id: "OD_uint8" + accelerator: "npu" + accelerator_desc: "npu" + configuration: "Samsung Exynos" + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Float32" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v1_0/Samsung/od.nnc" + md5_checksum: "a3c7b5e8d6b978c05807e8926584758c" + single_stream_expected_latency_ns: 1000000 +} + +benchmark_setting { + benchmark_id: "LU_gpu_float32" + accelerator: "gpu" + accelerator_desc: "gpu" + configuration: "Samsung Exynos" + custom_setting { + id: "i_type" + value: "Int32" + } + custom_setting { + id: "o_type" + value: "Float32" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v1_0/Samsung/lu.nnc" + md5_checksum: "215ee3b9224d15dc50b30d56fa7b7396" + single_stream_expected_latency_ns: 1000000 +} + +benchmark_setting { + benchmark_id: "IC_tpu_uint8_offline" + accelerator: "npudsp" + accelerator_desc: "npu" + configuration: "Samsung Exynos" + batch_size: 8192 + custom_setting { + id: "i_type" + value: "Uint8" + } + custom_setting { + id: "o_type" + value: "Float32" + } + src: "https://github.com/mlcommons/mobile_models/raw/main/v1_0/Samsung/ic_offline.nncgo" + md5_checksum: "c38acf6c66ca32c525c14ce25ead823a" + single_stream_expected_latency_ns: 1000000 +})SETTINGS"; + +} // namespace sbe +#endif diff --git a/mobile_back_samsung/samsung_backend/lib/sbe_core.cc b/mobile_back_samsung/samsung/lib/sbe_core.cc similarity index 100% rename from mobile_back_samsung/samsung_backend/lib/sbe_core.cc rename to mobile_back_samsung/samsung/lib/sbe_core.cc diff --git a/mobile_back_samsung/samsung_backend/lib/sbe_core.hpp b/mobile_back_samsung/samsung/lib/sbe_core.hpp similarity index 100% rename from mobile_back_samsung/samsung_backend/lib/sbe_core.hpp rename to mobile_back_samsung/samsung/lib/sbe_core.hpp diff --git a/mobile_back_samsung/samsung_backend/lib/sbe_helper.cc b/mobile_back_samsung/samsung/lib/sbe_helper.cc similarity index 100% rename from mobile_back_samsung/samsung_backend/lib/sbe_helper.cc rename to mobile_back_samsung/samsung/lib/sbe_helper.cc diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_helper.hpp b/mobile_back_samsung/samsung/lib/sbe_helper.hpp similarity index 100% rename from mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_helper.hpp rename to mobile_back_samsung/samsung/lib/sbe_helper.hpp diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_loader.hpp b/mobile_back_samsung/samsung/lib/sbe_loader.hpp similarity index 100% rename from mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_loader.hpp rename to mobile_back_samsung/samsung/lib/sbe_loader.hpp diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_model_container.hpp b/mobile_back_samsung/samsung/lib/sbe_model_container.hpp similarity index 100% rename from mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_model_container.hpp rename to mobile_back_samsung/samsung/lib/sbe_model_container.hpp diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_utils.hpp b/mobile_back_samsung/samsung/lib/sbe_utils.hpp similarity index 100% rename from mobile_back_samsung/cpp/sbe_backend/jni/include/sbe_utils.hpp rename to mobile_back_samsung/samsung/lib/sbe_utils.hpp diff --git a/mobile_back_samsung/cpp/sbe_backend/jni/include/type.h b/mobile_back_samsung/samsung/lib/type.h old mode 100755 new mode 100644 similarity index 100% rename from mobile_back_samsung/cpp/sbe_backend/jni/include/type.h rename to mobile_back_samsung/samsung/lib/type.h diff --git a/mobile_back_samsung/samsung_backend.mk b/mobile_back_samsung/samsung_backend.mk index 4ef75cd0e..9725b5f70 100644 --- a/mobile_back_samsung/samsung_backend.mk +++ b/mobile_back_samsung/samsung_backend.mk @@ -16,20 +16,23 @@ ifeq (${WITH_SAMSUNG},1) $(info WITH_SAMSUNG=1) - MOBILE_BACK_SAMSUNG_LIB_ROOT=$(shell echo mobile_back_samsung/samsung_backend/lib* | awk '{print $$NF}') + MOBILE_BACK_SAMSUNG_LIB_ROOT=$(shell echo mobile_back_samsung/samsung/lib* | awk '{print $$NF}') $(info MOBILE_BACK_SAMSUNG_LIB_ROOT=${MOBILE_BACK_SAMSUNG_LIB_ROOT}) backend_samsung_android_files= \ ${BAZEL_LINKS_PREFIX}bin/flutter/android/commonlibs/lib_arm64/libc++_shared.so \ ${MOBILE_BACK_SAMSUNG_LIB_ROOT}/libsamsungbackend.so \ ${MOBILE_BACK_SAMSUNG_LIB_ROOT}/libenn_public_api_cpp.so \ - ${MOBILE_BACK_SAMSUNG_LIB_ROOT}/libsbe2200_core.so \ + ${MOBILE_BACK_SAMSUNG_LIB_ROOT}/libenn_extension.so \ ${MOBILE_BACK_SAMSUNG_LIB_ROOT}/libsbe1200_core.so \ + ${MOBILE_BACK_SAMSUNG_LIB_ROOT}/libsbe2100_core.so \ + ${MOBILE_BACK_SAMSUNG_LIB_ROOT}/libsbe2200_core.so \ + ${MOBILE_BACK_SAMSUNG_LIB_ROOT}/libsbe2300_core.so \ ${MOBILE_BACK_SAMSUNG_LIB_ROOT}/libc++.so \ ${MOBILE_BACK_SAMSUNG_LIB_ROOT}/libeden_nn_on_system.so \ # main binaries for Samsung backend are prebuilt backend_samsung_android_target= \ - //mobile_back_samsung/samsung_backend/lib:libsamsungbackend.so \ + //mobile_back_samsung/samsung/lib:libsamsungbackend.so \ //flutter/android/commonlibs:commonlibs backend_samsung_filename=libsamsungbackend endif diff --git a/mobile_back_samsung/samsung_backend/README.md b/mobile_back_samsung/samsung_backend/README.md deleted file mode 100644 index 7f2da5e3c..000000000 --- a/mobile_back_samsung/samsung_backend/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Building MLPerf Open app with Samsung backend - -To build the app, use the following command - -```bash -bazel-4.2.1 build --verbose_failures -c opt --cxxopt='--std=c++14' --host_cxxopt='--std=c++14' --fat_apk_cp -u=arm64-v8a --//android/java/org/mlperf/inference:with_samsung="1" //android/java/org/mlperf/inference:ml -perf_app -``` diff --git a/mobile_back_samsung/samsung_backend/lib/sbe_config.hpp b/mobile_back_samsung/samsung_backend/lib/sbe_config.hpp deleted file mode 100644 index f461a0cbf..000000000 --- a/mobile_back_samsung/samsung_backend/lib/sbe_config.hpp +++ /dev/null @@ -1,282 +0,0 @@ -/* Copyright 2020 The MLPerf Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ -#include - -#ifndef SBE_CONFIG_H -#define SBE_CONFIG_H - -/** - * @file sbe_config.hpp - * @brief description of benchmark_setting for samsung backend core - * @date 2022-01-04 - * @author soobong Huh (soobong.huh@samsung.com) - */ - -namespace sbe { - -const std::string sbe2200_flutter_config = R"SETTINGS( -benchmark_setting { - benchmark_id: "IC_tpu_uint8" - accelerator: "samsung npu" - accelerator_desc: "NPU" - configuration: "Samsung Exynos" - custom_setting { - id: "mode" - value: "3" - } - custom_setting { - id: "preset" - value: "1001" - } - custom_setting { - id: "i_type" - value: "Uint8" - } - custom_setting { - id: "o_type" - value: "Float32" - } - custom_setting { - id: "fpc_mode" - value: "true" - } - custom_setting { - id: "freezing" - value: "300" - } - custom_setting { - id: "lazy_mode" - value: "false" - } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_single.nnc" - md5_checksum: "a49175f3f4f37f59780995cec540dbf2" - single_stream_expected_latency_ns: 900000 -} - -benchmark_setting { - benchmark_id: "IS_uint8_mosaic" - accelerator: "samsung npu" - accelerator_desc: "NPU" - configuration: "Samsung Exynos" - custom_setting { - id: "mode" - value: "3" - } - custom_setting { - id: "preset" - value: "1004" - } - custom_setting { - id: "i_type" - value: "Uint8" - } - custom_setting { - id: "o_type" - value: "Uint8" - } - custom_setting { - id: "fpc_mode" - value: "false" - } - custom_setting { - id: "freezing" - value: "0" - } - custom_setting { - id: "lazy_mode" - value: "false" - } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/sm_uint8.nnc" - md5_checksum: "f715f55818863f371336ad29ecba1183" - single_stream_expected_latency_ns: 1000000 -} - -benchmark_setting { - benchmark_id: "OD_uint8" - accelerator: "samsung npu" - accelerator_desc: "NPU" - configuration: "Samsung Exynos" - custom_setting { - id: "mode" - value: "3" - } - custom_setting { - id: "preset" - value: "1003" - } - custom_setting { - id: "i_type" - value: "Uint8" - } - custom_setting { - id: "o_type" - value: "Float32" - } - custom_setting { - id: "fpc_mode" - value: "true" - } - custom_setting { - id: "freezing" - value: "200" - } - custom_setting { - id: "lazy_mode" - value: "false" - } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/od.nnc" - md5_checksum: "6b34201b6696fa75311d0d43820e03d2" - single_stream_expected_latency_ns: 1000000 -} - -benchmark_setting { - benchmark_id: "LU_gpu_float32" - accelerator: "gpu" - accelerator_desc: "gpu" - configuration: "Samsung Exynos" - custom_setting { - id: "mode" - value: "3" - } - custom_setting { - id: "preset" - value: "1000" - } - custom_setting { - id: "i_type" - value: "Int32" - } - custom_setting { - id: "o_type" - value: "Float32" - } - custom_setting { - id: "fpc_mode" - value: "false" - } - custom_setting { - id: "freezing" - value: "0" - } - custom_setting { - id: "lazy_mode" - value: "false" - } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/mobile_bert_gpu.nnc" - md5_checksum: "d98dfcc37ad33fa7081d6fbb5bc6ddd1" - single_stream_expected_latency_ns: 1000000 -} - -benchmark_setting { - benchmark_id: "IC_tpu_uint8_offline" - accelerator: "samsung npu" - accelerator_desc: "npu" - configuration: "Samsung Exynos" - batch_size: 8192 - custom_setting { - id: "scenario" - value: "offline" - } - custom_setting { - id: "mode" - value: "1" - } - custom_setting { - id: "preset" - value: "1002" - } - custom_setting { - id: "i_type" - value: "Uint8" - } - custom_setting { - id: "o_type" - value: "Float32" - } - custom_setting { - id: "fpc_mode" - value: "false" - } - custom_setting { - id: "freezing" - value: "0" - } - custom_setting { - id: "lazy_mode" - value: "false" - } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_offline.nnc" - md5_checksum: "8832370c770fa820dfde83e039e3243c" - single_stream_expected_latency_ns: 1000000 -})SETTINGS"; - -const std::string sbe1200_config = R"SETTINGS( -benchmark_setting { - benchmark_id: "IC_tpu_uint8" - accelerator: "npu" - accelerator_desc: "npu" - configuration: "Samsung Exynos" - custom_setting { - id: "i_type" - value: "Uint8" - } - custom_setting { - id: "o_type" - value: "Float32" - } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_single.nnc" - md5_checksum: "a49175f3f4f37f59780995cec540dbf2" - single_stream_expected_latency_ns: 1000000 -} - -benchmark_setting { - benchmark_id: "OD_uint8" - accelerator: "npu" - accelerator_desc: "npu" - configuration: "Samsung Exynos" - custom_setting { - id: "i_type" - value: "Uint8" - } - custom_setting { - id: "o_type" - value: "Float32" - } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/od.nnc" - md5_checksum: "6b34201b6696fa75311d0d43820e03d2" - single_stream_expected_latency_ns: 1000000 -} - -benchmark_setting { - benchmark_id: "IC_tpu_uint8_offline" - accelerator: "npu" - accelerator_desc: "npu" - configuration: "Samsung Exynos" - batch_size: 48 - custom_setting { - id: "i_type" - value: "Uint8" - } - custom_setting { - id: "o_type" - value: "Float32" - } - src: "https://github.com/mlcommons/mobile_models/raw/main/v2_0/Samsung/ic_offline.nnc" - md5_checksum: "8832370c770fa820dfde83e039e3243c" - single_stream_expected_latency_ns: 1000000 -})SETTINGS"; - -} // namespace sbe -#endif diff --git a/mobile_back_samsung/samsung_backend/lib/sbe_helper.hpp b/mobile_back_samsung/samsung_backend/lib/sbe_helper.hpp deleted file mode 100644 index 3ba2011f8..000000000 --- a/mobile_back_samsung/samsung_backend/lib/sbe_helper.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright 2020-2022 Samsung Electronics Co. LTD All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ -#ifndef SBE_HELPER_H_ -#define SBE_HELPER_H_ - -/** - * @file sbe_helper.hpp - * @brief helper class of samsung backend core for samsung exynos - * @date 2022-01-04 - * @author soobong Huh (soobong.huh@samsung.com) - */ - -#include -#include -#include - -#include - -#include "sbe_config.hpp" -#include "sbe_utils.hpp" - -namespace sbe { -class core_ctrl { - public: - static int support_sbe(const char *, const char *); - static const char *get_benchmark_config(int core_id); - static int get_core_id(); -}; -} // namespace sbe - -#endif diff --git a/mobile_back_samsung/samsung_backend/lib/sbe_loader.hpp b/mobile_back_samsung/samsung_backend/lib/sbe_loader.hpp deleted file mode 100644 index 63ef1a97d..000000000 --- a/mobile_back_samsung/samsung_backend/lib/sbe_loader.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* Copyright 2020-2022 Samsung Electronics Co. LTD All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ -#ifndef SBE_LOADER_H_ -#define SBE_LOADER_H_ - -/** - * @file sbe_loader.hpp - * @brief dynamic loader for samsung exynos libraries - * @date 2022-01-04 - * @author soobong Huh (soobong.huh@samsung.com) - */ - -#include - -#include "sbe_utils.hpp" -#include "type.h" - -namespace sbe { -std::string sbe_core_libs[CORE_MAX] = { - "libsbe1200_core.so", /* TODO it must be replaced to libsbe2100_core */ - "libsbe1200_core.so", - "libsbe2200_core.so", -}; - -void* load_symbol(void* dl_handle, const char* name) { - auto func_pt = dlsym(dl_handle, name); - if (func_pt == nullptr) { - MLOGD("dlopen fail. symbol[%s]", name); - } - return func_pt; -} - -#define link_symbol(dl_handle, symbol_name) \ - reinterpret_cast(load_symbol(dl_handle, #symbol_name)) -} // namespace sbe - -#endif \ No newline at end of file diff --git a/mobile_back_samsung/samsung_backend/lib/sbe_model_container.hpp b/mobile_back_samsung/samsung_backend/lib/sbe_model_container.hpp deleted file mode 100644 index 4f16794fd..000000000 --- a/mobile_back_samsung/samsung_backend/lib/sbe_model_container.hpp +++ /dev/null @@ -1,404 +0,0 @@ -#ifndef MODEL_CONTAINER_H_ -#define MODEL_CONTAINER_H_ - -/** - * @file mnodel_container.hpp - * @brief model container for samsung specific model - * @date 2021-12-29 - * @author soobong Huh (soobong.huh@samsung.com) - */ - -#include "sbe_utils.hpp" -#include "type.h" - -namespace sbe { -enum MODEL_IDX { - OBJECT_DETECTION = 0, - IMAGE_CLASSIFICATION, - IMAGE_SEGMENTATION, - MOBILE_BERT, - MAX_MODEL_IDX -}; - -class model_container { - public: - int m_model_id; - int m_width; - int m_height; - int m_channel; - - /* mdl config */ - int m_in_cnt; - int m_out_cnt; - int m_inbuf_size; - int m_outbuf_size; - - /* perf config */ - int m_freeze; - bool b_enable_lazy; - bool b_enable_fpc; - - mlperf_data_t::Type m_inbuf_type; - mlperf_data_t::Type m_outbuf_type; - - private: - std::vector m_input_data; - std::vector m_output_data; - - public: - void set_input_data(mlperf_data_t v) { m_input_data.push_back(v); } - - void set_output_data(mlperf_data_t v) { m_output_data.push_back(v); } - - int get_buf_size() { return m_width * m_height * m_channel; } - - int get_input_size() { return m_input_data.size(); } - int get_output_size() { return m_output_data.size(); } - - mlperf_data_t get_input_type(int idx) { return m_input_data.at(idx); } - mlperf_data_t get_output_type(int idx) { return m_output_data.at(idx); } - - void unset_lazy() { b_enable_lazy = false; } - virtual void init() = 0; - - void deinit() { - m_input_data.clear(); - m_input_data.shrink_to_fit(); - - m_output_data.clear(); - m_output_data.shrink_to_fit(); - } - - model_container(int w, int h, int c, int in, int out, int mdl_id) { - m_model_id = mdl_id; - m_width = w; - m_height = h; - m_channel = c; - m_in_cnt = in; - m_out_cnt = out; - m_freeze = 0; - b_enable_lazy = false; - b_enable_fpc = false; - } - - ~model_container() { deinit(); } -}; - -class mdl_attribute_template { - public: - /* model attribute */ - int m_width; - int m_height; - int m_channel; - - int m_in_cnt; - int m_out_cnt; - int m_inbuf_size; - int m_outbuf_size; - - mlperf_data_t::Type m_inbuf_type; - mlperf_data_t::Type m_outbuf_type; - - /* others */ - int m_preset_id; - bool b_enable_fpc; - int m_freeze; - bool b_enable_lazy; - - public: - int get_byte(mlperf_data_t::Type type) { - switch (type) { - case mlperf_data_t::Uint8: - return 1; - case mlperf_data_t::Int8: - return 1; - case mlperf_data_t::Float16: - return 2; - case mlperf_data_t::Int32: - case mlperf_data_t::Float32: - return 4; - case mlperf_data_t::Int64: - return 8; - } - } - - void update(model_container* ptr) { - ptr->m_in_cnt = m_in_cnt; - ptr->m_out_cnt = m_out_cnt; - - ptr->m_inbuf_size = m_inbuf_size; - ptr->m_outbuf_size = m_outbuf_size; - ptr->m_inbuf_type = m_inbuf_type; - ptr->m_outbuf_type = m_outbuf_type; - ptr->b_enable_fpc = b_enable_fpc; - ptr->m_freeze = m_freeze; - ptr->b_enable_lazy = b_enable_lazy; - } - - void show() { - MLOGV("mdl_attribute_template : "); - MLOGV("m_preset_id : %d", m_preset_id); - MLOGV("m_width : %d", m_width); - MLOGV("m_height : %d", m_height); - MLOGV("m_channel : %d", m_channel); - MLOGV("m_in_cnt : %d", m_in_cnt); - MLOGV("m_out_cnt : %d", m_out_cnt); - MLOGV("m_inbuf_size : %d", m_inbuf_size); - MLOGV("m_outbuf_size : %d", m_outbuf_size); - MLOGV("m_inbuf_type : %d", m_inbuf_type); - MLOGV("m_outbuf_type : %d", m_outbuf_type); - MLOGV("b_enable_fpc : %d", b_enable_fpc); - MLOGV("m_freeze : %d", m_freeze); - MLOGV("b_lazy : %d", b_enable_lazy); - } - - public: - mdl_attribute_template() { - m_width = 0; - m_height = 0; - m_channel = 0; - m_in_cnt = 1; - m_out_cnt = 1; - m_inbuf_size = 0; - m_outbuf_size = 0; - m_inbuf_type = mlperf_data_t::Uint8; - m_outbuf_type = mlperf_data_t::Uint8; - m_preset_id = 1001; - b_enable_fpc = false; - m_freeze = 0; - b_enable_lazy = false; - } -}; -mdl_attribute_template mdl_attr; - -namespace sbeID2200 { -class classification : public model_container { - public: - void init() override { - MLOGV("on target model : classification"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({(m_inbuf_type), m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data( - {m_outbuf_type, (int64_t)(m_outbuf_size / sizeof(float))}); - } - - public: - classification() : model_container(224, 224, 3, 1, 1, IMAGE_CLASSIFICATION) {} -}; - -class classification_offline : public model_container { - public: - void init() override { - MLOGV("on target model : classification offline"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data( - {m_outbuf_type, (int64_t)(m_outbuf_size / sizeof(float))}); - } - - public: - classification_offline() - : model_container(224, 224, 3, 1, 1, IMAGE_CLASSIFICATION) {} -}; - -class mobilebert : public model_container { - public: - void init() override { - MLOGV("on target model [mobile_bert]"); - for (int i = 0; i < m_in_cnt; i++) set_input_data({m_inbuf_type, 384}); - - for (int i = 0; i < m_out_cnt; i++) set_output_data({m_outbuf_type, 384}); - } - - public: - mobilebert() : model_container(384, 384, 3, 3, 2, MOBILE_BERT) {} -}; - -class segmentation : public model_container { - public: - void init() override { - MLOGV("on target model : segemenatation"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data({m_outbuf_type, m_outbuf_size}); - } - - public: - segmentation() : model_container(512, 512, 3, 1, 1, IMAGE_SEGMENTATION) {} -}; - -class detection : public model_container { - public: - void init() override { - MLOGV("on target model : detection"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - set_output_data({m_outbuf_type, m_outbuf_size / 7}); - set_output_data({m_outbuf_type, m_outbuf_size / 28}); - set_output_data({m_outbuf_type, m_outbuf_size / 28}); - set_output_data({m_outbuf_type, 1}); - } - - public: - int det_block_cnt; - int det_block_size; - - public: - detection() - : model_container(320, 320, 3, 1, 1, OBJECT_DETECTION), - det_block_cnt(11), - det_block_size(7) {} -}; - -detection obj_od; -classification obj_ic; -classification_offline obj_ic_offline; -segmentation obj_is; -mobilebert obj_bert; -} // namespace sbeID2200 - -namespace sbeID1200 { -class detection : public model_container { - public: - void init() override { - MLOGV("on target model : detection"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - set_output_data({m_outbuf_type, m_outbuf_size / 7}); - set_output_data({m_outbuf_type, m_outbuf_size / 28}); - set_output_data({m_outbuf_type, m_outbuf_size / 28}); - set_output_data({m_outbuf_type, 1}); - } - - public: - int det_block_cnt; - int det_block_size; - - public: - detection() - : model_container(320, 320, 3, 1, 1, OBJECT_DETECTION), - det_block_cnt(11), - det_block_size(7) {} -}; - -class classification : public model_container { - public: - void init() override { - MLOGV("on target model : classification"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({(m_inbuf_type), m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data( - {m_outbuf_type, (int64_t)(m_outbuf_size / sizeof(float))}); - } - - public: - classification() : model_container(224, 224, 3, 1, 1, IMAGE_CLASSIFICATION) {} -}; - -class segmentation : public model_container { - public: - void init() override { - MLOGV("on target model : segemenatation"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data({m_outbuf_type, m_outbuf_size}); - } - - public: - segmentation() : model_container(512, 512, 3, 1, 1, IMAGE_SEGMENTATION) {} -}; - -detection obj_od; -classification obj_ic; -segmentation obj_is; -} // namespace sbeID1200 - -namespace sbeID2100 { -class detection : public model_container { - public: - void init() override { - MLOGV("on target model : detection"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - set_output_data({m_outbuf_type, m_outbuf_size / 7}); - set_output_data({m_outbuf_type, m_outbuf_size / 28}); - set_output_data({m_outbuf_type, m_outbuf_size / 28}); - set_output_data({m_outbuf_type, 1}); - } - - public: - int det_block_cnt; - int det_block_size; - - public: - detection() - : model_container(320, 320, 3, 1, 4, OBJECT_DETECTION), - det_block_cnt(11), - det_block_size(7) {} -}; - -class classification : public model_container { - public: - void init() override { - MLOGV("on target model : classification"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({(m_inbuf_type), m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data( - {m_outbuf_type, (int64_t)(m_outbuf_size / sizeof(float))}); - } - - public: - classification() : model_container(224, 224, 3, 1, 1, IMAGE_CLASSIFICATION) {} -}; - -class segmentation : public model_container { - public: - void init() override { - MLOGV("on target model : segemenatation"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data({m_outbuf_type, m_outbuf_size}); - } - - public: - segmentation() : model_container(512, 512, 3, 1, 1, IMAGE_SEGMENTATION) {} -}; - -class mobilebert : public model_container { - public: - void init() override { - MLOGV("on target model [mobile_bert]"); - for (int i = 0; i < m_in_cnt; i++) set_input_data({m_inbuf_type, 384}); - - for (int i = 0; i < m_out_cnt; i++) set_output_data({m_outbuf_type, 384}); - } - - public: - mobilebert() : model_container(384, 384, 3, 3, 2, MOBILE_BERT) {} -}; - -detection obj_od; -classification obj_ic; -segmentation obj_is; -mobilebert obj_bert; -} // namespace sbeID2100 -} // namespace sbe - -#endif \ No newline at end of file diff --git a/mobile_back_samsung/samsung_backend/lib/sbe_utils.hpp b/mobile_back_samsung/samsung_backend/lib/sbe_utils.hpp deleted file mode 100644 index 224c14efc..000000000 --- a/mobile_back_samsung/samsung_backend/lib/sbe_utils.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/* Copyright 2020-2022 Samsung Electronics Co. LTD All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ -#ifndef SBE_UTILS_H_ -#define SBE_UTILS_H_ - -/** - * @file sbe_utils.hpp - * @brief utility for samsung exynos backend - * @date 2022-01-04 - * @author soobong Huh (soobong.huh@samsung.com) - */ - -#include - -namespace sbe { -enum DEVICE_ID { - CORE_INVALID = -1, - CORE_2100 = 0, - CORE_1200, - CORE_2200, - CORE_MAX -}; - -#ifndef LOG_TAG -#define LOG_TAG "sbe" -#endif - -#define LOG_ENABLE -#undef LOG_ENABLE - -#define __SHARP_X(x) #x -#define __STR(x) __SHARP_X(x) -#define _MLOG(_loglevel, fmt, ...) \ - __android_log_print(_loglevel, "MLPerf", \ - "[Backend][" LOG_TAG "] %s:" __STR(__LINE__) ": " fmt \ - "\n", \ - __FUNCTION__, ##__VA_ARGS__) - -#ifdef LOG_ENABLE -#define MLOGV(fmt, ...) _MLOG(ANDROID_LOG_VERBOSE, fmt, ##__VA_ARGS__) -#define MLOGD(fmt, ...) _MLOG(ANDROID_LOG_DEBUG, fmt, ##__VA_ARGS__) -#define MLOGE(fmt, ...) _MLOG(ANDROID_LOG_ERROR, fmt, ##__VA_ARGS__) -#else -#define MLOGV(fmt, ...) _MLOG(ANDROID_LOG_VERBOSE, fmt, ##__VA_ARGS__) -#define MLOGD(fmt, ...) -#define MLOGE(fmt, ...) -#endif -} // namespace sbe -#endif \ No newline at end of file diff --git a/mobile_back_samsung/samsung_backend/lib/type.h b/mobile_back_samsung/samsung_backend/lib/type.h deleted file mode 100644 index 5b45d9f4b..000000000 --- a/mobile_back_samsung/samsung_backend/lib/type.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Copyright 2020 The MLPerf Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ -#ifndef MLPERF_C_TYPE_H_ -#define MLPERF_C_TYPE_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -typedef void* mlperf_backend_ptr_t; - -typedef enum { - MLPERF_SUCCESS = 0, - MLPERF_FAILURE = 1, -} mlperf_status_t; - -// Requirements of the data for a specific input. It contains the type and size -// of that input. -typedef struct { - enum Type { - Float32 = 0, - Uint8 = 1, - Int8 = 2, - Float16 = 3, - Int32 = 4, - Int64 = 5, - }; - - enum Type type; - int64_t size; -} mlperf_data_t; - -const int kMaxMLPerfBackendConfigs = 256; -typedef struct { - const char* accelerator; - uint32_t batch_size; - int count = 0; - const char* keys[kMaxMLPerfBackendConfigs]; - const char* values[kMaxMLPerfBackendConfigs]; -} mlperf_backend_configuration_t; - -typedef struct { - const char* model; - const char* manufacturer; -} mlperf_device_info_t; - -#ifdef __cplusplus -} -#endif // __cplusplus - -#endif // MLPERF_C_TYPE_H_ From f4a916d648a5f604d2602d6c42375c5420c8b804 Mon Sep 17 00:00:00 2001 From: AhmedTElthakeb <38337765+AhmedTElthakeb@users.noreply.github.com> Date: Fri, 4 Nov 2022 01:14:44 -0700 Subject: [PATCH 2/3] Update README.md --- mobile_back_samsung/README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mobile_back_samsung/README.md b/mobile_back_samsung/README.md index 2cacbb2b0..2ae3c31d4 100644 --- a/mobile_back_samsung/README.md +++ b/mobile_back_samsung/README.md @@ -1,13 +1,20 @@ # Building MLPerf Open app with Samsung backend -1. Update the "lib" folder at 'mobile_app_open/mobile_back_samsung/samsung/lib' by copying it from [here](https://github.com/mlcommons/mobile_back_samsung/tree/submission_v2.1_samsung_backend/samsung_libs/mobile_back_samsung/samsung). Here are the .so libs hashes: +1. Update the entire "lib" folder at 'mobile_app_open/mobile_back_samsung/samsung/lib' by copying it from [here](https://github.com/mlcommons/mobile_back_samsung/tree/submission_v2.1_samsung_backend/samsung_libs/mobile_back_samsung/samsung). Here are the .so libs hashes: ``` +dd31eddd832578ade29c473ff03f0b7ec1061eaaabb761108f5291dc7f2e4b6f libc++_shared.so +e2f78216c1a3e0d925e17e4d6e7befbc1a2a853867864c6f30e553bf971f2a42 libc++.so +aaa17ed170b0270a0389bce6765443630e43ab7860364223f2e8c3e54def5372 libeden_nn_on_system.so +acd7000ea36c6f00a0d900574cea8679ca35dd283ca005ee5be5e57721b6a9f2 libenn_extension.so +97202acb183aa26d83f393d185f0f3cd94f648678916c6b27d91a8445f354472 libenn_public_api_cpp.so +cc921615cd844b47871646b30f146048044b55cdb9bf17d3bd9c5f4569ec2efe libofi_rt_framework_user_vendor.so 5aceeaf47af8c3c1847906a12a7b5de70260e5cbd36a70ab2d163c08682399eb libsamsungbackend.so 2104ff038a520180ac4eb6ca5797fa4bd93f1a50943a4412de9bb783947b3194 libsbe1200_core.so 9333a90f065f65610e0ddc788003b33b55c9940f73e665b3d6a0282de11c046c libsbe2100_core.so 959e772790516649eb5454fd17c4219e3778e35af620061e5c62c6c4a88e1d67 libsbe2200_core.so d5a475d949018179c8e6aa18a5e524c79197a55e07092d5a63e04d5da10d281c libsbe2300_core.so + ``` 2. Change directory to the main path (mobile_app_open) 3. Run the build command From e19ff79f53c01c349e93947343b3715e75ee3c31 Mon Sep 17 00:00:00 2001 From: Ahmed Taha ELthakeb Date: Fri, 4 Nov 2022 01:46:02 -0700 Subject: [PATCH 3/3] update --- mobile_back_samsung/samsung/lib/sbe_core.cc | 200 ++-- mobile_back_samsung/samsung/lib/sbe_core.hpp | 168 ++-- mobile_back_samsung/samsung/lib/sbe_helper.cc | 260 ++--- .../samsung/lib/sbe_helper.hpp | 34 +- .../samsung/lib/sbe_loader.hpp | 19 +- .../samsung/lib/sbe_model_container.hpp | 902 ++++++++++-------- mobile_back_samsung/samsung/lib/sbe_utils.hpp | 72 +- 7 files changed, 918 insertions(+), 737 deletions(-) diff --git a/mobile_back_samsung/samsung/lib/sbe_core.cc b/mobile_back_samsung/samsung/lib/sbe_core.cc index 2d0ead8ef..ceed0c520 100644 --- a/mobile_back_samsung/samsung/lib/sbe_core.cc +++ b/mobile_back_samsung/samsung/lib/sbe_core.cc @@ -12,11 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "sbe_core.hpp" - #include - -#include #include #include #include @@ -25,144 +21,160 @@ limitations under the License. #include #include #include +#include #include +#include "sbe_core.hpp" #include "sbe_utils.hpp" using namespace sbe; -static sbe_core_holder* sbe_core = nullptr; +static sbe_core_holder *sbe_core = nullptr; -bool mlperf_backend_matches_hardware(const char** not_allowed_message, - const char** settings, - const mlperf_device_info_t* device_info) { - MLOGD("Check a support manufacturer: %s model: %s", - device_info->manufacturer, device_info->model); - MLOGD("+ mlperf_backend_matches_hardware"); +bool mlperf_backend_matches_hardware(const char **not_allowed_message, const char **settings, + const mlperf_device_info_t *device_info) +{ + MLOGD("Check a support manufacturer: %s model: %s", device_info->manufacturer, device_info->model); + MLOGD("+ mlperf_backend_matches_hardware"); - *not_allowed_message = nullptr; + *not_allowed_message = nullptr; - int support = - core_ctrl::support_sbe(device_info->manufacturer, device_info->model); - if (support != CORE_INVALID && support != CORE_2100) { - MLOGD("backend core selected [%d]", support); - *settings = core_ctrl::get_benchmark_config(support); - return true; - } + int selected = core_ctrl::support_sbe(device_info->manufacturer, device_info->model); + if (selected != CORE_INVALID) + { + MLOGV("backend core selected [%d]", selected); + *settings = core_ctrl::get_benchmark_config(selected); + return true; + } - MLOGD("Soc Not supported. Trying next backend"); - *not_allowed_message = "UnsupportedSoc"; - return false; + MLOGE("Soc Not supported. Trying next backend"); + *not_allowed_message = "UnsupportedSoc"; + return false; } -const char* mlperf_backend_vendor_name(mlperf_backend_ptr_t backend_ptr) { - static const char name[] = "samsung"; - return name; +const char *mlperf_backend_vendor_name(mlperf_backend_ptr_t backend_ptr) +{ + static const char name[] = "samsung"; + return name; } -const char* mlperf_backend_name(mlperf_backend_ptr_t backend_ptr) { - static const char name[] = "samsung"; - return name; +const char* mlperf_backend_accelerator_name(mlperf_backend_ptr_t backend_ptr) +{ + return "samsung npu"; } -const char* mlperf_backend_accelerator_name(mlperf_backend_ptr_t backend_ptr) { - static const char name[] = "npu"; - return name; +const char *mlperf_backend_name(mlperf_backend_ptr_t backend_ptr) +{ + static const char name[] = "samsung"; + return name; } -mlperf_status_t mlperf_backend_flush_queries(mlperf_backend_ptr_t backend_ptr) { - return MLPERF_SUCCESS; +mlperf_status_t mlperf_backend_flush_queries(mlperf_backend_ptr_t backend_ptr) +{ + return MLPERF_SUCCESS; } mlperf_backend_ptr_t mlperf_backend_create( - const char* model_path, mlperf_backend_configuration_t* configs, - const char* native_lib_path) { - MLOGD("mlperf_backend_create", "mlperf_backend_create"); + const char *model_path, mlperf_backend_configuration_t *configs, + const char *native_lib_path) +{ + MLOGD("mlperf_backend_create", "mlperf_backend_create"); - if (sbe_core) { - MLOGD("sbe object exist."); - sbe_core->unload_core_library(); - } + if (sbe_core) + { + MLOGD("sbe object exist."); + sbe_core->unload_core_library(); + } - MLOGD("ready to load sbe library"); - sbe_core = new sbe_core_holder(); - bool ret = sbe_core->load_core_library(native_lib_path); - if (ret == false) return nullptr; - sbe_core->create_fp(model_path, configs, native_lib_path); - MLOGD("ptr of sbe_core[%p]", sbe_core); - return (mlperf_backend_ptr_t)sbe_core; + MLOGD("ready to load sbe library"); + sbe_core = new sbe_core_holder(); + bool ret = sbe_core->load_core_library(native_lib_path); + if (ret == false) + return nullptr; + sbe_core->create_fp(model_path, configs, native_lib_path); + MLOGD("ptr of sbe_core[%p]", sbe_core); + return (mlperf_backend_ptr_t)sbe_core; } -int32_t mlperf_backend_get_input_count(mlperf_backend_ptr_t backend_ptr) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_get_input_count with ptr[%x]", ptr); - return ptr->get_input_count_fp(); +int32_t mlperf_backend_get_input_count(mlperf_backend_ptr_t backend_ptr) +{ + sbe_core_holder *ptr = (sbe_core_holder *)backend_ptr; + MLOGD("+ mlperf_backend_get_input_count with ptr[%x]", ptr); + return ptr->get_input_count_fp(); } -mlperf_data_t mlperf_backend_get_input_type(mlperf_backend_ptr_t backend_ptr, - int32_t i) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_get_input_type with ptr[%p]", ptr); - return ptr->get_input_type_fp(i); +mlperf_data_t mlperf_backend_get_input_type(mlperf_backend_ptr_t backend_ptr, int32_t i) +{ + sbe_core_holder *ptr = (sbe_core_holder *)backend_ptr; + MLOGD("+ mlperf_backend_get_input_type with ptr[%p]", ptr); + return ptr->get_input_type_fp(i); } mlperf_status_t mlperf_backend_set_input(mlperf_backend_ptr_t backend_ptr, int32_t batchIndex, int32_t i, - void* data) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_set_input with ptr[%p]", ptr); - return ptr->set_input_fp(batchIndex, i, data); + void *data) +{ + sbe_core_holder *ptr = (sbe_core_holder *)backend_ptr; + MLOGD("+ mlperf_backend_set_input with sbe_core_holder[%p]", ptr); + return ptr->set_input_fp(batchIndex, i, data); } -int32_t mlperf_backend_get_output_count(mlperf_backend_ptr_t backend_ptr) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_get_output_count with ptr[%p]", ptr); - return ptr->get_output_count_fp(); +int32_t mlperf_backend_get_output_count(mlperf_backend_ptr_t backend_ptr) +{ + sbe_core_holder *ptr = (sbe_core_holder *)backend_ptr; + MLOGD("+ mlperf_backend_get_output_count with ptr[%p]", ptr); + return ptr->get_output_count_fp(); } -mlperf_data_t mlperf_backend_get_output_type(mlperf_backend_ptr_t backend_ptr, - int32_t i) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_get_output_type with ptr[%p]", ptr); - return ptr->get_output_type_fp(i); +mlperf_data_t mlperf_backend_get_output_type(mlperf_backend_ptr_t backend_ptr, int32_t i) +{ + sbe_core_holder *ptr = (sbe_core_holder *)backend_ptr; + MLOGD("+ mlperf_backend_get_output_type with ptr[%p]", ptr); + return ptr->get_output_type_fp(i); } -mlperf_status_t mlperf_backend_issue_query(mlperf_backend_ptr_t backend_ptr) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_issue_query with ptr[%p]", ptr); - return ptr->issue_query_fp(); +mlperf_status_t mlperf_backend_issue_query(mlperf_backend_ptr_t backend_ptr) +{ + sbe_core_holder *ptr = (sbe_core_holder *)backend_ptr; + MLOGD("+ mlperf_backend_issue_query with ptr[%p]", ptr); + return ptr->issue_query_fp(); } mlperf_status_t mlperf_backend_get_output(mlperf_backend_ptr_t backend_ptr, uint32_t batchIndex, int32_t i, - void** data) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_get_output with ptr[%p]", ptr); - return ptr->get_output_fp(batchIndex, i, data); + void **data) +{ + sbe_core_holder *ptr = (sbe_core_holder *)backend_ptr; + MLOGD("+ mlperf_backend_get_output with ptr[%p]", ptr); + return ptr->get_output_fp(batchIndex, i, data); } -void mlperf_backend_convert_inputs(void* backend_ptr, int bytes, int width, - int height, uint8_t* data) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_convert_inputs with ptr[%p]", ptr); - ptr->convert_inputs_fp(bytes, width, height, data); +void mlperf_backend_convert_inputs(void *backend_ptr, + int bytes, int width, int height, uint8_t *data) +{ + sbe_core_holder *ptr = (sbe_core_holder *)backend_ptr; + MLOGD("+ mlperf_backend_convert_inputs with ptr[%p]", ptr); + ptr->convert_inputs_fp(bytes, width, height, data); } -void mlperf_backend_delete(mlperf_backend_ptr_t backend_ptr) { - sbe_core_holder* ptr = (sbe_core_holder*)backend_ptr; - MLOGD("+ mlperf_backend_delete with ptr[%p]", ptr); - ptr->delete_fp(); +void mlperf_backend_delete(mlperf_backend_ptr_t backend_ptr) +{ + sbe_core_holder *ptr = (sbe_core_holder *)backend_ptr; + MLOGD("+ mlperf_backend_delete with ptr[%p]", ptr); + ptr->delete_fp(); - delete (ptr); - ptr = nullptr; + delete (ptr); + ptr = nullptr; } -void* mlperf_backend_get_buffer(size_t size) { - MLOGD("+ mlperf_backend_get_buffer with size[%d]", size); - return sbe_core->get_buffer_fp(size); +void *mlperf_backend_get_buffer(size_t size) +{ + MLOGD("+ mlperf_backend_get_buffer with size[%d]", size); + return sbe_core->get_buffer_fp(size); } -void mlperf_backend_release_buffer(void* p) { - MLOGD("+ mlperf_backend_release_buffer with ptr[%p]", p); - sbe_core->release_buffer_fp(p); +void mlperf_backend_release_buffer(void *p) +{ + MLOGD("+ mlperf_backend_release_buffer with ptr[%p]", p); + sbe_core->release_buffer_fp(p); } \ No newline at end of file diff --git a/mobile_back_samsung/samsung/lib/sbe_core.hpp b/mobile_back_samsung/samsung/lib/sbe_core.hpp index 371f64919..7d2b09018 100644 --- a/mobile_back_samsung/samsung/lib/sbe_core.hpp +++ b/mobile_back_samsung/samsung/lib/sbe_core.hpp @@ -1,3 +1,4 @@ + /* Copyright 2020-2022 Samsung Electronics Co. LTD All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,105 +24,96 @@ limitations under the License. */ #include "backend_c.h" -#include "sbe_helper.hpp" -#include "sbe_loader.hpp" #include "type.h" +#include "sbe_loader.hpp" +#include "sbe_helper.hpp" namespace sbe { class sbe_core_holder { - public: - ~sbe_core_holder() { MLOGD("Destruct a sbe_core_holder object"); } + public: + ~sbe_core_holder() { + MLOGD("Destruct a sbe_core_holder object"); + } - using backend_create_t = std::add_pointer::type; - using backend_get_input_count_t = std::add_pointer::type; - using backend_get_input_type_t = - std::add_pointer::type; - using backend_set_input_t = - std::add_pointer::type; - using backend_get_output_count_t = std::add_pointer::type; - using backend_get_output_type_t = - std::add_pointer::type; - using backend_get_output_t = - std::add_pointer::type; - using backend_issue_query_t = std::add_pointer::type; - using backend_convert_inputs_t = - std::add_pointer::type; - using backend_delete_t = std::add_pointer::type; - using backend_get_buffer_t = std::add_pointer::type; - using backend_release_buffer_t = std::add_pointer::type; + using backend_create_t = std::add_pointer::type; + using backend_get_input_count_t = std::add_pointer::type; + using backend_get_input_type_t = std::add_pointer::type; + using backend_set_input_t = std::add_pointer::type; + using backend_get_output_count_t = std::add_pointer::type; + using backend_get_output_type_t = std::add_pointer::type; + using backend_get_output_t = std::add_pointer::type; + using backend_issue_query_t = std::add_pointer::type; + using backend_convert_inputs_t = std::add_pointer::type; + using backend_delete_t = std::add_pointer::type; + using backend_get_buffer_t = std::add_pointer::type; + using backend_release_buffer_t = std::add_pointer::type; - backend_create_t create_fp; - backend_delete_t delete_fp; - backend_issue_query_t issue_query_fp; - backend_get_input_count_t get_input_count_fp; - backend_get_input_type_t get_input_type_fp; - backend_set_input_t set_input_fp; - backend_get_output_count_t get_output_count_fp; - backend_get_output_type_t get_output_type_fp; - backend_get_output_t get_output_fp; - backend_convert_inputs_t convert_inputs_fp; - backend_get_buffer_t get_buffer_fp; - backend_release_buffer_t release_buffer_fp; + backend_create_t create_fp; + backend_delete_t delete_fp; + backend_issue_query_t issue_query_fp; + backend_get_input_count_t get_input_count_fp; + backend_get_input_type_t get_input_type_fp; + backend_set_input_t set_input_fp; + backend_get_output_count_t get_output_count_fp; + backend_get_output_type_t get_output_type_fp; + backend_get_output_t get_output_fp; + backend_convert_inputs_t convert_inputs_fp; + backend_get_buffer_t get_buffer_fp; + backend_release_buffer_t release_buffer_fp; - bool load_core_library(const char *lib_path) { - char *error = nullptr; - /* load sbe core */ - int core_id = core_ctrl::get_core_id(); - MLOGD("acquired core id[%d]", core_id); + bool load_core_library(const char* lib_path) + { + char *error = nullptr; + /* load sbe core */ + sbe::core_id = core_ctrl::get_core_id(); + MLOGD("acquired core id[%d]", sbe::core_id); - if (core_id == CORE_INVALID) { - MLOGD("fail to get sbe core libarary. core_id[%d]", core_id); - return false; - } + if(core_id == CORE_INVALID) { + MLOGE("fail to get sbe core libarary. core_id[%d]", sbe::core_id); + return false; + } - std::string core_lib_path = - std::string(lib_path) + "/" + sbe_core_libs[core_id]; - void *handle = dlopen(core_lib_path.c_str(), RTLD_NOW); - MLOGD("native library path[%s], handle[%p]", core_lib_path.c_str(), handle); - if (!handle) { - MLOGD("fail to get handle of shared library"); - if ((error = dlerror()) != NULL) { - MLOGD("dlopen error with %s\n", error); - } - return false; - } + std::string core_lib_path = std::string(lib_path) + "/" + sbe_core_libs[sbe::core_id]; + void *handle = dlopen(core_lib_path.c_str(), RTLD_NOW); + MLOGD("native library path[%s], handle[%p]", core_lib_path.c_str(), handle); + if(!handle) { + MLOGE("fail to get handle of shared library"); + if ((error = dlerror()) != NULL) { + MLOGE("dlopen error with %s\n", error); + } + return false; + } - create_fp = link_symbol(handle, backend_create); - delete_fp = link_symbol(handle, backend_delete); - issue_query_fp = link_symbol(handle, backend_issue_query); - get_input_count_fp = link_symbol(handle, backend_get_input_count); - get_input_type_fp = link_symbol(handle, backend_get_input_type); - set_input_fp = link_symbol(handle, backend_set_input); - get_output_count_fp = link_symbol(handle, backend_get_output_count); - get_output_type_fp = link_symbol(handle, backend_get_output_type); - get_output_fp = link_symbol(handle, backend_get_output); - convert_inputs_fp = link_symbol(handle, backend_convert_inputs); - get_buffer_fp = link_symbol(handle, backend_get_buffer); - release_buffer_fp = link_symbol(handle, backend_release_buffer); - return true; - } + create_fp = link_symbol(handle, backend_create); + delete_fp = link_symbol(handle, backend_delete); + issue_query_fp = link_symbol(handle, backend_issue_query); + get_input_count_fp = link_symbol(handle, backend_get_input_count); + get_input_type_fp = link_symbol(handle, backend_get_input_type); + set_input_fp = link_symbol(handle, backend_set_input); + get_output_count_fp = link_symbol(handle, backend_get_output_count); + get_output_type_fp = link_symbol(handle, backend_get_output_type); + get_output_fp = link_symbol(handle, backend_get_output); + convert_inputs_fp = link_symbol(handle, backend_convert_inputs); + get_buffer_fp = link_symbol(handle, backend_get_buffer); + release_buffer_fp = link_symbol(handle, backend_release_buffer); + return true; + } - void unload_core_library() { - /* TODO: to something */ - MLOGD("unload native library"); - } + void unload_core_library() + { + /* TODO: to something */ + MLOGD("unload native library"); + } - sbe_core_holder() - : create_fp(nullptr), - delete_fp(nullptr), - issue_query_fp(nullptr), - get_input_count_fp(nullptr), - get_input_type_fp(nullptr), - set_input_fp(nullptr), - get_output_count_fp(nullptr), - get_output_type_fp(nullptr), - get_output_fp(nullptr), - convert_inputs_fp(nullptr), - get_buffer_fp(nullptr), - release_buffer_fp(nullptr) { - MLOGD("Construct a sbe_core_holder object"); - } + sbe_core_holder():create_fp(nullptr), delete_fp(nullptr), + issue_query_fp(nullptr), get_input_count_fp(nullptr), + get_input_type_fp(nullptr), set_input_fp(nullptr), + get_output_count_fp(nullptr), get_output_type_fp(nullptr), + get_output_fp(nullptr), convert_inputs_fp(nullptr), + get_buffer_fp(nullptr), release_buffer_fp(nullptr) + { + MLOGD("Construct a sbe_core_holder object"); + } }; -} // namespace sbe +} // namespace sbe #endif diff --git a/mobile_back_samsung/samsung/lib/sbe_helper.cc b/mobile_back_samsung/samsung/lib/sbe_helper.cc index 4d7c01cd4..d9d85dc6a 100644 --- a/mobile_back_samsung/samsung/lib/sbe_helper.cc +++ b/mobile_back_samsung/samsung/lib/sbe_helper.cc @@ -12,116 +12,156 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#include "sbe_helper.hpp" - #include - #include +#include +#include +#include "sbe_helper.hpp" -namespace sbe { -static std::string get_core_info() { - std::array buffer; - std::string core_info; - - std::unique_ptr pipe( - popen("getprop | grep ro.hardware", "r"), pclose); - if (!pipe) { - __android_log_print(ANDROID_LOG_INFO, "TAG", - "Can not find Samsung specific information"); - return ""; - } - while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { - core_info += buffer.data(); - } - MLOGD("completed hardware info [%s]", core_info.c_str()); - return core_info; -} - -static bool get_manufacturer(const char *manufacturer) { - MLOGD("Check for support manufacturer[%s]", manufacturer); - if (strstr((char *)manufacturer, "samsung") || - strstr((char *)manufacturer, "Samsung")) - return true; - return false; -} - -static bool retrieve_model_surfix(const char *model, int core_id) { - MLOGD("Check for surfix model[%s] with [%d]", model, core_id); - if (core_id == CORE_2200) { - if (strstr((char *)model, "B") || strstr((char *)model, "B/DS")) - return true; - else if (strstr((char *)model, "UNIVERSAL") || - strstr((char *)model, "universal")) - return true; - } else { - /* TBD */ - return true; - } - return false; -} - -static int get_core_id_from_model(const char *model) { - MLOGD("Check for support model[%s]", model); - int core_id = CORE_INVALID; - - if (strstr((char *)model, "G998") || strstr((char *)model, "G996") || - strstr((char *)model, "G991") || strstr((char *)model, "UNIVERSAL2100")) - core_id = CORE_2100; - else if (strstr((char *)model, "ERD9925") || - strstr((char *)model, "S5E9925") || strstr((char *)model, "S901") || - strstr((char *)model, "S906") || strstr((char *)model, "S908")) - core_id = CORE_2200; - else if (strstr((char *)model, "ERD8825")) - core_id = CORE_1200; - else - return CORE_INVALID; - return retrieve_model_surfix(model, core_id) ? core_id : CORE_INVALID; -} - -static int get_core_id_from_hardware(const char *hardware) { - MLOGD("Check for support hardware[%s]", hardware); - int core_id = CORE_INVALID; - - if (strstr((char *)hardware, "2100")) - core_id = CORE_INVALID; - else if (strstr((char *)hardware, "9925")) - core_id = CORE_2200; - else if (strstr((char *)hardware, "8825")) - core_id = CORE_1200; - else - return CORE_INVALID; - return core_id; -} - -int core_ctrl::support_sbe(const char *manufacturer, const char *model) { - bool is_samsung = get_manufacturer(manufacturer); - int core_id = get_core_id_from_model(model); - if (is_samsung && (core_id > CORE_INVALID)) { - return core_id; - } - return CORE_INVALID; -} - -const char *core_ctrl::get_benchmark_config(int core_id) { - const char *settings = nullptr; - ; - if (core_id == CORE_2100) { - MLOGE("Not supported"); - return settings; - } else if (core_id == CORE_1200) { - settings = sbe1200_config.c_str(); - } else if (core_id == CORE_2200) { - settings = sbe2200_flutter_config.c_str(); - } - return settings; -} - -// called mlperf_create -int core_ctrl::get_core_id() { - std::string temp = get_core_info(); - const char *core_model = temp.c_str(); - MLOGD("check system info. core[%s]", core_model); - if (!core_model) return CORE_INVALID; - return get_core_id_from_hardware(core_model); -} -} // namespace sbe \ No newline at end of file +namespace sbe +{ + static std::string get_core_info() + { + std::array buffer; + std::string core_info; + + std::unique_ptr pipe(popen("getprop | grep ro.hardware", "r"), pclose); + if (!pipe) + { + MLOGD("Can not find Samsung specific information"); + return ""; + } + while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) + { + core_info += buffer.data(); + } + MLOGD("completed hardware info [%s]", core_info.c_str()); + return core_info; + } + + static bool get_manufacturer(const char *manufacturer) + { + MLOGD("Check for support manufacturer[%s]", manufacturer); + if (strstr((char *)manufacturer, "samsung") || + strstr((char *)manufacturer, "Samsung")) + return true; + return false; + } + + static bool retrieve_model_surfix(const char *model, int core_id) + { + MLOGD("Check for surfix model[%s] with [%d]", model, core_id); + if (core_id == CORE_2200) + { + if (strstr((char *)model, "B") || + strstr((char *)model, "B/DS")) + return true; + else if (strstr((char *)model, "UNIVERSAL") || + strstr((char *)model, "universal")) + return true; + else if (strstr((char *)model, "ERD") || + strstr((char *)model, "erd")) + return true; + } + else + { + /* TBD 1200, 2100. 2300*/ + return true; + } + return false; + } + + static int get_core_id_from_model(const char *model) + { + MLOGD("Check for support model[%s]", model); + int core_id = CORE_INVALID; + + if (strstr((char *)model, "ERD8825") || + strstr((char *)model, "A536") || + strstr((char *)model, "S5E8825")) + core_id = CORE_1200; + else if (strstr((char *)model, "G998") || + strstr((char *)model, "G996") || + strstr((char *)model, "G991") || + strstr((char *)model, "G998") || + strstr((char *)model, "UNIVERSAL2100")) + core_id = CORE_2100; + else if (strstr((char *)model, "ERD9925") || + strstr((char *)model, "S5E9925") || + strstr((char *)model, "S901") || + strstr((char *)model, "S906") || + strstr((char *)model, "S908")) + core_id = CORE_2200; + else if (strstr((char *)model, "ERD9935") || + strstr((char *)model, "S5E9935") || + strstr((char *)model, "S919O")) + core_id = CORE_2300; + else + return CORE_INVALID; + return retrieve_model_surfix(model, core_id) ? core_id : CORE_INVALID; + } + + static int get_core_id_from_hardware(const char *hardware) + { + MLOGD("Check for support hardware[%s]", hardware); + int core_id = CORE_INVALID; + + if (strstr((char *)hardware, "8825")) + core_id = CORE_1200; + else if (strstr((char *)hardware, "2100")) + core_id = CORE_2100; + else if (strstr((char *)hardware, "9925")) + core_id = CORE_2200; + else if (strstr((char *)hardware, "9935")) + core_id = CORE_2300; + else + return CORE_INVALID; + return core_id; + } + + int core_ctrl::support_sbe(const char *manufacturer, const char *model) + { + std::string version = VERSION(MAJOR, MINOR, PATCH); + MLOGV("sbe version [%s]", version.c_str()); + bool is_samsung = get_manufacturer(manufacturer); + int core_id = get_core_id_from_model(model); + if (is_samsung && (core_id > CORE_INVALID)) + { + return core_id; + } + return CORE_INVALID; + } + + const char *core_ctrl::get_benchmark_config(int core_id) + { + const char *settings = nullptr; + ; + if (core_id == CORE_1200) + { + settings = sbe1200_config.c_str(); + } + else if (core_id == CORE_2100) + { + settings = sbe2100_config.c_str(); + } + else if (core_id == CORE_2200) + { + settings = sbe2200_config.c_str(); + } + else if (core_id == CORE_2300) + { + settings = sbe2300_config.c_str(); + } + return settings; + } + + int core_ctrl::get_core_id() + { + std::string temp = get_core_info(); + const char *core_model = temp.c_str(); + MLOGD("check system info. core[%s]", core_model); + if (!core_model) + return CORE_INVALID; + return get_core_id_from_hardware(core_model); + } +} \ No newline at end of file diff --git a/mobile_back_samsung/samsung/lib/sbe_helper.hpp b/mobile_back_samsung/samsung/lib/sbe_helper.hpp index 3ba2011f8..e3cb9faad 100644 --- a/mobile_back_samsung/samsung/lib/sbe_helper.hpp +++ b/mobile_back_samsung/samsung/lib/sbe_helper.hpp @@ -22,22 +22,28 @@ limitations under the License. * @author soobong Huh (soobong.huh@samsung.com) */ -#include #include -#include - #include - -#include "sbe_config.hpp" +#include +#include +#include #include "sbe_utils.hpp" +#include "sbe_config.hpp" namespace sbe { -class core_ctrl { - public: - static int support_sbe(const char *, const char *); - static const char *get_benchmark_config(int core_id); - static int get_core_id(); -}; -} // namespace sbe - -#endif + static int core_id; + #define DECO(x) #x + #define MAJOR DECO(2) + #define MINOR DECO(3) + #define PATCH DECO(6) + #define VERSION(a, b, c) a "." b "." c + + class core_ctrl { + public: + static int support_sbe(const char *, const char *); + static const char* get_benchmark_config(int); + static int get_core_id(); + }; +} + +#endif \ No newline at end of file diff --git a/mobile_back_samsung/samsung/lib/sbe_loader.hpp b/mobile_back_samsung/samsung/lib/sbe_loader.hpp index 63ef1a97d..bad2b43e1 100644 --- a/mobile_back_samsung/samsung/lib/sbe_loader.hpp +++ b/mobile_back_samsung/samsung/lib/sbe_loader.hpp @@ -23,27 +23,28 @@ limitations under the License. */ #include - -#include "sbe_utils.hpp" #include "type.h" +#include "sbe_utils.hpp" namespace sbe { std::string sbe_core_libs[CORE_MAX] = { - "libsbe1200_core.so", /* TODO it must be replaced to libsbe2100_core */ - "libsbe1200_core.so", - "libsbe2200_core.so", + "libsbe1200_core.so", + "libsbe2100_core.so", + "libsbe2200_core.so", + "libsbe2300_core.so", }; void* load_symbol(void* dl_handle, const char* name) { auto func_pt = dlsym(dl_handle, name); - if (func_pt == nullptr) { - MLOGD("dlopen fail. symbol[%s]", name); + if(func_pt==nullptr) { + MLOGE("dlopen fail. symbol[%s]", name); } return func_pt; } #define link_symbol(dl_handle, symbol_name) \ - reinterpret_cast(load_symbol(dl_handle, #symbol_name)) -} // namespace sbe + reinterpret_cast( \ + load_symbol(dl_handle, #symbol_name)) +} #endif \ No newline at end of file diff --git a/mobile_back_samsung/samsung/lib/sbe_model_container.hpp b/mobile_back_samsung/samsung/lib/sbe_model_container.hpp index 4f16794fd..a0068bcec 100644 --- a/mobile_back_samsung/samsung/lib/sbe_model_container.hpp +++ b/mobile_back_samsung/samsung/lib/sbe_model_container.hpp @@ -8,397 +8,521 @@ * @author soobong Huh (soobong.huh@samsung.com) */ -#include "sbe_utils.hpp" #include "type.h" +#include "sbe_utils.hpp" namespace sbe { -enum MODEL_IDX { - OBJECT_DETECTION = 0, - IMAGE_CLASSIFICATION, - IMAGE_SEGMENTATION, - MOBILE_BERT, - MAX_MODEL_IDX -}; - -class model_container { - public: - int m_model_id; - int m_width; - int m_height; - int m_channel; - - /* mdl config */ - int m_in_cnt; - int m_out_cnt; - int m_inbuf_size; - int m_outbuf_size; - - /* perf config */ - int m_freeze; - bool b_enable_lazy; - bool b_enable_fpc; - - mlperf_data_t::Type m_inbuf_type; - mlperf_data_t::Type m_outbuf_type; - - private: - std::vector m_input_data; - std::vector m_output_data; - - public: - void set_input_data(mlperf_data_t v) { m_input_data.push_back(v); } - - void set_output_data(mlperf_data_t v) { m_output_data.push_back(v); } - - int get_buf_size() { return m_width * m_height * m_channel; } - - int get_input_size() { return m_input_data.size(); } - int get_output_size() { return m_output_data.size(); } - - mlperf_data_t get_input_type(int idx) { return m_input_data.at(idx); } - mlperf_data_t get_output_type(int idx) { return m_output_data.at(idx); } - - void unset_lazy() { b_enable_lazy = false; } - virtual void init() = 0; - - void deinit() { - m_input_data.clear(); - m_input_data.shrink_to_fit(); - - m_output_data.clear(); - m_output_data.shrink_to_fit(); - } - - model_container(int w, int h, int c, int in, int out, int mdl_id) { - m_model_id = mdl_id; - m_width = w; - m_height = h; - m_channel = c; - m_in_cnt = in; - m_out_cnt = out; - m_freeze = 0; - b_enable_lazy = false; - b_enable_fpc = false; - } - - ~model_container() { deinit(); } -}; - -class mdl_attribute_template { - public: - /* model attribute */ - int m_width; - int m_height; - int m_channel; - - int m_in_cnt; - int m_out_cnt; - int m_inbuf_size; - int m_outbuf_size; - - mlperf_data_t::Type m_inbuf_type; - mlperf_data_t::Type m_outbuf_type; - - /* others */ - int m_preset_id; - bool b_enable_fpc; - int m_freeze; - bool b_enable_lazy; - - public: - int get_byte(mlperf_data_t::Type type) { - switch (type) { - case mlperf_data_t::Uint8: - return 1; - case mlperf_data_t::Int8: - return 1; - case mlperf_data_t::Float16: - return 2; - case mlperf_data_t::Int32: - case mlperf_data_t::Float32: - return 4; - case mlperf_data_t::Int64: - return 8; - } - } - - void update(model_container* ptr) { - ptr->m_in_cnt = m_in_cnt; - ptr->m_out_cnt = m_out_cnt; - - ptr->m_inbuf_size = m_inbuf_size; - ptr->m_outbuf_size = m_outbuf_size; - ptr->m_inbuf_type = m_inbuf_type; - ptr->m_outbuf_type = m_outbuf_type; - ptr->b_enable_fpc = b_enable_fpc; - ptr->m_freeze = m_freeze; - ptr->b_enable_lazy = b_enable_lazy; - } - - void show() { - MLOGV("mdl_attribute_template : "); - MLOGV("m_preset_id : %d", m_preset_id); - MLOGV("m_width : %d", m_width); - MLOGV("m_height : %d", m_height); - MLOGV("m_channel : %d", m_channel); - MLOGV("m_in_cnt : %d", m_in_cnt); - MLOGV("m_out_cnt : %d", m_out_cnt); - MLOGV("m_inbuf_size : %d", m_inbuf_size); - MLOGV("m_outbuf_size : %d", m_outbuf_size); - MLOGV("m_inbuf_type : %d", m_inbuf_type); - MLOGV("m_outbuf_type : %d", m_outbuf_type); - MLOGV("b_enable_fpc : %d", b_enable_fpc); - MLOGV("m_freeze : %d", m_freeze); - MLOGV("b_lazy : %d", b_enable_lazy); - } - - public: - mdl_attribute_template() { - m_width = 0; - m_height = 0; - m_channel = 0; - m_in_cnt = 1; - m_out_cnt = 1; - m_inbuf_size = 0; - m_outbuf_size = 0; - m_inbuf_type = mlperf_data_t::Uint8; - m_outbuf_type = mlperf_data_t::Uint8; - m_preset_id = 1001; - b_enable_fpc = false; - m_freeze = 0; - b_enable_lazy = false; - } -}; -mdl_attribute_template mdl_attr; - -namespace sbeID2200 { -class classification : public model_container { - public: - void init() override { - MLOGV("on target model : classification"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({(m_inbuf_type), m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data( - {m_outbuf_type, (int64_t)(m_outbuf_size / sizeof(float))}); - } - - public: - classification() : model_container(224, 224, 3, 1, 1, IMAGE_CLASSIFICATION) {} -}; - -class classification_offline : public model_container { - public: - void init() override { - MLOGV("on target model : classification offline"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data( - {m_outbuf_type, (int64_t)(m_outbuf_size / sizeof(float))}); - } - - public: - classification_offline() - : model_container(224, 224, 3, 1, 1, IMAGE_CLASSIFICATION) {} -}; - -class mobilebert : public model_container { - public: - void init() override { - MLOGV("on target model [mobile_bert]"); - for (int i = 0; i < m_in_cnt; i++) set_input_data({m_inbuf_type, 384}); - - for (int i = 0; i < m_out_cnt; i++) set_output_data({m_outbuf_type, 384}); - } - - public: - mobilebert() : model_container(384, 384, 3, 3, 2, MOBILE_BERT) {} -}; - -class segmentation : public model_container { - public: - void init() override { - MLOGV("on target model : segemenatation"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data({m_outbuf_type, m_outbuf_size}); - } - - public: - segmentation() : model_container(512, 512, 3, 1, 1, IMAGE_SEGMENTATION) {} -}; - -class detection : public model_container { - public: - void init() override { - MLOGV("on target model : detection"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - set_output_data({m_outbuf_type, m_outbuf_size / 7}); - set_output_data({m_outbuf_type, m_outbuf_size / 28}); - set_output_data({m_outbuf_type, m_outbuf_size / 28}); - set_output_data({m_outbuf_type, 1}); - } - - public: - int det_block_cnt; - int det_block_size; - - public: - detection() - : model_container(320, 320, 3, 1, 1, OBJECT_DETECTION), - det_block_cnt(11), - det_block_size(7) {} -}; - -detection obj_od; -classification obj_ic; -classification_offline obj_ic_offline; -segmentation obj_is; -mobilebert obj_bert; -} // namespace sbeID2200 - -namespace sbeID1200 { -class detection : public model_container { - public: - void init() override { - MLOGV("on target model : detection"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - set_output_data({m_outbuf_type, m_outbuf_size / 7}); - set_output_data({m_outbuf_type, m_outbuf_size / 28}); - set_output_data({m_outbuf_type, m_outbuf_size / 28}); - set_output_data({m_outbuf_type, 1}); - } - - public: - int det_block_cnt; - int det_block_size; - - public: - detection() - : model_container(320, 320, 3, 1, 1, OBJECT_DETECTION), - det_block_cnt(11), - det_block_size(7) {} -}; - -class classification : public model_container { - public: - void init() override { - MLOGV("on target model : classification"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({(m_inbuf_type), m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data( - {m_outbuf_type, (int64_t)(m_outbuf_size / sizeof(float))}); - } - - public: - classification() : model_container(224, 224, 3, 1, 1, IMAGE_CLASSIFICATION) {} -}; - -class segmentation : public model_container { - public: - void init() override { - MLOGV("on target model : segemenatation"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data({m_outbuf_type, m_outbuf_size}); - } - - public: - segmentation() : model_container(512, 512, 3, 1, 1, IMAGE_SEGMENTATION) {} -}; - -detection obj_od; -classification obj_ic; -segmentation obj_is; -} // namespace sbeID1200 - -namespace sbeID2100 { -class detection : public model_container { - public: - void init() override { - MLOGV("on target model : detection"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - set_output_data({m_outbuf_type, m_outbuf_size / 7}); - set_output_data({m_outbuf_type, m_outbuf_size / 28}); - set_output_data({m_outbuf_type, m_outbuf_size / 28}); - set_output_data({m_outbuf_type, 1}); - } - - public: - int det_block_cnt; - int det_block_size; - - public: - detection() - : model_container(320, 320, 3, 1, 4, OBJECT_DETECTION), - det_block_cnt(11), - det_block_size(7) {} -}; - -class classification : public model_container { - public: - void init() override { - MLOGV("on target model : classification"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({(m_inbuf_type), m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data( - {m_outbuf_type, (int64_t)(m_outbuf_size / sizeof(float))}); - } - - public: - classification() : model_container(224, 224, 3, 1, 1, IMAGE_CLASSIFICATION) {} -}; - -class segmentation : public model_container { - public: - void init() override { - MLOGV("on target model : segemenatation"); - for (int i = 0; i < m_in_cnt; i++) - set_input_data({m_inbuf_type, m_inbuf_size}); - - for (int i = 0; i < m_out_cnt; i++) - set_output_data({m_outbuf_type, m_outbuf_size}); - } - - public: - segmentation() : model_container(512, 512, 3, 1, 1, IMAGE_SEGMENTATION) {} -}; - -class mobilebert : public model_container { - public: - void init() override { - MLOGV("on target model [mobile_bert]"); - for (int i = 0; i < m_in_cnt; i++) set_input_data({m_inbuf_type, 384}); - - for (int i = 0; i < m_out_cnt; i++) set_output_data({m_outbuf_type, 384}); - } - - public: - mobilebert() : model_container(384, 384, 3, 3, 2, MOBILE_BERT) {} -}; - -detection obj_od; -classification obj_ic; -segmentation obj_is; -mobilebert obj_bert; -} // namespace sbeID2100 -} // namespace sbe + enum MODEL_IDX { + OBJECT_DETECTION = 0, + IMAGE_CLASSIFICATION, + IMAGE_SEGMENTATION, + MOBILE_BERT, + MAX_MODEL_IDX + }; + + enum ACCER_IDX { + NPU = 0, + GPU, + DSP, + NPUDSP, + MAX_ACCER_IDX + }; + + class model_container { + public: + int m_model_id; + int m_batch; + int m_width; + int m_height; + int m_channel; + + /* mdl config */ + int m_in_cnt; + int m_out_cnt; + int m_inbuf_size; + int m_outbuf_size; + + /* perf config */ + bool b_enable_lazy; + bool b_extension; + + mlperf_data_t::Type m_inbuf_type; + mlperf_data_t::Type m_outbuf_type; + + ACCER_IDX m_accer_idx; + + private: + std::vector m_input_data; + std::vector m_output_data; + + public: + void set_input_data(mlperf_data_t v) + { + v.size /= m_batch; + m_input_data.push_back(v); + } + + void set_output_data(mlperf_data_t v) + { + v.size /= m_batch; + m_output_data.push_back(v); + } + + int get_buf_size() + { + return m_batch * m_width * m_height * m_channel; + } + + int get_input_size() { return m_input_data.size(); } + int get_output_size() { return m_output_data.size(); } + + mlperf_data_t get_input_type(int idx) { return m_input_data.at(idx); } + mlperf_data_t get_output_type(int idx) { return m_output_data.at(idx); } + + void unset_lazy() { b_enable_lazy = false; } + virtual void init()=0; + + void deinit() { + m_input_data.clear(); + m_input_data.shrink_to_fit(); + + m_output_data.clear(); + m_output_data.shrink_to_fit(); + } + + model_container(int n, int h, int w, int c, int in, int out, int mdl_id) { + m_model_id = mdl_id; + m_batch = n; + m_width = w; + m_height = h; + m_channel = c; + m_in_cnt = in; + m_out_cnt = out; + b_enable_lazy = false; + b_extension = false; + m_accer_idx = ACCER_IDX::NPU; + } + + ~model_container() { + deinit(); + } + }; + + class mdl_attribute_template { + public: + /* model attribute */ + int m_batch; + int m_width; + int m_height; + int m_channel; + + int m_in_cnt; + int m_out_cnt; + int m_inbuf_size; // total size of inbuf + int m_outbuf_size; // total size of outbuf + + mlperf_data_t::Type m_inbuf_type; + mlperf_data_t::Type m_outbuf_type; + + ACCER_IDX m_accer_idx; + + /* others */ + int m_preset_id; + bool b_extension; + bool b_enable_lazy; + + public: + int get_byte(mlperf_data_t::Type type) { + switch (type) { + case mlperf_data_t::Uint8: + return 1; + case mlperf_data_t::Int8: + return 1; + case mlperf_data_t::Float16: + return 2; + case mlperf_data_t::Int32: + case mlperf_data_t::Float32: + return 4; + case mlperf_data_t::Int64: + return 8; + } + } + + void update(model_container* ptr) + { + IS_VALID(ptr->m_batch, m_batch); + IS_VALID(ptr->m_width, m_width); + IS_VALID(ptr->m_height, m_height); + IS_VALID(ptr->m_channel, m_channel); + + ptr->m_in_cnt = m_in_cnt; + ptr->m_out_cnt = m_out_cnt; + + ptr->m_inbuf_size = m_inbuf_size; + ptr->m_outbuf_size = m_outbuf_size; + ptr->m_inbuf_type = m_inbuf_type; + ptr->m_outbuf_type = m_outbuf_type; + ptr->b_extension = b_extension; + ptr->b_enable_lazy = b_enable_lazy; + ptr->m_accer_idx = m_accer_idx; + } + + void show() { + MLOGV("mdl_attribute_template : "); + MLOGV("m_preset_id : %d", m_preset_id); + MLOGV("m_batch : %d", m_batch); + MLOGV("m_width : %d", m_width); + MLOGV("m_height : %d", m_height); + MLOGV("m_channel : %d", m_channel); + MLOGV("m_in_cnt : %d", m_in_cnt); + MLOGV("m_out_cnt : %d", m_out_cnt); + MLOGV("m_inbuf_size : %d", m_inbuf_size); + MLOGV("m_outbuf_size : %d", m_outbuf_size); + MLOGV("m_inbuf_type : %d", m_inbuf_type); + MLOGV("m_outbuf_type : %d", m_outbuf_type); + MLOGV("b_extension : %d", b_extension); + MLOGV("b_lazy : %d", b_enable_lazy); + MLOGV("m_accer_idx : %d", m_accer_idx); + } + + public: + mdl_attribute_template() { + m_batch=0; + m_width=0; + m_height=0; + m_channel=0; + m_in_cnt=1; + m_out_cnt=1; + m_inbuf_size=0; + m_outbuf_size=0; + m_inbuf_type=mlperf_data_t::Uint8; + m_outbuf_type=mlperf_data_t::Uint8; + m_preset_id=1001; + b_extension=false; + b_enable_lazy = false; + m_accer_idx = ACCER_IDX::NPU; + } + }; + mdl_attribute_template mdl_attr; + namespace sbeID2300 { + class classification : public model_container { + public : + void init() override { + MLOGV("on target model : classification"); + for(int i=0;i namespace sbe { -enum DEVICE_ID { - CORE_INVALID = -1, - CORE_2100 = 0, - CORE_1200, - CORE_2200, - CORE_MAX -}; - -#ifndef LOG_TAG -#define LOG_TAG "sbe" -#endif - -#define LOG_ENABLE -#undef LOG_ENABLE - -#define __SHARP_X(x) #x -#define __STR(x) __SHARP_X(x) -#define _MLOG(_loglevel, fmt, ...) \ - __android_log_print(_loglevel, "MLPerf", \ - "[Backend][" LOG_TAG "] %s:" __STR(__LINE__) ": " fmt \ - "\n", \ - __FUNCTION__, ##__VA_ARGS__) - -#ifdef LOG_ENABLE -#define MLOGV(fmt, ...) _MLOG(ANDROID_LOG_VERBOSE, fmt, ##__VA_ARGS__) -#define MLOGD(fmt, ...) _MLOG(ANDROID_LOG_DEBUG, fmt, ##__VA_ARGS__) -#define MLOGE(fmt, ...) _MLOG(ANDROID_LOG_ERROR, fmt, ##__VA_ARGS__) -#else -#define MLOGV(fmt, ...) _MLOG(ANDROID_LOG_VERBOSE, fmt, ##__VA_ARGS__) -#define MLOGD(fmt, ...) -#define MLOGE(fmt, ...) -#endif -} // namespace sbe + enum DEVICE_ID { + CORE_INVALID=-1, + CORE_1200=0, + CORE_2100, + CORE_2200, + CORE_2300, + CORE_MAX + }; + + #ifndef LOG_TAG + #define LOG_TAG "sbe" + #endif + + #define LOG_ENABLE + #undef LOG_ENABLE + + #define __SHARP_X(x) #x + #define __STR(x) __SHARP_X(x) + #define _MLOG(_loglevel, fmt, ...) \ + __android_log_print(_loglevel, "MLPerf", \ + "[Backend][" LOG_TAG "] %s:" __STR(__LINE__) ": " fmt \ + "\n", \ + __FUNCTION__, ##__VA_ARGS__) + + #ifdef LOG_ENABLE + #define MLOGV(fmt, ...) _MLOG(ANDROID_LOG_VERBOSE, fmt, ##__VA_ARGS__) + #define MLOGD(fmt, ...) _MLOG(ANDROID_LOG_DEBUG, fmt, ##__VA_ARGS__) + #define MLOGE(fmt, ...) _MLOG(ANDROID_LOG_ERROR, fmt, ##__VA_ARGS__) + #else + #define MLOGV(fmt, ...) _MLOG(ANDROID_LOG_VERBOSE, fmt, ##__VA_ARGS__) + #define MLOGD(fmt, ...) + #define MLOGE(fmt, ...) _MLOG(ANDROID_LOG_ERROR, fmt, ##__VA_ARGS__) + #endif + + #define IS_VALID(a, b) \ + if(a != b) { \ + MLOGV("NOT MATCHED ATTR %d, %d", a, b); \ + } +} // namespace sbe #endif \ No newline at end of file