• 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/tests/hlo_test_base.h"
17 
18 namespace xla {
19 namespace gpu {
20 namespace {
21 
22 class GpuConvolutionRegressionTest : public HloTestBase {
23  public:
24   // RunHloPasses goes through convolution autotuning, which performs
25   // correctness cross-checking.
CheckForHloText(absl::string_view hlo_string)26   void CheckForHloText(absl::string_view hlo_string) {
27     HloModuleConfig config;
28     config.set_debug_options(GetDebugOptionsFromFlags());
29     (void)backend().compiler()->RunHloPasses(
30         ParseAndReturnVerifiedModule(hlo_string, config).value(),
31         backend().default_stream_executor(), backend().memory_allocator());
32   }
33 };
34 
TEST_F(GpuConvolutionRegressionTest,Computation1)35 TEST_F(GpuConvolutionRegressionTest, Computation1) {
36   CheckForHloText(R"(
37 HloModule TestModule
38 
39 %TestComputation1 (param_0: f32[1,20,257], param_1: f32[31,257,136]) -> (f32[1,23,136], u8[0]) {
40   %param_0 = f32[1,20,257]{2,1,0} parameter(0)
41   %copy.3 = f32[1,20,257]{1,2,0} copy(f32[1,20,257]{2,1,0} %param_0)
42   %param_1 = f32[31,257,136]{2,1,0} parameter(1)
43   %copy.4 = f32[31,257,136]{0,2,1} copy(f32[31,257,136]{2,1,0} %param_1)
44   %custom-call.1 = (f32[1,23,136]{1,2,0}, u8[0]{0}) custom-call(f32[1,20,257]{1,2,0} %copy.3, f32[31,257,136]{0,2,1} %copy.4), window={size=31 stride=2 pad=23_23}, dim_labels=b0f_0oi->b0f, custom_call_target="__cudnn$convBackwardInput", backend_config="{conv_result_scale:1}"
45   %get-tuple-element.2 = f32[1,23,136]{1,2,0} get-tuple-element((f32[1,23,136]{1,2,0}, u8[0]{0}) %custom-call.1), index=0
46   %copy.5 = f32[1,23,136]{2,1,0} copy(f32[1,23,136]{1,2,0} %get-tuple-element.2)
47   %get-tuple-element.3 = u8[0]{0} get-tuple-element((f32[1,23,136]{1,2,0}, u8[0]{0}) %custom-call.1), index=1
48   ROOT %tuple.1 = (f32[1,23,136]{2,1,0}, u8[0]{0}) tuple(f32[1,23,136]{2,1,0} %copy.5, u8[0]{0} %get-tuple-element.3)
49 })");
50 }
51 
TEST_F(GpuConvolutionRegressionTest,Computation2)52 TEST_F(GpuConvolutionRegressionTest, Computation2) {
53   CheckForHloText(R"(
54 HloModule TestModule
55 
56 %TestComputation3 (param_0: f32[138,20,1], param_1: f32[31,1,1]) -> (f32[138,23,1], u8[0]) {
57   %param_0 = f32[138,20,1]{2,1,0} parameter(0)
58   %bitcast = f32[138,20,1]{1,2,0} bitcast(f32[138,20,1]{2,1,0} %param_0)
59   %param_1 = f32[31,1,1]{2,1,0} parameter(1)
60   %bitcast.1 = f32[31,1,1]{0,2,1} bitcast(f32[31,1,1]{2,1,0} %param_1)
61   %custom-call.1 = (f32[138,23,1]{1,2,0}, u8[0]{0}) custom-call(f32[138,20,1]{1,2,0} %bitcast, f32[31,1,1]{0,2,1} %bitcast.1), window={size=31 stride=2 pad=23_23}, dim_labels=b0f_0oi->b0f, custom_call_target="__cudnn$convBackwardInput", backend_config="{conv_result_scale:1}"
62   %get-tuple-element.2 = f32[138,23,1]{1,2,0} get-tuple-element((f32[138,23,1]{1,2,0}, u8[0]{0}) %custom-call.1), index=0
63   %bitcast.2 = f32[138,23,1]{2,1,0} bitcast(f32[138,23,1]{1,2,0} %get-tuple-element.2)
64   %get-tuple-element.3 = u8[0]{0} get-tuple-element((f32[138,23,1]{1,2,0}, u8[0]{0}) %custom-call.1), index=1
65   ROOT %tuple.1 = (f32[138,23,1]{2,1,0}, u8[0]{0}) tuple(f32[138,23,1]{2,1,0} %bitcast.2, u8[0]{0} %get-tuple-element.3)
66 })");
67 }
68 
TEST_F(GpuConvolutionRegressionTest,Computation3)69 TEST_F(GpuConvolutionRegressionTest, Computation3) {
70   CheckForHloText(R"(
71 HloModule TestModule
72 
73 %TestComputation5 (param_0: f32[138,100,136], param_1: f32[31,136,1]) -> (f32[138,183,1], u8[0]) {
74   %param_0 = f32[138,100,136]{2,1,0} parameter(0)
75   %copy.3 = f32[138,100,136]{1,2,0} copy(f32[138,100,136]{2,1,0} %param_0)
76   %param_1 = f32[31,136,1]{2,1,0} parameter(1)
77   %copy.4 = f32[31,136,1]{0,2,1} copy(f32[31,136,1]{2,1,0} %param_1)
78   %custom-call.1 = (f32[138,183,1]{1,2,0}, u8[0]{0}) custom-call(f32[138,100,136]{1,2,0} %copy.3, f32[31,136,1]{0,2,1} %copy.4), window={size=31 stride=2 pad=23_23}, dim_labels=b0f_0oi->b0f, custom_call_target="__cudnn$convBackwardInput", backend_config="{conv_result_scale:1}"
79   %get-tuple-element.2 = f32[138,183,1]{1,2,0} get-tuple-element((f32[138,183,1]{1,2,0}, u8[0]{0}) %custom-call.1), index=0
80   %bitcast = f32[138,183,1]{2,1,0} bitcast(f32[138,183,1]{1,2,0} %get-tuple-element.2)
81   %get-tuple-element.3 = u8[0]{0} get-tuple-element((f32[138,183,1]{1,2,0}, u8[0]{0}) %custom-call.1), index=1
82   ROOT %tuple.1 = (f32[138,183,1]{2,1,0}, u8[0]{0}) tuple(f32[138,183,1]{2,1,0} %bitcast, u8[0]{0} %get-tuple-element.3)
83 })");
84 }
85 
TEST_F(GpuConvolutionRegressionTest,BackwardFilterAlgo0Incorrect)86 TEST_F(GpuConvolutionRegressionTest, BackwardFilterAlgo0Incorrect) {
87   CheckForHloText(R"(
88 HloModule TestModule
89 
90 ENTRY %TestComputation {
91   %param_0 = f16[7680,96,6,6]{1,3,2,0} parameter(0)
92   %param_1 = f16[7680,64,4,4]{1,3,2,0} parameter(1)
93   ROOT %custom-call.1 = (f16[64,96,3,3]{1,3,2,0}, u8[0]{0}) custom-call(f16[7680,96,6,6]{1,3,2,0} %param_0, f16[7680,64,4,4]{1,3,2,0} %param_1), window={size=3x3}, dim_labels=bf01_oi01->bf01, custom_call_target="__cudnn$convBackwardFilter", backend_config="{conv_result_scale:1}"
94 })");
95 }
96 
97 // See b/135429938.
TEST_F(GpuConvolutionRegressionTest,RedzoneCheckerFailure1)98 TEST_F(GpuConvolutionRegressionTest, RedzoneCheckerFailure1) {
99   CheckForHloText(R"(
100 HloModule TestModule
101 
102 ENTRY %TestComputation {
103   %param_0 = f32[2,128,1,378]{3,2,1,0} parameter(0)
104   %param_1 = f32[1,5,128,128]{1,0,2,3} parameter(1)
105   ROOT %custom-call.1 = (f32[2,128,1,378]{3,2,1,0}, u8[0]{0}) custom-call(%param_0, %param_1), window={size=1x5 pad=0_0x2_2}, dim_labels=bf01_01io->bf01, custom_call_target="__cudnn$convForward", backend_config="{conv_result_scale:1}"
106 })");
107 }
108 
TEST_F(GpuConvolutionRegressionTest,Conv0D)109 TEST_F(GpuConvolutionRegressionTest, Conv0D) {
110   CheckForHloText(R"(
111 HloModule TestModule
112 
113 ENTRY TestComputation {
114   %parameter.1 = f32[10,5]{1,0} parameter(0)
115   %parameter.2 = f32[5,7]{0,1} parameter(1)
116   ROOT %custom-call.1 = (f32[10,7]{1,0}, u8[0]{0}) custom-call(f32[10,5]{1,0} %parameter.1, f32[5,7]{0,1} %parameter.2), window={}, dim_labels=bf_io->bf, custom_call_target="__cudnn$convForward", backend_config="{conv_result_scale:1}"
117 })");
118 }
119 
TEST_F(GpuConvolutionRegressionTest,ConvFwdEng42IllegalMemFail)120 TEST_F(GpuConvolutionRegressionTest, ConvFwdEng42IllegalMemFail) {
121   CheckForHloText(R"(
122     HloModule TestModule
123 
124 ENTRY TestComputation {
125   param_0 = f32[64,30,30,16]{2,1,0,3} parameter(0)
126   param_1 = f32[64,25,25,32]{2,1,0,3} parameter(1)
127   %cudnn-conv.14 = (f32[6,6,32,16]{1,0,2,3}, u8[0]{0}) custom-call(f32[64,30,30,16]{2,1,0,3} param_0, f32[64,25,25,32]{2,1,0,3} param_1), window={size=25x25 rhs_reversal=1x1}, dim_labels=f01b_i01o->01fb, custom_call_target="__cudnn$convForward", backend_config="{\"conv_result_scale\":1,\"activation_mode\":\"0\",\"side_input_scale\":0}"
128 })");
129 }
130 
131 }  // namespace
132 }  // namespace gpu
133 }  // namespace xla
134