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