1 /** 2 * Copyright (c) Glow Contributors. See CONTRIBUTORS file. 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 #ifndef GLOW_BACKENDS_BACKENDOPTIONS_H 17 #define GLOW_BACKENDS_BACKENDOPTIONS_H 18 19 #include "llvm/ADT/SmallVector.h" 20 #include "llvm/ADT/StringMap.h" 21 22 #include <map> 23 #include <string> 24 #include <unordered_map> 25 #include <vector> 26 27 namespace glow { 28 class Function; 29 class Node; 30 class Storage; 31 32 /// Hints provided to the Backend, the backend is not required to honor them. 33 struct BackendHints { 34 /// Number of execution units to reserve, these are the processing elements 35 /// like cores, 0 for unspecified. 36 unsigned executionUnits{0}; 37 38 /// Storage nodes to be pinned to SRAM listed in order of priority. 39 std::vector<std::string> SRAMPrioritization; 40 }; 41 42 /// A flexible map used for storing options for a backend. Keys are usually 43 /// prefixed with a Backend's name, e.g. "Interpreter_OptionA". 44 using BackendSpecificOptions = std::map<std::string, std::string>; 45 46 /// A structure used for storing backend-specific information for Nodes in a 47 /// Function. The outer map with Functions as a key map to another map with 48 /// Nodes as a key, where all Nodes in that map are children of the original 49 /// Function. The StringMap for each Node maps from an option name to a vector 50 /// of values for that option. 51 using BackendSpecificNodeInfo = std::unordered_map< 52 const Function *, 53 std::unordered_map<const Node *, 54 llvm::StringMap<std::vector<std::string>>>>; 55 56 /// Options relevant to Backends during compilation. 57 struct BackendOptions { 58 /// Allocate and collect constant Tensors in the RuntimeBundle. 59 bool collectConstants{true}; 60 61 /// Insert TraceEvents between all instructions for profiling. 62 bool autoInstrument{false}; 63 64 /// Hints for the compiler for this compilation. 65 BackendHints backendHints; 66 67 /// Options that are specific to a backend. Backend is responsible for 68 /// parsing. 69 BackendSpecificOptions backendSpecificOpts; 70 71 /// Options that are specified per-Node. Note that this structure is keyed off 72 /// of Functions and then Nodes. The Node keys for this structure are Node 73 /// pointers, so any changes of Nodes should be tracked and propagated into 74 /// new Nodes once this is set. 75 BackendSpecificNodeInfo backendSpecificNodeInfo; 76 }; 77 78 }; // namespace glow 79 80 #endif // GLOW_BACKENDS_BACKENDOPTIONS_H 81