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
27namespace glow {
28class Function;
29class Node;
30class Storage;
31
32/// Hints provided to the Backend, the backend is not required to honor them.
33struct 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".
44using 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.
51using 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.
57struct 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 /// Use a serialized precompiled function instead of compiling.
65 bool useDeserialize{false};
66
67 /// Hints for the compiler for this compilation.
68 BackendHints backendHints;
69
70 /// Options that are specific to a backend. Backend is responsible for
71 /// parsing.
72 BackendSpecificOptions backendSpecificOpts;
73
74 /// Options that are specified per-Node. Note that this structure is keyed off
75 /// of Functions and then Nodes. The Node keys for this structure are Node
76 /// pointers, so any changes of Nodes should be tracked and propagated into
77 /// new Nodes once this is set.
78 BackendSpecificNodeInfo backendSpecificNodeInfo;
79};
80
81}; // namespace glow
82
83#endif // GLOW_BACKENDS_BACKENDOPTIONS_H
84