1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#ifndef OHOS_HDI_NNRT_V1_0_MODELTYPES_H 17#define OHOS_HDI_NNRT_V1_0_MODELTYPES_H 18 19#include <cstdbool> 20#include <cstdint> 21#include <string> 22#include <vector> 23#include "nnrt/v1_0/nnrt_types.h" 24 25#ifndef HDI_BUFF_MAX_SIZE 26#define HDI_BUFF_MAX_SIZE (1024 * 200) 27#endif 28 29#ifndef HDI_CHECK_VALUE_RETURN 30#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \ 31 if ((lv) compare (rv)) { \ 32 return ret; \ 33 } \ 34} while (false) 35#endif 36 37#ifndef HDI_CHECK_VALUE_RET_GOTO 38#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \ 39 if ((lv) compare (rv)) { \ 40 ret = value; \ 41 goto table; \ 42 } \ 43} while (false) 44#endif 45 46namespace OHOS { 47class MessageParcel; 48} 49 50namespace OHOS { 51namespace HDI { 52namespace Nnrt { 53namespace V1_0 { 54 55using namespace OHOS; 56 57struct Tensor { 58 std::string name; 59 OHOS::HDI::Nnrt::V1_0::DataType dataType; 60 std::vector<int32_t> dims; 61 OHOS::HDI::Nnrt::V1_0::Format format; 62 OHOS::HDI::Nnrt::V1_0::SharedBuffer data; 63 std::vector<OHOS::HDI::Nnrt::V1_0::QuantParam> quantParams; 64}; 65 66struct Node { 67 std::string name; 68 OHOS::HDI::Nnrt::V1_0::NodeType nodeType; 69 std::vector<int8_t> nodeAttr; 70 std::vector<uint32_t> inputIndex; 71 std::vector<uint32_t> outputIndex; 72 OHOS::HDI::Nnrt::V1_0::QuantType quantType; 73}; 74 75struct SubGraph { 76 std::string name; 77 std::vector<uint32_t> inputIndices; 78 std::vector<uint32_t> outputIndices; 79 std::vector<uint32_t> nodeIndices; 80}; 81 82struct Model { 83 std::string name; 84 std::vector<uint32_t> inputIndex; 85 std::vector<uint32_t> outputIndex; 86 std::vector<OHOS::HDI::Nnrt::V1_0::Node> nodes; 87 std::vector<OHOS::HDI::Nnrt::V1_0::Tensor> allTensors; 88 std::vector<OHOS::HDI::Nnrt::V1_0::SubGraph> subGraph; 89}; 90 91bool TensorBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Nnrt::V1_0::Tensor& dataBlock); 92 93bool TensorBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Nnrt::V1_0::Tensor& dataBlock); 94 95bool NodeBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Nnrt::V1_0::Node& dataBlock); 96 97bool NodeBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Nnrt::V1_0::Node& dataBlock); 98 99bool SubGraphBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Nnrt::V1_0::SubGraph& dataBlock); 100 101bool SubGraphBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Nnrt::V1_0::SubGraph& dataBlock); 102 103bool ModelBlockMarshalling(OHOS::MessageParcel &data, const OHOS::HDI::Nnrt::V1_0::Model& dataBlock); 104 105bool ModelBlockUnmarshalling(OHOS::MessageParcel &data, OHOS::HDI::Nnrt::V1_0::Model& dataBlock); 106 107} // V1_0 108} // Nnrt 109} // HDI 110} // OHOS 111 112#endif // OHOS_HDI_NNRT_V1_0_MODELTYPES_H 113 114