• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstdlib>
19 #include <string>
20 
21 #include "tensorflow/core/platform/env.h"
22 #include "tensorflow/core/platform/path.h"
23 #include "tensorflow/core/platform/resource_loader.h"
24 #include "tensorflow/core/platform/test.h"
25 #include "tensorflow/stream_executor/dnn.h"
26 
27 namespace xla {
28 namespace gpu {
29 namespace {
30 
31 class DenylistTest : public testing::Test {
32  protected:
DenylistTest()33   DenylistTest() {
34     std::string existing_xla_flags;
35     const char* env = std::getenv("XLA_FLAGS");
36     if (env != nullptr) {
37       existing_xla_flags = absl::StrCat(env, " ");
38     }
39 
40     tensorflow::setenv(
41         "XLA_FLAGS",
42         absl::StrCat(
43             existing_xla_flags, "--xla_gpu_algorithm_denylist_path=",
44             tensorflow::GetDataDependencyFilepath(tensorflow::io::JoinPath(
45                 "tensorflow", "compiler", "xla", "service", "gpu", "data",
46                 "hlo_algorithm_denylist.pbtxt")))
47             .data(),
48         /*overwrite=*/true);
49   }
50 };
51 
TEST_F(DenylistTest,DefaultTest)52 TEST_F(DenylistTest, DefaultTest) {
53   tensorflow::ComputeCapability cc;
54   cc.set_major(7);
55   cc.set_minor(0);
56   tensorflow::CudnnVersion cudnn_version;
57   cudnn_version.set_major(7);
58   cudnn_version.set_minor(6);
59   cudnn_version.set_patch(2);
60   auto list = GetDisabledConvAlgorithms(
61       cc, cudnn_version, /*blas_version=*/"9000",
62       R"((f16[256,112,112,64]{3,2,1,0}, u8[0]{0}) custom-call(f16[256,224,224,4]{3,2,1,0}, f16[7,7,4,64]{2,1,0,3}), window={size=7x7 stride=2x2 pad=3_3x3_3}, dim_labels=b01f_01io->b01f, custom_call_target="__cudnn$convForward", backend_config="{conv_result_scale:1}")");
63   ASSERT_EQ(4, list.size());
64   EXPECT_EQ(stream_executor::dnn::AlgorithmDesc(0, false), list[0]);
65   EXPECT_EQ(stream_executor::dnn::AlgorithmDesc(0, true), list[1]);
66   EXPECT_EQ(stream_executor::dnn::AlgorithmDesc(1, false), list[2]);
67   EXPECT_EQ(stream_executor::dnn::AlgorithmDesc(1, true), list[3]);
68 }
69 
TEST_F(DenylistTest,NegativeTest)70 TEST_F(DenylistTest, NegativeTest) {
71   tensorflow::ComputeCapability cc;
72   cc.set_major(7);
73   cc.set_minor(0);
74   tensorflow::CudnnVersion cudnn_version;
75   cudnn_version.set_major(7);
76   cudnn_version.set_minor(6);
77   cudnn_version.set_minor(2);
78   auto list =
79       GetDisabledConvAlgorithms(cc, cudnn_version, "9000", R"(invalid hlo)");
80   ASSERT_EQ(0, list.size());
81 }
82 
83 }  // namespace
84 }  // namespace gpu
85 }  // namespace xla
86