1 /* Copyright 2020 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 #include <utility>
16
17 #include "tensorflow/compiler/xla/service/gpu/tests/gpu_codegen_test.h"
18 #include "tensorflow/compiler/xla/service/hlo_instruction.h"
19 #include "tensorflow/compiler/xla/service/hlo_module_config.h"
20
21 namespace xla {
22 namespace gpu {
23 class GpuDynamicShapeTest : public GpuCodegenTest {};
24
TEST_F(GpuDynamicShapeTest,DynamicShapeR2)25 TEST_F(GpuDynamicShapeTest, DynamicShapeR2) {
26 HloComputation::Builder builder(TestName());
27
28 xla::Shape dyn_input_shape = xla::ShapeUtil::MakeShape(xla::F32, {2, 4});
29 dyn_input_shape.set_dynamic_dimension(0, true);
30 HloInstruction* param_x = builder.AddInstruction(
31 HloInstruction::CreateParameter(0, dyn_input_shape, "x"));
32
33 builder.AddInstruction(HloInstruction::CreateUnary(
34 dyn_input_shape, HloOpcode::kNegate, param_x));
35 auto hlo_module = CreateNewVerifiedModule();
36 hlo_module->AddEntryComputation(builder.Build());
37
38 CompileAndVerifyIr(std::move(hlo_module),
39 R"(
40 ; CHECK-LABEL: is_thread_0-true
41 ; CHECK-LABEL: custom_call.in_dyn_bounds-true
42 ; CHECK-LABEL: custom_call.in_bounds-true
43 ; CHECK: %[[dyn_dim_size:.*]] = load i32, ptr
44 ; CHECK: %[[dyn_element_total:.*]] = mul i32 1, %[[dyn_dim_size:.*]]
45 ; CHECK: %[[linear_index:.*]] = add nuw nsw i32
46 ; CHECK: %[[linear_index_in_range:.*]] = icmp ult i32 %[[linear_index:.*]],
47 ; CHECK: store i32 %[[dyn_dim_size:.*]], ptr
48 )",
49 /*match_optimized_ir=*/false);
50 }
51
52 } // namespace gpu
53 } // namespace xla
54