1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_LITE_DELEGATES_GPU_COMMON_MODEL_HINTS_H_ 17 #define TENSORFLOW_LITE_DELEGATES_GPU_COMMON_MODEL_HINTS_H_ 18 19 #include <cstdint> 20 21 namespace tflite { 22 namespace gpu { 23 24 struct ModelHints { 25 using ModelHint = uint64_t; 26 27 // By default we want the fastest inference. 28 static constexpr ModelHint kFastestInference = 0x00000000; 29 // Can improve compilation time, but inference can be slower. 30 static constexpr ModelHint kReduceKernelsCount = 0x00000001; 31 // Can improve tuning time, but inference can be slower. 32 static constexpr ModelHint kFastTuning = 0x00000001 << 1; 33 34 // Can improve performance and memory consumption, but slow down 35 // initialization and create more unique kernels. 36 static constexpr ModelHint kAllowSpecialKernels = 0x00000001 << 2; 37 38 // By default we apply Winograd optimized kernels and it improves performance. 39 // But it also can increase memory usage and decrease precision. 40 // This hint can disable Winograd optimizations. 41 static constexpr ModelHint kNoWinogradOptimizations = 0x00000001 << 3; 42 43 // By default, the same weights can be duplicated among different nodes of 44 // convolution. With this hint we will try to reuse common object, when it 45 // possible. 46 // Can decrease constant memory usage(if model has the same weights). 47 static constexpr ModelHint kReuseConvWeights = 0x00000001 << 4; 48 AddModelHints49 void Add(ModelHint hint) { 50 if (hint == kFastestInference) { 51 hints = kFastestInference; 52 } else { 53 hints |= hint; 54 } 55 } 56 CheckModelHints57 bool Check(ModelHint hint) const { return hints & hint; } 58 59 uint64_t hints = kFastestInference; 60 }; 61 62 } // namespace gpu 63 } // namespace tflite 64 65 #endif // TENSORFLOW_LITE_DELEGATES_GPU_COMMON_MODEL_HINTS_H_ 66