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