1 /* Copyright 2015 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 #include "tensorflow/core/util/use_cudnn.h" 17 18 #include "tensorflow/core/lib/core/stringpiece.h" 19 #include "tensorflow/core/lib/strings/str_util.h" 20 #include "tensorflow/core/platform/types.h" 21 #include "tensorflow/core/util/env_var.h" 22 23 namespace tensorflow { 24 25 #define ADD_CUDNN_FLAG(func_name, flag_name, default_value) \ 26 bool func_name() { \ 27 bool value; \ 28 Status status = ReadBoolFromEnvVar(#flag_name, default_value, &value); \ 29 if (!status.ok()) { \ 30 LOG(ERROR) << status; \ 31 } \ 32 return value; \ 33 } 34 35 ADD_CUDNN_FLAG(CanUseCudnn, TF_USE_CUDNN, true); 36 ADD_CUDNN_FLAG(CudnnUseAutotune, TF_CUDNN_USE_AUTOTUNE, true); 37 ADD_CUDNN_FLAG(CudnnDisableConv1x1Optimization, 38 TF_CUDNN_DISABLE_CONV_1X1_OPTIMIZATION, false); 39 40 #undef ADD_CUDNN_FLAG 41 42 FP16ConvMode CudnnConvComputeMode() { 43 string value; 44 Status status = ReadStringFromEnvVar("TF_FP16_CONV_MODE", "accurate", &value); 45 if (!status.ok()) { 46 LOG(ERROR) << status; 47 } 48 string lowercase_value = str_util::Lowercase(value); 49 if (lowercase_value == "accurate") { 50 return FP16ConvMode::kAccurate; 51 } else if (lowercase_value == "fast") { 52 return FP16ConvMode::kFast; 53 } else { 54 LOG(ERROR) << "FP16ConvMode only supports two modes, ACCURATE and FAST. " 55 "Got unknown mode: " 56 << value; 57 } 58 return FP16ConvMode::kAccurate; 59 } 60 61 } // namespace tensorflow 62