diff --git a/Android.bp b/Android.bp index 37a025637..f4996e139 100644 --- a/Android.bp +++ b/Android.bp @@ -9,6 +9,7 @@ cc_library_shared { srcs: [ "Driver.cpp", "BasePreparedModel.cpp", + "DetectionClient.cpp", "utils.cpp", "IENetwork.cpp", "ModelManager.cpp", @@ -24,10 +25,20 @@ cc_library_shared { ], include_dirs: [ - "frameworks/ml/nn/common/include", - "frameworks/ml/nn/runtime/include", + "packages/modules/NeuralNetworks/common/include", + "packages/modules/NeuralNetworks/runtime/include", "frameworks/native/libs/nativewindow/include", - "external/mesa3d/include/android_stub" + "external/mesa3d/include/android_stub", + "external/grpc-grpc", + "external/grpc-grpc/include", + "external/grpc-grpc/third_party/cares", + "external/grpc-grpc/third_party/cares/config_android", + "external/grpc-grpc/src/core/ext/filters/client_channel", + "external/grpc-grpc/third_party/nanopb", + "external/protobuf", + "external/protobuf/src", + "external/protobuf/config", + "external/protobuf/android" ], header_libs: [ @@ -90,10 +101,13 @@ cc_library_shared { "libhidlmemory", "liblog", "libnativewindow", + "libtextclassifier_hash", "libutils", "libinference_engine", "libngraph", - "libMKLDNNPlugin" + "libMKLDNNPlugin", + "libgrpc++", + "libprotobuf-cpp-full" ], static_libs: [ @@ -102,10 +116,51 @@ cc_library_shared { "libngraph_creator", ], + generated_headers: [ + "ObjectDetectionProtoStub_h", + ], + generated_sources: [ + "ObjectDetectionProtoStub_cc", + ], + defaults: [ "neuralnetworks_defaults" - ] + ], + + vintf_fragments: ["android.hardware.neuralnetworks@1.3.xml"] + +} + +genrule { + name: "ObjectDetectionProtoStub_h", + tools: [ + "aprotoc", + "protoc-gen-grpc-cpp-plugin", + ], + cmd: "$(location aprotoc) -I$$(dirname $(in)) -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-cpp-plugin) $(in) --grpc_out=$(genDir) --cpp_out=$(genDir)", + srcs: [ + "proto/nnhal_object_detection.proto", + ], + out: [ + "nnhal_object_detection.pb.h", + "nnhal_object_detection.grpc.pb.h", + ], +} +genrule { + name: "ObjectDetectionProtoStub_cc", + tools: [ + "aprotoc", + "protoc-gen-grpc-cpp-plugin", + ], + cmd: "$(location aprotoc) -I$$(dirname $(in)) -Iexternal/protobuf/src --plugin=protoc-gen-grpc=$(location protoc-gen-grpc-cpp-plugin) $(in) --grpc_out=$(genDir) --cpp_out=$(genDir)", + srcs: [ + "proto/nnhal_object_detection.proto", + ], + out: [ + "nnhal_object_detection.pb.cc", + "nnhal_object_detection.grpc.pb.cc", + ], } //############################################################## @@ -120,8 +175,8 @@ cc_binary { srcs: ["service.cpp"], include_dirs: [ - "frameworks/ml/nn/common/include", - "frameworks/ml/nn/runtime/include", + "packages/modules/NeuralNetworks/common/include", + "packages/modules/NeuralNetworks/runtime/include", "frameworks/native/libs/nativewindow/include", "external/mesa3d/include/android_stub" ], @@ -155,4 +210,11 @@ cc_binary { ], compile_multilib: "64", -} \ No newline at end of file +} + +//############################################################## +cc_library_headers { + name: "libnnhal_headers", + vendor: true, + export_include_dirs: ["."], +} diff --git a/BUILD.gn b/BUILD.gn index 288347ebc..5f3a67d8a 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -160,6 +160,7 @@ shared_library("intel_nnhal") { "ModelManager.cpp", "cpu/CpuPreparedModel.cpp", "BasePreparedModel.cpp", + "DetectionClient.cpp", ] include_dirs = [ diff --git a/BasePreparedModel.cpp b/BasePreparedModel.cpp index 94704fdec..aca248dde 100644 --- a/BasePreparedModel.cpp +++ b/BasePreparedModel.cpp @@ -36,6 +36,8 @@ namespace nnhal { using namespace android::nn; static const Timing kNoTiming = {.timeOnDevice = UINT64_MAX, .timeInDriver = UINT64_MAX}; +bool mRemoteCheck = false; +std::shared_ptr mDetectionClient; void BasePreparedModel::deinitialize() { ALOGV("Entering %s", __func__); @@ -56,6 +58,45 @@ bool BasePreparedModel::initialize() { return true; } +bool BasePreparedModel::checkRemoteConnection() { + char grpc_prop[PROPERTY_VALUE_MAX] = ""; + bool is_success = false; + if(getGrpcIpPort(grpc_prop)) { + ALOGV("Attempting GRPC via TCP : %s", grpc_prop); + mDetectionClient = std::make_shared( + grpc::CreateChannel(grpc_prop, grpc::InsecureChannelCredentials())); + if(mDetectionClient) { + auto reply = mDetectionClient->prepare(is_success); + ALOGI("GRPC(TCP) prepare response is %d : %s", is_success, reply.c_str()); + } + } + if (!is_success && getGrpcSocketPath(grpc_prop)) { + ALOGV("Attempting GRPC via unix : %s", grpc_prop); + mDetectionClient = std::make_shared( + grpc::CreateChannel(std::string("unix:") + grpc_prop, grpc::InsecureChannelCredentials())); + if(mDetectionClient) { + auto reply = mDetectionClient->prepare(is_success); + ALOGI("GRPC(unix) prepare response is %d : %s", is_success, reply.c_str()); + } + } + mRemoteCheck = is_success; + return is_success; +} + +bool BasePreparedModel::loadRemoteModel() { + ALOGI("Entering %s", __func__); + bool is_success = false; + if(mDetectionClient) { + auto reply = mDetectionClient->sendIRs(is_success); + ALOGI("sendIRs response GRPC %d %s", is_success, reply.c_str()); + } + else { + ALOGE("%s mDetectionClient is null",__func__); + } + mRemoteCheck = is_success; + return is_success; +} + static Return notify(const sp& callback, const ErrorStatus& status, const hidl_vec&, Timing) { return callback->notify(status); @@ -201,7 +242,7 @@ void asyncExecute(const Request& request, MeasureTiming measure, BasePreparedMod ALOGD("Ignorning output at index(%d), since it is invalid", outIndex); continue; } - ALOGD("Output index: %d layername : %s", outIndex, outputNodeName.c_str()); + ALOGV("Output index: %d layername : %s", outIndex, outputNodeName.c_str()); auto srcBlob = plugin->getBlob(outputNodeName); auto operandType = modelInfo->getOperandType(outIndex); uint32_t actualLength = srcBlob->byteSize(); @@ -337,41 +378,56 @@ static std::tuple, Timing> executeSynch ALOGD("Ignorning input at index(%d), since it is invalid", inIndex); continue; } - ALOGD("Input index: %d layername : %s", inIndex, inputNodeName.c_str()); - auto destBlob = plugin->getBlob(inputNodeName); - if (modelInfo->getOperandType(inIndex) == OperandType::TENSOR_FLOAT16) { - float* dest = destBlob->buffer().as(); - _Float16* src = (_Float16*)srcPtr; - - for (unsigned int i = 0; i < len / 2; i++) { - dest[i] = src[i]; - } + 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(inputNodeName, (uint8_t*)srcPtr, ngraphNw->getOutputShape(inIndex)); } else { - uint8_t* dest = destBlob->buffer().as(); - std::memcpy(dest, (uint8_t*)srcPtr, len); + auto destBlob = plugin->getBlob(inputNodeName); + if (modelInfo->getOperandType(inIndex) == OperandType::TENSOR_FLOAT16) { + float* dest = destBlob->buffer().as(); + _Float16* src = (_Float16*)srcPtr; + + for (unsigned int i = 0; i < len / 2; i++) { + dest[i] = src[i]; + } + } else { + uint8_t* dest = destBlob->buffer().as(); + std::memcpy(dest, (uint8_t*)srcPtr, len); + } } + } - ALOGD("%s Run", __func__); + ALOGV("%s Run", __func__); if (measure == MeasureTiming::YES) deviceStart = now(); - try { - plugin->infer(); - } catch (const std::exception& ex) { - ALOGE("%s Exception !!! %s", __func__, ex.what()); - return {ErrorStatus::GENERAL_FAILURE, {}, kNoTiming}; + 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 { + ALOGV("%s Client Infer", __func__); + plugin->infer(); + } catch (const std::exception& ex) { + ALOGE("%s Exception !!! %s", __func__, ex.what()); + return {ErrorStatus::GENERAL_FAILURE, {}, kNoTiming}; + } } if (measure == MeasureTiming::YES) deviceEnd = now(); for (size_t i = 0; i < request.outputs.size(); i++) { auto outIndex = modelInfo->getModelOutputIndex(i); - ALOGI("OutputIndex: %d", outIndex); + ALOGV("OutputIndex: %d", outIndex); const std::string& outputNodeName = ngraphNw->getNodeName(outIndex); if (outputNodeName == "") { ALOGD("Ignorning output at index(%d), since it is invalid", outIndex); continue; } - ALOGD("Output index: %d layername : %s", outIndex, outputNodeName.c_str()); + ALOGV("Output index: %d layername : %s", outIndex, outputNodeName.c_str()); auto srcBlob = plugin->getBlob(outputNodeName); auto operandType = modelInfo->getOperandType(outIndex); uint32_t actualLength = srcBlob->byteSize(); @@ -379,7 +435,7 @@ static std::tuple, Timing> executeSynch void* destPtr = modelInfo->getBlobFromMemoryPoolOut(request, i, expectedLength); auto outputBlobDims = srcBlob->getTensorDesc().getDims(); - ALOGD("output precision: %d", static_cast(srcBlob->getTensorDesc().getPrecision())); + ALOGV("output precision: %d", static_cast(srcBlob->getTensorDesc().getPrecision())); switch (operandType) { case OperandType::TENSOR_BOOL8: @@ -420,44 +476,50 @@ static std::tuple, Timing> executeSynch "OUTPUT_INSUFFICIENT_SIZE error"); return {ErrorStatus::OUTPUT_INSUFFICIENT_SIZE, modelInfo->getOutputShapes(), kNoTiming}; } - - switch (operandType) { - case OperandType::TENSOR_INT32: - case OperandType::TENSOR_FLOAT32: { - std::memcpy((uint8_t*)destPtr, srcBlob->buffer().as(), - srcBlob->byteSize()); - break; - } - case OperandType::TENSOR_BOOL8: { - floatToUint8(srcBlob->buffer().as(), (uint8_t*)destPtr, srcBlob->size()); - break; - } - case OperandType::TENSOR_QUANT8_ASYMM: { - floatToUint8(srcBlob->buffer().as(), (uint8_t*)destPtr, srcBlob->size()); - break; - } - case OperandType::TENSOR_QUANT8_SYMM: - case OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL: - case OperandType::TENSOR_QUANT8_ASYMM_SIGNED: { - floatToint8(srcBlob->buffer().as(), (int8_t*)destPtr, srcBlob->size()); - break; - } - case OperandType::TENSOR_FLOAT16: { - floatToFloat16(srcBlob->buffer().as(), (_Float16*)destPtr, srcBlob->size()); - break; - } - case OperandType::TENSOR_QUANT16_SYMM: { - floatToInt16(srcBlob->buffer().as(), (int16_t*)destPtr, srcBlob->size()); - break; - } - case OperandType::TENSOR_QUANT16_ASYMM: { - floatToUInt16(srcBlob->buffer().as(), (uint16_t*)destPtr, srcBlob->size()); - break; + //copy output from remote infer + //TODO: Add support for other OperandType + if (mRemoteCheck && mDetectionClient && mDetectionClient->get_status()) { + mDetectionClient->get_output_data(outputNodeName, (uint8_t*)destPtr, ngraphNw->getOutputShape(outIndex)); + } else { + switch (operandType) { + case OperandType::TENSOR_INT32: + case OperandType::TENSOR_FLOAT32: { + std::memcpy((uint8_t*)destPtr, srcBlob->buffer().as(), + srcBlob->byteSize()); + break; + } + case OperandType::TENSOR_BOOL8: { + floatToUint8(srcBlob->buffer().as(), (uint8_t*)destPtr, srcBlob->size()); + break; + } + case OperandType::TENSOR_QUANT8_ASYMM: { + floatToUint8(srcBlob->buffer().as(), (uint8_t*)destPtr, srcBlob->size()); + break; + } + case OperandType::TENSOR_QUANT8_SYMM: + case OperandType::TENSOR_QUANT8_SYMM_PER_CHANNEL: + case OperandType::TENSOR_QUANT8_ASYMM_SIGNED: { + floatToint8(srcBlob->buffer().as(), (int8_t*)destPtr, srcBlob->size()); + break; + } + case OperandType::TENSOR_FLOAT16: { + floatToFloat16(srcBlob->buffer().as(), (_Float16*)destPtr, srcBlob->size()); + break; + } + case OperandType::TENSOR_QUANT16_SYMM: { + floatToInt16(srcBlob->buffer().as(), (int16_t*)destPtr, srcBlob->size()); + break; + } + case OperandType::TENSOR_QUANT16_ASYMM: { + floatToUInt16(srcBlob->buffer().as(), (uint16_t*)destPtr, srcBlob->size()); + break; + } + default: + std::memcpy((uint8_t*)destPtr, srcBlob->buffer().as(), + srcBlob->byteSize()); + break; } - default: - std::memcpy((uint8_t*)destPtr, srcBlob->buffer().as(), - srcBlob->byteSize()); - break; + } } @@ -465,6 +527,9 @@ 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 (measure == MeasureTiming::YES) { driverEnd = now(); diff --git a/BasePreparedModel.h b/BasePreparedModel.h index ba9b2e2e6..c2ff83cb5 100755 --- a/BasePreparedModel.h +++ b/BasePreparedModel.h @@ -33,6 +33,7 @@ #include "Driver.h" #include "IENetwork.h" #include "ModelManager.h" +#include "DetectionClient.h" #include "utils.h" #if __ANDROID__ @@ -51,7 +52,8 @@ namespace 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: BasePreparedModel(const Model& model) : mTargetDevice(IntelDeviceType::CPU) { @@ -89,6 +91,8 @@ class BasePreparedModel : public V1_3::IPreparedModel { executeFenced_cb cb) override; virtual bool initialize(); + virtual bool checkRemoteConnection(); + virtual bool loadRemoteModel(); std::shared_ptr getModelInfo() { return mModelInfo; } diff --git a/DetectionClient.cpp b/DetectionClient.cpp new file mode 100644 index 000000000..7f36a8b91 --- /dev/null +++ b/DetectionClient.cpp @@ -0,0 +1,129 @@ +#include "DetectionClient.h" + +#undef LOG_TAG +#define LOG_TAG "DetectionClient" + +std::string DetectionClient::prepare(bool& flag) { + RequestString request; + request.set_value(""); + ReplyStatus reply; + ClientContext context; + time_point deadline = std::chrono::system_clock::now() + std::chrono::milliseconds(100); + context.set_deadline(deadline); + + Status status = stub_->prepare(&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; + uint32_t CHUNK_SIZE = 1024 * 1024; + std::ifstream fin(fileName, std::ifstream::binary); + std::vector buffer(CHUNK_SIZE, 0); + ALOGV("GRPC sendFile %s", fileName.c_str()); + ALOGI("GRPC sendFile %d sized chunks", CHUNK_SIZE); + + if (!fin.is_open()) ALOGE("GRPC sendFile file Open Error "); + while (!fin.eof()) { + fin.read(buffer.data(), buffer.size()); + std::streamsize s = fin.gcount(); + // ALOGI("GRPC sendFile read %d", s); + request.set_data(buffer.data(), s); + if (!writer->Write(request)) { + ALOGE("GRPC Broken Stream "); + break; + } + } + + writer->WritesDone(); + ALOGI("GRPC sendFile completed"); + return writer->Finish(); +} + +std::string DetectionClient::sendIRs(bool& flag) { + ReplyStatus reply; + ClientContext context; + std::unique_ptr > writerXml = + std::unique_ptr >(stub_->sendXml(&context, &reply)); + Status status = sendFile(IR_XML, writerXml); + + if (status.ok()) { + ClientContext newContext; + std::unique_ptr > writerBin = + std::unique_ptr >( + stub_->sendBin(&newContext, &reply)); + status = sendFile(IR_BIN, writerBin); + if (status.ok()) { + flag = reply.status(); + return (flag ? "status True" : "status False"); + } + } + return std::string(status.error_message()); +} + +void DetectionClient::add_input_data(std::string label, const uint8_t* buffer, std::vector shape) { + const float* src; + size_t index; + size_t size = 1; + + DataTensor* input = request.add_data_tensors(); + input->set_node_name(label); + for (index = 0; index < shape.size(); index++) { + input->add_tensor_shape(shape[index]); + size *= shape[index]; + } + input->set_data(buffer, size * sizeof(float)); +} + +void DetectionClient::get_output_data(std::string label, uint8_t* buffer, std::vector shape) { + std::string src; + size_t index; + size_t size = 1; + + for (index = 0; index < shape.size(); index++) { + size *= shape[index]; + } + 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(); + memcpy(buffer, src.data(), src.length()); + break; + } + } +} + +void DetectionClient::clear_data() { + request.clear_data_tensors(); + reply.clear_data_tensors(); +} + +std::string DetectionClient::remote_infer() { + ClientContext context; + time_point deadline = std::chrono::system_clock::now() + std::chrono::milliseconds(1000); + context.set_deadline(deadline); + + status = stub_->getInferResult(&context, request, &reply); + if (status.ok()) { + if (reply.data_tensors_size() == 0) ALOGE("GRPC reply empty, ovms failure ?"); + return "Success"; + } else { + ALOGE("GRPC Error code: %d, message: %s", status.error_code(), + status.error_message().c_str()); + return std::string(status.error_message()); + } +} + +bool DetectionClient::get_status() { + if (status.ok() && (reply.data_tensors_size() > 0)) + return 1; + else { + return 0; + } +} \ No newline at end of file diff --git a/DetectionClient.h b/DetectionClient.h new file mode 100644 index 000000000..1b272f699 --- /dev/null +++ b/DetectionClient.h @@ -0,0 +1,52 @@ +#ifndef __DETECTION_CLIENT_H +#define __DETECTION_CLIENT_H + +#include +#include +#include +#include +#include +#include +#include "nnhal_object_detection.grpc.pb.h" + +using grpc::Channel; +using grpc::ClientContext; +using grpc::ClientWriter; +using grpc::Status; +using objectDetection::DataTensor; +using objectDetection::Detection; +using objectDetection::ReplyDataTensors; +using objectDetection::ReplyStatus; +using objectDetection::RequestDataChunks; +using objectDetection::RequestDataTensors; +using objectDetection::RequestString; +using time_point = std::chrono::system_clock::time_point; + +static std::string IR_XML("/data/vendor/neuralnetworks/ngraph_ir.xml"); +static std::string IR_BIN("/data/vendor/neuralnetworks/ngraph_ir.bin"); + +class DetectionClient { +public: + DetectionClient(std::shared_ptr channel) : stub_(Detection::NewStub(channel)){} + + std::string prepare(bool& flag); + + Status sendFile(std::string fileName, + std::unique_ptr >& writer); + + std::string sendIRs(bool& flag); + + void add_input_data(std::string label, const uint8_t* buffer, std::vector shape); + void get_output_data(std::string label, uint8_t* buffer, std::vector shape); + void clear_data(); + std::string remote_infer(); + bool get_status(); + +private: + std::unique_ptr stub_; + RequestDataTensors request; + ReplyDataTensors reply; + Status status; +}; + +#endif \ No newline at end of file diff --git a/Driver.cpp b/Driver.cpp index 06a86f5f3..af690d03a 100644 --- a/Driver.cpp +++ b/Driver.cpp @@ -124,7 +124,7 @@ Return Driver::prepareModel(const V1_0_Model& model, ALOGE("failed to create preparedmodel"); return ErrorStatus::INVALID_ARGUMENT; } - for (auto opn : model.operations) dumpOperation(opn); + for (auto& opn : model.operations) dumpOperation(opn); if (!driverPreparedModel->initialize()) { ALOGE("failed to initialize preparedmodel"); @@ -179,7 +179,7 @@ Return Driver::prepareModel_1_1(const V1_1_Model& model, ALOGE("failed to create preparedmodel"); return ErrorStatus::INVALID_ARGUMENT; } - for (auto opn : model.operations) dumpOperation(opn); + for (auto& opn : model.operations) dumpOperation(opn); if (!driverPreparedModel->initialize()) { ALOGE("failed to initialize preparedmodel"); @@ -284,7 +284,7 @@ Return Driver::prepareModel_1_2(const V1_2_Model& model, ALOGE("failed to create preparedmodel"); return ErrorStatus::INVALID_ARGUMENT; } - for (auto opn : model.operations) dumpOperation(opn); + for (auto& opn : model.operations) dumpOperation(opn); if (!driverPreparedModel->initialize()) { ALOGE("failed to initialize preparedmodel"); diff --git a/IENetwork.cpp b/IENetwork.cpp index f0c481c52..9b8360964 100644 --- a/IENetwork.cpp +++ b/IENetwork.cpp @@ -1,10 +1,6 @@ #include "IENetwork.h" #include "ie_common.h" - -#include -#include #include -#include #undef LOG_TAG #define LOG_TAG "IENetwork" @@ -15,7 +11,7 @@ namespace neuralnetworks { namespace nnhal { bool IENetwork::loadNetwork() { - ALOGD("%s", __func__); + ALOGV("%s", __func__); #if __ANDROID__ InferenceEngine::Core ie(std::string("/vendor/etc/openvino/plugins.xml")); @@ -26,7 +22,7 @@ bool IENetwork::loadNetwork() { if (mNetwork) { mExecutableNw = ie.LoadNetwork(*mNetwork, "CPU"); - ALOGD("LoadNetwork is done...."); + ALOGD("loadNetwork is done...."); mInferRequest = mExecutableNw.CreateInferRequest(); ALOGD("CreateInfereRequest is done...."); @@ -69,7 +65,7 @@ InferenceEngine::TBlob::Ptr IENetwork::getBlob(const std::string& outName } void IENetwork::infer() { - ALOGI("Infer Network\n"); + ALOGI("infer Network\n"); mInferRequest.StartAsync(); mInferRequest.Wait(10000); ALOGI("infer request completed"); diff --git a/IENetwork.h b/IENetwork.h index d00faf438..54f0545e3 100644 --- a/IENetwork.h +++ b/IENetwork.h @@ -9,6 +9,10 @@ #include #include "utils.h" +#include +#include +#include +#include // #include "ie_blob.h" // #include "ie_common.h" // #include "ie_core.hpp" @@ -56,6 +60,8 @@ class IENetwork : public IIENetwork { InferenceEngine::InferRequest getInferRequest() { return mInferRequest; } void queryState() {} void infer(); + bool getGrpcIpPort(char *ip_port); + }; } // namespace nnhal diff --git a/ModelManager.cpp b/ModelManager.cpp index 3cd2f104f..ad6f944dd 100644 --- a/ModelManager.cpp +++ b/ModelManager.cpp @@ -46,11 +46,11 @@ bool NnapiModelInfo::initializeRunTimeOperandInfo() { } to.scale = from.scale; + ALOGV("OperandType = %d\n", from.type); switch (from.type) { case OperandType::TENSOR_FLOAT32: case OperandType::FLOAT32: to.type = OperandType::TENSOR_FLOAT32; - ALOGD("OperandType = %d\n", from.type); break; case OperandType::INT32: case OperandType::UINT32: @@ -170,7 +170,7 @@ const uint8_t* NnapiModelInfo::GetOperandMemory(int index, uint32_t& lenOut) { V1_3::ErrorStatus NnapiModelInfo::setRunTimePoolInfosFromHidlMemories( const hidl_vec& pools) { - ALOGD("Number of pools: %zu", pools.size()); + ALOGV("Number of pools: %zu", pools.size()); mRequestPoolInfos.resize(pools.size()); for (size_t i = 0; i < pools.size(); i++) { auto& poolInfo = mRequestPoolInfos[i]; @@ -197,7 +197,7 @@ V1_3::ErrorStatus NnapiModelInfo::setRunTimePoolInfosFromHidlMemories( ErrorStatus NnapiModelInfo::setRunTimePoolInfosFromHidlMemories( const hidl_vec& pools) { - ALOGD("Number of pools: %zu", pools.size()); + ALOGV("Number of pools: %zu", pools.size()); mRequestPoolInfos.resize(pools.size()); for (size_t i = 0; i < pools.size(); i++) { @@ -229,7 +229,7 @@ void* NnapiModelInfo::getBlobFromMemoryPoolIn(const Request& request, uint32_t i operand.buffer = r.buffer + arg.location.offset; operand.length = arg.location.length; - ALOGI("%s Operand length:%d pointer:%p offset:%d pool index: %d", __func__, operand.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; @@ -244,7 +244,7 @@ void* NnapiModelInfo::getBlobFromMemoryPoolOut(const Request& request, uint32_t nnAssert(poolIndex < mRequestPoolInfos.size()); auto& r = mRequestPoolInfos[poolIndex]; - ALOGD("%s lifetime:%d location offset:%d length:%d pool index:%d", __func__, operand.lifetime, + 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) { @@ -258,7 +258,7 @@ void* NnapiModelInfo::getBlobFromMemoryPoolOut(const Request& request, uint32_t operand.buffer = r.buffer + arg.location.offset; operand.length = arg.location.length; rBufferLength = operand.length; - ALOGI("%s Operand length:%d pointer:%p", __func__, operand.length, + ALOGV("%s Operand length:%d pointer:%p", __func__, operand.length, (r.buffer + arg.location.offset)); return (r.buffer + arg.location.offset); } diff --git a/ModelManager.h b/ModelManager.h index e432f2bc0..a666579b1 100755 --- a/ModelManager.h +++ b/ModelManager.h @@ -177,7 +177,7 @@ class NnapiModelInfo { const hidl_vec& pools); bool updateRequestPoolInfos() { - for (auto runtimeInfo : mRequestPoolInfos) { + for (auto& runtimeInfo : mRequestPoolInfos) { runtimeInfo.update(); } @@ -187,7 +187,7 @@ class NnapiModelInfo { std::vector getOutputShapes() { return mOutputShapes; } void unmapRuntimeMemPools() { - for (auto runtimeInfo : mRequestPoolInfos) { + for (auto& runtimeInfo : mRequestPoolInfos) { runtimeInfo.unmap_mem(); } } diff --git a/android.hardware.neuralnetworks@1.3.xml b/android.hardware.neuralnetworks@1.3.xml new file mode 100644 index 000000000..aba0ff0e0 --- /dev/null +++ b/android.hardware.neuralnetworks@1.3.xml @@ -0,0 +1,11 @@ + + + android.hardware.neuralnetworks + hwbinder + 1.3 + + IDevice + CPU + + + diff --git a/cpu/CpuPreparedModel.cpp b/cpu/CpuPreparedModel.cpp index 1c3fa986e..22df0a521 100755 --- a/cpu/CpuPreparedModel.cpp +++ b/cpu/CpuPreparedModel.cpp @@ -31,6 +31,7 @@ bool CpuPreparedModel::initialize() { ALOGE("Failed to initialize Model runtime parameters!!"); return false; } + BasePreparedModel::checkRemoteConnection(); mNgraphNetCreator = std::make_shared(mModelInfo, mTargetDevice); if (!mNgraphNetCreator->validateOperations()) return false; @@ -50,6 +51,12 @@ bool CpuPreparedModel::initialize() { #endif mPlugin = std::make_shared(cnnNetworkPtr); mPlugin->loadNetwork(); + if(mRemoteCheck) { + auto resp = loadRemoteModel(); + 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; diff --git a/ngraph_creator/Android.bp b/ngraph_creator/Android.bp index d013ceace..c5028db30 100755 --- a/ngraph_creator/Android.bp +++ b/ngraph_creator/Android.bp @@ -95,11 +95,11 @@ cc_library_static { header_libs: [ "libngraph_headers", "libinference_headers", + "libnnhal_headers", ], include_dirs: [ - "vendor/intel/external/project-celadon/nn-hal", - "frameworks/ml/nn/common/include", - "frameworks/ml/nn/runtime/include", + "packages/modules/NeuralNetworks/common/include", + "packages/modules/NeuralNetworks/runtime/include", "external/mesa3d/include/android_stub" ], local_include_dirs: [ diff --git a/ngraph_creator/include/NgraphNetworkCreator.hpp b/ngraph_creator/include/NgraphNetworkCreator.hpp index c2ff98d6a..3d51e8a1d 100644 --- a/ngraph_creator/include/NgraphNetworkCreator.hpp +++ b/ngraph_creator/include/NgraphNetworkCreator.hpp @@ -27,6 +27,7 @@ class NgraphNetworkCreator { bool validateOperations(); const std::string& getNodeName(uint32_t index); + std::vector getOutputShape(uint32_t index); std::shared_ptr generateGraph(); }; diff --git a/ngraph_creator/include/NgraphNodes.hpp b/ngraph_creator/include/NgraphNodes.hpp index 783d23634..79f95055f 100644 --- a/ngraph_creator/include/NgraphNodes.hpp +++ b/ngraph_creator/include/NgraphNodes.hpp @@ -35,6 +35,7 @@ class NgraphNodes { const std::string& getNodeName(size_t index); void removeInputParameter(std::string name, size_t index); + std::vector getOutputShape(size_t index); std::shared_ptr generateGraph(); // Setting the node name to empty string "". Caller of getNodeName should validate against "". diff --git a/ngraph_creator/operations/src/AveragePool2D.cpp b/ngraph_creator/operations/src/AveragePool2D.cpp index f72c71486..c5abdd6af 100644 --- a/ngraph_creator/operations/src/AveragePool2D.cpp +++ b/ngraph_creator/operations/src/AveragePool2D.cpp @@ -53,6 +53,9 @@ std::shared_ptr AveragePool2D::createNode() { isExplicit = true; } else if (inputsSize >= 7 && inputsSize <= 8) { isImplicit = true; + } else { + ALOGE("%s inputsSize %lu NOT SUPPORTED", __func__, inputsSize); + return inputNode; } if (isExplicit) { diff --git a/ngraph_creator/operations/src/Concat.cpp b/ngraph_creator/operations/src/Concat.cpp index bdc4425a9..ea1f52dd0 100644 --- a/ngraph_creator/operations/src/Concat.cpp +++ b/ngraph_creator/operations/src/Concat.cpp @@ -31,12 +31,12 @@ std::shared_ptr Concat::createNode() { auto axis = sModelInfo->ParseOperationInput(mNnapiOperationIndex, n); // n: concatenation axis std::vector> inputs; - ALOGD("createNode n %lu, axis %d", n, axis); + ALOGV("createNode n %lu, axis %d", n, axis); for (size_t i = 0; i < n; i++) { auto inputIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, i); auto inputOp = getInputNode(i); const auto op = sModelInfo->getOperand(inputIndex); - ALOGD("createNode inputIndex %d, lifetime %d", inputIndex, op.lifetime); + 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 4f210399f..732fe7669 100644 --- a/ngraph_creator/operations/src/Conv2d.cpp +++ b/ngraph_creator/operations/src/Conv2d.cpp @@ -39,6 +39,8 @@ bool Conv2d::validate() { } std::shared_ptr Conv2d::createNode() { + std::shared_ptr inputNode; + inputNode = getInputNode(0); const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); ALOGD("%s inputsSize %lu", __func__, inputsSize); @@ -49,6 +51,9 @@ std::shared_ptr Conv2d::createNode() { isExplicit = true; } else if (inputsSize >= 7 && inputsSize <= 10) { isImplicit = true; + } else { + ALOGE("%s inputsSize %lu NOT SUPPORTED", __func__, inputsSize); + return inputNode; } int32_t padding_left, padding_right; @@ -108,15 +113,6 @@ std::shared_ptr Conv2d::createNode() { if (layout) useNchw = true; auto_pad = ngraph::op::PadType::EXPLICIT; - { - if (useNchw) { - input_width = inputDimensions[3]; - input_height = inputDimensions[2]; - } else { - input_width = inputDimensions[2]; - input_height = inputDimensions[1]; - } - } } if (isImplicit) { @@ -172,10 +168,9 @@ std::shared_ptr Conv2d::createNode() { } } - std::shared_ptr inputNode, filterNode, biasNode; + std::shared_ptr filterNode, biasNode; const auto& biasIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); - inputNode = getInputNode(0); filterNode = getInputNode(1); biasNode = getInputNode(2); diff --git a/ngraph_creator/operations/src/DepthwiseConv2d.cpp b/ngraph_creator/operations/src/DepthwiseConv2d.cpp index 3507c67c4..dd67aabaa 100644 --- a/ngraph_creator/operations/src/DepthwiseConv2d.cpp +++ b/ngraph_creator/operations/src/DepthwiseConv2d.cpp @@ -41,6 +41,8 @@ bool DepthwiseConv2d::validate() { } std::shared_ptr DepthwiseConv2d::createNode() { + std::shared_ptr inputNode; + inputNode = getInputNode(0); const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); ALOGD("%s inputsSize %lu", __func__, inputsSize); bool isImplicit = false, isExplicit = false; @@ -50,6 +52,9 @@ std::shared_ptr DepthwiseConv2d::createNode() { isExplicit = true; } else if (inputsSize >= 8 && inputsSize <= 11) { isImplicit = true; + } else { + ALOGE("%s inputsSize %lu NOT SUPPORTED", __func__, inputsSize); + return inputNode; } int32_t padding_left, padding_right; @@ -123,8 +128,7 @@ std::shared_ptr DepthwiseConv2d::createNode() { } } } - - if (isImplicit) { + else if (isImplicit) { padding_scheme = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 3); stride_width = sModelInfo->ParseOperationInput(mNnapiOperationIndex, 4); @@ -181,10 +185,9 @@ std::shared_ptr DepthwiseConv2d::createNode() { } } - std::shared_ptr inputNode, filterNode, biasNode; + std::shared_ptr filterNode, biasNode; const auto& biasIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); - inputNode = getInputNode(0); filterNode = getInputNode(1); biasNode = getInputNode(2); diff --git a/ngraph_creator/operations/src/GroupedConv2d.cpp b/ngraph_creator/operations/src/GroupedConv2d.cpp index 7c09a2fd6..6deca60d3 100644 --- a/ngraph_creator/operations/src/GroupedConv2d.cpp +++ b/ngraph_creator/operations/src/GroupedConv2d.cpp @@ -35,6 +35,8 @@ bool GroupedConv2d::validate() { } std::shared_ptr GroupedConv2d::createNode() { + std::shared_ptr inputNode; + inputNode = getInputNode(0); const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); bool isImplicit = false, isExplicit = false; @@ -43,17 +45,20 @@ std::shared_ptr GroupedConv2d::createNode() { isExplicit = true; } else if (inputsSize >= 8 && inputsSize <= 9) { isImplicit = true; + } else { + ALOGE("%s inputsSize %lu NOT SUPPORTED", __func__, inputsSize); + return inputNode; } - int32_t padding_left, padding_right; - int32_t padding_top, padding_bottom; + int32_t padding_left = 0, padding_right = 0; + int32_t padding_top = 0, padding_bottom = 0; int32_t stride_width, stride_height; int32_t dilation_width_factor = 1, dilation_height_factor = 1; int32_t number_groups; int32_t activationFn; int32_t layout = 0; int32_t padding_scheme; - int32_t input_width, input_height, input_channel; + int32_t input_width, input_height; int32_t filter_width, filter_height; bool useNchw = false; std::vector strides; @@ -89,17 +94,6 @@ std::shared_ptr GroupedConv2d::createNode() { if (layout) useNchw = true; auto_pad = ngraph::op::PadType::EXPLICIT; - { - if (useNchw) { // NCHW - input_width = inputDimensions[3]; - input_height = inputDimensions[2]; - input_channel = inputDimensions[1]; - } else { // NHWC - input_width = inputDimensions[2]; - input_height = inputDimensions[1]; - input_channel = inputDimensions[3]; - } - } } if (isImplicit) { @@ -120,11 +114,9 @@ std::shared_ptr GroupedConv2d::createNode() { if (useNchw) { input_width = inputDimensions[3]; input_height = inputDimensions[2]; - input_channel = inputDimensions[1]; } else { input_width = inputDimensions[2]; input_height = inputDimensions[1]; - input_channel = inputDimensions[3]; } if (padding_scheme == 1) { @@ -144,10 +136,9 @@ std::shared_ptr GroupedConv2d::createNode() { } } - std::shared_ptr inputNode, filterNode, biasNode; + std::shared_ptr filterNode, biasNode; const auto& biasIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); - inputNode = getInputNode(0); filterNode = getInputNode(1); biasNode = getInputNode(2); diff --git a/ngraph_creator/operations/src/L2Pooling2D.cpp b/ngraph_creator/operations/src/L2Pooling2D.cpp index d8520b132..c23600a0f 100644 --- a/ngraph_creator/operations/src/L2Pooling2D.cpp +++ b/ngraph_creator/operations/src/L2Pooling2D.cpp @@ -12,6 +12,8 @@ L2Pooling2D::L2Pooling2D(int operationIndex) : OperationsBase(operationIndex) { } std::shared_ptr L2Pooling2D::createNode() { + std::shared_ptr inputNode; + inputNode = getInputNode(0); const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); bool isImplicit = false, isExplicit = false; @@ -19,10 +21,13 @@ std::shared_ptr L2Pooling2D::createNode() { isExplicit = true; } else if (inputsSize >= 7 && inputsSize <= 8) { isImplicit = true; + } else { + ALOGE("%s inputsSize %lu NOT SUPPORTED", __func__, inputsSize); + return inputNode; } - int32_t padding_left, padding_right; - int32_t padding_top, padding_bottom; + int32_t padding_left = 0, padding_right = 0; + int32_t padding_top = 0, padding_bottom = 0; int32_t stride_width, stride_height; int32_t activationFn; int32_t layout = 0; @@ -59,13 +64,6 @@ std::shared_ptr L2Pooling2D::createNode() { if (layout) useNchw = true; auto_pad = ngraph::op::PadType::EXPLICIT; - if (useNchw) { - input_width = inputDimensions[3]; - input_height = inputDimensions[2]; - } else { - input_width = inputDimensions[2]; - input_height = inputDimensions[1]; - } } if (isImplicit) { @@ -110,8 +108,7 @@ std::shared_ptr L2Pooling2D::createNode() { } } - std::shared_ptr inputNode, inputSquared, sqrtOutput; - inputNode = getInputNode(0); + std::shared_ptr inputSquared, sqrtOutput; inputSquared = std::make_shared(inputNode, inputNode); if (!useNchw) { diff --git a/ngraph_creator/operations/src/MaxPool2d.cpp b/ngraph_creator/operations/src/MaxPool2d.cpp index bf320b897..639990b6a 100644 --- a/ngraph_creator/operations/src/MaxPool2d.cpp +++ b/ngraph_creator/operations/src/MaxPool2d.cpp @@ -12,6 +12,8 @@ MaxPool2d::MaxPool2d(int operationIndex) : OperationsBase(operationIndex) { } std::shared_ptr MaxPool2d::createNode() { + std::shared_ptr inputNode; + inputNode = getInputNode(0); const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); ALOGD("%s inputsSize %lu", __func__, inputsSize); @@ -21,6 +23,9 @@ std::shared_ptr MaxPool2d::createNode() { isExplicit = true; } else if (inputsSize >= 7 && inputsSize <= 8) { isImplicit = true; + } else { + ALOGE("%s inputsSize %lu NOT SUPPORTED", __func__, inputsSize); + return inputNode; } int32_t padding_left, padding_right; @@ -61,13 +66,6 @@ std::shared_ptr MaxPool2d::createNode() { if (layout) useNchw = true; auto_pad = ngraph::op::PadType::EXPLICIT; - if (useNchw) { - input_width = inputDimensions[3]; - input_height = inputDimensions[2]; - } else { - input_width = inputDimensions[2]; - input_height = inputDimensions[1]; - } } if (isImplicit) { @@ -112,9 +110,6 @@ std::shared_ptr MaxPool2d::createNode() { } } - std::shared_ptr inputNode; - inputNode = getInputNode(0); - if (!useNchw) { // No conversion needed if useNchw set inputNode = transpose(NHWC_NCHW, inputNode); } diff --git a/ngraph_creator/operations/src/OperationsBase.cpp b/ngraph_creator/operations/src/OperationsBase.cpp index 3df23c0f9..020033eff 100755 --- a/ngraph_creator/operations/src/OperationsBase.cpp +++ b/ngraph_creator/operations/src/OperationsBase.cpp @@ -109,7 +109,7 @@ bool OperationsBase::checkOperandType(uint32_t operandIndex, const int32_t expec const std::string& strLogInfo) { const auto operandType = (int32_t)sModelInfo->getOperandType(operandIndex); if (operandType != expectedOperandType) { - ALOGE("OperationIndex %d %s Index %d type %d invalid", mNnapiOperationIndex, + ALOGV("OperationIndex %d %s Index %d type %d invalid", mNnapiOperationIndex, strLogInfo.c_str(), operandIndex, operandType); return false; } diff --git a/ngraph_creator/operations/src/TransposeConv2D.cpp b/ngraph_creator/operations/src/TransposeConv2D.cpp index 5b9d6999a..1b0cc3c88 100644 --- a/ngraph_creator/operations/src/TransposeConv2D.cpp +++ b/ngraph_creator/operations/src/TransposeConv2D.cpp @@ -46,6 +46,8 @@ bool TransposeConv2D::validate() { } std::shared_ptr TransposeConv2D::createNode() { + std::shared_ptr inputNode; + inputNode = getInputNode(0); const auto& inputsSize = sModelInfo->getOperationInputsSize(mNnapiOperationIndex); ALOGD("%s inputsSize %lu", __func__, inputsSize); @@ -55,6 +57,9 @@ std::shared_ptr TransposeConv2D::createNode() { isExplicit = true; } else if (inputsSize == 9) { isImplicit = true; + } else { + ALOGE("%s inputsSize %lu NOT SUPPORTED", __func__, inputsSize); + return inputNode; } int32_t padding_left, padding_right; @@ -152,10 +157,9 @@ std::shared_ptr TransposeConv2D::createNode() { padding_bottom = 0; } - std::shared_ptr inputNode, filterNode, biasNode; + std::shared_ptr filterNode, biasNode; const auto& biasIndex = sModelInfo->getOperationInput(mNnapiOperationIndex, 2); - inputNode = getInputNode(0); filterNode = getInputNode(1); biasNode = getInputNode(2); diff --git a/ngraph_creator/src/NgraphNetworkCreator.cpp b/ngraph_creator/src/NgraphNetworkCreator.cpp index 69209129a..c9980f7f4 100644 --- a/ngraph_creator/src/NgraphNetworkCreator.cpp +++ b/ngraph_creator/src/NgraphNetworkCreator.cpp @@ -159,6 +159,11 @@ const std::string& NgraphNetworkCreator::getNodeName(uint32_t index) { return mNgraphNodes->getNodeName(index); } +std::vector NgraphNetworkCreator::getOutputShape(uint32_t index) { + + ALOGV("%s get node %d outputsize ", __func__, index); + return mNgraphNodes->getOutputShape(index); +} std::shared_ptr NgraphNetworkCreator::generateGraph() { ALOGV("%s Called", __func__); std::shared_ptr ret; diff --git a/ngraph_creator/src/NgraphNodes.cpp b/ngraph_creator/src/NgraphNodes.cpp index ebdbc1788..2b97800a6 100644 --- a/ngraph_creator/src/NgraphNodes.cpp +++ b/ngraph_creator/src/NgraphNodes.cpp @@ -27,18 +27,24 @@ ngraph::Output NgraphNodes::getOperationOutput(size_t index) { } void NgraphNodes::setResultNode(size_t outputIndex, std::shared_ptr resultNode) { - ALOGD("setResultNode %zu", outputIndex); + ALOGV("setResultNode %zu", outputIndex); mResultNodes.push_back(resultNode); } const std::string& NgraphNodes::getNodeName(size_t index) { if (mNodeNames.find(index) == mNodeNames.end()) { mNodeNames[index] = mOutputAtOperandIndex[index].get_node_shared_ptr()->get_name(); - ALOGD("%s index %zu, name %s", __func__, index, mNodeNames[index].c_str()); + ALOGV("%s index %zu, name %s", __func__, index, mNodeNames[index].c_str()); } ALOGV("%s index %zu, name %s", __func__, index, mNodeNames[index].c_str()); return mNodeNames[index]; } + +std::vector NgraphNodes::getOutputShape(size_t index) { + ALOGV("%s outputshape of node %zu index ", __func__, index); + return mOutputAtOperandIndex[index].get_node_shared_ptr()->get_output_shape(0); +} + // remove null input node parameter void NgraphNodes::removeInputParameter(std::string name, size_t index) { for (size_t i = 0; i < mInputParams.size(); i++) { diff --git a/proto/nnhal_object_detection.proto b/proto/nnhal_object_detection.proto new file mode 100644 index 000000000..e0f14722a --- /dev/null +++ b/proto/nnhal_object_detection.proto @@ -0,0 +1,60 @@ +// 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. + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "com.intel.examples.objectDetection"; +option java_outer_classname = "objectDetectionProto"; +option objc_class_prefix = "HLW"; + +package objectDetection; + +// The Detection service definition. +service Detection { + // Send Input Blobs and receive Output Blobs + rpc getInferResult (RequestDataTensors) returns (ReplyDataTensors) {} + rpc sendXml (stream RequestDataChunks) returns (ReplyStatus) {} + rpc sendBin (stream RequestDataChunks) returns (ReplyStatus) {} + rpc prepare (RequestString) returns (ReplyStatus) {} //Placeholder for any future support : RequestString +} + + +message RequestDataChunks { + bytes data = 1; +} + +message RequestString { + string value = 1; +} +message ReplyStatus { + bool status = 1; +} + +// Structure defining the structure of the Data Tensor(blob) +message DataTensor { + bytes data = 1; + string node_name = 2; + repeated int32 tensor_shape = 3; +} + +// Reply message containing the Output Data Tensors(blobs) +message ReplyDataTensors { + repeated DataTensor data_tensors = 1; +} + +// Request message containing the Input Data Tensors(blobs) +message RequestDataTensors { + repeated DataTensor data_tensors = 1; +} \ No newline at end of file diff --git a/utils.cpp b/utils.cpp index cbd2dd52a..e4fa0f205 100644 --- a/utils.cpp +++ b/utils.cpp @@ -482,34 +482,20 @@ int sizeOfData(OperandType type, std::vector dims) { return size; } -// TODO: Hide under debug flag or remove from code -bool createDirs(std::string path) { - char delim = '/'; - int start = 0; - - auto pos = path.find(delim); - while (pos != std::string::npos) { - auto dir = path.substr(start, pos - start + 1); - - struct stat sb; - if (!((stat(dir.c_str(), &sb) == 0) && (S_ISDIR(sb.st_mode)))) { - if (mkdir(dir.c_str(), 0777) != 0) return false; - } - pos = path.find(delim, pos + 1); +bool getGrpcSocketPath(char *socket_path) { + if (property_get("vendor.nn.hal.grpc_socket_path", socket_path, NULL) <= 0) { + ALOGV("%s : failed to read vendor.nn.hal.grpc_socket_path", __func__); + return false; } - return true; } -void writeBufferToFile(std::string filename, const float* buf, size_t length) { - if (!createDirs(filename)) return; - - std::ofstream ofs; - ofs.open(filename.c_str(), std::ofstream::out | std::ofstream::trunc); - for (size_t i = 0; i < length; i++) { - ofs << buf[i] << "\n"; +bool getGrpcIpPort(char *ip_port) { + if (property_get("vendor.nn.hal.grpc_ip_port", ip_port, NULL) <= 0) { + ALOGV("%s : failed to read vendor.nn.hal.grpc_ip_port", __func__); + return false; } - ofs.close(); + return true; } } // namespace nnhal diff --git a/utils.h b/utils.h old mode 100755 new mode 100644 index 8e5315738..aea1cafc5 --- a/utils.h +++ b/utils.h @@ -89,19 +89,19 @@ enum PaddingScheme { #define VLOGDIMS(l, d, header) \ do { \ auto size = (d).size(); \ - ALOGI("%s: vectors {%d, %d, %d, %d}", header, (d)[0], size > 1 ? (d)[1] : 0, \ + ALOGV("%s: vectors {%d, %d, %d, %d}", header, (d)[0], size > 1 ? (d)[1] : 0, \ size > 2 ? (d)[2] : 0, size > 3 ? (d)[3] : 0); \ } while (0) #define dumpOperand(index, model) \ do { \ const auto op = model.operands[index]; \ - ALOGI("Operand (%zu) %s", index, toString(op).c_str()); \ + ALOGV("Operand (%zu) %s", index, toString(op).c_str()); \ } while (0) #define dumpOperation(operation) \ do { \ - ALOGI("Operation: %s", toString(operation).c_str()); \ + ALOGV("Operation: %s", toString(operation).c_str()); \ } while (0) #define WRONG_DIM (-1) @@ -252,7 +252,8 @@ T getOperandConstVal(const Model& model, const Operand& operand) { int sizeOfData(OperandType type, std::vector dims); -void writeBufferToFile(std::string filename, const float* buf, size_t length); +bool getGrpcSocketPath(char *socket_path); +bool getGrpcIpPort(char *ip_port); template std::shared_ptr As(const std::shared_ptr& src) { return std::static_pointer_cast(src);