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 #include "tensorflow/compiler/xla/service/gpu/hlo_algorithm_denylist.h"
17
18 #include <string>
19
20 #include "absl/container/flat_hash_map.h"
21 #include "tensorflow/compiler/xla/debug_options_flags.h"
22 #include "tensorflow/compiler/xla/service/gpu/gpu_autotuning.pb.h"
23
24 namespace xla {
25 namespace gpu {
26
27 constexpr char kDefaultDenylist[] = R"pb(
28 entries {
29 hlo: "(f32[4,32,32,32]{2,1,3,0}, u8[0]{0}) custom-call(f32[4,32,32,32]{2,1,3,0}, f32[5,5,32,32]{1,0,2,3}), window={size=5x5 pad=2_2x2_2}, dim_labels=b01f_01io->b01f, custom_call_target=\"__cudnn$convForward\", backend_config=\"{conv_result_scale:1}\""
30 cc { major: 7 }
31 cudnn_version { major: 7 minor: 6 patch: 4 }
32 algos { id: 7 }
33 blas_version: "10201"
34 }
35 entries {
36 hlo: "(f32[4,32,32,32]{2,1,3,0}, u8[0]{0}) custom-call(f32[4,32,32,32]{2,1,3,0}, f32[5,5,32,32]{1,0,2,3}), window={size=5x5 pad=2_2x2_2}, dim_labels=b01f_01io->b01f, custom_call_target=\"__cudnn$convForward\", backend_config=\"{conv_result_scale:1}\""
37 cc { major: 7 }
38 cudnn_version { major: 7 minor: 6 patch: 4 }
39 algos { id: 7 tensor_ops: true }
40 blas_version: "10201"
41 }
42 )pb";
43
GetDisabledConvAlgorithms(tensorflow::ComputeCapability cc,tensorflow::CudnnVersion cudnn_version,const std::string & blas_version,const std::string & hlo)44 absl::Span<const stream_executor::dnn::AlgorithmDesc> GetDisabledConvAlgorithms(
45 tensorflow::ComputeCapability cc, tensorflow::CudnnVersion cudnn_version,
46 const std::string& blas_version, const std::string& hlo) {
47 // Key is the tuple of canonicalized hlo, compute capability major/minor,
48 // cudnn version major/minor/patch, blas version.
49 using MapType = absl::flat_hash_map<
50 std::tuple<std::string, int, int, int, int, int, std::string>,
51 std::vector<stream_executor::dnn::AlgorithmDesc>>;
52
53 static MapType* denylist = [] {
54 MapType* list = new MapType();
55 AlgorithmDenylist proto;
56 std::string file_path =
57 GetDebugOptionsFromFlags().xla_gpu_algorithm_denylist_path();
58 if (!file_path.empty()) {
59 TF_CHECK_OK(tensorflow::ReadTextProto(tensorflow::Env::Default(),
60 file_path, &proto));
61 } else {
62 CHECK(tensorflow::protobuf::TextFormat::ParseFromString(
63 std::string(kDefaultDenylist), &proto));
64 }
65 for (const auto& entry : proto.entries()) {
66 for (const auto& algo : entry.algos()) {
67 (*list)[std::make_tuple(
68 std::string(entry.hlo()), entry.cc().major(),
69 entry.cc().minor(), entry.cudnn_version().major(),
70 entry.cudnn_version().minor(),
71 entry.cudnn_version().patch(), entry.blas_version())]
72 .push_back({algo.id(), algo.tensor_ops()});
73 }
74 }
75 return list;
76 }();
77
78 auto iter = denylist->find(std::make_tuple(
79 hlo, cc.major(), cc.minor(), cudnn_version.major(), cudnn_version.minor(),
80 cudnn_version.patch(), std::string(blas_version)));
81 if (iter != denylist->end()) {
82 return iter->second;
83 }
84 return {};
85 }
86
87 } // namespace gpu
88 } // namespace xla
89