1 /* 2 * Copyright (C) 2021 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_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_CANONICAL_BURST_H 18 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_CANONICAL_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 #include <vector> 29 30 #include "CanonicalPreparedModel.h" 31 32 namespace android::nn::sample { 33 34 // Class that adapts nn::sample::PreparedModel to nn::sample::IBurst. 35 class Burst final : public IBurst { 36 public: 37 explicit Burst(std::shared_ptr<const PreparedModel> preparedModel); 38 39 OptionalCacheHold cacheMemory(const SharedMemory& memory) const override; 40 41 ExecutionResult<std::pair<std::vector<OutputShape>, Timing>> execute( 42 const Request& request, MeasureTiming measure, const nn::OptionalTimePoint& deadline, 43 const nn::OptionalDuration& loopTimeoutDuration, 44 const std::vector<TokenValuePair>& hints, 45 const std::vector<ExtensionNameAndPrefix>& extensionNameToPrefix) const override; 46 47 GeneralResult<SharedExecution> createReusableExecution( 48 const Request& request, MeasureTiming measure, 49 const nn::OptionalDuration& loopTimeoutDuration, 50 const std::vector<TokenValuePair>& hints, 51 const std::vector<ExtensionNameAndPrefix>& extensionNameToPrefix) const override; 52 53 private: 54 const std::shared_ptr<const PreparedModel> kPreparedModel; 55 }; 56 57 } // namespace android::nn::sample 58 59 #endif // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_DRIVER_SAMPLE_CANONICAL_BURST_H 60