1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_1_0_UTILS_BURST_H 18 #define ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_1_0_UTILS_BURST_H 19 20 #include <nnapi/IBurst.h> 21 #include <nnapi/IPreparedModel.h> 22 #include <nnapi/Result.h> 23 #include <nnapi/Types.h> 24 25 #include <memory> 26 #include <optional> 27 #include <utility> 28 29 // See hardware/interfaces/neuralnetworks/utils/README.md for more information on HIDL interface 30 // lifetimes across processes and for protecting asynchronous calls across HIDL. 31 32 namespace android::hardware::neuralnetworks::V1_0::utils { 33 34 // Class that adapts nn::IPreparedModel to nn::IBurst. 35 class Burst final : public nn::IBurst { 36 struct PrivateConstructorTag {}; 37 38 public: 39 static nn::GeneralResult<std::shared_ptr<const Burst>> create( 40 nn::SharedPreparedModel preparedModel); 41 42 Burst(PrivateConstructorTag tag, nn::SharedPreparedModel preparedModel); 43 44 OptionalCacheHold cacheMemory(const nn::SharedMemory& memory) const override; 45 46 nn::ExecutionResult<std::pair<std::vector<nn::OutputShape>, nn::Timing>> execute( 47 const nn::Request& request, nn::MeasureTiming measure, 48 const nn::OptionalTimePoint& deadline, 49 const nn::OptionalDuration& loopTimeoutDuration) const override; 50 51 nn::GeneralResult<nn::SharedExecution> createReusableExecution( 52 const nn::Request& request, nn::MeasureTiming measure, 53 const nn::OptionalDuration& loopTimeoutDuration) const override; 54 55 private: 56 const nn::SharedPreparedModel kPreparedModel; 57 }; 58 59 } // namespace android::hardware::neuralnetworks::V1_0::utils 60 61 #endif // ANDROID_HARDWARE_INTERFACES_NEURALNETWORKS_1_0_UTILS_BURST_H 62