1 /* Copyright 2022 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_CORE_CONFIG_FLAGS_H_ 17 #define TENSORFLOW_CORE_CONFIG_FLAGS_H_ 18 19 #include "tensorflow/core/platform/stringpiece.h" 20 21 namespace tensorflow { 22 namespace config { 23 24 // Container class for a single feature flag. 25 // Note: this class is not thread safe. 26 class Flag { 27 public: 28 explicit Flag(StringPiece flag_name, bool default_value); value()29 bool value() { return value_; } reset(bool value)30 void reset(bool value) { value_ = value; } 31 32 private: 33 bool value_; 34 }; 35 36 // Macro to declare new flags. Declare all flags in core/config/flag_defs.h 37 // These flags can be overridden by setting the associated environment variable 38 // TF_FLAG_* flag to true or false. E.g. setting TF_FLAG_MY_FLAG=false will 39 // override the default value for a flag named `my_flag` to false. 40 #define TF_DECLARE_FLAG(flag_name, default_value, doc) \ 41 ::tensorflow::config::Flag flag_name = \ 42 ::tensorflow::config::Flag("TF_FLAG_" #flag_name, default_value); 43 44 } // namespace config 45 } // namespace tensorflow 46 47 #endif // TENSORFLOW_CORE_CONFIG_FLAGS_H_ 48