diff --git a/BasePreparedModel.cpp b/BasePreparedModel.cpp index 31c04b49c..696705ddd 100644 --- a/BasePreparedModel.cpp +++ b/BasePreparedModel.cpp @@ -33,19 +33,22 @@ namespace android::hardware::neuralnetworks::nnhal { using namespace android::nn; static const Timing kNoTiming = {.timeOnDevice = UINT64_MAX, .timeInDriver = UINT64_MAX}; -bool mRemoteCheck = false; -std::shared_ptr mDetectionClient; uint32_t BasePreparedModel::mFileId = 0; void BasePreparedModel::deinitialize() { ALOGV("Entering %s", __func__); + bool is_success = false; mModelInfo->unmapRuntimeMemPools(); auto ret_xml = std::remove(mXmlFile.c_str()); auto ret_bin = std::remove(mBinFile.c_str()); if ((ret_xml != 0) || (ret_bin != 0)) { ALOGW("%s Deletion status of xml:%d, bin:%d", __func__, ret_xml, ret_bin); } - + if (mRemoteCheck && mDetectionClient) { + auto reply = mDetectionClient->release(is_success); + ALOGI("GRPC release response is %d : %s", is_success, reply.c_str()); + setRemoteEnabled(false); + } ALOGV("Exiting %s", __func__); } @@ -62,11 +65,10 @@ bool BasePreparedModel::initialize() { ALOGE("Failed to initialize Model runtime parameters!!"); return false; } - checkRemoteConnection(); mNgraphNetCreator = std::make_shared(mModelInfo, mTargetDevice); if (!mNgraphNetCreator->validateOperations()) return false; - ALOGI("Generating IR Graph"); + ALOGI("Generating IR Graph for Model %u", mFileId); auto ov_model = mNgraphNetCreator->generateGraph(); if (ov_model == nullptr) { ALOGE("%s Openvino model generation failed", __func__); @@ -75,17 +77,31 @@ bool BasePreparedModel::initialize() { try { mPlugin = std::make_unique(mTargetDevice, ov_model); mPlugin->loadNetwork(mXmlFile, mBinFile); - if(mRemoteCheck) { - auto resp = loadRemoteModel(mXmlFile, mBinFile); - ALOGD("%s Load Remote Model returns %d", __func__, resp); - } else { - ALOGD("%s Remote connection unavailable", __func__); - } } catch (const std::exception& ex) { ALOGE("%s Exception !!! %s", __func__, ex.what()); return false; } - + bool disableOffload = false; + for (auto i : mModelInfo->getModelInputIndexes()) { + auto& nnapiOperandType = mModelInfo->getOperand(i).type; + switch (nnapiOperandType) { + case OperandType::FLOAT32: + case OperandType::FLOAT16: + case OperandType::TENSOR_FLOAT32: + case OperandType::TENSOR_FLOAT16: + case OperandType::TENSOR_INT32: + case OperandType::INT32: + break; + default : + ALOGD("GRPC Remote Infer not enabled for %d", nnapiOperandType); + disableOffload = true; + break; + } + if (disableOffload) break; + } + if (!disableOffload) { + loadRemoteModel(mXmlFile, mBinFile); + } ALOGV("Exiting %s", __func__); return true; } @@ -95,38 +111,53 @@ bool BasePreparedModel::checkRemoteConnection() { bool is_success = false; if(getGrpcIpPort(grpc_prop)) { ALOGV("Attempting GRPC via TCP : %s", grpc_prop); + grpc::ChannelArguments args; + args.SetMaxReceiveMessageSize(INT_MAX); + args.SetMaxSendMessageSize(INT_MAX); mDetectionClient = std::make_shared( - grpc::CreateChannel(grpc_prop, grpc::InsecureChannelCredentials())); - if(mDetectionClient) { + grpc::CreateCustomChannel(grpc_prop, grpc::InsecureChannelCredentials(), args), mFileId); + if (mDetectionClient) { auto reply = mDetectionClient->prepare(is_success); ALOGI("GRPC(TCP) prepare response is %d : %s", is_success, reply.c_str()); + } else { + ALOGE("%s mDetectionClient is null", __func__); } } if (!is_success && getGrpcSocketPath(grpc_prop)) { ALOGV("Attempting GRPC via unix : %s", grpc_prop); + grpc::ChannelArguments args; + args.SetMaxReceiveMessageSize(INT_MAX); + args.SetMaxSendMessageSize(INT_MAX); mDetectionClient = std::make_shared( - grpc::CreateChannel(std::string("unix:") + grpc_prop, grpc::InsecureChannelCredentials())); - if(mDetectionClient) { + grpc::CreateCustomChannel(std::string("unix:") + grpc_prop, grpc::InsecureChannelCredentials(), args), mFileId); + if (mDetectionClient) { auto reply = mDetectionClient->prepare(is_success); ALOGI("GRPC(unix) prepare response is %d : %s", is_success, reply.c_str()); + } else { + ALOGE("%s mDetectionClient is null", __func__); } } - mRemoteCheck = is_success; return is_success; } -bool BasePreparedModel::loadRemoteModel(const std::string& ir_xml, const std::string& ir_bin) { - ALOGI("Entering %s", __func__); +void BasePreparedModel::loadRemoteModel(const std::string& ir_xml, const std::string& ir_bin) { + ALOGI("Entering %s for Model %u", __func__, mFileId); bool is_success = false; - if(mDetectionClient) { + if(checkRemoteConnection() && mDetectionClient) { auto reply = mDetectionClient->sendIRs(is_success, ir_xml, ir_bin); ALOGI("sendIRs response GRPC %d %s", is_success, reply.c_str()); + if (reply == "status False") { + ALOGE("%s Model Load Failed",__func__); + } + setRemoteEnabled(is_success); } - else { - ALOGE("%s mDetectionClient is null",__func__); +} + +void BasePreparedModel::setRemoteEnabled(bool flag) { + if(mRemoteCheck != flag) { + ALOGD("GRPC %s Remote Connection", flag ? "ACQUIRED" : "RELEASED"); + mRemoteCheck = flag; } - mRemoteCheck = is_success; - return is_success; } static Return notify(const sp& callback, const ErrorStatus& status, @@ -268,20 +299,14 @@ void asyncExecute(const Request& request, MeasureTiming measure, BasePreparedMod ALOGD("%s Run", __func__); if (measure == MeasureTiming::YES) deviceStart = now(); - if(mRemoteCheck) { - ALOGI("%s GRPC Remote Infer", __func__); - auto reply = mDetectionClient->remote_infer(); - ALOGI("***********GRPC server response************* %s", reply.c_str()); - } - if (!mRemoteCheck || !mDetectionClient->get_status()){ - try { - plugin->infer(); - } catch (const std::exception& ex) { - ALOGE("%s Exception !!! %s", __func__, ex.what()); - notify(callback, ErrorStatus::GENERAL_FAILURE, {}, kNoTiming); - return; - } + try { + plugin->infer(); + } catch (const std::exception& ex) { + ALOGE("%s Exception !!! %s", __func__, ex.what()); + notify(callback, ErrorStatus::GENERAL_FAILURE, {}, kNoTiming); + return; } + if (measure == MeasureTiming::YES) deviceEnd = now(); tensorIndex = 0; @@ -332,50 +357,45 @@ void asyncExecute(const Request& request, MeasureTiming measure, BasePreparedMod return; } - if (mRemoteCheck && mDetectionClient && mDetectionClient->get_status()) { - mDetectionClient->get_output_data(std::to_string(i), (uint8_t*)destPtr, - ngraphNw->getOutputShape(outIndex)); - } else { - switch (operandType) { - case OperandType::TENSOR_INT32: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_FLOAT32: - std::memcpy((uint8_t*)destPtr, srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_BOOL8: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_QUANT8_ASYMM: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_QUANT8_SYMM: - case OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL: - case OperandType::TENSOR_QUANT8_ASYMM_SIGNED: - std::memcpy((int8_t*)destPtr, (int8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_FLOAT16: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_QUANT16_SYMM: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_QUANT16_ASYMM: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - default: - std::memcpy((uint8_t*)destPtr, srcTensor.data(), - srcTensor.get_byte_size()); - break; - } + switch (operandType) { + case OperandType::TENSOR_INT32: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_FLOAT32: + std::memcpy((uint8_t*)destPtr, srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_BOOL8: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_QUANT8_ASYMM: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_QUANT8_SYMM: + case OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL: + case OperandType::TENSOR_QUANT8_ASYMM_SIGNED: + std::memcpy((int8_t*)destPtr, (int8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_FLOAT16: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_QUANT16_SYMM: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_QUANT16_ASYMM: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + default: + std::memcpy((uint8_t*)destPtr, srcTensor.data(), + srcTensor.get_byte_size()); + break; } } @@ -392,6 +412,11 @@ void asyncExecute(const Request& request, MeasureTiming measure, BasePreparedMod } else { returned = notify(callback, ErrorStatus::NONE, modelInfo->getOutputShapes(), kNoTiming); } + + if (!modelInfo->unmapRuntimeMemPools()) { + ALOGE("Failed to unmap the request pool infos"); + } + if (!returned.isOk()) { ALOGE("hidl callback failed to return properly: %s", returned.description().c_str()); } @@ -399,7 +424,7 @@ void asyncExecute(const Request& request, MeasureTiming measure, BasePreparedMod } static std::tuple, Timing> executeSynchronouslyBase( - const Request& request, MeasureTiming measure, BasePreparedModel* preparedModel, + const V1_3::Request& request, MeasureTiming measure, BasePreparedModel* preparedModel, time_point driverStart) { ALOGV("Entering %s", __func__); auto modelInfo = preparedModel->getModelInfo(); @@ -408,7 +433,7 @@ static std::tuple, Timing> executeSynch time_point driverEnd, deviceStart, deviceEnd; std::vector requestPoolInfos; auto errorStatus = modelInfo->setRunTimePoolInfosFromHidlMemories(request.pools); - if (errorStatus != ErrorStatus::NONE) { + if (errorStatus != V1_3::ErrorStatus::NONE) { ALOGE("Failed to set runtime pool info from HIDL memories"); return {ErrorStatus::GENERAL_FAILURE, {}, kNoTiming}; } @@ -427,8 +452,9 @@ static std::tuple, Timing> executeSynch ALOGV("Input index: %d layername : %s", inIndex, inputNodeName.c_str()); //check if remote infer is available //TODO: Need to add FLOAT16 support for remote inferencing - if(mRemoteCheck && mDetectionClient) { - mDetectionClient->add_input_data(std::to_string(i), (uint8_t*)srcPtr, ngraphNw->getOutputShape(inIndex), len); + if(preparedModel->mRemoteCheck && preparedModel->mDetectionClient) { + auto inOperandType = modelInfo->getOperandType(inIndex); + preparedModel->mDetectionClient->add_input_data(std::to_string(i), (uint8_t*)srcPtr, ngraphNw->getOutputShape(inIndex), len, inOperandType); } else { ov::Tensor destTensor; try { @@ -493,12 +519,15 @@ static std::tuple, Timing> executeSynch ALOGV("%s Run", __func__); if (measure == MeasureTiming::YES) deviceStart = now(); - if(mRemoteCheck) { + if(preparedModel->mRemoteCheck) { ALOGI("%s GRPC Remote Infer", __func__); - auto reply = mDetectionClient->remote_infer(); + auto reply = preparedModel->mDetectionClient->remote_infer(); ALOGI("***********GRPC server response************* %s", reply.c_str()); } - if (!mRemoteCheck || !mDetectionClient->get_status()){ + if (!preparedModel->mRemoteCheck || !preparedModel->mDetectionClient->get_status()){ + if(preparedModel->mRemoteCheck) { + preparedModel->setRemoteEnabled(false); + } try { ALOGV("%s Client Infer", __func__); plugin->infer(); @@ -555,9 +584,9 @@ static std::tuple, Timing> executeSynch } //copy output from remote infer //TODO: Add support for other OperandType - if (mRemoteCheck && mDetectionClient && mDetectionClient->get_status()) { - mDetectionClient->get_output_data(std::to_string(i), (uint8_t*)destPtr, - ngraphNw->getOutputShape(outIndex)); + if (preparedModel->mRemoteCheck && preparedModel->mDetectionClient && preparedModel->mDetectionClient->get_status()) { + preparedModel->mDetectionClient->get_output_data(std::to_string(i), (uint8_t*)destPtr, + ngraphNw->getOutputShape(outIndex), expectedLength); } else { switch (operandType) { case OperandType::TENSOR_INT32: @@ -606,8 +635,8 @@ static std::tuple, Timing> executeSynch ALOGE("Failed to update the request pool infos"); return {ErrorStatus::GENERAL_FAILURE, {}, kNoTiming}; } - if (mRemoteCheck && mDetectionClient && mDetectionClient->get_status()) { - mDetectionClient->clear_data(); + if (preparedModel->mRemoteCheck && preparedModel->mDetectionClient && preparedModel->mDetectionClient->get_status()) { + preparedModel->mDetectionClient->clear_data(); } if (measure == MeasureTiming::YES) { @@ -617,6 +646,9 @@ static std::tuple, Timing> executeSynch return {ErrorStatus::NONE, modelInfo->getOutputShapes(), timing}; } ALOGV("Exiting %s", __func__); + if (!modelInfo->unmapRuntimeMemPools()) { + ALOGE("Failed to unmap the request pool infos"); + } return {ErrorStatus::NONE, modelInfo->getOutputShapes(), kNoTiming}; } @@ -631,7 +663,7 @@ Return BasePreparedModel::executeSynchronously(const Request& request, Mea return Void(); } auto [status, outputShapes, timing] = - executeSynchronouslyBase(request, measure, this, driverStart); + executeSynchronouslyBase(convertToV1_3(request), measure, this, driverStart); cb(status, std::move(outputShapes), timing); ALOGV("Exiting %s", __func__); return Void(); @@ -646,12 +678,12 @@ Return BasePreparedModel::executeSynchronously_1_3(const V1_3::Request& re time_point driverStart; if (measure == MeasureTiming::YES) driverStart = now(); - if (!validateRequest(convertToV1_0(request), convertToV1_2(mModelInfo->getModel()))) { + if (!validateRequest(request, mModelInfo->getModel())) { cb(V1_3::ErrorStatus::INVALID_ARGUMENT, {}, kNoTiming); return Void(); } auto [status, outputShapes, timing] = - executeSynchronouslyBase(convertToV1_0(request), measure, this, driverStart); + executeSynchronouslyBase(request, measure, this, driverStart); cb(convertToV1_3(status), std::move(outputShapes), timing); ALOGV("Exiting %s", __func__); return Void(); @@ -820,19 +852,12 @@ Return BasePreparedModel::executeFenced(const V1_3::Request& request1_3, time_point deviceStart, deviceEnd; if (measure == MeasureTiming::YES) deviceStart = now(); - if(mRemoteCheck) { - ALOGI("%s GRPC Remote Infer", __func__); - auto reply = mDetectionClient->remote_infer(); - ALOGI("***********GRPC server response************* %s", reply.c_str()); - } - if (!mRemoteCheck || !mDetectionClient->get_status()){ - try { - mPlugin->infer(); - } catch (const std::exception& ex) { - ALOGE("%s Exception !!! %s", __func__, ex.what()); - cb(V1_3::ErrorStatus::GENERAL_FAILURE, hidl_handle(nullptr), nullptr); - return Void(); - } + try { + mPlugin->infer(); + } catch (const std::exception& ex) { + ALOGE("%s Exception !!! %s", __func__, ex.what()); + cb(V1_3::ErrorStatus::GENERAL_FAILURE, hidl_handle(nullptr), nullptr); + return Void(); } if (measure == MeasureTiming::YES) deviceEnd = now(); @@ -870,50 +895,45 @@ Return BasePreparedModel::executeFenced(const V1_3::Request& request1_3, mModelInfo->updateOutputshapes(i, outDims); } - if (mRemoteCheck && mDetectionClient && mDetectionClient->get_status()) { - mDetectionClient->get_output_data(std::to_string(i), (uint8_t*)destPtr, - mNgraphNetCreator->getOutputShape(outIndex)); - } else { - switch (operandType) { - case OperandType::TENSOR_INT32: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_FLOAT32: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_BOOL8: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_QUANT8_ASYMM: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_QUANT8_SYMM: - case OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL: - case OperandType::TENSOR_QUANT8_ASYMM_SIGNED: - std::memcpy((int8_t*)destPtr, (int8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_FLOAT16: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_QUANT16_SYMM: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - case OperandType::TENSOR_QUANT16_ASYMM: - std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), - srcTensor.get_byte_size()); - break; - default: - std::memcpy((uint8_t*)destPtr, srcTensor.data(), - srcTensor.get_byte_size()); - break; - } + switch (operandType) { + case OperandType::TENSOR_INT32: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_FLOAT32: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_BOOL8: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_QUANT8_ASYMM: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_QUANT8_SYMM: + case OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL: + case OperandType::TENSOR_QUANT8_ASYMM_SIGNED: + std::memcpy((int8_t*)destPtr, (int8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_FLOAT16: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_QUANT16_SYMM: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + case OperandType::TENSOR_QUANT16_ASYMM: + std::memcpy((uint8_t*)destPtr, (uint8_t*)srcTensor.data(), + srcTensor.get_byte_size()); + break; + default: + std::memcpy((uint8_t*)destPtr, srcTensor.data(), + srcTensor.get_byte_size()); + break; } } diff --git a/BasePreparedModel.h b/BasePreparedModel.h index 9fbdd1abd..aef1513fb 100755 --- a/BasePreparedModel.h +++ b/BasePreparedModel.h @@ -49,14 +49,13 @@ namespace android::hardware::neuralnetworks::nnhal { template using vec = std::vector; typedef uint8_t* memory; -extern bool mRemoteCheck; -extern std::shared_ptr mDetectionClient; class BasePreparedModel : public V1_3::IPreparedModel { public: + bool mRemoteCheck = false; BasePreparedModel(const IntelDeviceType device, const Model& model) : mTargetDevice(device) { mModelInfo = std::make_shared(model); - mXmlFile = std::string("/data/vendor/neuralnetworks/") + std::to_string(mFileId) + std::string(".xml"); - mBinFile = std::string("/data/vendor/neuralnetworks/") + std::to_string(mFileId) + std::string(".bin"); + mXmlFile = MODEL_DIR + std::to_string(mFileId) + std::string(".xml"); + mBinFile = MODEL_DIR + std::to_string(mFileId) + std::string(".bin"); mFileId++; } @@ -89,7 +88,8 @@ class BasePreparedModel : public V1_3::IPreparedModel { virtual bool initialize(); virtual bool checkRemoteConnection(); - virtual bool loadRemoteModel(const std::string& ir_xml, const std::string& ir_bin); + virtual void loadRemoteModel(const std::string& ir_xml, const std::string& ir_bin); + virtual void setRemoteEnabled(bool flag); std::shared_ptr getModelInfo() { return mModelInfo; } @@ -98,6 +98,7 @@ class BasePreparedModel : public V1_3::IPreparedModel { std::shared_ptr getPlugin() { return mPlugin; } std::shared_ptr modelPtr; + std::shared_ptr mDetectionClient; protected: virtual void deinitialize(); diff --git a/DetectionClient.cpp b/DetectionClient.cpp index 4d0716180..09e39b1b1 100644 --- a/DetectionClient.cpp +++ b/DetectionClient.cpp @@ -5,10 +5,10 @@ std::string DetectionClient::prepare(bool& flag) { RequestString request; - request.set_value(""); + request.mutable_token()->set_data(mToken); ReplyStatus reply; ClientContext context; - time_point deadline = std::chrono::system_clock::now() + std::chrono::milliseconds(100); + time_point deadline = std::chrono::system_clock::now() + std::chrono::milliseconds(10000); context.set_deadline(deadline); Status status = stub_->prepare(&context, request, &reply); @@ -21,9 +21,26 @@ std::string DetectionClient::prepare(bool& flag) { } } +std::string DetectionClient::release(bool& flag) { + RequestString request; + request.mutable_token()->set_data(mToken); + ReplyStatus reply; + ClientContext context; + + Status status = stub_->release(&context, request, &reply); + + if (status.ok()) { + flag = reply.status(); + return (flag ? "status True" : "status False"); + } else { + return std::string(status.error_message()); + } +} + Status DetectionClient::sendFile(std::string fileName, std::unique_ptr >& writer) { RequestDataChunks request; + request.mutable_token()->set_data(mToken); uint32_t CHUNK_SIZE = 1024 * 1024; std::ifstream fin(fileName, std::ifstream::binary); std::vector buffer(CHUNK_SIZE, 0); @@ -47,6 +64,22 @@ Status DetectionClient::sendFile(std::string fileName, return writer->Finish(); } +bool DetectionClient::isModelLoaded(std::string fileName) { + ReplyStatus reply; + ClientContext context; + RequestString request; + request.mutable_token()->set_data(mToken); + time_point deadline = std::chrono::system_clock::now() + std::chrono::milliseconds(20000); + context.set_deadline(deadline); + status = stub_->loadModel(&context, request, &reply); + if(status.ok()) { + return reply.status(); + } else { + ALOGE("Model Load failure: %s", status.error_message().c_str()); + } + return false; +} + std::string DetectionClient::sendIRs(bool& flag, const std::string& ir_xml, const std::string& ir_bin) { ReplyStatus reply; ClientContext context; @@ -62,25 +95,75 @@ std::string DetectionClient::sendIRs(bool& flag, const std::string& ir_xml, cons status = sendFile(ir_bin, writerBin); if (status.ok()) { flag = reply.status(); - return (flag ? "status True" : "status False"); + //if model is sent succesfully trigger model loading + if (flag && isModelLoaded(ir_xml) ) { + flag = true; + return ("status True"); + } else { + flag = false; + ALOGE("Model Loading Failed!!!"); + return ("status False"); + } + } else { + return ("status False"); } } return std::string(status.error_message()); } -void DetectionClient::add_input_data(std::string label, const uint8_t* buffer, std::vector shape, uint32_t size) { +void DetectionClient::add_input_data(std::string label, const uint8_t* buffer, std::vector shape, uint32_t size, android::hardware::neuralnetworks::nnhal::OperandType operandType) { const float* src; size_t index; DataTensor* input = request.add_data_tensors(); input->set_node_name(label); + switch(operandType) { + case android::hardware::neuralnetworks::nnhal::OperandType::TENSOR_INT32: { + input->set_data_type(DataTensor::i32); + break; + } + case android::hardware::neuralnetworks::nnhal::OperandType::TENSOR_FLOAT16: { + input->set_data_type(DataTensor::f16); + break; + } + case android::hardware::neuralnetworks::nnhal::OperandType::TENSOR_FLOAT32: { + input->set_data_type(DataTensor::f32); + break; + } + case android::hardware::neuralnetworks::nnhal::OperandType::TENSOR_BOOL8: { + input->set_data_type(DataTensor::boolean); + break; + } + case android::hardware::neuralnetworks::nnhal::OperandType::TENSOR_QUANT8_ASYMM: { + input->set_data_type(DataTensor::u8); + break; + } + case android::hardware::neuralnetworks::nnhal::OperandType::TENSOR_QUANT8_SYMM: + case android::hardware::neuralnetworks::nnhal::OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL: + case android::hardware::neuralnetworks::nnhal::OperandType::TENSOR_QUANT8_ASYMM_SIGNED: { + input->set_data_type(DataTensor::i8); + break; + } + case android::hardware::neuralnetworks::nnhal::OperandType::TENSOR_QUANT16_SYMM: { + input->set_data_type(DataTensor::i16); + break; + } + case android::hardware::neuralnetworks::nnhal::OperandType::TENSOR_QUANT16_ASYMM: { + input->set_data_type(DataTensor::u16); + break; + } + default: { + input->set_data_type(DataTensor::u8); + break; + } + } for (index = 0; index < shape.size(); index++) { input->add_tensor_shape(shape[index]); } input->set_data(buffer, size); } -void DetectionClient::get_output_data(std::string label, uint8_t* buffer, std::vector shape) { +void DetectionClient::get_output_data(std::string label, uint8_t* buffer, std::vector shape, uint32_t expectedLength) { std::string src; size_t index; size_t size = 1; @@ -91,6 +174,9 @@ void DetectionClient::get_output_data(std::string label, uint8_t* buffer, std::v for (index = 0; index < reply.data_tensors_size(); index++) { if (label.compare(reply.data_tensors(index).node_name()) == 0) { src = reply.data_tensors(index).data(); + if(expectedLength != src.length()) { + ALOGE("Length Mismatch error: expected length %d , actual length %d", expectedLength, src.length()); + } memcpy(buffer, src.data(), src.length()); break; } @@ -104,9 +190,10 @@ void DetectionClient::clear_data() { std::string DetectionClient::remote_infer() { ClientContext context; - time_point deadline = std::chrono::system_clock::now() + std::chrono::milliseconds(20000); + time_point deadline = std::chrono::system_clock::now() + std::chrono::milliseconds(10000); context.set_deadline(deadline); + request.mutable_token()->set_data(mToken); status = stub_->getInferResult(&context, request, &reply); if (status.ok()) { if (reply.data_tensors_size() == 0) ALOGE("GRPC reply empty, ovms failure ?"); diff --git a/DetectionClient.h b/DetectionClient.h index dece36ae4..dcfe2ec70 100644 --- a/DetectionClient.h +++ b/DetectionClient.h @@ -8,6 +8,7 @@ #include #include #include "nnhal_object_detection.grpc.pb.h" +#include "Driver.h" using grpc::Channel; using grpc::ClientContext; @@ -22,19 +23,23 @@ using objectDetection::RequestDataTensors; using objectDetection::RequestString; using time_point = std::chrono::system_clock::time_point; +#define MODEL_DIR std::string("/data/vendor/neuralnetworks/") + class DetectionClient { public: - DetectionClient(std::shared_ptr channel) : stub_(Detection::NewStub(channel)){} + DetectionClient(std::shared_ptr channel, uint32_t token) : stub_(Detection::NewStub(channel)), mToken(token) {} std::string prepare(bool& flag); + std::string release(bool& flag); Status sendFile(std::string fileName, std::unique_ptr >& writer); std::string sendIRs(bool& flag, const std::string& ir_xml, const std::string& ir_bin); + bool isModelLoaded(std::string fileName); - void add_input_data(std::string label, const uint8_t* buffer, std::vector shape, uint32_t size); - void get_output_data(std::string label, uint8_t* buffer, std::vector shape); + void add_input_data(std::string label, const uint8_t* buffer, std::vector shape, uint32_t size, android::hardware::neuralnetworks::nnhal::OperandType operandType); + void get_output_data(std::string label, uint8_t* buffer, std::vector shape, uint32_t expectedLength); void clear_data(); std::string remote_infer(); bool get_status(); @@ -44,6 +49,7 @@ class DetectionClient { RequestDataTensors request; ReplyDataTensors reply; Status status; + uint32_t mToken; }; #endif \ No newline at end of file diff --git a/Driver.cpp b/Driver.cpp index 36fcec5a1..df1bc3729 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -403,6 +403,7 @@ Return Driver::prepareModel_1_3( // TODO: make asynchronous later sp driverPreparedModel = ModelFactory(mDeviceType, model); + for (auto& opn : model.main.operations) dumpOperation(opn); if (!driverPreparedModel->initialize()) { ALOGI("Failed to initialize prepared model"); cb->notify_1_3(convertToV1_3(ErrorStatus::INVALID_ARGUMENT), nullptr); diff --git a/ModelManager.cpp b/ModelManager.cpp index e162ec55a..e1d0e6ebe 100644 --- a/ModelManager.cpp +++ b/ModelManager.cpp @@ -233,6 +233,31 @@ void* NnapiModelInfo::getBlobFromMemoryPoolIn(const Request& request, uint32_t i return (r.buffer + arg.location.offset); } +void* NnapiModelInfo::getBlobFromMemoryPoolIn(const V1_3::Request& request, uint32_t index, + uint32_t& rBufferLength) { + RunTimeOperandInfo& operand = mOperands[mModel.main.inputIndexes[index]]; + const V1_0::RequestArgument& arg = request.inputs[index]; + auto poolIndex = arg.location.poolIndex; + nnAssert(poolIndex < mRequestPoolInfos.size()); + auto& r = mRequestPoolInfos[poolIndex]; + + if (arg.dimensions.size() > 0) { + // It's the responsibility of the caller to validate that + // from.dimensions only modifies the dimensions that were + // unspecified in the model. That's the case in SampleDriver.cpp + // with the call to validateRequest(). + operand.dimensions = arg.dimensions; + } + + operand.buffer = r.buffer + arg.location.offset; + operand.length = arg.location.length; + ALOGV("%s Operand length:%d pointer:%p offset:%d pool index: %d", __func__, operand.length, + (r.buffer + arg.location.offset), arg.location.offset, poolIndex); + rBufferLength = operand.length; + + return (r.buffer + arg.location.offset); +} + void* NnapiModelInfo::getBlobFromMemoryPoolOut(const Request& request, uint32_t index, uint32_t& rBufferLength) { RunTimeOperandInfo& operand = mOperands[mModel.main.outputIndexes[index]]; @@ -260,6 +285,33 @@ void* NnapiModelInfo::getBlobFromMemoryPoolOut(const Request& request, uint32_t return (r.buffer + arg.location.offset); } +void* NnapiModelInfo::getBlobFromMemoryPoolOut(const V1_3::Request& request, uint32_t index, + uint32_t& rBufferLength) { + RunTimeOperandInfo& operand = mOperands[mModel.main.outputIndexes[index]]; + const V1_0::RequestArgument& arg = request.outputs[index]; + auto poolIndex = arg.location.poolIndex; + nnAssert(poolIndex < mRequestPoolInfos.size()); + auto& r = mRequestPoolInfos[poolIndex]; + + ALOGV("%s lifetime:%d location offset:%d length:%d pool index:%d", __func__, operand.lifetime, + arg.location.offset, arg.location.length, poolIndex); + + if (arg.dimensions.size() > 0) { + // It's the responsibility of the caller to validate that + // from.dimensions only modifies the dimensions that were + // unspecified in the model. That's the case in SampleDriver.cpp + // with the call to validateRequest(). + operand.dimensions = arg.dimensions; + } + + operand.buffer = r.buffer + arg.location.offset; + operand.length = arg.location.length; + rBufferLength = operand.length; + ALOGV("%s Operand length:%d pointer:%p", __func__, operand.length, + (r.buffer + arg.location.offset)); + return (r.buffer + arg.location.offset); +} + bool NnapiModelInfo::isOmittedInput(int operationIndex, uint32_t index) { uint32_t inputIndex = mModel.main.operations[operationIndex].inputs[index]; const auto op = mModel.main.operands[inputIndex]; diff --git a/ModelManager.h b/ModelManager.h index 67e1a4b3d..2ba2454ff 100755 --- a/ModelManager.h +++ b/ModelManager.h @@ -133,7 +133,6 @@ class NnapiModelInfo { const auto value = GetConstOperand(inputIndex); ALOGV("Operation input index: %d, operand index: %d", index, inputIndex); ALOGV("Operation: %s", toString(mModel.main.operations[operationIndex]).c_str()); - printHelper::print(value, toString(operand).c_str()); return value; } @@ -167,7 +166,9 @@ class NnapiModelInfo { T GetConstFromBuffer(const uint8_t* buf, uint32_t len); void* getBlobFromMemoryPoolIn(const Request& request, uint32_t index, uint32_t& rBufferLength); + void* getBlobFromMemoryPoolIn(const V1_3::Request& request, uint32_t index, uint32_t& rBufferLength); void* getBlobFromMemoryPoolOut(const Request& request, uint32_t index, uint32_t& rBufferLength); + void* getBlobFromMemoryPoolOut(const V1_3::Request& request, uint32_t index, uint32_t& rBufferLength); Model getModel() { return mModel; } @@ -185,10 +186,11 @@ class NnapiModelInfo { std::vector getOutputShapes() { return mOutputShapes; } - void unmapRuntimeMemPools() { + bool unmapRuntimeMemPools() { for (auto& runtimeInfo : mRequestPoolInfos) { runtimeInfo.unmap_mem(); } + return true; } bool isOmittedInput(int operationIndex, uint32_t index); diff --git a/ngraph_creator/Android.bp b/ngraph_creator/Android.bp index 5a4175aa6..3199dee87 100755 --- a/ngraph_creator/Android.bp +++ b/ngraph_creator/Android.bp @@ -35,6 +35,7 @@ cc_library_static { "operations/src/Greater.cpp", "operations/src/GreaterEqual.cpp", "operations/src/GroupedConv2d.cpp", + "operations/src/HardSwish.cpp", "operations/src/InstanceNormalization.cpp", "operations/src/L2Normalization.cpp", "operations/src/L2Pooling2D.cpp", diff --git a/ngraph_creator/include/OperationsFactory.hpp b/ngraph_creator/include/OperationsFactory.hpp index 11331071d..712eafc7f 100644 --- a/ngraph_creator/include/OperationsFactory.hpp +++ b/ngraph_creator/include/OperationsFactory.hpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -89,6 +90,7 @@ namespace nnhal { class OperationsFactory { private: std::shared_ptr mNgraphNodes; + GraphMetadata mGraphMetadata; public: OperationsFactory(IntelDeviceType deviceType, std::shared_ptr modelInfo, diff --git a/ngraph_creator/operations/include/Abs.hpp b/ngraph_creator/operations/include/Abs.hpp index 09c410619..051b7a5ad 100644 --- a/ngraph_creator/operations/include/Abs.hpp +++ b/ngraph_creator/operations/include/Abs.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Abs : public OperationsBase { public: - Abs(int operationIndex); + Abs(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Add.hpp b/ngraph_creator/operations/include/Add.hpp index 26016feb5..55dcbdb36 100644 --- a/ngraph_creator/operations/include/Add.hpp +++ b/ngraph_creator/operations/include/Add.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Add : public OperationsBase { public: - Add(int operationIndex); + Add(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; std::shared_ptr createNodeForPlugin() override; diff --git a/ngraph_creator/operations/include/Argmax.hpp b/ngraph_creator/operations/include/Argmax.hpp index 74ceb439d..ec55c7a13 100644 --- a/ngraph_creator/operations/include/Argmax.hpp +++ b/ngraph_creator/operations/include/Argmax.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Argmax : public OperationsBase { public: - Argmax(int operationIndex); + Argmax(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Argmin.hpp b/ngraph_creator/operations/include/Argmin.hpp index 2b21217d6..b4d4c4ad0 100644 --- a/ngraph_creator/operations/include/Argmin.hpp +++ b/ngraph_creator/operations/include/Argmin.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Argmin : public OperationsBase { public: - Argmin(int operationIndex); + Argmin(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/AveragePool2D.hpp b/ngraph_creator/operations/include/AveragePool2D.hpp index 80afd7820..493b39c43 100644 --- a/ngraph_creator/operations/include/AveragePool2D.hpp +++ b/ngraph_creator/operations/include/AveragePool2D.hpp @@ -9,7 +9,7 @@ namespace nnhal { class AveragePool2D : public OperationsBase { public: - AveragePool2D(int operationIndex); + AveragePool2D(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/BatchToSpace.hpp b/ngraph_creator/operations/include/BatchToSpace.hpp index 4f150799e..ada4a2706 100644 --- a/ngraph_creator/operations/include/BatchToSpace.hpp +++ b/ngraph_creator/operations/include/BatchToSpace.hpp @@ -9,7 +9,7 @@ namespace nnhal { class BatchToSpace : public OperationsBase { public: - BatchToSpace(int operationIndex); + BatchToSpace(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/BidirectionalSequenceRNN.hpp b/ngraph_creator/operations/include/BidirectionalSequenceRNN.hpp index 60d1fb2b7..a4d0aa8e9 100644 --- a/ngraph_creator/operations/include/BidirectionalSequenceRNN.hpp +++ b/ngraph_creator/operations/include/BidirectionalSequenceRNN.hpp @@ -9,7 +9,7 @@ namespace nnhal { class BidirectionalSequenceRNN : public OperationsBase { public: - BidirectionalSequenceRNN(int operationIndex); + BidirectionalSequenceRNN(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; void connectOperationToGraph() override; bool isValidInputTensor(uint32_t inputIndex); diff --git a/ngraph_creator/operations/include/Cast.hpp b/ngraph_creator/operations/include/Cast.hpp index 7a045d07e..222b8ac47 100644 --- a/ngraph_creator/operations/include/Cast.hpp +++ b/ngraph_creator/operations/include/Cast.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Cast : public OperationsBase { public: - Cast(int operationIndex); + Cast(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; void connectOperationToGraph() override; }; diff --git a/ngraph_creator/operations/include/ChannelShuffle.hpp b/ngraph_creator/operations/include/ChannelShuffle.hpp index b81498046..29574f31a 100644 --- a/ngraph_creator/operations/include/ChannelShuffle.hpp +++ b/ngraph_creator/operations/include/ChannelShuffle.hpp @@ -9,7 +9,7 @@ namespace nnhal { class ChannelShuffle : public OperationsBase { public: - ChannelShuffle(int operationIndex); + ChannelShuffle(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Concat.hpp b/ngraph_creator/operations/include/Concat.hpp index 7f3b694bd..ae94ee6a4 100644 --- a/ngraph_creator/operations/include/Concat.hpp +++ b/ngraph_creator/operations/include/Concat.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Concat : public OperationsBase { public: - Concat(int operationIndex); + Concat(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Conv2d.hpp b/ngraph_creator/operations/include/Conv2d.hpp index a548f4aef..9118c50fc 100644 --- a/ngraph_creator/operations/include/Conv2d.hpp +++ b/ngraph_creator/operations/include/Conv2d.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Conv2d : public OperationsBase { public: - Conv2d(int operationIndex); + Conv2d(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/DepthToSpace.hpp b/ngraph_creator/operations/include/DepthToSpace.hpp index 8dd2baf6c..2f0b1eaaf 100644 --- a/ngraph_creator/operations/include/DepthToSpace.hpp +++ b/ngraph_creator/operations/include/DepthToSpace.hpp @@ -9,7 +9,7 @@ namespace nnhal { class DepthToSpace : public OperationsBase { public: - DepthToSpace(int operationIndex); + DepthToSpace(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/DepthwiseConv2d.hpp b/ngraph_creator/operations/include/DepthwiseConv2d.hpp index 20a70fa0f..6d14b9a5b 100644 --- a/ngraph_creator/operations/include/DepthwiseConv2d.hpp +++ b/ngraph_creator/operations/include/DepthwiseConv2d.hpp @@ -9,7 +9,7 @@ namespace nnhal { class DepthwiseConv2d : public OperationsBase { public: - DepthwiseConv2d(int operationIndex); + DepthwiseConv2d(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Dequantize.hpp b/ngraph_creator/operations/include/Dequantize.hpp index 7e4b7a810..e2a88648c 100644 --- a/ngraph_creator/operations/include/Dequantize.hpp +++ b/ngraph_creator/operations/include/Dequantize.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Dequantize : public OperationsBase { public: - Dequantize(int operationIndex); + Dequantize(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Div.hpp b/ngraph_creator/operations/include/Div.hpp index c3887dbef..8639c0acf 100644 --- a/ngraph_creator/operations/include/Div.hpp +++ b/ngraph_creator/operations/include/Div.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Div : public OperationsBase { public: - Div(int operationIndex); + Div(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/EmbeddingLookup.hpp b/ngraph_creator/operations/include/EmbeddingLookup.hpp index cbf4bb3d3..b03eda57d 100644 --- a/ngraph_creator/operations/include/EmbeddingLookup.hpp +++ b/ngraph_creator/operations/include/EmbeddingLookup.hpp @@ -9,7 +9,7 @@ namespace nnhal { class EmbeddingLookup : public OperationsBase { public: - EmbeddingLookup(int operationIndex); + EmbeddingLookup(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Equal.hpp b/ngraph_creator/operations/include/Equal.hpp index 3586d42f9..aeb013222 100644 --- a/ngraph_creator/operations/include/Equal.hpp +++ b/ngraph_creator/operations/include/Equal.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Equal : public OperationsBase { public: - Equal(int operationIndex); + Equal(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Exp.hpp b/ngraph_creator/operations/include/Exp.hpp index 0520428c2..bd54dfc13 100644 --- a/ngraph_creator/operations/include/Exp.hpp +++ b/ngraph_creator/operations/include/Exp.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Exp : public OperationsBase { public: - Exp(int operationIndex); + Exp(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/ExpandDims.hpp b/ngraph_creator/operations/include/ExpandDims.hpp index 1ea7bc642..c2e0927a8 100644 --- a/ngraph_creator/operations/include/ExpandDims.hpp +++ b/ngraph_creator/operations/include/ExpandDims.hpp @@ -9,7 +9,7 @@ namespace nnhal { class ExpandDims : public OperationsBase { public: - ExpandDims(int operationIndex); + ExpandDims(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Floor.hpp b/ngraph_creator/operations/include/Floor.hpp index 5e3564ed1..9300c3023 100644 --- a/ngraph_creator/operations/include/Floor.hpp +++ b/ngraph_creator/operations/include/Floor.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Floor : public OperationsBase { public: - Floor(int operationIndex); + Floor(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/FullyConnected.hpp b/ngraph_creator/operations/include/FullyConnected.hpp index d093192b3..f3268fa8b 100644 --- a/ngraph_creator/operations/include/FullyConnected.hpp +++ b/ngraph_creator/operations/include/FullyConnected.hpp @@ -9,7 +9,7 @@ namespace nnhal { class FullyConnected : public OperationsBase { public: - FullyConnected(int operationIndex); + FullyConnected(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Gather.hpp b/ngraph_creator/operations/include/Gather.hpp index 26bac1f84..fe41eeda3 100644 --- a/ngraph_creator/operations/include/Gather.hpp +++ b/ngraph_creator/operations/include/Gather.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Gather : public OperationsBase { public: - Gather(int operationIndex); + Gather(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Greater.hpp b/ngraph_creator/operations/include/Greater.hpp index 1359a5314..5ebba0dc9 100644 --- a/ngraph_creator/operations/include/Greater.hpp +++ b/ngraph_creator/operations/include/Greater.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Greater : public OperationsBase { public: - Greater(int operationIndex); + Greater(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/GreaterEqual.hpp b/ngraph_creator/operations/include/GreaterEqual.hpp index fdf54e5e5..670275c2c 100644 --- a/ngraph_creator/operations/include/GreaterEqual.hpp +++ b/ngraph_creator/operations/include/GreaterEqual.hpp @@ -9,7 +9,7 @@ namespace nnhal { class GreaterEqual : public OperationsBase { public: - GreaterEqual(int operationIndex); + GreaterEqual(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/GroupedConv2d.hpp b/ngraph_creator/operations/include/GroupedConv2d.hpp index 46cf485fb..038bc74eb 100644 --- a/ngraph_creator/operations/include/GroupedConv2d.hpp +++ b/ngraph_creator/operations/include/GroupedConv2d.hpp @@ -9,7 +9,7 @@ namespace nnhal { class GroupedConv2d : public OperationsBase { public: - GroupedConv2d(int operationIndex); + GroupedConv2d(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/HardSwish.hpp b/ngraph_creator/operations/include/HardSwish.hpp new file mode 100644 index 000000000..d12883022 --- /dev/null +++ b/ngraph_creator/operations/include/HardSwish.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include + +namespace android { +namespace hardware { +namespace neuralnetworks { +namespace nnhal { + +class HardSwish : public OperationsBase { +public: + HardSwish(int operationIndex, GraphMetadata graphMetadata); + bool validate() override; + std::shared_ptr createNode() override; +}; + +} // namespace nnhal +} // namespace neuralnetworks +} // namespace hardware +} // namespace android diff --git a/ngraph_creator/operations/include/InstanceNormalization.hpp b/ngraph_creator/operations/include/InstanceNormalization.hpp index 5eaf40ac4..293b671f5 100755 --- a/ngraph_creator/operations/include/InstanceNormalization.hpp +++ b/ngraph_creator/operations/include/InstanceNormalization.hpp @@ -9,7 +9,7 @@ namespace nnhal { class InstanceNormalization : public OperationsBase { public: - InstanceNormalization(int operationIndex); + InstanceNormalization(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/L2Normalization.hpp b/ngraph_creator/operations/include/L2Normalization.hpp index e0592c6d2..30c2aa51b 100644 --- a/ngraph_creator/operations/include/L2Normalization.hpp +++ b/ngraph_creator/operations/include/L2Normalization.hpp @@ -9,7 +9,7 @@ namespace nnhal { class L2Normalization : public OperationsBase { public: - L2Normalization(int operationIndex); + L2Normalization(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/L2Pooling2D.hpp b/ngraph_creator/operations/include/L2Pooling2D.hpp index 56bd049d9..81d525d80 100644 --- a/ngraph_creator/operations/include/L2Pooling2D.hpp +++ b/ngraph_creator/operations/include/L2Pooling2D.hpp @@ -9,7 +9,7 @@ namespace nnhal { class L2Pooling2D : public OperationsBase { public: - L2Pooling2D(int operationIndex); + L2Pooling2D(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/LSTM.hpp b/ngraph_creator/operations/include/LSTM.hpp index 59983c9ae..ebed3682d 100644 --- a/ngraph_creator/operations/include/LSTM.hpp +++ b/ngraph_creator/operations/include/LSTM.hpp @@ -9,7 +9,7 @@ namespace nnhal { class LSTM : public OperationsBase { public: - LSTM(int operationIndex); + LSTM(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; void connectOperationToGraph() override; diff --git a/ngraph_creator/operations/include/Less.hpp b/ngraph_creator/operations/include/Less.hpp index 36a06bec8..8f8181172 100644 --- a/ngraph_creator/operations/include/Less.hpp +++ b/ngraph_creator/operations/include/Less.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Less : public OperationsBase { public: - Less(int operationIndex); + Less(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/LessEqual.hpp b/ngraph_creator/operations/include/LessEqual.hpp index ecb190a3c..2a1642652 100644 --- a/ngraph_creator/operations/include/LessEqual.hpp +++ b/ngraph_creator/operations/include/LessEqual.hpp @@ -9,7 +9,7 @@ namespace nnhal { class LessEqual : public OperationsBase { public: - LessEqual(int operationIndex); + LessEqual(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Log.hpp b/ngraph_creator/operations/include/Log.hpp index 29f99bd50..4964ef588 100644 --- a/ngraph_creator/operations/include/Log.hpp +++ b/ngraph_creator/operations/include/Log.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Log : public OperationsBase { public: - Log(int operationIndex); + Log(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/LogSoftmax.hpp b/ngraph_creator/operations/include/LogSoftmax.hpp index 87a0c9ae8..ae3d334e7 100644 --- a/ngraph_creator/operations/include/LogSoftmax.hpp +++ b/ngraph_creator/operations/include/LogSoftmax.hpp @@ -9,7 +9,7 @@ namespace nnhal { class LogSoftmax : public OperationsBase { public: - LogSoftmax(int operationIndex); + LogSoftmax(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/LogicalAnd.hpp b/ngraph_creator/operations/include/LogicalAnd.hpp index 395d02cb1..9a57da048 100644 --- a/ngraph_creator/operations/include/LogicalAnd.hpp +++ b/ngraph_creator/operations/include/LogicalAnd.hpp @@ -9,7 +9,7 @@ namespace nnhal { class LogicalAnd : public OperationsBase { public: - LogicalAnd(int operationIndex); + LogicalAnd(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/LogicalNot.hpp b/ngraph_creator/operations/include/LogicalNot.hpp index 25d400fb2..731a0b8f1 100644 --- a/ngraph_creator/operations/include/LogicalNot.hpp +++ b/ngraph_creator/operations/include/LogicalNot.hpp @@ -9,7 +9,7 @@ namespace nnhal { class LogicalNot : public OperationsBase { public: - LogicalNot(int operationIndex); + LogicalNot(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/LogicalOr.hpp b/ngraph_creator/operations/include/LogicalOr.hpp index f6b12bd09..20b81fc4c 100644 --- a/ngraph_creator/operations/include/LogicalOr.hpp +++ b/ngraph_creator/operations/include/LogicalOr.hpp @@ -9,7 +9,7 @@ namespace nnhal { class LogicalOr : public OperationsBase { public: - LogicalOr(int operationIndex); + LogicalOr(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Logistic.hpp b/ngraph_creator/operations/include/Logistic.hpp index 3009f25f2..3ae4c5435 100644 --- a/ngraph_creator/operations/include/Logistic.hpp +++ b/ngraph_creator/operations/include/Logistic.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Logistic : public OperationsBase { public: - Logistic(int operationIndex); + Logistic(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/MaxPool2d.hpp b/ngraph_creator/operations/include/MaxPool2d.hpp index f63edd9dc..af4dcb3b5 100644 --- a/ngraph_creator/operations/include/MaxPool2d.hpp +++ b/ngraph_creator/operations/include/MaxPool2d.hpp @@ -9,7 +9,7 @@ namespace nnhal { class MaxPool2d : public OperationsBase { public: - MaxPool2d(int operationIndex); + MaxPool2d(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Maximum.hpp b/ngraph_creator/operations/include/Maximum.hpp index 58c3203cc..58838c618 100644 --- a/ngraph_creator/operations/include/Maximum.hpp +++ b/ngraph_creator/operations/include/Maximum.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Maximum : public OperationsBase { public: - Maximum(int operationIndex); + Maximum(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Mean.hpp b/ngraph_creator/operations/include/Mean.hpp index 4c2e38753..621f9a726 100644 --- a/ngraph_creator/operations/include/Mean.hpp +++ b/ngraph_creator/operations/include/Mean.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Mean : public OperationsBase { public: - Mean(int operationIndex); + Mean(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Minimum.hpp b/ngraph_creator/operations/include/Minimum.hpp index b82a838b3..e28e4918b 100644 --- a/ngraph_creator/operations/include/Minimum.hpp +++ b/ngraph_creator/operations/include/Minimum.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Minimum : public OperationsBase { public: - Minimum(int operationIndex); + Minimum(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Mul.hpp b/ngraph_creator/operations/include/Mul.hpp index 0b4e87473..6702f3046 100644 --- a/ngraph_creator/operations/include/Mul.hpp +++ b/ngraph_creator/operations/include/Mul.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Mul : public OperationsBase { public: - Mul(int operationIndex); + Mul(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Neg.hpp b/ngraph_creator/operations/include/Neg.hpp index eee1abbf4..7ef0fae66 100644 --- a/ngraph_creator/operations/include/Neg.hpp +++ b/ngraph_creator/operations/include/Neg.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Neg : public OperationsBase { public: - Neg(int operationIndex); + Neg(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/NotEqual.hpp b/ngraph_creator/operations/include/NotEqual.hpp index 2b2f658a7..4d00f5e41 100644 --- a/ngraph_creator/operations/include/NotEqual.hpp +++ b/ngraph_creator/operations/include/NotEqual.hpp @@ -9,7 +9,7 @@ namespace nnhal { class NotEqual : public OperationsBase { public: - NotEqual(int operationIndex); + NotEqual(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/OperationsBase.hpp b/ngraph_creator/operations/include/OperationsBase.hpp index 8eedbaa20..b10b7186e 100644 --- a/ngraph_creator/operations/include/OperationsBase.hpp +++ b/ngraph_creator/operations/include/OperationsBase.hpp @@ -19,6 +19,11 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { +struct GraphMetadata { + std::shared_ptr modelInfo; + IntelDeviceType pluginType; +}; + class OperationsBase { protected: enum ConversionType { @@ -43,13 +48,15 @@ class OperationsBase { int mNnapiOperationIndex; std::shared_ptr transpose(ConversionType type, ov::Output input); virtual std::shared_ptr createNode() = 0; - // override createNodeForPlugin in case sPluginType specific implementation is required + // override createNodeForPlugin in case mPluginType specific implementation is required virtual std::shared_ptr createNodeForPlugin(); void addResultNode(size_t index, std::shared_ptr resultNode); // helper functions bool checkOperandType(uint32_t operandIndex, const int32_t expectedOperandType, const std::string& strLogInfo = "Operand"); + //index should be the argument index number of outputs + //(if there are 4 outputs and want to check type for the 1st output index will be 0) bool checkOutputOperandType(uint32_t index, const int32_t expectedOperandType); bool checkInputOperandType(uint32_t index, const int32_t expectedOperandType); const vec getInputOperandDimensions(uint32_t inputIndex); @@ -57,33 +64,33 @@ class OperationsBase { std::shared_ptr getInputNode(uint32_t inputIndex, bool dequantize = true) { std::shared_ptr input; - auto operandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, inputIndex); - auto operandType = sModelInfo->getOperandType(operandIndex); - if (sModelInfo->isOperandLifeTimeConst(operandIndex)) { + auto operandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, inputIndex); + auto operandType = mOpModelInfo->getOperandType(operandIndex); + if (mOpModelInfo->isOperandLifeTimeConst(operandIndex)) { auto operandDims = getInputOperandDimensions(inputIndex); ov::element::Type elementType; switch (operandType) { case OperandType::TENSOR_FLOAT32: { elementType = ov::element::f32; - auto operandValues = sModelInfo->GetConstVecOperand(operandIndex); + auto operandValues = mOpModelInfo->GetConstVecOperand(operandIndex); input = createConstNode(elementType, toNgraphShape(operandDims), operandValues); break; } case OperandType::TENSOR_INT32: { elementType = ov::element::i32; - auto operandValues = sModelInfo->GetConstVecOperand(operandIndex); + auto operandValues = mOpModelInfo->GetConstVecOperand(operandIndex); input = createConstNode(elementType, toNgraphShape(operandDims), operandValues); break; } case OperandType::TENSOR_BOOL8: { elementType = ov::element::boolean; - auto operandValues = sModelInfo->GetConstVecOperand(operandIndex); + auto operandValues = mOpModelInfo->GetConstVecOperand(operandIndex); input = createConstNode(elementType, toNgraphShape(operandDims), operandValues); break; } case OperandType::TENSOR_QUANT8_ASYMM: { elementType = ov::element::u8; - auto operandValues = sModelInfo->GetConstVecOperand(operandIndex); + auto operandValues = mOpModelInfo->GetConstVecOperand(operandIndex); input = createConstNode(elementType, toNgraphShape(operandDims), operandValues); break; } @@ -91,25 +98,25 @@ class OperationsBase { case OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL: case OperandType::TENSOR_QUANT8_ASYMM_SIGNED: { elementType = ov::element::i8; - auto operandValues = sModelInfo->GetConstVecOperand(operandIndex); + auto operandValues = mOpModelInfo->GetConstVecOperand(operandIndex); input = createConstNode(elementType, toNgraphShape(operandDims), operandValues); break; } case OperandType::TENSOR_FLOAT16: { elementType = ov::element::f16; - auto operandValues = sModelInfo->GetConstVecOperand<_Float16>(operandIndex); + auto operandValues = mOpModelInfo->GetConstVecOperand<_Float16>(operandIndex); input = createConstNode(elementType, toNgraphShape(operandDims), operandValues); break; } case OperandType::TENSOR_QUANT16_SYMM: { elementType = ov::element::i16; - auto operandValues = sModelInfo->GetConstVecOperand(operandIndex); + auto operandValues = mOpModelInfo->GetConstVecOperand(operandIndex); input = createConstNode(elementType, toNgraphShape(operandDims), operandValues); break; } case OperandType::TENSOR_QUANT16_ASYMM: { elementType = ov::element::u16; - auto operandValues = sModelInfo->GetConstVecOperand(operandIndex); + auto operandValues = mOpModelInfo->GetConstVecOperand(operandIndex); input = createConstNode(elementType, toNgraphShape(operandDims), operandValues); break; } @@ -139,7 +146,7 @@ class OperationsBase { } // remove null input node parameter void removeInputNode(uint32_t inputIndex) { - auto operandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, inputIndex); + auto operandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, inputIndex); auto nodeName = mNgraphNodes->getNodeName(operandIndex); mNgraphNodes->removeInputParameter(nodeName, operandIndex); } @@ -164,18 +171,18 @@ class OperationsBase { ov::element::Type dequantizeType); const Operand& getInputOperand(uint32_t index) { - auto inputIdx = sModelInfo->getOperationInput(mNnapiOperationIndex, index); - return sModelInfo->getOperand(inputIdx); + auto inputIdx = mOpModelInfo->getOperationInput(mNnapiOperationIndex, index); + return mOpModelInfo->getOperand(inputIdx); } const Operand& getOutputOperand(uint32_t index) { - auto outputIdx = sModelInfo->getOperationOutput(mNnapiOperationIndex, index); - return sModelInfo->getOperand(outputIdx); + auto outputIdx = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, index); + return mOpModelInfo->getOperand(outputIdx); } bool isZeroSizedInput(uint32_t index) { - auto inputIdx = sModelInfo->getOperationInput(mNnapiOperationIndex, index); - auto operand = sModelInfo->getOperand(inputIdx); + auto inputIdx = mOpModelInfo->getOperationInput(mNnapiOperationIndex, index); + auto operand = mOpModelInfo->getOperand(inputIdx); auto& dims = operand.dimensions; if ((dims.size() > 0) && (dims[0] != 0)) return false; @@ -184,14 +191,14 @@ class OperationsBase { } public: - static std::shared_ptr sModelInfo; - static IntelDeviceType sPluginType; + std::shared_ptr mOpModelInfo; + IntelDeviceType mPluginType; std::shared_ptr mNgraphNodes; - OperationsBase(int operationIndex); + OperationsBase(int operationIndex, GraphMetadata graphMetadata = {}); void setNgraphNodes(std::shared_ptr nodes); bool transposed = false; virtual bool validate(); - // override validateForPlugin in case sPluginType specific implementation is required + // override validateForPlugin in case mPluginType specific implementation is required virtual bool validateForPlugin(); // override connectOperationToGraph in case Operation has multiple outputs virtual void connectOperationToGraph(); diff --git a/ngraph_creator/operations/include/PRelu.hpp b/ngraph_creator/operations/include/PRelu.hpp index 0d475d4f2..4cf763ad9 100644 --- a/ngraph_creator/operations/include/PRelu.hpp +++ b/ngraph_creator/operations/include/PRelu.hpp @@ -9,7 +9,7 @@ namespace nnhal { class PRelu : public OperationsBase { public: - PRelu(int operationIndex); + PRelu(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Pad.hpp b/ngraph_creator/operations/include/Pad.hpp index 17c138116..278605674 100644 --- a/ngraph_creator/operations/include/Pad.hpp +++ b/ngraph_creator/operations/include/Pad.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Pad : public OperationsBase { public: - Pad(int operationIndex); + Pad(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/PadV2.hpp b/ngraph_creator/operations/include/PadV2.hpp index 52ccdfe23..cf5535905 100644 --- a/ngraph_creator/operations/include/PadV2.hpp +++ b/ngraph_creator/operations/include/PadV2.hpp @@ -9,7 +9,7 @@ namespace nnhal { class PadV2 : public OperationsBase { public: - PadV2(int operationIndex); + PadV2(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Pow.hpp b/ngraph_creator/operations/include/Pow.hpp index 39bd820b0..9c22d13b3 100644 --- a/ngraph_creator/operations/include/Pow.hpp +++ b/ngraph_creator/operations/include/Pow.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Pow : public OperationsBase { public: - Pow(int operationIndex); + Pow(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Quantize.hpp b/ngraph_creator/operations/include/Quantize.hpp index 0caf03ede..190c1e70d 100644 --- a/ngraph_creator/operations/include/Quantize.hpp +++ b/ngraph_creator/operations/include/Quantize.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Quantize : public OperationsBase { public: - Quantize(int operationIndex); + Quantize(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; void connectOperationToGraph() override; }; diff --git a/ngraph_creator/operations/include/RNN.hpp b/ngraph_creator/operations/include/RNN.hpp index 3dc9cd8d0..5e9581aa7 100644 --- a/ngraph_creator/operations/include/RNN.hpp +++ b/ngraph_creator/operations/include/RNN.hpp @@ -9,7 +9,7 @@ namespace nnhal { class RNN : public OperationsBase { public: - RNN(int operationIndex); + RNN(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; void connectOperationToGraph() override; }; diff --git a/ngraph_creator/operations/include/ROIAlign.hpp b/ngraph_creator/operations/include/ROIAlign.hpp index 38fd99097..a8412a6b0 100755 --- a/ngraph_creator/operations/include/ROIAlign.hpp +++ b/ngraph_creator/operations/include/ROIAlign.hpp @@ -9,7 +9,7 @@ namespace nnhal { class ROIAlign : public OperationsBase { public: - ROIAlign(int operationIndex); + ROIAlign(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/ROIPooling.hpp b/ngraph_creator/operations/include/ROIPooling.hpp index 0b568587a..3a01fb167 100644 --- a/ngraph_creator/operations/include/ROIPooling.hpp +++ b/ngraph_creator/operations/include/ROIPooling.hpp @@ -9,7 +9,7 @@ namespace nnhal { class ROIPooling : public OperationsBase { public: - ROIPooling(int operationIndex); + ROIPooling(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/RSQRT.hpp b/ngraph_creator/operations/include/RSQRT.hpp index 92a9e715c..24cfbd60f 100644 --- a/ngraph_creator/operations/include/RSQRT.hpp +++ b/ngraph_creator/operations/include/RSQRT.hpp @@ -9,7 +9,7 @@ namespace nnhal { class RSQRT : public OperationsBase { public: - RSQRT(int operationIndex); + RSQRT(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/ReduceAll.hpp b/ngraph_creator/operations/include/ReduceAll.hpp index b71fca615..f6fdbe5ae 100644 --- a/ngraph_creator/operations/include/ReduceAll.hpp +++ b/ngraph_creator/operations/include/ReduceAll.hpp @@ -9,7 +9,7 @@ namespace nnhal { class ReduceAll : public OperationsBase { public: - ReduceAll(int operationIndex); + ReduceAll(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/ReduceAny.hpp b/ngraph_creator/operations/include/ReduceAny.hpp index e88083483..99cc596ea 100644 --- a/ngraph_creator/operations/include/ReduceAny.hpp +++ b/ngraph_creator/operations/include/ReduceAny.hpp @@ -9,7 +9,7 @@ namespace nnhal { class ReduceAny : public OperationsBase { public: - ReduceAny(int operationIndex); + ReduceAny(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/ReduceMax.hpp b/ngraph_creator/operations/include/ReduceMax.hpp index 60abe25fb..c8cbfa432 100644 --- a/ngraph_creator/operations/include/ReduceMax.hpp +++ b/ngraph_creator/operations/include/ReduceMax.hpp @@ -9,7 +9,7 @@ namespace nnhal { class ReduceMax : public OperationsBase { public: - ReduceMax(int operationIndex); + ReduceMax(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/ReduceMin.hpp b/ngraph_creator/operations/include/ReduceMin.hpp index eb9274b7d..da909d5c6 100644 --- a/ngraph_creator/operations/include/ReduceMin.hpp +++ b/ngraph_creator/operations/include/ReduceMin.hpp @@ -9,7 +9,7 @@ namespace nnhal { class ReduceMin : public OperationsBase { public: - ReduceMin(int operationIndex); + ReduceMin(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/ReduceProd.hpp b/ngraph_creator/operations/include/ReduceProd.hpp index 0b968273c..06fe61bc8 100644 --- a/ngraph_creator/operations/include/ReduceProd.hpp +++ b/ngraph_creator/operations/include/ReduceProd.hpp @@ -9,7 +9,7 @@ namespace nnhal { class ReduceProd : public OperationsBase { public: - ReduceProd(int operationIndex); + ReduceProd(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/ReduceSum.hpp b/ngraph_creator/operations/include/ReduceSum.hpp index 26647b855..3e5f3e61e 100644 --- a/ngraph_creator/operations/include/ReduceSum.hpp +++ b/ngraph_creator/operations/include/ReduceSum.hpp @@ -9,7 +9,7 @@ namespace nnhal { class ReduceSum : public OperationsBase { public: - ReduceSum(int operationIndex); + ReduceSum(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Relu.hpp b/ngraph_creator/operations/include/Relu.hpp index d1b84dce7..40a87cee7 100644 --- a/ngraph_creator/operations/include/Relu.hpp +++ b/ngraph_creator/operations/include/Relu.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Relu : public OperationsBase { public: - Relu(int operationIndex); + Relu(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Relu1.hpp b/ngraph_creator/operations/include/Relu1.hpp index 63b202370..b967ef706 100644 --- a/ngraph_creator/operations/include/Relu1.hpp +++ b/ngraph_creator/operations/include/Relu1.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Relu1 : public OperationsBase { public: - Relu1(int operationIndex); + Relu1(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Relu6.hpp b/ngraph_creator/operations/include/Relu6.hpp index 9204d5bd9..41da76109 100644 --- a/ngraph_creator/operations/include/Relu6.hpp +++ b/ngraph_creator/operations/include/Relu6.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Relu6 : public OperationsBase { public: - Relu6(int operationIndex); + Relu6(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Reshape.hpp b/ngraph_creator/operations/include/Reshape.hpp index 181f06d9f..828e9ec2f 100644 --- a/ngraph_creator/operations/include/Reshape.hpp +++ b/ngraph_creator/operations/include/Reshape.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Reshape : public OperationsBase { public: - Reshape(int operationIndex); + Reshape(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/ResizeBilinear.hpp b/ngraph_creator/operations/include/ResizeBilinear.hpp index 5e948f1df..aaa12c4bb 100644 --- a/ngraph_creator/operations/include/ResizeBilinear.hpp +++ b/ngraph_creator/operations/include/ResizeBilinear.hpp @@ -9,7 +9,7 @@ namespace nnhal { class ResizeBilinear : public OperationsBase { public: - ResizeBilinear(int operationIndex); + ResizeBilinear(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/ResizeNearestNeighbor.hpp b/ngraph_creator/operations/include/ResizeNearestNeighbor.hpp index c222be9d5..05ec8a3fa 100644 --- a/ngraph_creator/operations/include/ResizeNearestNeighbor.hpp +++ b/ngraph_creator/operations/include/ResizeNearestNeighbor.hpp @@ -9,7 +9,7 @@ namespace nnhal { class ResizeNearestNeighbor : public OperationsBase { public: - ResizeNearestNeighbor(int operationIndex); + ResizeNearestNeighbor(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/SQRT.hpp b/ngraph_creator/operations/include/SQRT.hpp index ffe7f5d65..fe6dab57e 100644 --- a/ngraph_creator/operations/include/SQRT.hpp +++ b/ngraph_creator/operations/include/SQRT.hpp @@ -9,7 +9,7 @@ namespace nnhal { class SQRT : public OperationsBase { public: - SQRT(int operationIndex); + SQRT(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Select.hpp b/ngraph_creator/operations/include/Select.hpp index ea3aa0929..33c349087 100644 --- a/ngraph_creator/operations/include/Select.hpp +++ b/ngraph_creator/operations/include/Select.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Select : public OperationsBase { public: - Select(int operationIndex); + Select(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Sin.hpp b/ngraph_creator/operations/include/Sin.hpp index 84fc9cdf1..693fe5dde 100644 --- a/ngraph_creator/operations/include/Sin.hpp +++ b/ngraph_creator/operations/include/Sin.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Sin : public OperationsBase { public: - Sin(int operationIndex); + Sin(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Softmax.hpp b/ngraph_creator/operations/include/Softmax.hpp index a2c3c54b8..910f1dc72 100644 --- a/ngraph_creator/operations/include/Softmax.hpp +++ b/ngraph_creator/operations/include/Softmax.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Softmax : public OperationsBase { public: - Softmax(int operationIndex); + Softmax(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/SpaceToBatch.hpp b/ngraph_creator/operations/include/SpaceToBatch.hpp index a001cbfdd..acddf8562 100644 --- a/ngraph_creator/operations/include/SpaceToBatch.hpp +++ b/ngraph_creator/operations/include/SpaceToBatch.hpp @@ -9,7 +9,7 @@ namespace nnhal { class SpaceToBatch : public OperationsBase { public: - SpaceToBatch(int operationIndex); + SpaceToBatch(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/SpaceToDepth.hpp b/ngraph_creator/operations/include/SpaceToDepth.hpp index c42f34b5a..c0140307f 100644 --- a/ngraph_creator/operations/include/SpaceToDepth.hpp +++ b/ngraph_creator/operations/include/SpaceToDepth.hpp @@ -9,7 +9,7 @@ namespace nnhal { class SpaceToDepth : public OperationsBase { public: - SpaceToDepth(int operationIndex); + SpaceToDepth(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Split.hpp b/ngraph_creator/operations/include/Split.hpp index 633c30628..04ef8afd8 100644 --- a/ngraph_creator/operations/include/Split.hpp +++ b/ngraph_creator/operations/include/Split.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Split : public OperationsBase { public: - Split(int operationIndex); + Split(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; void connectOperationToGraph() override; }; diff --git a/ngraph_creator/operations/include/Squeeze.hpp b/ngraph_creator/operations/include/Squeeze.hpp index ef29220e6..8df403238 100644 --- a/ngraph_creator/operations/include/Squeeze.hpp +++ b/ngraph_creator/operations/include/Squeeze.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Squeeze : public OperationsBase { public: - Squeeze(int operationIndex); + Squeeze(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/StridedSlice.hpp b/ngraph_creator/operations/include/StridedSlice.hpp index bbab7ff7a..ad32cb4c6 100644 --- a/ngraph_creator/operations/include/StridedSlice.hpp +++ b/ngraph_creator/operations/include/StridedSlice.hpp @@ -9,7 +9,7 @@ namespace nnhal { class StridedSlice : public OperationsBase { public: - StridedSlice(int operationIndex); + StridedSlice(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; std::vector getMaskBits(int32_t maskValue, size_t vec_size); diff --git a/ngraph_creator/operations/include/Sub.hpp b/ngraph_creator/operations/include/Sub.hpp index 1e0fa1998..e83cfd8f7 100644 --- a/ngraph_creator/operations/include/Sub.hpp +++ b/ngraph_creator/operations/include/Sub.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Sub : public OperationsBase { public: - Sub(int operationIndex); + Sub(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/Tanh.hpp b/ngraph_creator/operations/include/Tanh.hpp index eab7339f1..1f1595b37 100644 --- a/ngraph_creator/operations/include/Tanh.hpp +++ b/ngraph_creator/operations/include/Tanh.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Tanh : public OperationsBase { public: - Tanh(int operationIndex); + Tanh(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/TopkV2.hpp b/ngraph_creator/operations/include/TopkV2.hpp index d94615f36..6ba75f73a 100644 --- a/ngraph_creator/operations/include/TopkV2.hpp +++ b/ngraph_creator/operations/include/TopkV2.hpp @@ -9,7 +9,7 @@ namespace nnhal { class TopkV2 : public OperationsBase { public: - TopkV2(int operationIndex); + TopkV2(int operationIndex, GraphMetadata graphMetadata); std::shared_ptr createNode() override; void connectOperationToGraph() override; }; diff --git a/ngraph_creator/operations/include/Transpose.hpp b/ngraph_creator/operations/include/Transpose.hpp index 21bc9b2bc..2b4812bde 100644 --- a/ngraph_creator/operations/include/Transpose.hpp +++ b/ngraph_creator/operations/include/Transpose.hpp @@ -9,7 +9,7 @@ namespace nnhal { class Transpose : public OperationsBase { public: - Transpose(int operationIndex); + Transpose(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/TransposeConv2D.hpp b/ngraph_creator/operations/include/TransposeConv2D.hpp index 6a745c5b1..bc8a165f4 100644 --- a/ngraph_creator/operations/include/TransposeConv2D.hpp +++ b/ngraph_creator/operations/include/TransposeConv2D.hpp @@ -9,7 +9,7 @@ namespace nnhal { class TransposeConv2D : public OperationsBase { public: - TransposeConv2D(int operationIndex); + TransposeConv2D(int operationIndex, GraphMetadata graphMetadata); bool validate() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/include/UnidirectionalSequenceRNN.hpp b/ngraph_creator/operations/include/UnidirectionalSequenceRNN.hpp index 87ba84890..ac0736b51 100644 --- a/ngraph_creator/operations/include/UnidirectionalSequenceRNN.hpp +++ b/ngraph_creator/operations/include/UnidirectionalSequenceRNN.hpp @@ -9,7 +9,7 @@ namespace nnhal { class UnidirectionalSequenceRNN : public OperationsBase { public: - UnidirectionalSequenceRNN(int operationIndex); + UnidirectionalSequenceRNN(int operationIndex, GraphMetadata graphMetadata); void connectOperationToGraph() override; std::shared_ptr createNode() override; }; diff --git a/ngraph_creator/operations/src/Abs.cpp b/ngraph_creator/operations/src/Abs.cpp index 60390db1b..e11e3f683 100644 --- a/ngraph_creator/operations/src/Abs.cpp +++ b/ngraph_creator/operations/src/Abs.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Abs::Abs(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Abs::Abs(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Abs::createNode() { diff --git a/ngraph_creator/operations/src/Add.cpp b/ngraph_creator/operations/src/Add.cpp index 079a07713..065e56f61 100644 --- a/ngraph_creator/operations/src/Add.cpp +++ b/ngraph_creator/operations/src/Add.cpp @@ -8,15 +8,15 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Add::Add(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Add::Add(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool Add::validate() { ALOGV("%s PASSED", __func__); - const auto& activationIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); - if (!sModelInfo->isOperandLifeTimeConst(activationIndex)) { + const auto& activationIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 2); + if (!mOpModelInfo->isOperandLifeTimeConst(activationIndex)) { ALOGE("%s Only Constant supported for specifying Activation", __func__); return false; } @@ -31,7 +31,7 @@ std::shared_ptr Add::createNode() { input1 = getInputNode(0); input2 = getInputNode(1); - auto activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); auto addNode = std::make_shared(input1, input2, ov::op::AutoBroadcastType::NUMPY); auto outputNode = applyActivation(addNode, activationFn); @@ -41,9 +41,9 @@ std::shared_ptr Add::createNode() { std::shared_ptr Add::createNodeForPlugin() { #if 0 - if (sPluginType == IntelDeviceType::VPU) { + if (mPluginType == IntelDeviceType::VPU) { auto input = mNgraphNodes->getOperationOutput( - sModelInfo->getOperationInput(mNnapiOperationIndex, 0)); + mOpModelInfo->getOperationInput(mNnapiOperationIndex, 0)); std::shared_ptr constantOp = std::make_shared(ov::element::f32, input.get_shape()); auto transposedOp = transpose(NHWC_NCHW, constantOp); diff --git a/ngraph_creator/operations/src/Argmax.cpp b/ngraph_creator/operations/src/Argmax.cpp index 2f69cb258..9653ef85d 100644 --- a/ngraph_creator/operations/src/Argmax.cpp +++ b/ngraph_creator/operations/src/Argmax.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Argmax::Argmax(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Argmax::Argmax(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Argmax::createNode() { @@ -17,7 +17,7 @@ std::shared_ptr Argmax::createNode() { input = getInputNode(0); - int32_t axis = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + int32_t axis = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); ALOGD("createNode axis %d", axis); auto k_node = createConstNode(ov::element::i32, {}, convertToVector(1)); diff --git a/ngraph_creator/operations/src/Argmin.cpp b/ngraph_creator/operations/src/Argmin.cpp index e002d917c..984d9bb33 100644 --- a/ngraph_creator/operations/src/Argmin.cpp +++ b/ngraph_creator/operations/src/Argmin.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Argmin::Argmin(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Argmin::Argmin(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Argmin::createNode() { @@ -17,7 +17,7 @@ std::shared_ptr Argmin::createNode() { input = getInputNode(0); - int32_t axis = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + int32_t axis = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); ALOGD("createNode axis %d", axis); auto k_node = createConstNode(ov::element::i32, {}, convertToVector(1)); diff --git a/ngraph_creator/operations/src/AveragePool2D.cpp b/ngraph_creator/operations/src/AveragePool2D.cpp index 47e004c0b..a79709331 100644 --- a/ngraph_creator/operations/src/AveragePool2D.cpp +++ b/ngraph_creator/operations/src/AveragePool2D.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -AveragePool2D::AveragePool2D(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +AveragePool2D::AveragePool2D(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool AveragePool2D::validate() { @@ -26,7 +26,7 @@ bool AveragePool2D::validate() { std::shared_ptr AveragePool2D::createNode() { std::shared_ptr inputNode; const auto& inDims = getInputOperandDimensions(0); - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); inputNode = getInputNode(0); @@ -59,21 +59,21 @@ std::shared_ptr AveragePool2D::createNode() { } if (isExplicit) { - padding_left = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); - padding_right = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); - padding_top = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - padding_bottom = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + padding_left = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + padding_right = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + padding_top = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + padding_bottom = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); - filter_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); - filter_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); + filter_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + filter_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); if (inputsSize == 11) { - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); } if (layout) useNchw = true; @@ -82,18 +82,18 @@ std::shared_ptr AveragePool2D::createNode() { } if (isImplicit) { - padding_scheme = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + padding_scheme = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - filter_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - filter_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + filter_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + filter_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); if (inputsSize == 8) { - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); } if (layout) useNchw = true; diff --git a/ngraph_creator/operations/src/BatchToSpace.cpp b/ngraph_creator/operations/src/BatchToSpace.cpp index be5ccb692..1292c9bd7 100644 --- a/ngraph_creator/operations/src/BatchToSpace.cpp +++ b/ngraph_creator/operations/src/BatchToSpace.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -BatchToSpace::BatchToSpace(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +BatchToSpace::BatchToSpace(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool BatchToSpace::validate() { @@ -17,10 +17,10 @@ bool BatchToSpace::validate() { if (inputRank != 4) return false; - const auto& block_shape_OperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& block_shape_OperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); // TODO: Add Support for all_tensors_as_inputs - if (!sModelInfo->isOperandLifeTimeConst(block_shape_OperandIndex)) { + if (!mOpModelInfo->isOperandLifeTimeConst(block_shape_OperandIndex)) { ALOGE("%s Only Constant dimensions supported now", __func__); return false; } @@ -32,19 +32,19 @@ bool BatchToSpace::validate() { std::shared_ptr BatchToSpace::createNode() { int32_t layout = 0; bool useNchw = false; - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); ALOGD("%s inputsSize %lu", __func__, inputsSize); auto inputNode = getInputNode(0); auto& inDims = getInputOperandDimensions(0); - const auto& block_shape_OperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - auto block_shape = sModelInfo->GetConstVecOperand(block_shape_OperandIndex); + const auto& block_shape_OperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + auto block_shape = mOpModelInfo->GetConstVecOperand(block_shape_OperandIndex); // Compensation for the shape to be same as the size of data input shape block_shape.insert(block_shape.begin(), 1); block_shape.insert(block_shape.begin(), 1); - if (inputsSize == 3) layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + if (inputsSize == 3) layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); if (layout) useNchw = true; std::vector shape(inDims.size(), 0); diff --git a/ngraph_creator/operations/src/BidirectionalSequenceRNN.cpp b/ngraph_creator/operations/src/BidirectionalSequenceRNN.cpp index 251d39f0e..6d920adad 100644 --- a/ngraph_creator/operations/src/BidirectionalSequenceRNN.cpp +++ b/ngraph_creator/operations/src/BidirectionalSequenceRNN.cpp @@ -9,9 +9,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -BidirectionalSequenceRNN::BidirectionalSequenceRNN(int operationIndex) - : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +BidirectionalSequenceRNN::BidirectionalSequenceRNN(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } void BidirectionalSequenceRNN::connectOperationToGraph() { createNode(); } @@ -50,9 +49,9 @@ std::shared_ptr BidirectionalSequenceRNN::createNode() { hasAuxInputs = true; } - auto activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 12); - auto isTimeMajor = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 13); - auto mergeOutputs = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 14); + auto activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 12); + auto isTimeMajor = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 13); + auto mergeOutputs = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 14); const auto& inDims = getInputOperandDimensions(0); uint32_t maxTime; @@ -206,15 +205,15 @@ std::shared_ptr BidirectionalSequenceRNN::createNode() { fwOutputNode = std::make_shared(concat_output, 2); } - const auto& outputsSize = sModelInfo->getOperationOutputsSize(mNnapiOperationIndex); + const auto& outputsSize = mOpModelInfo->getOperationOutputsSize(mNnapiOperationIndex); - auto fwOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); + auto fwOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); mNgraphNodes->setOutputAtOperandIndex(fwOutputIndex, fwOutputNode); ALOGD("%s Set Output index %d", __func__, fwOutputIndex); - const auto fwOp = sModelInfo->getOperand(fwOutputIndex); + const auto fwOp = mOpModelInfo->getOperand(fwOutputIndex); if (!mergeOutputs) { - auto bwOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 1); + auto bwOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 1); mNgraphNodes->setOutputAtOperandIndex(bwOutputIndex, bwOutputNode); ALOGD("%s Set Output index %d", __func__, bwOutputIndex); } @@ -230,13 +229,13 @@ std::shared_ptr BidirectionalSequenceRNN::createNode() { } auto forward_hidden_state_output_Index = - sModelInfo->getOperationOutput(mNnapiOperationIndex, fw_hidden_op_index); + mOpModelInfo->getOperationOutput(mNnapiOperationIndex, fw_hidden_op_index); mNgraphNodes->setOutputAtOperandIndex(forward_hidden_state_output_Index, fw_op_lastTimestep); ALOGD("%s Set Output index %d", __func__, forward_hidden_state_output_Index); auto backward_hidden_state_output_Index = - sModelInfo->getOperationOutput(mNnapiOperationIndex, bw_hidden_op_index); + mOpModelInfo->getOperationOutput(mNnapiOperationIndex, bw_hidden_op_index); mNgraphNodes->setOutputAtOperandIndex(backward_hidden_state_output_Index, bw_op_lastTimestep); ALOGD("%s Set Output index %d", __func__, backward_hidden_state_output_Index); diff --git a/ngraph_creator/operations/src/Cast.cpp b/ngraph_creator/operations/src/Cast.cpp index e38bfe296..5ee308623 100755 --- a/ngraph_creator/operations/src/Cast.cpp +++ b/ngraph_creator/operations/src/Cast.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Cast::Cast(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Cast::Cast(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } void Cast::connectOperationToGraph() { createNode(); } @@ -19,11 +19,11 @@ std::shared_ptr Cast::createNode() { input = getInputNode(0, false); - auto inputIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 0); - auto outputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); + auto inputIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 0); + auto outputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); - const auto& inputType = sModelInfo->getOperandType(inputIndex); - const auto& outputType = sModelInfo->getOperandType(outputIndex); + const auto& inputType = mOpModelInfo->getOperandType(inputIndex); + const auto& outputType = mOpModelInfo->getOperandType(outputIndex); ov::element::Type elementType; // change to outputbased element type std::shared_ptr outputNode; diff --git a/ngraph_creator/operations/src/ChannelShuffle.cpp b/ngraph_creator/operations/src/ChannelShuffle.cpp index 0122d1cf3..7598b3545 100644 --- a/ngraph_creator/operations/src/ChannelShuffle.cpp +++ b/ngraph_creator/operations/src/ChannelShuffle.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -ChannelShuffle::ChannelShuffle(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +ChannelShuffle::ChannelShuffle(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool ChannelShuffle::validate() { @@ -20,7 +20,7 @@ bool ChannelShuffle::validate() { } // Check axis range - int64_t axis = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + int64_t axis = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); if (!(axis >= -inputRank && axis < inputRank)) { ALOGE("%s Axis %ld not in the range [-inputRank, inputRank)", __func__, axis); return false; @@ -32,8 +32,8 @@ bool ChannelShuffle::validate() { std::shared_ptr ChannelShuffle::createNode() { // Creating input nodes auto inputNode = getInputNode(0); - int64_t group = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); - int64_t axis = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + int64_t group = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + int64_t axis = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); auto inputRank = getInputOperandDimensions(0).size(); axis = (axis >= 0) ? axis : (axis + inputRank); diff --git a/ngraph_creator/operations/src/Concat.cpp b/ngraph_creator/operations/src/Concat.cpp index 29e75ea24..1c78d5746 100644 --- a/ngraph_creator/operations/src/Concat.cpp +++ b/ngraph_creator/operations/src/Concat.cpp @@ -7,13 +7,13 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Concat::Concat(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Concat::Concat(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool Concat::validate() { // check concatenation axis - auto n = sModelInfo->getOperationInputsSize(mNnapiOperationIndex) - + auto n = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex) - 1; // 0 ~ n-1: The list of n input tensors for (size_t i = 0; i < n; i++) { if (!isValidInputTensor(i)) { @@ -26,16 +26,16 @@ bool Concat::validate() { } std::shared_ptr Concat::createNode() { - auto n = sModelInfo->getOperationInputsSize(mNnapiOperationIndex) - + auto n = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex) - 1; // 0 ~ n-1: The list of n input tensors - auto axis = sModelInfo->ParseOperationInput(mNnapiOperationIndex, + auto axis = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, n); // n: concatenation axis std::vector> inputs; ALOGV("createNode n %lu, axis %d", n, axis); for (size_t i = 0; i < n; i++) { - auto inputIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, i); + auto inputIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, i); auto inputOp = getInputNode(i); - const auto op = sModelInfo->getOperand(inputIndex); + const auto op = mOpModelInfo->getOperand(inputIndex); ALOGV("createNode inputIndex %d, lifetime %d", inputIndex, op.lifetime); inputs.push_back(inputOp); } diff --git a/ngraph_creator/operations/src/Conv2d.cpp b/ngraph_creator/operations/src/Conv2d.cpp index 11cfd75d2..7b396fd35 100644 --- a/ngraph_creator/operations/src/Conv2d.cpp +++ b/ngraph_creator/operations/src/Conv2d.cpp @@ -8,8 +8,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Conv2d::Conv2d(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Conv2d::Conv2d(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool Conv2d::validate() { @@ -27,8 +27,8 @@ bool Conv2d::validate() { } if (checkInputOperandType(1, (int32_t)OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL)) { - const auto& operandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - const auto& operand = sModelInfo->getOperand(operandIndex); + const auto& operandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& operand = mOpModelInfo->getOperand(operandIndex); if (operand.extraParams.channelQuant().channelDim != 0) { return false; } @@ -41,7 +41,7 @@ bool Conv2d::validate() { std::shared_ptr Conv2d::createNode() { std::shared_ptr inputNode; inputNode = getInputNode(0); - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); ALOGD("%s inputsSize %lu", __func__, inputsSize); bool isImplicit = false, isExplicit = false; @@ -82,28 +82,28 @@ std::shared_ptr Conv2d::createNode() { // TODO: create a generic function to support conv, depthwise, grouped_conv and transpose_conv // operations if (isExplicit) { - padding_left = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - padding_right = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - padding_top = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - padding_bottom = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + padding_left = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + padding_right = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + padding_top = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + padding_bottom = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); if (inputsSize > 10 && inputsSize <= 13) { switch (inputsSize) { case 13: dilation_height_factor = - sModelInfo->ParseOperationInput(mNnapiOperationIndex, 12); + mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 12); __attribute__((fallthrough)); case 12: dilation_width_factor = - sModelInfo->ParseOperationInput(mNnapiOperationIndex, 11); + mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 11); __attribute__((fallthrough)); case 11: - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); __attribute__((fallthrough)); default: break; @@ -116,25 +116,25 @@ std::shared_ptr Conv2d::createNode() { } if (isImplicit) { - padding_scheme = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + padding_scheme = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); if (inputsSize > 7 && inputsSize <= 10) { switch (inputsSize) { case 10: dilation_height_factor = - sModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); + mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); __attribute__((fallthrough)); case 9: dilation_width_factor = - sModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); + mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); __attribute__((fallthrough)); case 8: - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); __attribute__((fallthrough)); default: break; @@ -169,16 +169,16 @@ std::shared_ptr Conv2d::createNode() { } std::shared_ptr filterNode, biasNode; - const auto& biasIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); + const auto& biasIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 2); filterNode = getInputNode(1); biasNode = getInputNode(2); if (checkInputOperandType(1, (int32_t)OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL)) { - auto filterIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - const auto& filterOperand = sModelInfo->getOperand(filterIndex); + auto filterIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& filterOperand = mOpModelInfo->getOperand(filterIndex); vec filterScales = filterOperand.extraParams.channelQuant().scales; - float inputScale = sModelInfo->getOperandScale(0); + float inputScale = mOpModelInfo->getOperandScale(0); auto filterScalesNode = createConstNode(ov::element::f32, ov::Shape{filterScales.size()}, filterScales); auto inputScalesNode = diff --git a/ngraph_creator/operations/src/DepthToSpace.cpp b/ngraph_creator/operations/src/DepthToSpace.cpp index 3a259d7a2..3215f8fb8 100644 --- a/ngraph_creator/operations/src/DepthToSpace.cpp +++ b/ngraph_creator/operations/src/DepthToSpace.cpp @@ -7,23 +7,23 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -DepthToSpace::DepthToSpace(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +DepthToSpace::DepthToSpace(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr DepthToSpace::createNode() { // Creating input nodes std::shared_ptr input; bool useNchw = false; - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); if (inputsSize == 3) { - auto layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); if (layout) useNchw = true; } input = getInputNode(0); - auto block_size = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + auto block_size = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); if (!useNchw) // No conversion needed if useNchw set input = transpose(NHWC_NCHW, input); diff --git a/ngraph_creator/operations/src/DepthwiseConv2d.cpp b/ngraph_creator/operations/src/DepthwiseConv2d.cpp index 1b1f9af7b..c9e049218 100644 --- a/ngraph_creator/operations/src/DepthwiseConv2d.cpp +++ b/ngraph_creator/operations/src/DepthwiseConv2d.cpp @@ -8,8 +8,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -DepthwiseConv2d::DepthwiseConv2d(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +DepthwiseConv2d::DepthwiseConv2d(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool DepthwiseConv2d::validate() { @@ -29,8 +29,8 @@ bool DepthwiseConv2d::validate() { } if (checkInputOperandType(1, (int32_t)OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL)) { - const auto& operandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - const auto& operand = sModelInfo->getOperand(operandIndex); + const auto& operandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& operand = mOpModelInfo->getOperand(operandIndex); if (operand.extraParams.channelQuant().channelDim != 3) { return false; } @@ -43,7 +43,7 @@ bool DepthwiseConv2d::validate() { std::shared_ptr DepthwiseConv2d::createNode() { std::shared_ptr inputNode; inputNode = getInputNode(0); - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); ALOGD("%s inputsSize %lu", __func__, inputsSize); bool isImplicit = false, isExplicit = false; @@ -83,30 +83,30 @@ std::shared_ptr DepthwiseConv2d::createNode() { } if (isExplicit) { - padding_left = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - padding_right = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - padding_top = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - padding_bottom = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + padding_left = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + padding_right = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + padding_top = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + padding_bottom = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); - depthwise_multiplier = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); + depthwise_multiplier = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); if (inputsSize > 11 && inputsSize <= 14) { switch (inputsSize) { case 14: dilation_height_factor = - sModelInfo->ParseOperationInput(mNnapiOperationIndex, 13); + mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 13); __attribute__((fallthrough)); case 13: dilation_width_factor = - sModelInfo->ParseOperationInput(mNnapiOperationIndex, 12); + mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 12); __attribute__((fallthrough)); case 12: - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 11); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 11); __attribute__((fallthrough)); default: break; @@ -129,27 +129,27 @@ std::shared_ptr DepthwiseConv2d::createNode() { } } else if (isImplicit) { - padding_scheme = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + padding_scheme = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - depthwise_multiplier = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + depthwise_multiplier = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); if (inputsSize > 8 && inputsSize <= 11) { switch (inputsSize) { case 11: dilation_height_factor = - sModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); + mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); __attribute__((fallthrough)); case 10: dilation_width_factor = - sModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); + mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); __attribute__((fallthrough)); case 9: - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); __attribute__((fallthrough)); default: break; @@ -186,16 +186,16 @@ std::shared_ptr DepthwiseConv2d::createNode() { } std::shared_ptr filterNode, biasNode; - const auto& biasIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); + const auto& biasIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 2); filterNode = getInputNode(1); biasNode = getInputNode(2); if (checkInputOperandType(1, (int32_t)OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL)) { - auto filterIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - const auto& filterOperand = sModelInfo->getOperand(filterIndex); + auto filterIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& filterOperand = mOpModelInfo->getOperand(filterIndex); vec filterScales = filterOperand.extraParams.channelQuant().scales; - float inputScale = sModelInfo->getOperandScale(0); + float inputScale = mOpModelInfo->getOperandScale(0); auto filterScalesNode = createConstNode(ov::element::f32, ov::Shape{filterScales.size()}, filterScales); auto inputScalesNode = diff --git a/ngraph_creator/operations/src/Dequantize.cpp b/ngraph_creator/operations/src/Dequantize.cpp index 32788eab4..aa573d3b5 100644 --- a/ngraph_creator/operations/src/Dequantize.cpp +++ b/ngraph_creator/operations/src/Dequantize.cpp @@ -7,15 +7,15 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Dequantize::Dequantize(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Dequantize::Dequantize(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Dequantize::createNode() { // Creating input nodes std::shared_ptr input, outputNode; input = getInputNode(0, false); - const auto& inputIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 0); + const auto& inputIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 0); if (checkOutputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT16)) outputNode = DequantizeNode(input, inputIndex, ov::element::f16); diff --git a/ngraph_creator/operations/src/Div.cpp b/ngraph_creator/operations/src/Div.cpp index 4a10152cb..7f365b5f0 100644 --- a/ngraph_creator/operations/src/Div.cpp +++ b/ngraph_creator/operations/src/Div.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Div::Div(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Div::Div(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Div::createNode() { @@ -16,7 +16,7 @@ std::shared_ptr Div::createNode() { auto input1 = getInputNode(0); auto input2 = getInputNode(1); - auto activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); auto DivNode = std::make_shared(input1, input2, ov::op::AutoBroadcastType::NUMPY); diff --git a/ngraph_creator/operations/src/EmbeddingLookup.cpp b/ngraph_creator/operations/src/EmbeddingLookup.cpp index a1ee91e69..65da5f735 100644 --- a/ngraph_creator/operations/src/EmbeddingLookup.cpp +++ b/ngraph_creator/operations/src/EmbeddingLookup.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -EmbeddingLookup::EmbeddingLookup(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +EmbeddingLookup::EmbeddingLookup(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool EmbeddingLookup::validate() { diff --git a/ngraph_creator/operations/src/Equal.cpp b/ngraph_creator/operations/src/Equal.cpp index 313aa1979..6b96b0b1e 100644 --- a/ngraph_creator/operations/src/Equal.cpp +++ b/ngraph_creator/operations/src/Equal.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Equal::Equal(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Equal::Equal(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Equal::createNode() { diff --git a/ngraph_creator/operations/src/Exp.cpp b/ngraph_creator/operations/src/Exp.cpp index 4c029eb11..2293714e1 100644 --- a/ngraph_creator/operations/src/Exp.cpp +++ b/ngraph_creator/operations/src/Exp.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Exp::Exp(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Exp::Exp(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Exp::createNode() { diff --git a/ngraph_creator/operations/src/ExpandDims.cpp b/ngraph_creator/operations/src/ExpandDims.cpp index 7107e0586..c462ca17c 100644 --- a/ngraph_creator/operations/src/ExpandDims.cpp +++ b/ngraph_creator/operations/src/ExpandDims.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -ExpandDims::ExpandDims(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +ExpandDims::ExpandDims(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool ExpandDims::validate() { @@ -22,7 +22,7 @@ bool ExpandDims::validate() { std::shared_ptr ExpandDims::createNode() { // Creating input nodes auto input = getInputNode(0); - auto index = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + auto index = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); auto axes = createConstNode(ov::element::i32, {}, convertToVector(index)); diff --git a/ngraph_creator/operations/src/Floor.cpp b/ngraph_creator/operations/src/Floor.cpp index cb57bf483..9696a3553 100644 --- a/ngraph_creator/operations/src/Floor.cpp +++ b/ngraph_creator/operations/src/Floor.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Floor::Floor(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Floor::Floor(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Floor::createNode() { diff --git a/ngraph_creator/operations/src/FullyConnected.cpp b/ngraph_creator/operations/src/FullyConnected.cpp index f4dca33d1..9806aecdc 100644 --- a/ngraph_creator/operations/src/FullyConnected.cpp +++ b/ngraph_creator/operations/src/FullyConnected.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -FullyConnected::FullyConnected(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +FullyConnected::FullyConnected(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } // Supports only FP32 input. Will add support for QUANT8 through decompose node @@ -49,13 +49,13 @@ std::shared_ptr FullyConnected::createNode() { multiplyNode = std::make_shared(inputNode, weightsNode, false, true); } - if (!sModelInfo->isOmittedInput(mNnapiOperationIndex, 2) && biasDims.size() != 0) { + if (!mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 2) && biasDims.size() != 0) { biasNode = getInputNode(2); if (checkInputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM) || checkInputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM_SIGNED)) biasNode = DequantizeNode( - biasNode, sModelInfo->getOperationInput(mNnapiOperationIndex, 2), ov::element::f32); + biasNode, mOpModelInfo->getOperationInput(mNnapiOperationIndex, 2), ov::element::f32); addNode = std::make_shared(multiplyNode, biasNode, ov::op::AutoBroadcastType::NUMPY); @@ -64,7 +64,7 @@ std::shared_ptr FullyConnected::createNode() { addNode = multiplyNode; } - auto activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + auto activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); activationNode = applyActivation(addNode, activationFn); return activationNode ? activationNode : addNode; } diff --git a/ngraph_creator/operations/src/Gather.cpp b/ngraph_creator/operations/src/Gather.cpp index d1eefc9e5..4a89973d1 100644 --- a/ngraph_creator/operations/src/Gather.cpp +++ b/ngraph_creator/operations/src/Gather.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Gather::Gather(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Gather::Gather(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Gather::createNode() { @@ -18,7 +18,7 @@ std::shared_ptr Gather::createNode() { gatherVals = getInputNode(0); // axis range [-n, n] - auto axis = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + auto axis = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); auto axisNode = createConstNode(ov::element::i32, {}, convertToVector(axis)); auto indices = getInputNode(2); diff --git a/ngraph_creator/operations/src/Greater.cpp b/ngraph_creator/operations/src/Greater.cpp index c98953437..2c67f52c6 100644 --- a/ngraph_creator/operations/src/Greater.cpp +++ b/ngraph_creator/operations/src/Greater.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Greater::Greater(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Greater::Greater(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Greater::createNode() { diff --git a/ngraph_creator/operations/src/GreaterEqual.cpp b/ngraph_creator/operations/src/GreaterEqual.cpp index 6213f4fa2..062158e38 100644 --- a/ngraph_creator/operations/src/GreaterEqual.cpp +++ b/ngraph_creator/operations/src/GreaterEqual.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -GreaterEqual::GreaterEqual(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +GreaterEqual::GreaterEqual(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr GreaterEqual::createNode() { diff --git a/ngraph_creator/operations/src/GroupedConv2d.cpp b/ngraph_creator/operations/src/GroupedConv2d.cpp index 3552d59b6..ed2411437 100644 --- a/ngraph_creator/operations/src/GroupedConv2d.cpp +++ b/ngraph_creator/operations/src/GroupedConv2d.cpp @@ -8,8 +8,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -GroupedConv2d::GroupedConv2d(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +GroupedConv2d::GroupedConv2d(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool GroupedConv2d::validate() { @@ -23,8 +23,8 @@ bool GroupedConv2d::validate() { } if (checkInputOperandType(1, (int32_t)OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL)) { - const auto& operandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - const auto& operand = sModelInfo->getOperand(operandIndex); + const auto& operandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& operand = mOpModelInfo->getOperand(operandIndex); if (operand.extraParams.channelQuant().channelDim != 0) { return false; } @@ -37,7 +37,7 @@ bool GroupedConv2d::validate() { std::shared_ptr GroupedConv2d::createNode() { std::shared_ptr inputNode; inputNode = getInputNode(0); - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); bool isImplicit = false, isExplicit = false; if (inputsSize >= 11 && inputsSize <= 12 && @@ -76,20 +76,20 @@ std::shared_ptr GroupedConv2d::createNode() { } if (isExplicit) { - padding_left = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - padding_right = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - padding_top = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - padding_bottom = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + padding_left = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + padding_right = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + padding_top = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + padding_bottom = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); - number_groups = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); + number_groups = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); if (inputsSize == 12) - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 11); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 11); if (layout) useNchw = true; @@ -97,17 +97,17 @@ std::shared_ptr GroupedConv2d::createNode() { } if (isImplicit) { - padding_scheme = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + padding_scheme = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - number_groups = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + number_groups = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); if (inputsSize == 9) - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); if (layout) useNchw = true; @@ -137,16 +137,16 @@ std::shared_ptr GroupedConv2d::createNode() { } std::shared_ptr filterNode, biasNode; - const auto& biasIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); + const auto& biasIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 2); filterNode = getInputNode(1); biasNode = getInputNode(2); if (checkInputOperandType(1, (int32_t)OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL)) { - auto filterIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - const auto& filterOperand = sModelInfo->getOperand(filterIndex); + auto filterIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& filterOperand = mOpModelInfo->getOperand(filterIndex); vec filterScales = filterOperand.extraParams.channelQuant().scales; - float inputScale = sModelInfo->getOperandScale(0); + float inputScale = mOpModelInfo->getOperandScale(0); auto filterScalesNode = createConstNode(ov::element::f32, ov::Shape{filterScales.size()}, filterScales); auto inputScalesNode = diff --git a/ngraph_creator/operations/src/HardSwish.cpp b/ngraph_creator/operations/src/HardSwish.cpp new file mode 100644 index 000000000..0f5a7191b --- /dev/null +++ b/ngraph_creator/operations/src/HardSwish.cpp @@ -0,0 +1,30 @@ +#include +#define LOG_TAG "HardSwish" + +namespace android { +namespace hardware { +namespace neuralnetworks { +namespace nnhal { + +HardSwish::HardSwish(int operationIndex, GraphMetadata graphMetadata) : OperationsBase(operationIndex, graphMetadata) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +} + +bool HardSwish::validate() { + ALOGV("%s PASSED", __func__); + return true; +} + +std::shared_ptr HardSwish::createNode() { + std::shared_ptr outputNode, inputNode; + inputNode = getInputNode(0); + + outputNode = std::make_shared(inputNode); + + return outputNode; +} + +} // namespace nnhal +} // namespace neuralnetworks +} // namespace hardware +} // namespace android diff --git a/ngraph_creator/operations/src/InstanceNormalization.cpp b/ngraph_creator/operations/src/InstanceNormalization.cpp index 355c003c4..35cc97f4e 100644 --- a/ngraph_creator/operations/src/InstanceNormalization.cpp +++ b/ngraph_creator/operations/src/InstanceNormalization.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -InstanceNormalization::InstanceNormalization(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +InstanceNormalization::InstanceNormalization(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool InstanceNormalization::validate() { @@ -39,15 +39,15 @@ std::shared_ptr InstanceNormalization::createNode() { std::shared_ptr inputNode; bool useNchw = false; - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); ALOGD("%s inputsSize %lu", __func__, inputsSize); // Read inputs inputNode = getInputNode(0); - auto gamma = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); - auto beta = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); - auto epsilon = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - auto layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + auto gamma = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + auto beta = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto epsilon = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + auto layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); if (layout) useNchw = true; if (!useNchw) // No conversion needed if useNchw set diff --git a/ngraph_creator/operations/src/L2Normalization.cpp b/ngraph_creator/operations/src/L2Normalization.cpp index 7891ad5e9..466d0f9d8 100644 --- a/ngraph_creator/operations/src/L2Normalization.cpp +++ b/ngraph_creator/operations/src/L2Normalization.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -L2Normalization::L2Normalization(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +L2Normalization::L2Normalization(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool L2Normalization::validate() { @@ -26,12 +26,12 @@ std::shared_ptr L2Normalization::createNode() { std::shared_ptr inputNode; int32_t inputAxes = -1; - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); ALOGD("%s inputsSize %lu", __func__, inputsSize); inputNode = getInputNode(0); // NN-HAL 1.2 specific optional input if (inputsSize == 2) { - inputAxes = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + inputAxes = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); } auto inputAxesNode = createConstNode(ov::element::i32, {1}, convertToVector(inputAxes)); // TODO: Add support for NNAPI feature level 4, if the elements along an axis are all zeros, the diff --git a/ngraph_creator/operations/src/L2Pooling2D.cpp b/ngraph_creator/operations/src/L2Pooling2D.cpp index b4cede404..c4d4aa511 100644 --- a/ngraph_creator/operations/src/L2Pooling2D.cpp +++ b/ngraph_creator/operations/src/L2Pooling2D.cpp @@ -7,14 +7,14 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -L2Pooling2D::L2Pooling2D(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +L2Pooling2D::L2Pooling2D(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr L2Pooling2D::createNode() { std::shared_ptr inputNode; inputNode = getInputNode(0); - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); bool isImplicit = false, isExplicit = false; if (inputsSize >= 10 && inputsSize <= 11) { @@ -44,21 +44,21 @@ std::shared_ptr L2Pooling2D::createNode() { const auto& inputDimensions = getInputOperandDimensions(0); if (isExplicit) { - padding_left = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); - padding_right = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); - padding_top = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - padding_bottom = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + padding_left = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + padding_right = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + padding_top = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + padding_bottom = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); - filter_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); - filter_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); + filter_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + filter_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); if (inputsSize == 11) { - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); } if (layout) useNchw = true; @@ -67,18 +67,18 @@ std::shared_ptr L2Pooling2D::createNode() { } if (isImplicit) { - padding_scheme = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + padding_scheme = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - filter_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - filter_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + filter_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + filter_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); if (inputsSize == 8) { - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); } if (layout) useNchw = true; diff --git a/ngraph_creator/operations/src/LSTM.cpp b/ngraph_creator/operations/src/LSTM.cpp index 7fbd61742..380c23795 100755 --- a/ngraph_creator/operations/src/LSTM.cpp +++ b/ngraph_creator/operations/src/LSTM.cpp @@ -13,13 +13,13 @@ namespace nnhal { #define ACTIVATION_FUNCTION_TANH 4 #define ACTIVATION_FUNCTION_SIGMOID 6 -LSTM::LSTM(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +LSTM::LSTM(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool LSTM::validate() { - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); - const auto& outputsSize = sModelInfo->getOperationOutputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& outputsSize = mOpModelInfo->getOperationOutputsSize(mNnapiOperationIndex); if (inputsSize != 23) { if (inputsSize != 27) return false; @@ -34,15 +34,15 @@ bool LSTM::validate() { void LSTM::connectOperationToGraph() { createNode(); } std::shared_ptr LSTM::createNode() { - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); bool isCIFGenabled = false, isPeepholeUsed = false, isProjectionUsed = false, isLayerNormUsed = false, isCifgDimsEmpty = true; // checking if CIFG enabled - if (sModelInfo->isOmittedInput(mNnapiOperationIndex, 1) && - sModelInfo->isOmittedInput(mNnapiOperationIndex, 5) && - sModelInfo->isOmittedInput(mNnapiOperationIndex, 12)) { + if (mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 1) && + mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 5) && + mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 12)) { isCIFGenabled = true; } else { if (isValidInputTensor(1) && isValidInputTensor(5) && isValidInputTensor(12)) @@ -52,9 +52,9 @@ std::shared_ptr LSTM::createNode() { } // checking if peephole enabled - if (sModelInfo->isOmittedInput(mNnapiOperationIndex, 9) && - sModelInfo->isOmittedInput(mNnapiOperationIndex, 10) && - sModelInfo->isOmittedInput(mNnapiOperationIndex, 11)) { + if (mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 9) && + mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 10) && + mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 11)) { isPeepholeUsed = false; } else { if (!isCIFGenabled && !isValidInputTensor(9) && isValidInputTensor(10) && @@ -76,7 +76,7 @@ std::shared_ptr LSTM::createNode() { } // checking if projection enabled - if (sModelInfo->isOmittedInput(mNnapiOperationIndex, 16)) { + if (mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 16)) { isProjectionUsed = false; } else { if (isValidInputTensor(16)) @@ -87,10 +87,10 @@ std::shared_ptr LSTM::createNode() { if (inputsSize == 27) { // checking if layer normalization enabled - if (sModelInfo->isOmittedInput(mNnapiOperationIndex, 23) && - sModelInfo->isOmittedInput(mNnapiOperationIndex, 24) && - sModelInfo->isOmittedInput(mNnapiOperationIndex, 25) && - sModelInfo->isOmittedInput(mNnapiOperationIndex, 26)) { + if (mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 23) && + mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 24) && + mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 25) && + mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 26)) { isLayerNormUsed = false; } else { if (isCIFGenabled) { @@ -186,16 +186,16 @@ std::shared_ptr LSTM::createNode() { initial_hidden_state = getInputNode(18); // h_{t-1} initial_cell_state = getInputNode(19); // C_{t-1} - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 20); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 20); if (checkInputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT16)) { - cell_state_clipping = sModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 21); + cell_state_clipping = mOpModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 21); if (isProjectionUsed) - proj_clipping = sModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 22); + proj_clipping = mOpModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 22); } else { - cell_state_clipping = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 21); + cell_state_clipping = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 21); if (isProjectionUsed) - proj_clipping = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 22); + proj_clipping = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 22); } std::shared_ptr i_t, f_t, c_t, o_t; @@ -326,7 +326,7 @@ std::shared_ptr LSTM::createNode() { LstmOutputs[3] = H; for (int i = 0; i < 4; i++) { - auto outputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, i); + auto outputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, i); mNgraphNodes->setOutputAtOperandIndex(outputIndex, LstmOutputs[i]); } diff --git a/ngraph_creator/operations/src/Less.cpp b/ngraph_creator/operations/src/Less.cpp index eb3ece88f..807e5b417 100644 --- a/ngraph_creator/operations/src/Less.cpp +++ b/ngraph_creator/operations/src/Less.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Less::Less(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Less::Less(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Less::createNode() { diff --git a/ngraph_creator/operations/src/LessEqual.cpp b/ngraph_creator/operations/src/LessEqual.cpp index 60333402a..ebac0bc04 100644 --- a/ngraph_creator/operations/src/LessEqual.cpp +++ b/ngraph_creator/operations/src/LessEqual.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -LessEqual::LessEqual(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +LessEqual::LessEqual(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr LessEqual::createNode() { diff --git a/ngraph_creator/operations/src/Log.cpp b/ngraph_creator/operations/src/Log.cpp index ff02ade65..f007f51af 100644 --- a/ngraph_creator/operations/src/Log.cpp +++ b/ngraph_creator/operations/src/Log.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Log::Log(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Log::Log(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Log::createNode() { diff --git a/ngraph_creator/operations/src/LogSoftmax.cpp b/ngraph_creator/operations/src/LogSoftmax.cpp index 768ffe8d2..4445d8369 100644 --- a/ngraph_creator/operations/src/LogSoftmax.cpp +++ b/ngraph_creator/operations/src/LogSoftmax.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -LogSoftmax::LogSoftmax(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +LogSoftmax::LogSoftmax(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr LogSoftmax::createNode() { @@ -20,15 +20,15 @@ std::shared_ptr LogSoftmax::createNode() { std::shared_ptr betaNode; if (checkInputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT16)) { - auto beta = sModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 1); + auto beta = mOpModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 1); betaNode = createConstNode(ov::element::f16, {}, convertToVector(beta)); } else { - auto beta = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + auto beta = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); betaNode = createConstNode(ov::element::f32, {}, convertToVector(beta)); } int axis = -1; - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); - if (inputsSize == 3) axis = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); + if (inputsSize == 3) axis = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); const auto axisNode = createConstNode(ov::element::i32, {1}, convertToVector(axis)); diff --git a/ngraph_creator/operations/src/LogicalAnd.cpp b/ngraph_creator/operations/src/LogicalAnd.cpp index a4c556e7b..cc73ca2a1 100644 --- a/ngraph_creator/operations/src/LogicalAnd.cpp +++ b/ngraph_creator/operations/src/LogicalAnd.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -LogicalAnd::LogicalAnd(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +LogicalAnd::LogicalAnd(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr LogicalAnd::createNode() { diff --git a/ngraph_creator/operations/src/LogicalNot.cpp b/ngraph_creator/operations/src/LogicalNot.cpp index 9f51e810c..32038b1f5 100644 --- a/ngraph_creator/operations/src/LogicalNot.cpp +++ b/ngraph_creator/operations/src/LogicalNot.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -LogicalNot::LogicalNot(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +LogicalNot::LogicalNot(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr LogicalNot::createNode() { diff --git a/ngraph_creator/operations/src/LogicalOr.cpp b/ngraph_creator/operations/src/LogicalOr.cpp index d9dd69abf..677f761dd 100644 --- a/ngraph_creator/operations/src/LogicalOr.cpp +++ b/ngraph_creator/operations/src/LogicalOr.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -LogicalOr::LogicalOr(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +LogicalOr::LogicalOr(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr LogicalOr::createNode() { diff --git a/ngraph_creator/operations/src/Logistic.cpp b/ngraph_creator/operations/src/Logistic.cpp index a1857461f..c1479fbc8 100644 --- a/ngraph_creator/operations/src/Logistic.cpp +++ b/ngraph_creator/operations/src/Logistic.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Logistic::Logistic(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Logistic::Logistic(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Logistic::createNode() { diff --git a/ngraph_creator/operations/src/MaxPool2d.cpp b/ngraph_creator/operations/src/MaxPool2d.cpp index a3859de91..936923495 100644 --- a/ngraph_creator/operations/src/MaxPool2d.cpp +++ b/ngraph_creator/operations/src/MaxPool2d.cpp @@ -7,14 +7,14 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -MaxPool2d::MaxPool2d(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +MaxPool2d::MaxPool2d(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr MaxPool2d::createNode() { std::shared_ptr inputNode; inputNode = getInputNode(0); - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); ALOGD("%s inputsSize %lu", __func__, inputsSize); bool isImplicit = false, isExplicit = false; @@ -46,21 +46,21 @@ std::shared_ptr MaxPool2d::createNode() { const auto& inputDimensions = getInputOperandDimensions(0); if (isExplicit) { - padding_left = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); - padding_right = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); - padding_top = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - padding_bottom = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + padding_left = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + padding_right = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + padding_top = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + padding_bottom = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); - filter_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); - filter_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); + filter_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + filter_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); if (inputsSize == 11) { - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); } if (layout) useNchw = true; @@ -69,18 +69,18 @@ std::shared_ptr MaxPool2d::createNode() { } if (isImplicit) { - padding_scheme = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + padding_scheme = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - filter_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - filter_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + filter_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + filter_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); if (inputsSize == 8) { - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); } if (layout) useNchw = true; diff --git a/ngraph_creator/operations/src/Maximum.cpp b/ngraph_creator/operations/src/Maximum.cpp index d5168cf97..7265a4364 100644 --- a/ngraph_creator/operations/src/Maximum.cpp +++ b/ngraph_creator/operations/src/Maximum.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Maximum::Maximum(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Maximum::Maximum(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Maximum::createNode() { diff --git a/ngraph_creator/operations/src/Mean.cpp b/ngraph_creator/operations/src/Mean.cpp index 120be5703..cbbf62f8d 100644 --- a/ngraph_creator/operations/src/Mean.cpp +++ b/ngraph_creator/operations/src/Mean.cpp @@ -7,15 +7,15 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Mean::Mean(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Mean::Mean(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool Mean::validate() { // TODO: Add Support for all_tensors_as_inputs - const auto& axesOperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& axesOperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); - if (!sModelInfo->isOperandLifeTimeConst(axesOperandIndex)) { + if (!mOpModelInfo->isOperandLifeTimeConst(axesOperandIndex)) { ALOGE("%s Only Constant dimensions supported now", __func__); return false; } @@ -30,7 +30,7 @@ std::shared_ptr Mean::createNode() { input = getInputNode(0); auto reduction_axes = getInputNode(1); - auto reduce_dims = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto reduce_dims = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); bool keep_dims = (reduce_dims > 0) ? true : false; std::shared_ptr outputNode; diff --git a/ngraph_creator/operations/src/Minimum.cpp b/ngraph_creator/operations/src/Minimum.cpp index afc2dd390..4b062942f 100644 --- a/ngraph_creator/operations/src/Minimum.cpp +++ b/ngraph_creator/operations/src/Minimum.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Minimum::Minimum(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Minimum::Minimum(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Minimum::createNode() { diff --git a/ngraph_creator/operations/src/Mul.cpp b/ngraph_creator/operations/src/Mul.cpp index f944506d8..b0787372f 100644 --- a/ngraph_creator/operations/src/Mul.cpp +++ b/ngraph_creator/operations/src/Mul.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Mul::Mul(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Mul::Mul(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Mul::createNode() { @@ -18,7 +18,7 @@ std::shared_ptr Mul::createNode() { input1 = getInputNode(0); input2 = getInputNode(1); - auto activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); auto mulNode = std::make_shared(input1, input2, ov::op::AutoBroadcastType::NUMPY); diff --git a/ngraph_creator/operations/src/Neg.cpp b/ngraph_creator/operations/src/Neg.cpp index 0f4c71d2b..b089b73fa 100644 --- a/ngraph_creator/operations/src/Neg.cpp +++ b/ngraph_creator/operations/src/Neg.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Neg::Neg(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Neg::Neg(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Neg::createNode() { diff --git a/ngraph_creator/operations/src/NotEqual.cpp b/ngraph_creator/operations/src/NotEqual.cpp index c788c9e4c..74fe43cd8 100644 --- a/ngraph_creator/operations/src/NotEqual.cpp +++ b/ngraph_creator/operations/src/NotEqual.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -NotEqual::NotEqual(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +NotEqual::NotEqual(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr NotEqual::createNode() { diff --git a/ngraph_creator/operations/src/OperationsBase.cpp b/ngraph_creator/operations/src/OperationsBase.cpp index 686bf9fac..638217c08 100755 --- a/ngraph_creator/operations/src/OperationsBase.cpp +++ b/ngraph_creator/operations/src/OperationsBase.cpp @@ -7,9 +7,6 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -IntelDeviceType OperationsBase::sPluginType; -std::shared_ptr OperationsBase::sModelInfo; - std::shared_ptr OperationsBase::transpose(ConversionType type, ov::Output input) { ov::AxisVector order; @@ -62,13 +59,13 @@ std::shared_ptr OperationsBase::transpose(ConversionType type, return std::make_shared(input, order_node); } -// override createNodeForPlugin in case sPluginType specific implementation is required +// override createNodeForPlugin in case mPluginType specific implementation is required std::shared_ptr OperationsBase::createNodeForPlugin() { return createNode(); } // override connectOperationToGraph in case Operation has multiple outputs void OperationsBase::connectOperationToGraph() { auto outputNode = createNodeForPlugin(); - const auto op = sModelInfo->getOperand(mDefaultOutputIndex); + const auto op = mOpModelInfo->getOperand(mDefaultOutputIndex); if (op.type == OperandType::TENSOR_QUANT8_ASYMM) { outputNode = QuantizeNode(outputNode, mDefaultOutputIndex, ov::element::u8); } @@ -96,8 +93,10 @@ void OperationsBase::addResultNode(size_t index, std::shared_ptr resul mNgraphNodes->setResultNode(index, resultNode); } -OperationsBase::OperationsBase(int operationIndex) : mNnapiOperationIndex(operationIndex) { +OperationsBase::OperationsBase(int operationIndex, GraphMetadata graphMetadata) : mNnapiOperationIndex(operationIndex) { mDefaultOutputIndex = 0; + mOpModelInfo = graphMetadata.modelInfo; + mPluginType = graphMetadata.pluginType; } void OperationsBase::setNgraphNodes(std::shared_ptr nodes) { mNgraphNodes = nodes; } @@ -111,7 +110,7 @@ bool OperationsBase::validateForPlugin() { bool OperationsBase::checkOperandType(uint32_t operandIndex, const int32_t expectedOperandType, const std::string& strLogInfo) { - const auto operandType = (int32_t)sModelInfo->getOperandType(operandIndex); + const auto operandType = (int32_t)mOpModelInfo->getOperandType(operandIndex); if (operandType != expectedOperandType) { ALOGV("OperationIndex %d %s Index %d type %d invalid", mNnapiOperationIndex, strLogInfo.c_str(), operandIndex, operandType); @@ -122,16 +121,16 @@ bool OperationsBase::checkOperandType(uint32_t operandIndex, const int32_t expec return true; } bool OperationsBase::checkOutputOperandType(uint32_t index, const int32_t expectedOperandType) { - const auto& operandIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, index); + const auto& operandIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, index); return checkOperandType(operandIndex, expectedOperandType, "Output"); } bool OperationsBase::checkInputOperandType(uint32_t index, const int32_t expectedOperandType) { - const auto& operandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, index); + const auto& operandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, index); return checkOperandType(operandIndex, expectedOperandType, "Input"); } const vec OperationsBase::getInputOperandDimensions(uint32_t inputIndex) { - const auto& operandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, inputIndex); - const auto& operand = sModelInfo->getOperand(operandIndex); + const auto& operandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, inputIndex); + const auto& operand = mOpModelInfo->getOperand(operandIndex); return operand.dimensions; } @@ -153,21 +152,22 @@ std::shared_ptr OperationsBase::QuantizeNode(std::shared_ptr auto floatElementType = ov::element::f32; auto intElementType = ov::element::i32; - float inputScale = sModelInfo->getOperandScale(index); - int inputZeroPoint = sModelInfo->getOperandZeroPoint(index); + float inputScale = mOpModelInfo->getOperandScale(index); + int inputZeroPoint = mOpModelInfo->getOperandZeroPoint(index); auto scale = createConstNode(floatElementType, {}, convertToVector(inputScale)); auto zeroPoint = createConstNode(intElementType, {}, convertToVector(inputZeroPoint)); - if (input->get_element_type() != ov::element::f32) + if (input->get_element_type() != ov::element::f32) { input = std::make_shared(input, floatElementType); + } auto div = std::make_shared(input, scale); ov::op::v5::Round::RoundMode mode = ov::op::v5::Round::RoundMode::HALF_TO_EVEN; auto round = std::make_shared(div, mode); auto convertRound = std::make_shared(round, ov::element::i32); auto sum = std::make_shared(convertRound, zeroPoint); std::shared_ptr data; - const auto operand = sModelInfo->getOperand(index); + const auto operand = mOpModelInfo->getOperand(index); if (operand.type == OperandType::TENSOR_QUANT8_ASYMM) data = std::make_shared(sum, 0, 255); else if (operand.type == OperandType::TENSOR_QUANT8_SYMM || @@ -179,18 +179,18 @@ std::shared_ptr OperationsBase::QuantizeNode(std::shared_ptr data = std::make_shared(sum, 0, 65535); std::shared_ptr outputNode; - if (data != nullptr && data->get_element_type() != quantizeType) + if (data != nullptr && data->get_element_type() != quantizeType) { outputNode = std::make_shared(data, quantizeType); - else + } else { outputNode = data; - + } return outputNode; } std::shared_ptr OperationsBase::DequantizeNode(std::shared_ptr input, uint32_t index, ov::element::Type dequantizeType) { - const auto operand = sModelInfo->getOperand(index); + const auto operand = mOpModelInfo->getOperand(index); std::shared_ptr outputNode; if (input->get_element_type() != ov::element::f32) @@ -208,9 +208,9 @@ std::shared_ptr OperationsBase::DequantizeNode(std::shared_ptr(input, scaleNode); } else { auto scaleNode = createConstNode(ov::element::f32, {}, - convertToVector(sModelInfo->getOperandScale(index))); + convertToVector(mOpModelInfo->getOperandScale(index))); auto zeroPointNode = createConstNode( - ov::element::f32, {}, convertToVector(sModelInfo->getOperandZeroPoint(index))); + ov::element::f32, {}, convertToVector(mOpModelInfo->getOperandZeroPoint(index))); if (operand.type == OperandType::TENSOR_QUANT8_ASYMM || operand.type == OperandType::TENSOR_QUANT16_ASYMM || @@ -221,8 +221,9 @@ std::shared_ptr OperationsBase::DequantizeNode(std::shared_ptr(outputNode, dequantizeType); + } return outputNode; } diff --git a/ngraph_creator/operations/src/PRelu.cpp b/ngraph_creator/operations/src/PRelu.cpp index 22fd9623b..ef964d108 100644 --- a/ngraph_creator/operations/src/PRelu.cpp +++ b/ngraph_creator/operations/src/PRelu.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -PRelu::PRelu(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +PRelu::PRelu(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool PRelu::validate() { diff --git a/ngraph_creator/operations/src/Pad.cpp b/ngraph_creator/operations/src/Pad.cpp index 7b5a318d8..00b3a81bc 100644 --- a/ngraph_creator/operations/src/Pad.cpp +++ b/ngraph_creator/operations/src/Pad.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Pad::Pad(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Pad::Pad(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool Pad::validate() { @@ -20,9 +20,9 @@ bool Pad::validate() { if (inputRank < 2) return false; // TODO: Add Support for all_tensors_as_inputs - const auto& padOperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& padOperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); - if (!sModelInfo->isOperandLifeTimeConst(padOperandIndex)) { + if (!mOpModelInfo->isOperandLifeTimeConst(padOperandIndex)) { ALOGE("%s Only Constant dimensions supported now", __func__); return false; } @@ -34,9 +34,9 @@ std::shared_ptr Pad::createNode() { // Creating input nodes auto inputNode = getInputNode(0); - const auto& paddingsOperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& paddingsOperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); // Fetch the 2D paddings as a 1D vector, and then split it into 2 - auto paddings_2d = sModelInfo->GetConstVecOperand(paddingsOperandIndex); + auto paddings_2d = mOpModelInfo->GetConstVecOperand(paddingsOperandIndex); auto half_size = paddings_2d.size() / 2; std::vector paddings_0(half_size); std::vector paddings_1(half_size); diff --git a/ngraph_creator/operations/src/PadV2.cpp b/ngraph_creator/operations/src/PadV2.cpp index 6194fffdb..f2c23e39d 100644 --- a/ngraph_creator/operations/src/PadV2.cpp +++ b/ngraph_creator/operations/src/PadV2.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -PadV2::PadV2(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +PadV2::PadV2(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool PadV2::validate() { @@ -20,9 +20,9 @@ bool PadV2::validate() { if (inputRank < 2) return false; // TODO: Add Support for all_tensors_as_inputs - const auto& padOperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& padOperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); - if (!sModelInfo->isOperandLifeTimeConst(padOperandIndex)) { + if (!mOpModelInfo->isOperandLifeTimeConst(padOperandIndex)) { ALOGE("%s Only Constant dimensions supported now", __func__); return false; } @@ -34,17 +34,17 @@ std::shared_ptr PadV2::createNode() { // Creating input nodes auto inputNode = getInputNode(0); std::shared_ptr pad_value; - auto inputIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 0); + auto inputIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 0); if (checkInputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT32)) { - auto pad_scalar_value = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto pad_scalar_value = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); pad_value = createConstNode(ov::element::f32, {}, convertToVector(pad_scalar_value)); } else if (checkInputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT16)) { - auto pad_scalar_value = sModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 2); + auto pad_scalar_value = mOpModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 2); pad_value = createConstNode(ov::element::f16, {}, convertToVector(pad_scalar_value)); } else if (checkInputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM) || checkInputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM_SIGNED)) { - auto pad_scalar_value = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto pad_scalar_value = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); pad_value = createConstNode(ov::element::i32, {}, convertToVector(pad_scalar_value)); // scale and zeropoint of pad value has to be same as in inputNode. so inputIndex is passed @@ -52,9 +52,9 @@ std::shared_ptr PadV2::createNode() { pad_value = DequantizeNode(pad_value, inputIndex, ov::element::f32); } - const auto& paddingsOperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& paddingsOperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); // Fetch the 2D paddings as a 1D vector, and then split it into 2 - auto paddings_2d = sModelInfo->GetConstVecOperand(paddingsOperandIndex); + auto paddings_2d = mOpModelInfo->GetConstVecOperand(paddingsOperandIndex); auto half_size = paddings_2d.size() / 2; std::vector paddings_0(half_size); std::vector paddings_1(half_size); diff --git a/ngraph_creator/operations/src/Pow.cpp b/ngraph_creator/operations/src/Pow.cpp index 385bba0c4..bfb7d4de8 100644 --- a/ngraph_creator/operations/src/Pow.cpp +++ b/ngraph_creator/operations/src/Pow.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Pow::Pow(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Pow::Pow(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Pow::createNode() { diff --git a/ngraph_creator/operations/src/Quantize.cpp b/ngraph_creator/operations/src/Quantize.cpp index 487aa2c64..637165bc4 100755 --- a/ngraph_creator/operations/src/Quantize.cpp +++ b/ngraph_creator/operations/src/Quantize.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Quantize::Quantize(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Quantize::Quantize(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } void Quantize::connectOperationToGraph() { createNode(); } @@ -16,10 +16,21 @@ void Quantize::connectOperationToGraph() { createNode(); } std::shared_ptr Quantize::createNode() { // Creating input nodes auto input = getInputNode(0); - const auto& outputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); - auto outputNode = QuantizeNode(input, outputIndex, ov::element::u8); + ov::element::Type elementType; + const auto& outputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); + if (checkOutputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM)) { + elementType = ov::element::u8; + } else if (checkOutputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM_SIGNED)) { + elementType = ov::element::i8; + } else { + ALOGE("Invalid Output Operand Type %d",mOpModelInfo->getOperandType(outputIndex)); + } + auto outputNode = QuantizeNode(input, outputIndex, elementType); - mNgraphNodes->setOutputAtOperandIndex(outputIndex, outputNode); + if (outputNode != nullptr) + { + mNgraphNodes->setOutputAtOperandIndex(outputIndex, outputNode); + } return nullptr; } diff --git a/ngraph_creator/operations/src/RNN.cpp b/ngraph_creator/operations/src/RNN.cpp index 2a05f67d2..64e4cb737 100755 --- a/ngraph_creator/operations/src/RNN.cpp +++ b/ngraph_creator/operations/src/RNN.cpp @@ -9,8 +9,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -RNN::RNN(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +RNN::RNN(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } void RNN::connectOperationToGraph() { createNode(); } @@ -25,7 +25,7 @@ std::shared_ptr RNN::createNode() { bias = getInputNode(3); initial_hidden_state = getInputNode(4); - auto activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + auto activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); // inputs * input_weights auto input_W = std::make_shared(input, W, false, true); @@ -39,7 +39,7 @@ std::shared_ptr RNN::createNode() { auto outputNode = applyActivation(i_t, activationFn); for (int i = 0; i < 2; i++) { - auto outputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, i); + auto outputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, i); std::shared_ptr outNode; if (i == 1) { outNode = outputNode; diff --git a/ngraph_creator/operations/src/ROIAlign.cpp b/ngraph_creator/operations/src/ROIAlign.cpp index 35f6d5514..a04d3d263 100644 --- a/ngraph_creator/operations/src/ROIAlign.cpp +++ b/ngraph_creator/operations/src/ROIAlign.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -ROIAlign::ROIAlign(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +ROIAlign::ROIAlign(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool ROIAlign::validate() { @@ -36,8 +36,8 @@ bool ROIAlign::validate() { // TODO: support for different height_ratio and width_ratio // values - auto height_ratio = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - auto width_ratio = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + auto height_ratio = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + auto width_ratio = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); if (height_ratio != width_ratio) { ALOGE( "%s: Ratio of Height and Ratio of Width from orginal image to feature map must be same " @@ -59,19 +59,19 @@ std::shared_ptr ROIAlign::createNode() { auto feat_maps = getInputNode(0); // 4D tensor auto rois = getInputNode(1); // 2D tensor auto batch_indices = getInputNode(2); // 1D tensor - auto output_height = sModelInfo->ParseOperationInput( + auto output_height = mOpModelInfo->ParseOperationInput( mNnapiOperationIndex, 3); // height of the output tensor - auto output_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, + auto output_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); // width of the output tensor - auto height_ratio = sModelInfo->ParseOperationInput( + auto height_ratio = mOpModelInfo->ParseOperationInput( mNnapiOperationIndex, 5); // ratio from the height of original image to the height of feature map. - // auto width_ratio = sModelInfo->ParseOperationInput( + // auto width_ratio = mOpModelInfo->ParseOperationInput( // mNnapiOperationIndex, // 6); // ratio from the width of original image to the height of feature map. - auto sampling_pts_h = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); - // auto sampling_pts_w = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); - auto layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); + auto sampling_pts_h = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + // auto sampling_pts_w = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); + auto layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); if (layout) useNchw = true; diff --git a/ngraph_creator/operations/src/ROIPooling.cpp b/ngraph_creator/operations/src/ROIPooling.cpp index 72400484a..7247d0c86 100755 --- a/ngraph_creator/operations/src/ROIPooling.cpp +++ b/ngraph_creator/operations/src/ROIPooling.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -ROIPooling::ROIPooling(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +ROIPooling::ROIPooling(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool ROIPooling::validate() { @@ -32,8 +32,8 @@ bool ROIPooling::validate() { // TODO: support for different height_ratio and width_ratio // values - auto height_ratio = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - auto width_ratio = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + auto height_ratio = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + auto width_ratio = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); if (height_ratio != width_ratio) { ALOGE( "%s: Ratio of Height and Ratio of Width from orginal image to feature map must be same " @@ -53,14 +53,14 @@ std::shared_ptr ROIPooling::createNode() { // Read inputs auto feat_maps = getInputNode(0); // 4D tensor - auto output_height = sModelInfo->ParseOperationInput( + auto output_height = mOpModelInfo->ParseOperationInput( mNnapiOperationIndex, 3); // height of the output tensor - auto output_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, + auto output_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); // width of the output tensor - auto height_ratio = sModelInfo->ParseOperationInput( + auto height_ratio = mOpModelInfo->ParseOperationInput( mNnapiOperationIndex, 5); // ratio from the height of original image to the height of feature map. - auto layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + auto layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); if (layout) useNchw = true; @@ -75,13 +75,13 @@ std::shared_ptr ROIPooling::createNode() { std::vector> inputs; auto axis = 1; // add bi node to inputs for concat - const auto& biOperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); - auto bi_vec = sModelInfo->GetConstVecOperand(biOperandIndex); + const auto& biOperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 2); + auto bi_vec = mOpModelInfo->GetConstVecOperand(biOperandIndex); const auto bi_node = createConstNode(ov::element::f32, ov::Shape{bi_vec.size(), 1}, bi_vec); inputs.push_back(bi_node); // add rois node to inputs for concat - auto inputIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); + auto inputIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); auto inputOp = mNgraphNodes->getOperationOutput(inputIndex); inputs.push_back(inputOp); diff --git a/ngraph_creator/operations/src/RSQRT.cpp b/ngraph_creator/operations/src/RSQRT.cpp index f77aa3459..46c180e46 100644 --- a/ngraph_creator/operations/src/RSQRT.cpp +++ b/ngraph_creator/operations/src/RSQRT.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -RSQRT::RSQRT(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +RSQRT::RSQRT(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr RSQRT::createNode() { diff --git a/ngraph_creator/operations/src/ReduceAll.cpp b/ngraph_creator/operations/src/ReduceAll.cpp index 21d9ac4a3..605a1f68b 100644 --- a/ngraph_creator/operations/src/ReduceAll.cpp +++ b/ngraph_creator/operations/src/ReduceAll.cpp @@ -7,15 +7,15 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -ReduceAll::ReduceAll(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +ReduceAll::ReduceAll(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr ReduceAll::createNode() { // Creating input nodes auto input = getInputNode(0); auto reduction_axes = getInputNode(1); - auto keep_dims = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto keep_dims = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); auto outputNode = std::make_shared(input, reduction_axes, keep_dims); diff --git a/ngraph_creator/operations/src/ReduceAny.cpp b/ngraph_creator/operations/src/ReduceAny.cpp index a891424d9..15367dada 100644 --- a/ngraph_creator/operations/src/ReduceAny.cpp +++ b/ngraph_creator/operations/src/ReduceAny.cpp @@ -7,15 +7,15 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -ReduceAny::ReduceAny(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +ReduceAny::ReduceAny(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr ReduceAny::createNode() { // Creating input nodes auto input = getInputNode(0); auto reduction_axes = getInputNode(1); - auto keep_dims = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto keep_dims = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); auto outputNode = std::make_shared(input, reduction_axes, keep_dims); diff --git a/ngraph_creator/operations/src/ReduceMax.cpp b/ngraph_creator/operations/src/ReduceMax.cpp index aff178c56..1607d7672 100644 --- a/ngraph_creator/operations/src/ReduceMax.cpp +++ b/ngraph_creator/operations/src/ReduceMax.cpp @@ -7,15 +7,15 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -ReduceMax::ReduceMax(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +ReduceMax::ReduceMax(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr ReduceMax::createNode() { // Creating input nodes auto input = getInputNode(0); auto reduction_axes = getInputNode(1); - auto keep_dims = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto keep_dims = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); std::shared_ptr outputNode; outputNode = std::make_shared(input, reduction_axes, keep_dims); diff --git a/ngraph_creator/operations/src/ReduceMin.cpp b/ngraph_creator/operations/src/ReduceMin.cpp index c6bcd2f08..1d8380501 100644 --- a/ngraph_creator/operations/src/ReduceMin.cpp +++ b/ngraph_creator/operations/src/ReduceMin.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -ReduceMin::ReduceMin(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +ReduceMin::ReduceMin(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr ReduceMin::createNode() { @@ -18,7 +18,7 @@ std::shared_ptr ReduceMin::createNode() { input = getInputNode(0); auto reduction_axes = getInputNode(1); - auto keep_dims = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto keep_dims = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); std::shared_ptr outputNode; outputNode = std::make_shared(input, reduction_axes, keep_dims); diff --git a/ngraph_creator/operations/src/ReduceProd.cpp b/ngraph_creator/operations/src/ReduceProd.cpp index c7741fcb5..20216397e 100644 --- a/ngraph_creator/operations/src/ReduceProd.cpp +++ b/ngraph_creator/operations/src/ReduceProd.cpp @@ -7,15 +7,15 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -ReduceProd::ReduceProd(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +ReduceProd::ReduceProd(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr ReduceProd::createNode() { // Creating input nodes auto input = getInputNode(0); auto reduction_axes = getInputNode(1); - auto keep_dims = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto keep_dims = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); auto outputNode = std::make_shared(input, reduction_axes, keep_dims); diff --git a/ngraph_creator/operations/src/ReduceSum.cpp b/ngraph_creator/operations/src/ReduceSum.cpp index eb8043a14..df53ce332 100644 --- a/ngraph_creator/operations/src/ReduceSum.cpp +++ b/ngraph_creator/operations/src/ReduceSum.cpp @@ -7,15 +7,15 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -ReduceSum::ReduceSum(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +ReduceSum::ReduceSum(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr ReduceSum::createNode() { // Creating input nodes auto input = getInputNode(0); auto reduction_axes = getInputNode(1); - auto keep_dims = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto keep_dims = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); auto outputNode = std::make_shared(input, reduction_axes, keep_dims); diff --git a/ngraph_creator/operations/src/Relu.cpp b/ngraph_creator/operations/src/Relu.cpp index c7eb6c275..f8edd556b 100644 --- a/ngraph_creator/operations/src/Relu.cpp +++ b/ngraph_creator/operations/src/Relu.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Relu::Relu(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Relu::Relu(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Relu::createNode() { diff --git a/ngraph_creator/operations/src/Relu1.cpp b/ngraph_creator/operations/src/Relu1.cpp index ab57a0c5e..791d8c5f2 100644 --- a/ngraph_creator/operations/src/Relu1.cpp +++ b/ngraph_creator/operations/src/Relu1.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Relu1::Relu1(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Relu1::Relu1(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Relu1::createNode() { diff --git a/ngraph_creator/operations/src/Relu6.cpp b/ngraph_creator/operations/src/Relu6.cpp index 5b94b2920..84e1a78a2 100644 --- a/ngraph_creator/operations/src/Relu6.cpp +++ b/ngraph_creator/operations/src/Relu6.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Relu6::Relu6(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Relu6::Relu6(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Relu6::createNode() { diff --git a/ngraph_creator/operations/src/Reshape.cpp b/ngraph_creator/operations/src/Reshape.cpp index 18e064fe4..7a3a5d35f 100644 --- a/ngraph_creator/operations/src/Reshape.cpp +++ b/ngraph_creator/operations/src/Reshape.cpp @@ -7,13 +7,13 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Reshape::Reshape(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Reshape::Reshape(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool Reshape::validate() { - const auto& dimsOperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - if (!sModelInfo->isOperandLifeTimeConst(dimsOperandIndex) || !isValidInputTensor(1)) { + const auto& dimsOperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + if (!mOpModelInfo->isOperandLifeTimeConst(dimsOperandIndex) || !isValidInputTensor(1)) { // TODO: Support CPU_reshape_all_tensors_as_inputs ALOGE("%s Only Constant non-zero dimensions supported now", __func__); return false; @@ -23,8 +23,8 @@ bool Reshape::validate() { } std::shared_ptr Reshape::createNode() { - const auto& dimsOperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - auto outDims = sModelInfo->GetConstVecOperand(dimsOperandIndex); + const auto& dimsOperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + auto outDims = mOpModelInfo->GetConstVecOperand(dimsOperandIndex); VLOGDIMS(L3, outDims, "Reshape::createNode dims"); std::shared_ptr inputOp; inputOp = getInputNode(0); diff --git a/ngraph_creator/operations/src/ResizeBilinear.cpp b/ngraph_creator/operations/src/ResizeBilinear.cpp index c69faf58c..0c4e13f59 100644 --- a/ngraph_creator/operations/src/ResizeBilinear.cpp +++ b/ngraph_creator/operations/src/ResizeBilinear.cpp @@ -7,23 +7,11 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -ResizeBilinear::ResizeBilinear(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +ResizeBilinear::ResizeBilinear(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool ResizeBilinear::validate() { - // TODO Add FLOAT16 check when VPUX plugin is supported - if (!checkOutputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT32) && - !checkOutputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM)) { - ALOGE("%s check for output types failed", __func__); - return false; - } - - if (!checkInputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT32) && - !checkInputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM)) { - return false; - } - const auto& inputDimensionsSize = getInputOperandDimensions(0).size(); if (inputDimensionsSize != 4) { ALOGE("%s Invalid dimensions size for input(%lu)", __func__, inputDimensionsSize); @@ -34,7 +22,7 @@ bool ResizeBilinear::validate() { } std::shared_ptr ResizeBilinear::createNode() { - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); std::shared_ptr outputNode; int32_t input_width = 0, input_height = 0; @@ -51,13 +39,13 @@ std::shared_ptr ResizeBilinear::createNode() { inputNode = getInputNode(0); switch (inputsSize) { case 6: - half_pixel = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + half_pixel = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); __attribute__((fallthrough)); case 5: - align_corners = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + align_corners = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); __attribute__((fallthrough)); case 4: - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); __attribute__((fallthrough)); default: break; @@ -72,25 +60,37 @@ std::shared_ptr ResizeBilinear::createNode() { input_height = inputDimensions[1]; } - if (!useNchw) inputNode = transpose(NHWC_NCHW, inputNode); + const auto& inputIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 0); + const auto inputOp = mOpModelInfo->getOperand(inputIndex); + if (!useNchw) { // No conversion needed if useNchw set + inputNode = transpose(NHWC_NCHW, inputNode); + } + // FLOAT16 type check added for future when VPUX plugin support is added - if (checkInputOperandType(1, (int32_t)OperandType::FLOAT32) || - checkInputOperandType(1, (int32_t)OperandType::FLOAT16)) { + if (checkInputOperandType(1, (int32_t)OperandType::FLOAT32)) { // In tensorflow lite, resizing by size is supported. Scaling factors are // calculated based on output shape. attrs.shape_calculation_mode = ov::op::v4::Interpolate::ShapeCalcMode::sizes; - width_scale = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); - height_scale = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + width_scale = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + height_scale = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); out_width = (int)(input_width * width_scale); out_height = (int)(input_height * height_scale); // Recalculating scaling factors here because of typecasting output shape to // integer width_scale = (float)out_width / (float)input_width; height_scale = (float)out_height / (float)input_height; + } else if (checkInputOperandType(1, (int32_t)OperandType::FLOAT16)) { + attrs.shape_calculation_mode = ov::op::v4::Interpolate::ShapeCalcMode::sizes; + width_scale = mOpModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 1); + height_scale = mOpModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 2); + out_width = (int)(input_width * width_scale); + out_height = (int)(input_height * height_scale); + width_scale = (float)out_width / (float)input_width; + height_scale = (float)out_height / (float)input_height; } else if (checkInputOperandType(1, (int32_t)OperandType::INT32)) { attrs.shape_calculation_mode = ov::op::v4::Interpolate::ShapeCalcMode::sizes; - out_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); - out_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + out_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + out_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); width_scale = (float)out_width / (float)input_width; height_scale = (float)out_height / (float)input_height; } @@ -109,7 +109,7 @@ std::shared_ptr ResizeBilinear::createNode() { } // mode is passed as "linear" for bilinear interpolation - attrs.mode = ov::op::v4::Interpolate::InterpolateMode::linear; + attrs.mode = ov::op::v4::Interpolate::InterpolateMode::linear_onnx; std::vector output_shape = {out_height, out_width}; auto outputShapeNode = createConstNode(ov::element::i32, {2}, output_shape); @@ -128,12 +128,14 @@ std::shared_ptr ResizeBilinear::createNode() { outputNode = std::make_shared(inputNode, outputShapeNode, scaleNode, axesNode, attrs); + auto outputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); if (!useNchw) { outputNode = transpose(NCHW_NHWC, outputNode); } return outputNode; } + } // namespace nnhal } // namespace neuralnetworks } // namespace hardware diff --git a/ngraph_creator/operations/src/ResizeNearestNeighbor.cpp b/ngraph_creator/operations/src/ResizeNearestNeighbor.cpp index 77411fd15..a61fa8776 100644 --- a/ngraph_creator/operations/src/ResizeNearestNeighbor.cpp +++ b/ngraph_creator/operations/src/ResizeNearestNeighbor.cpp @@ -7,23 +7,11 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -ResizeNearestNeighbor::ResizeNearestNeighbor(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +ResizeNearestNeighbor::ResizeNearestNeighbor(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool ResizeNearestNeighbor::validate() { - // TODO Add FLOAT16 check when VPUX plugin is supported - if (!checkOutputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT32) && - !checkOutputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM)) { - ALOGE("%s check for output types failed", __func__); - return false; - } - - if (!checkInputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT32) && - !checkInputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM)) { - return false; - } - const auto& inputDimensionsSize = getInputOperandDimensions(0).size(); if (inputDimensionsSize != 4) { ALOGE("%s Invalid dimensions size for input(%lu)", __func__, inputDimensionsSize); @@ -34,7 +22,7 @@ bool ResizeNearestNeighbor::validate() { } std::shared_ptr ResizeNearestNeighbor::createNode() { - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); std::shared_ptr outputNode; int32_t input_width = 0, input_height = 0; @@ -51,13 +39,13 @@ std::shared_ptr ResizeNearestNeighbor::createNode() { inputNode = getInputNode(0); switch (inputsSize) { case 6: - half_pixel = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + half_pixel = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); __attribute__((fallthrough)); case 5: - align_corners = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + align_corners = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); __attribute__((fallthrough)); case 4: - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); __attribute__((fallthrough)); default: break; @@ -72,25 +60,35 @@ std::shared_ptr ResizeNearestNeighbor::createNode() { input_height = inputDimensions[1]; } - if (!useNchw) inputNode = transpose(NHWC_NCHW, inputNode); - // FLOAT16 type check added for future when VPUX plugin support is added - if (checkInputOperandType(1, (int32_t)OperandType::FLOAT32) || - checkInputOperandType(1, (int32_t)OperandType::FLOAT16)) { + const auto& inputIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 0); + const auto inputOp = mOpModelInfo->getOperand(inputIndex); + if (!useNchw) { + inputNode = transpose(NHWC_NCHW, inputNode); + } + if (checkInputOperandType(1, (int32_t)OperandType::FLOAT32)) { // In tensorflow lite, resizing by size is supported. Scaling factors are // calculated based on output shape. attrs.shape_calculation_mode = ov::op::v4::Interpolate::ShapeCalcMode::sizes; - width_scale = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); - height_scale = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + width_scale = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + height_scale = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); out_width = (int)(input_width * width_scale); out_height = (int)(input_height * height_scale); // Recalculating scaling factors here because of typecasting output shape to // integer width_scale = (float)out_width / (float)input_width; height_scale = (float)out_height / (float)input_height; + } else if (checkInputOperandType(1, (int32_t)OperandType::FLOAT16)) { + attrs.shape_calculation_mode = ov::op::v4::Interpolate::ShapeCalcMode::sizes; + width_scale = mOpModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 1); + height_scale = mOpModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 2); + out_width = (int)(input_width * width_scale); + out_height = (int)(input_height * height_scale); + width_scale = (float)out_width / (float)input_width; + height_scale = (float)out_height / (float)input_height; } else if (checkInputOperandType(1, (int32_t)OperandType::INT32)) { attrs.shape_calculation_mode = ov::op::v4::Interpolate::ShapeCalcMode::sizes; - out_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); - out_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + out_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + out_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); width_scale = (float)out_width / (float)input_width; height_scale = (float)out_height / (float)input_height; } @@ -102,15 +100,14 @@ std::shared_ptr ResizeNearestNeighbor::createNode() { attrs.coordinate_transformation_mode = ov::op::v4::Interpolate::CoordinateTransformMode::half_pixel; } else { - // If none of the align_corners and half_pixel are true, transformation + // If none of the align_corners and half_pixel are false, transformation // mode is set to asymmetric attrs.coordinate_transformation_mode = ov::op::v4::Interpolate::CoordinateTransformMode::asymmetric; } - // mode is passed as "nearest" for Nearest Neighbor interpolation - attrs.mode = ov::op::v4::Interpolate::InterpolateMode::nearest; - attrs.nearest_mode = ov::op::v4::Interpolate::NearestMode::floor; + // mode is passed as "linear" for bilinear interpolation + attrs.mode = ov::op::v4::Interpolate::InterpolateMode::linear_onnx; std::vector output_shape = {out_height, out_width}; auto outputShapeNode = createConstNode(ov::element::i32, {2}, output_shape); diff --git a/ngraph_creator/operations/src/SQRT.cpp b/ngraph_creator/operations/src/SQRT.cpp index 729b8d4d3..18ef516a5 100644 --- a/ngraph_creator/operations/src/SQRT.cpp +++ b/ngraph_creator/operations/src/SQRT.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -SQRT::SQRT(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +SQRT::SQRT(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr SQRT::createNode() { diff --git a/ngraph_creator/operations/src/Select.cpp b/ngraph_creator/operations/src/Select.cpp index 83d57f4c4..4c817490a 100644 --- a/ngraph_creator/operations/src/Select.cpp +++ b/ngraph_creator/operations/src/Select.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Select::Select(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Select::Select(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Select::createNode() { diff --git a/ngraph_creator/operations/src/Sin.cpp b/ngraph_creator/operations/src/Sin.cpp index be05a39e8..2514436cd 100644 --- a/ngraph_creator/operations/src/Sin.cpp +++ b/ngraph_creator/operations/src/Sin.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Sin::Sin(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Sin::Sin(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Sin::createNode() { diff --git a/ngraph_creator/operations/src/Softmax.cpp b/ngraph_creator/operations/src/Softmax.cpp index 7c961deb9..21dad67a1 100644 --- a/ngraph_creator/operations/src/Softmax.cpp +++ b/ngraph_creator/operations/src/Softmax.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Softmax::Softmax(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Softmax::Softmax(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Softmax::createNode() { @@ -20,15 +20,15 @@ std::shared_ptr Softmax::createNode() { std::shared_ptr betaNode; if (checkInputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT16)) { - auto beta = sModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 1); + auto beta = mOpModelInfo->ParseOperationInput<_Float16>(mNnapiOperationIndex, 1); betaNode = createConstNode(ov::element::f16, {1}, convertToVector(beta)); } else { - auto beta = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + auto beta = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); betaNode = createConstNode(ov::element::f32, {1}, convertToVector(beta)); } int axis = -1; - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); - if (inputsSize == 3) axis = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); + if (inputsSize == 3) axis = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); const auto axisNode = createConstNode(ov::element::i32, {1}, convertToVector(axis)); diff --git a/ngraph_creator/operations/src/SpaceToBatch.cpp b/ngraph_creator/operations/src/SpaceToBatch.cpp index fa3c3bb51..3c90597a8 100644 --- a/ngraph_creator/operations/src/SpaceToBatch.cpp +++ b/ngraph_creator/operations/src/SpaceToBatch.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -SpaceToBatch::SpaceToBatch(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +SpaceToBatch::SpaceToBatch(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool SpaceToBatch::validate() { @@ -17,16 +17,16 @@ bool SpaceToBatch::validate() { if (inputRank != 4) return false; - auto& block_shape_OperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); + auto& block_shape_OperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); // TODO: Add Support for all_tensors_as_inputs - if (!sModelInfo->isOperandLifeTimeConst(block_shape_OperandIndex)) { + if (!mOpModelInfo->isOperandLifeTimeConst(block_shape_OperandIndex)) { ALOGE("%s Only Constant dimensions supported now", __func__); return false; } - auto pad_OperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); + auto pad_OperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 2); // TODO: Add Support for all_tensors_as_inputs - if (!sModelInfo->isOperandLifeTimeConst(pad_OperandIndex)) { + if (!mOpModelInfo->isOperandLifeTimeConst(pad_OperandIndex)) { ALOGE("%s Only Constant dimensions supported now", __func__); return false; } @@ -38,22 +38,22 @@ bool SpaceToBatch::validate() { std::shared_ptr SpaceToBatch::createNode() { int32_t layout = 0; bool useNchw = false; - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); auto inputNode = getInputNode(0); auto& inDims = getInputOperandDimensions(0); - const auto& block_shape_OperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - auto block_shape = sModelInfo->GetConstVecOperand(block_shape_OperandIndex); + const auto& block_shape_OperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + auto block_shape = mOpModelInfo->GetConstVecOperand(block_shape_OperandIndex); // Compensation for the shape to be same as the size of data input shape block_shape.insert(block_shape.begin(), 1); block_shape.insert(block_shape.begin(), 1); - const auto& pad_OperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); + const auto& pad_OperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 2); // Fetch the 2D pad as a 1D vector, and then split it into 2 - auto pad_2d = sModelInfo->GetConstVecOperand(pad_OperandIndex); + auto pad_2d = mOpModelInfo->GetConstVecOperand(pad_OperandIndex); auto half_size = pad_2d.size() / 2; std::vector pad_0(half_size); std::vector pad_1(half_size); @@ -74,7 +74,7 @@ std::shared_ptr SpaceToBatch::createNode() { const auto pad_begin = createConstNode(ov::element::i64, {inDims.size()}, pad_0); const auto pad_end = createConstNode(ov::element::i64, {inDims.size()}, pad_1); - if (inputsSize == 4) layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + if (inputsSize == 4) layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); if (layout) useNchw = true; if (!useNchw) // No conversion needed if useNchw set diff --git a/ngraph_creator/operations/src/SpaceToDepth.cpp b/ngraph_creator/operations/src/SpaceToDepth.cpp index 54f45e49f..2d4c14def 100644 --- a/ngraph_creator/operations/src/SpaceToDepth.cpp +++ b/ngraph_creator/operations/src/SpaceToDepth.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -SpaceToDepth::SpaceToDepth(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +SpaceToDepth::SpaceToDepth(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr SpaceToDepth::createNode() { @@ -16,15 +16,15 @@ std::shared_ptr SpaceToDepth::createNode() { std::shared_ptr input; bool useNchw = false; - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); if (inputsSize == 3) { - auto layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); if (layout) useNchw = true; } input = getInputNode(0); - auto block_size = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + auto block_size = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); if (!useNchw) // No conversion needed if useNchw set input = transpose(NHWC_NCHW, input); diff --git a/ngraph_creator/operations/src/Split.cpp b/ngraph_creator/operations/src/Split.cpp index b4a56a6ff..b3974570d 100755 --- a/ngraph_creator/operations/src/Split.cpp +++ b/ngraph_creator/operations/src/Split.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Split::Split(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Split::Split(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } void Split::connectOperationToGraph() { createNode(); } @@ -19,15 +19,15 @@ std::shared_ptr Split::createNode() { splitNode = getInputNode(0, false); - auto axis = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + auto axis = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); auto axisNode = createConstNode(ov::element::i32, {}, convertToVector(axis)); - auto numSplits = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto numSplits = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); auto outputNode = std::make_shared(splitNode, axisNode, numSplits)->outputs(); for (size_t i = 0; i < numSplits; i++) { - auto outputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, i); + auto outputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, i); // TODO: remove this dummy convert std::shared_ptr outNode; if (checkInputOperandType(0, (int32_t)OperandType::TENSOR_FLOAT32)) { @@ -36,9 +36,10 @@ std::shared_ptr Split::createNode() { outNode = std::make_shared(outputNode[i], ov::element::f16); } else if (checkInputOperandType(0, (int32_t)OperandType::TENSOR_INT32)) { outNode = std::make_shared(outputNode[i], ov::element::i32); - } else if (checkInputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM) || - checkInputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM_SIGNED)) { + } else if (checkInputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM)) { outNode = std::make_shared(outputNode[i], ov::element::u8); + } else if (checkInputOperandType(0, (int32_t)OperandType::TENSOR_QUANT8_ASYMM_SIGNED)) { + outNode = std::make_shared(outputNode[i], ov::element::i8); } // auto outNode = outputNode[i].get_node_shared_ptr(); diff --git a/ngraph_creator/operations/src/Squeeze.cpp b/ngraph_creator/operations/src/Squeeze.cpp index 3d7e6dc09..4037cb0bc 100644 --- a/ngraph_creator/operations/src/Squeeze.cpp +++ b/ngraph_creator/operations/src/Squeeze.cpp @@ -7,19 +7,19 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Squeeze::Squeeze(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Squeeze::Squeeze(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool Squeeze::validate() { // TODO: Add Support for all_tensors_as_inputs - const auto& dimsOperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& dimsOperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); // TODO: Support OmittedInput. // The empty 2nd argument in Squeeze op causes dynamic output // To add support, the dims will have to be calculated statically - if (sModelInfo->isOmittedInput(mNnapiOperationIndex, 1) || - !sModelInfo->isOperandLifeTimeConst(dimsOperandIndex)) { + if (mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 1) || + !mOpModelInfo->isOperandLifeTimeConst(dimsOperandIndex)) { ALOGE("%s Only Constant dimensions supported now", __func__); return false; } @@ -35,7 +35,7 @@ std::shared_ptr Squeeze::createNode() { std::shared_ptr dims; - if (!sModelInfo->isOmittedInput(mNnapiOperationIndex, 1)) + if (!mOpModelInfo->isOmittedInput(mNnapiOperationIndex, 1)) dims = getInputNode(1); else dims = createConstNode(ov::element::i32, {0}, std::vector{}); diff --git a/ngraph_creator/operations/src/StridedSlice.cpp b/ngraph_creator/operations/src/StridedSlice.cpp index 25e4445f4..ee11e0383 100644 --- a/ngraph_creator/operations/src/StridedSlice.cpp +++ b/ngraph_creator/operations/src/StridedSlice.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -StridedSlice::StridedSlice(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +StridedSlice::StridedSlice(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool StridedSlice::validate() { @@ -20,31 +20,31 @@ bool StridedSlice::validate() { } // TODO: Add Support for all_tensors_as_inputs - auto& begins_OperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - if (!sModelInfo->isOperandLifeTimeConst(begins_OperandIndex)) { + auto& begins_OperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + if (!mOpModelInfo->isOperandLifeTimeConst(begins_OperandIndex)) { ALOGE("%s Only Constant dimensions supported now", __func__); return false; } - auto ends_OperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); - if (!sModelInfo->isOperandLifeTimeConst(ends_OperandIndex)) { + auto ends_OperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 2); + if (!mOpModelInfo->isOperandLifeTimeConst(ends_OperandIndex)) { ALOGE("%s Only Constant dimensions supported now", __func__); return false; } - auto& strides_OperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 3); - if (!sModelInfo->isOperandLifeTimeConst(strides_OperandIndex)) { + auto& strides_OperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 3); + if (!mOpModelInfo->isOperandLifeTimeConst(strides_OperandIndex)) { ALOGE("%s Only Constant dimensions supported now", __func__); return false; } - auto shrink_axis_mask = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + auto shrink_axis_mask = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); std::vector shrink_axis_mask_bits = getMaskBits(shrink_axis_mask, inputRank); for (int i = 0; i < inputRank; i++) { if (shrink_axis_mask_bits[i]) { // Check for negative stride when shrink axis bit is set - auto stridesVector = sModelInfo->GetConstVecOperand(strides_OperandIndex); + auto stridesVector = mOpModelInfo->GetConstVecOperand(strides_OperandIndex); if (stridesVector[i] < 0) { ALOGE("%s Negative stride value when shrink axis bit set is not supported", __func__); @@ -52,8 +52,8 @@ bool StridedSlice::validate() { } // check for slice size larger than expected output - auto beginVector = sModelInfo->GetConstVecOperand(begins_OperandIndex); - auto endVector = sModelInfo->GetConstVecOperand(ends_OperandIndex); + auto beginVector = mOpModelInfo->GetConstVecOperand(begins_OperandIndex); + auto endVector = mOpModelInfo->GetConstVecOperand(ends_OperandIndex); if (((beginVector[i] - endVector[i]) > 1) || ((beginVector[i] - endVector[i]) < -1)) { ALOGE("%s Trying to access invalid slice size when shrink axis bit is set", __func__); @@ -72,9 +72,9 @@ std::shared_ptr StridedSlice::createNode() { std::shared_ptr end = getInputNode(2); std::shared_ptr strides = getInputNode(3); - auto begin_mask = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - auto end_mask = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - auto shrink_axis_mask = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + auto begin_mask = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + auto end_mask = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + auto shrink_axis_mask = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); const auto data_dim_size = getInputOperandDimensions(0).size(); std::vector begin_mask_bits, end_mask_bits, shrink_axis_mask_bits; diff --git a/ngraph_creator/operations/src/Sub.cpp b/ngraph_creator/operations/src/Sub.cpp index e2d02f9f0..00584094e 100644 --- a/ngraph_creator/operations/src/Sub.cpp +++ b/ngraph_creator/operations/src/Sub.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Sub::Sub(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Sub::Sub(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Sub::createNode() { @@ -18,7 +18,7 @@ std::shared_ptr Sub::createNode() { input1 = getInputNode(0); input2 = getInputNode(1); - auto activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); + auto activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 2); auto subNode = std::make_shared(input1, input2, ov::op::AutoBroadcastType::NUMPY); diff --git a/ngraph_creator/operations/src/Tanh.cpp b/ngraph_creator/operations/src/Tanh.cpp index 83ce62ba5..b57f7b042 100644 --- a/ngraph_creator/operations/src/Tanh.cpp +++ b/ngraph_creator/operations/src/Tanh.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Tanh::Tanh(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Tanh::Tanh(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } std::shared_ptr Tanh::createNode() { diff --git a/ngraph_creator/operations/src/TopkV2.cpp b/ngraph_creator/operations/src/TopkV2.cpp index 2e51b6a7a..a6cc96e13 100644 --- a/ngraph_creator/operations/src/TopkV2.cpp +++ b/ngraph_creator/operations/src/TopkV2.cpp @@ -7,8 +7,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -TopkV2::TopkV2(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +TopkV2::TopkV2(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } void TopkV2::connectOperationToGraph() { createNode(); } @@ -19,7 +19,7 @@ std::shared_ptr TopkV2::createNode() { input = getInputNode(0); - auto k = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); + auto k = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 1); int axis = -1; // to find largest entries for the last dimension. auto k_node = createConstNode(ov::element::i32, {}, convertToVector(k)); @@ -29,7 +29,7 @@ std::shared_ptr TopkV2::createNode() { auto outputNode = topk->outputs(); for (int i = 0; i < 2; i++) { - auto outputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, i); + auto outputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, i); // TODO: remove this dummy convert std::shared_ptr outNode; if (checkOutputOperandType(i, (int32_t)OperandType::TENSOR_FLOAT32)) { @@ -48,7 +48,7 @@ std::shared_ptr TopkV2::createNode() { mNgraphNodes->setOutputAtOperandIndex(outputIndex, outNode); ALOGD("%s Set Output index %d", __func__, outputIndex); - const auto op = sModelInfo->getOperand(outputIndex); + const auto op = mOpModelInfo->getOperand(outputIndex); } return nullptr; } diff --git a/ngraph_creator/operations/src/Transpose.cpp b/ngraph_creator/operations/src/Transpose.cpp index a05c2f3ec..e65dc4e6c 100644 --- a/ngraph_creator/operations/src/Transpose.cpp +++ b/ngraph_creator/operations/src/Transpose.cpp @@ -7,15 +7,15 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -Transpose::Transpose(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +Transpose::Transpose(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool Transpose::validate() { // TODO: Add Support for all_tensors_as_inputs - const auto& dimsOperandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& dimsOperandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); const auto& dims = getInputOperandDimensions(1); - if (!dims.empty() && dims[0] != 0 && !sModelInfo->isOperandLifeTimeConst(dimsOperandIndex)) { + if (!dims.empty() && dims[0] != 0 && !mOpModelInfo->isOperandLifeTimeConst(dimsOperandIndex)) { ALOGE("%s Only Constant dimensions supported now", __func__); return false; } diff --git a/ngraph_creator/operations/src/TransposeConv2D.cpp b/ngraph_creator/operations/src/TransposeConv2D.cpp index 784a4cca8..6689e2460 100644 --- a/ngraph_creator/operations/src/TransposeConv2D.cpp +++ b/ngraph_creator/operations/src/TransposeConv2D.cpp @@ -9,8 +9,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -TransposeConv2D::TransposeConv2D(int operationIndex) : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +TransposeConv2D::TransposeConv2D(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } bool TransposeConv2D::validate() { @@ -28,8 +28,8 @@ bool TransposeConv2D::validate() { } if (checkInputOperandType(1, (int32_t)OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL)) { - const auto& operandIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - const auto& operand = sModelInfo->getOperand(operandIndex); + const auto& operandIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& operand = mOpModelInfo->getOperand(operandIndex); if (operand.extraParams.channelQuant().channelDim != 0) { return false; } @@ -48,7 +48,7 @@ bool TransposeConv2D::validate() { std::shared_ptr TransposeConv2D::createNode() { std::shared_ptr inputNode; inputNode = getInputNode(0); - const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); + const auto& inputsSize = mOpModelInfo->getOperationInputsSize(mNnapiOperationIndex); ALOGD("%s inputsSize %lu", __func__, inputsSize); bool isImplicit = false, isExplicit = false; @@ -89,16 +89,16 @@ std::shared_ptr TransposeConv2D::createNode() { } if (isExplicit) { - padding_left = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); - padding_right = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - padding_top = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - padding_bottom = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + padding_left = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); + padding_right = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + padding_top = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + padding_bottom = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 9); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 10); if (layout) useNchw = true; @@ -116,19 +116,19 @@ std::shared_ptr TransposeConv2D::createNode() { if (isImplicit) { const auto& outputShapeOperandIndex = - sModelInfo->getOperationInput(mNnapiOperationIndex, 3); + mOpModelInfo->getOperationInput(mNnapiOperationIndex, 3); - auto outputShape = sModelInfo->GetConstVecOperand(outputShapeOperandIndex); + auto outputShape = mOpModelInfo->GetConstVecOperand(outputShapeOperandIndex); size_t spatial_dimensions_size = 2; std::vector spatial_dimensions(spatial_dimensions_size); - padding_scheme = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); + padding_scheme = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); - stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - stride_height = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + stride_width = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + stride_height = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); - activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); - layout = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); + activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 7); + layout = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 8); if (layout) useNchw = true; @@ -158,16 +158,16 @@ std::shared_ptr TransposeConv2D::createNode() { } std::shared_ptr filterNode, biasNode; - const auto& biasIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); + const auto& biasIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 2); filterNode = getInputNode(1); biasNode = getInputNode(2); if (checkInputOperandType(1, (int32_t)OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL)) { - auto filterIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 1); - const auto& filterOperand = sModelInfo->getOperand(filterIndex); + auto filterIndex = mOpModelInfo->getOperationInput(mNnapiOperationIndex, 1); + const auto& filterOperand = mOpModelInfo->getOperand(filterIndex); vec filterScales = filterOperand.extraParams.channelQuant().scales; - float inputScale = sModelInfo->getOperandScale(0); + float inputScale = mOpModelInfo->getOperandScale(0); auto filterScalesNode = createConstNode(ov::element::f32, ov::Shape{filterScales.size()}, filterScales); auto inputScalesNode = diff --git a/ngraph_creator/operations/src/UnidirectionalSequenceRNN.cpp b/ngraph_creator/operations/src/UnidirectionalSequenceRNN.cpp index 36e492b9e..b51be1916 100644 --- a/ngraph_creator/operations/src/UnidirectionalSequenceRNN.cpp +++ b/ngraph_creator/operations/src/UnidirectionalSequenceRNN.cpp @@ -9,9 +9,8 @@ namespace hardware { namespace neuralnetworks { namespace nnhal { -UnidirectionalSequenceRNN::UnidirectionalSequenceRNN(int operationIndex) - : OperationsBase(operationIndex) { - mDefaultOutputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); +UnidirectionalSequenceRNN::UnidirectionalSequenceRNN(int operationIndex, GraphMetadata graphMetadata ) : OperationsBase(operationIndex, graphMetadata ) { + mDefaultOutputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); } void UnidirectionalSequenceRNN::connectOperationToGraph() { createNode(); } @@ -26,8 +25,8 @@ std::shared_ptr UnidirectionalSequenceRNN::createNode() { bias = getInputNode(3); initial_hidden_state = getInputNode(4); - auto activationFn = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); - auto isTimeMajor = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); + auto activationFn = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 5); + auto isTimeMajor = mOpModelInfo->ParseOperationInput(mNnapiOperationIndex, 6); if (!isTimeMajor) { inputNode = transpose(BTS_TBS, inputNode); @@ -84,14 +83,14 @@ std::shared_ptr UnidirectionalSequenceRNN::createNode() { outputNode = transpose(BTS_TBS, outputNode); } - const auto& outputsSize = sModelInfo->getOperationOutputsSize(mNnapiOperationIndex); + const auto& outputsSize = mOpModelInfo->getOperationOutputsSize(mNnapiOperationIndex); - auto outputIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 0); + auto outputIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 0); mNgraphNodes->setOutputAtOperandIndex(outputIndex, outputNode); ALOGD("%s Set Output index %d", __func__, outputIndex); if (outputsSize == 2) { - auto hiddenStateIndex = sModelInfo->getOperationOutput(mNnapiOperationIndex, 1); + auto hiddenStateIndex = mOpModelInfo->getOperationOutput(mNnapiOperationIndex, 1); mNgraphNodes->setOutputAtOperandIndex(hiddenStateIndex, hidden_state_output_last_timestep); ALOGD("%s Set Output index %d", __func__, hiddenStateIndex); } diff --git a/ngraph_creator/src/OperationsFactory.cpp b/ngraph_creator/src/OperationsFactory.cpp index f31deb796..814495370 100755 --- a/ngraph_creator/src/OperationsFactory.cpp +++ b/ngraph_creator/src/OperationsFactory.cpp @@ -9,9 +9,8 @@ namespace nnhal { OperationsFactory::OperationsFactory(IntelDeviceType deviceType, std::shared_ptr modelInfo, - std::shared_ptr nodes) { - OperationsBase::sPluginType = deviceType; - OperationsBase::sModelInfo = modelInfo; + std::shared_ptr nodes) + : mGraphMetadata {modelInfo, deviceType} { ALOGV("%s Constructed", __func__); } OperationsFactory::~OperationsFactory() { ALOGV("%s Destructed", __func__); } @@ -19,165 +18,167 @@ std::shared_ptr OperationsFactory::getOperation( int operationIndex, const OperationType& operationType) { switch (operationType) { case OperationType::ABS: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::ADD: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::ARGMAX: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::ARGMIN: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::AVERAGE_POOL_2D: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::BATCH_TO_SPACE_ND: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::BIDIRECTIONAL_SEQUENCE_RNN: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::CAST: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::CHANNEL_SHUFFLE: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::CONCATENATION: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::CONV_2D: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::DEPTH_TO_SPACE: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::DEPTHWISE_CONV_2D: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::DEQUANTIZE: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::DIV: - return std::make_shared
(operationIndex); + return std::make_shared
(operationIndex, mGraphMetadata); case OperationType::EMBEDDING_LOOKUP: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::EQUAL: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::EXP: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::EXPAND_DIMS: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::FULLY_CONNECTED: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::FLOOR: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::GATHER: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::GREATER: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::GREATER_EQUAL: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::GROUPED_CONV_2D: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); + case OperationType::HARD_SWISH: + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::INSTANCE_NORMALIZATION: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::L2_POOL_2D: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::L2_NORMALIZATION: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::LSTM: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::LESS: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::LESS_EQUAL: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::LOG_SOFTMAX: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::LOG: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::LOGICAL_AND: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::LOGICAL_NOT: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::LOGICAL_OR: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::LOGISTIC: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::MAXIMUM: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::MAX_POOL_2D: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::MEAN: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::MINIMUM: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::MUL: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::NEG: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::NOT_EQUAL: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::PAD: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::PAD_V2: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::POW: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::PRELU: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::QUANTIZE: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::REDUCE_ALL: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::REDUCE_ANY: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::REDUCE_MAX: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::REDUCE_MIN: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::REDUCE_PROD: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::REDUCE_SUM: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::RELU: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::RELU1: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::RELU6: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::RESHAPE: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::RNN: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::ROI_ALIGN: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::ROI_POOLING: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::RSQRT: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::RESIZE_BILINEAR: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::RESIZE_NEAREST_NEIGHBOR: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::SELECT: - return std::make_shared(operationIndex, mGraphMetadata); case OperationType::SOFTMAX: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::SPACE_TO_BATCH_ND: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::SPACE_TO_DEPTH: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::SQRT: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::SIN: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::SPLIT: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::STRIDED_SLICE: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::SQUEEZE: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::SUB: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::TANH: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::TOPK_V2: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::TRANSPOSE_CONV_2D: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::TRANSPOSE: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); case OperationType::UNIDIRECTIONAL_SEQUENCE_RNN: - return std::make_shared(operationIndex); + return std::make_shared(operationIndex, mGraphMetadata); default: ALOGE("%s Cannot identify OperationType %d", __func__, operationType); break; diff --git a/proto/nnhal_object_detection.proto b/proto/nnhal_object_detection.proto index e0f14722a..d129ac575 100644 --- a/proto/nnhal_object_detection.proto +++ b/proto/nnhal_object_detection.proto @@ -1,16 +1,18 @@ -// Copyright 2015 gRPC authors. -// -// 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. +/* +* Copyright (c) 2022 Intel Corporation +* +* 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. +*/ syntax = "proto3"; @@ -27,16 +29,23 @@ service Detection { rpc getInferResult (RequestDataTensors) returns (ReplyDataTensors) {} rpc sendXml (stream RequestDataChunks) returns (ReplyStatus) {} rpc sendBin (stream RequestDataChunks) returns (ReplyStatus) {} + rpc loadModel(RequestString) returns (ReplyStatus) {} rpc prepare (RequestString) returns (ReplyStatus) {} //Placeholder for any future support : RequestString + rpc release (RequestString) returns (ReplyStatus) {} } +message Token { + uint32 data = 1; +} + message RequestDataChunks { bytes data = 1; + Token token = 2; } message RequestString { - string value = 1; + Token token = 1; } message ReplyStatus { bool status = 1; @@ -47,6 +56,25 @@ message DataTensor { bytes data = 1; string node_name = 2; repeated int32 tensor_shape = 3; + enum DATA_TYPE { + boolean = 0; + bf16 = 1; + f16 = 2; + f32 = 3; + f64 = 4; + i4 = 5; + i8 = 6; + i16 = 7; + i32 = 8; + i64 = 9; + u1 = 10; + u4 = 11; + u8 = 12; + u16 = 13; + u32 = 14; + u64 = 15; + } + DATA_TYPE data_type = 4; } // Reply message containing the Output Data Tensors(blobs) @@ -57,4 +85,5 @@ message ReplyDataTensors { // Request message containing the Input Data Tensors(blobs) message RequestDataTensors { repeated DataTensor data_tensors = 1; -} \ No newline at end of file + Token token = 2; +} diff --git a/utils.h b/utils.h index aea1cafc5..a67d051e9 100644 --- a/utils.h +++ b/utils.h @@ -96,12 +96,12 @@ enum PaddingScheme { #define dumpOperand(index, model) \ do { \ const auto op = model.operands[index]; \ - ALOGV("Operand (%zu) %s", index, toString(op).c_str()); \ + ALOGD("Operand (%zu) %s", index, toString(op).c_str()); \ } while (0) #define dumpOperation(operation) \ do { \ - ALOGV("Operation: %s", toString(operation).c_str()); \ + ALOGD("Operation: %s", toString(operation).c_str()); \ } while (0) #define WRONG_DIM (-1)