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 17 #ifndef NEURAL_NETWORK_RUNTIME_HDI_PREPARED_MODEL_V2_0_H 18 #define NEURAL_NETWORK_RUNTIME_HDI_PREPARED_MODEL_V2_0_H 19 20 #include <vector> 21 22 #include <v2_0/innrt_device.h> 23 #include <v2_0/iprepared_model.h> 24 #include <v2_0/nnrt_types.h> 25 26 #include "cpp_type.h" 27 #include "prepared_model.h" 28 #include "refbase.h" 29 30 namespace V2_0 = OHOS::HDI::Nnrt::V2_0; 31 32 namespace OHOS { 33 namespace NeuralNetworkRuntime { 34 class HDIPreparedModelV2_0 : public PreparedModel { 35 public: 36 explicit HDIPreparedModelV2_0(OHOS::sptr<V2_0::IPreparedModel> hdiPreparedModel); 37 ~HDIPreparedModelV2_0() override; 38 39 OH_NN_ReturnCode ExportModelCache(std::vector<Buffer>& modelCache) override; 40 41 OH_NN_ReturnCode Run(const std::vector<IOTensor>& inputs, 42 const std::vector<IOTensor>& outputs, 43 std::vector<std::vector<int32_t>>& outputsDims, 44 std::vector<bool>& isOutputBufferEnough) override; 45 46 OH_NN_ReturnCode Run(const std::vector<NN_Tensor*>& inputs, 47 const std::vector<NN_Tensor*>& outputs, 48 std::vector<std::vector<int32_t>>& outputsDims, 49 std::vector<bool>& isOutputBufferEnough) override; 50 51 OH_NN_ReturnCode GetModelID(uint32_t& modelId) const override; 52 53 OH_NN_ReturnCode GetInputDimRanges(std::vector<std::vector<uint32_t>>& minInputDims, 54 std::vector<std::vector<uint32_t>>& maxInputDims) override; 55 56 private: 57 // first: major version, second: minor version 58 std::pair<uint32_t, uint32_t> m_hdiVersion; 59 OHOS::sptr<V2_0::IPreparedModel> m_hdiPreparedModel {nullptr}; 60 std::vector<void *> m_addrs; 61 }; 62 } // namespace NeuralNetworkRuntime 63 } // OHOS 64 #endif // NEURAL_NETWORK_RUNTIME_HDI_PREPARED_MODEL_V2_0_H 65