1 /* 2 * Copyright (C) 2019 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_FRAMEWORKS_ML_NN_RUNTIME_BURST_BUILDER_H 18 #define ANDROID_FRAMEWORKS_ML_NN_RUNTIME_BURST_BUILDER_H 19 20 #include <nnapi/IBurst.h> 21 22 #include <atomic> 23 #include <memory> 24 #include <vector> 25 26 namespace android { 27 namespace nn { 28 29 class CompilationBuilder; 30 31 /* 32 * TODO: Could we "hide" the per-step burst controller instance inside 33 * StepExecutor? Today it's exposed as a "sibling" to StepExecutor: 34 * ExecutionPlan::next both generates a StepExecutor instance and finds a 35 * pointer to a burst controller; and StepExecutor::compute is passed a pointer 36 * to a burst controller. Instead, could ExecutionPlan::next stash the burst 37 * controller in the StepExecutor, so that it doesn't have to be passed to any 38 * of the StepExecutor methods? 39 */ 40 41 class BurstBuilder { 42 public: 43 BurstBuilder(const CompilationBuilder* compilation, std::vector<SharedBurst> burstControllers); 44 45 bool tryLock(); 46 void unlock(); 47 48 const CompilationBuilder* getCompilation() const; 49 SharedBurst getControllerAt(size_t index) const; 50 51 private: 52 std::atomic_flag mCurrentlyRunning = ATOMIC_FLAG_INIT; 53 const CompilationBuilder* mCompilation; 54 std::vector<SharedBurst> mBurstControllers; 55 }; 56 57 } // namespace nn 58 } // namespace android 59 60 #endif // ANDROID_FRAMEWORKS_ML_NN_RUNTIME_BURST_BUILDER_H 61