1/* 2 * Copyright (C) 2017 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_COMPILATION_BUILDER_H 18#define ANDROID_ML_NN_RUNTIME_COMPILATION_BUILDER_H 19 20#include "ExecutionPlan.h" 21#include "NeuralNetworks.h" 22 23#include <memory> 24#include <vector> 25 26namespace android { 27namespace nn { 28 29class Device; 30class ExecutionBuilder; 31class ModelBuilder; 32 33class CompilationBuilder { 34public: 35 friend class ExecutionBuilder; // TODO remove this 36 37 CompilationBuilder(const ModelBuilder* model); 38 39 int setPreference(int32_t preference); 40 41 int setPartitioning(uint32_t partitioning); 42 43 int finish(); 44 45 int finish(const std::vector<std::shared_ptr<Device>>& devices); 46 47 int createExecution(ExecutionBuilder** execution); 48 49 const ExecutionPlan& forTest_getExecutionPlan() const { return mPlan; } 50 51private: 52 const ModelBuilder* mModel; 53 54 ExecutionPlan mPlan; 55 56 // Whether the application prefers to go fast or use low power for this execution. 57 int32_t mPreference = ANEURALNETWORKS_PREFER_FAST_SINGLE_ANSWER; 58 59 // See class DeviceManager. When CompilationBuilder is 60 // instantiated, we capture partitioning from DeviceManager; but 61 // we can override this later. 62 uint32_t mPartitioning; 63 64 // Once the compilation has been finished, we should not allow further 65 // modifications to the compilation. 66 bool mFinished = false; 67}; 68 69} // namespace nn 70} // namespace android 71 72#endif // ANDROID_ML_NN_RUNTIME_COMPILATION_BUILDER_H 73