// get run mode // runMode is ACL_HOST which represents app is running in host // runMode is ACL_DEVICE which represents app is running in device aclrtRunMode runMode; ret = aclrtGetRunMode(&runMode); # 获取软件栈的运行模式 if (ret != ACL_SUCCESS) { ERROR_LOG("acl get run mode failed, errorCode = %d", static_cast<int32_t>(ret)); return FAILED; } g_isDevice = (runMode == ACL_DEVICE); INFO_LOG("get run mode success"); return SUCCESS; }
aclError aclRet = aclrtMalloc(&picDevBuffer, devBufferSize, ACL_MEM_MALLOC_NORMAL_ONLY); # 申请内存 if (aclRet != ACL_SUCCESS) { ERROR_LOG("malloc device buffer failed. size is %zu, errorCode is %d", devBufferSize, static_cast<int32_t>(aclRet)); return FAILED; }
ret = modelProcess.CreateInput(picDevBuffer, devBufferSize); # 创建输入 if (ret != SUCCESS) { ERROR_LOG("execute CreateInput failed"); aclrtFree(picDevBuffer); return FAILED; }
ret = modelProcess.CreateOutput(); # 创建输出 if (ret != SUCCESS) { aclrtFree(picDevBuffer); ERROR_LOG("execute CreateOutput failed"); return FAILED; }
for (size_t index = 0; index < sizeof(testFile) / sizeof(testFile[0]); ++index) { INFO_LOG("start to process file:%s", testFile[index].c_str()); // copy image data to device buffer ret = Utils::MemcpyFileToDeviceBuffer(testFile[index], picDevBuffer, devBufferSize); # 移入device buffer if(ret != SUCCESS){ aclrtFree(picDevBuffer); ERROR_LOG("memcpy device buffer failed, index is %zu", index); return FAILED; }
ret = modelProcess.Execute(); # 执行处理 if (ret != SUCCESS) { ERROR_LOG("execute inference failed"); aclrtFree(picDevBuffer); return FAILED; }
// Print the top 5 confidence values with indexes. // Use function [DumpModelOutputResult] if you want to dump results to file in the current directory. modelProcess.OutputModelResult(); # 获得输出
/** * @get input size by index * @param [in] index: input index * @param [out] inputSize: input size of index * @return result */ Result GetInputSizeByIndex(constsize_t index, size_t &inputSize);
/** * @brief create model input * @param [in] inputDataBuffer: input buffer * @param [in] bufferSize: input buffer size * @return result */ Result CreateInput(void *inputDataBuffer, size_t bufferSize);