|
| 1 | +From 3c5a3dc9cae6552fc6c58659d75077055f899126 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Dragan Mladjenovic < [email protected]> |
| 3 | +Date: Wed, 19 Feb 2025 10:36:32 -0600 |
| 4 | +Subject: [PATCH 5/6] [ROCm] Pass correct warp size to Triton pipeline |
| 5 | + |
| 6 | +--- |
| 7 | + xla/backends/gpu/codegen/triton/compilation_pipeline.h | 2 +- |
| 8 | + .../gpu/codegen/triton/compilation_pipeline_cuda.cc | 6 ++---- |
| 9 | + .../gpu/codegen/triton/compilation_pipeline_rocm.cc | 7 +++---- |
| 10 | + .../gpu/codegen/triton/compilation_pipeline_stub.cc | 2 +- |
| 11 | + xla/backends/gpu/codegen/triton/fusion_emitter.cc | 4 +--- |
| 12 | + .../gpu/codegen/triton/fusion_emitter_stub_test.cc | 2 +- |
| 13 | + xla/service/gpu/ir_emitter_unnested.cc | 7 ++++--- |
| 14 | + 7 files changed, 13 insertions(+), 17 deletions(-) |
| 15 | + |
| 16 | +diff --git a/xla/backends/gpu/codegen/triton/compilation_pipeline.h b/xla/backends/gpu/codegen/triton/compilation_pipeline.h |
| 17 | +index 9acd6fee99..c9e65798a5 100644 |
| 18 | +--- a/xla/backends/gpu/codegen/triton/compilation_pipeline.h |
| 19 | ++++ b/xla/backends/gpu/codegen/triton/compilation_pipeline.h |
| 20 | +@@ -41,7 +41,7 @@ namespace gpu { |
| 21 | + // parameter which would give a hint to Triton which cluster dims we prefer to |
| 22 | + // use, but that's not the case currently. |
| 23 | + absl::Status CreateTritonPipeline( |
| 24 | +- mlir::OpPassManager* pm, std::string arch_name, int num_warps, int num_ctas, |
| 25 | ++ mlir::OpPassManager* pm, const se::DeviceDescription& device_info, int num_warps, int num_ctas, |
| 26 | + int num_stages, mlir::triton::nvidia_gpu::ClusterInfo& out_cluster_info, |
| 27 | + bool is_xla_fusion); |
| 28 | + |
| 29 | +diff --git a/xla/backends/gpu/codegen/triton/compilation_pipeline_cuda.cc b/xla/backends/gpu/codegen/triton/compilation_pipeline_cuda.cc |
| 30 | +index b57300ea88..e0fcf5bfd1 100644 |
| 31 | +--- a/xla/backends/gpu/codegen/triton/compilation_pipeline_cuda.cc |
| 32 | ++++ b/xla/backends/gpu/codegen/triton/compilation_pipeline_cuda.cc |
| 33 | +@@ -43,13 +43,11 @@ namespace mt = ::mlir::triton; |
| 34 | + namespace mt_xla = ::mlir::triton::xla; |
| 35 | + |
| 36 | + absl::Status CreateTritonPipeline(mlir::OpPassManager* pm, |
| 37 | +- std::string arch_name, int num_warps, |
| 38 | ++ const se::DeviceDescription& device_info, int num_warps, |
| 39 | + int num_ctas, int num_stages, |
| 40 | + mt::nvidia_gpu::ClusterInfo& out_cluster_info, |
| 41 | + bool is_xla_fusion) { |
| 42 | +- TF_ASSIGN_OR_RETURN( |
| 43 | +- const stream_executor::CudaComputeCapability cc, |
| 44 | +- stream_executor::CudaComputeCapability::FromString(arch_name)); |
| 45 | ++ auto cc = device_info.cuda_compute_capability(); |
| 46 | + const int ccAsInt = cc.major * 10 + cc.minor; |
| 47 | + const int threadsPerWarp = 32; |
| 48 | + |
| 49 | +diff --git a/xla/backends/gpu/codegen/triton/compilation_pipeline_rocm.cc b/xla/backends/gpu/codegen/triton/compilation_pipeline_rocm.cc |
| 50 | +index 03fc4bb230..64a493ed2b 100644 |
| 51 | +--- a/xla/backends/gpu/codegen/triton/compilation_pipeline_rocm.cc |
| 52 | ++++ b/xla/backends/gpu/codegen/triton/compilation_pipeline_rocm.cc |
| 53 | +@@ -58,13 +58,12 @@ using ::mlir::Value; |
| 54 | + using mlir::ValueRange; |
| 55 | + |
| 56 | + absl::Status CreateTritonPipeline(mlir::OpPassManager* pm, |
| 57 | +- std::string arch_name, int num_warps, |
| 58 | ++ const se::DeviceDescription& device_info, int num_warps, |
| 59 | + int num_ctas, int num_stages, |
| 60 | + mt::nvidia_gpu::ClusterInfo& out_cluster_info, |
| 61 | + bool is_xla_fusion) { |
| 62 | +- // TODO(ROCm): Check why some test fail when threadsPerWarp is set to 64. |
| 63 | +- const int threadsPerWarp = 32; |
| 64 | +- auto cc = se::RocmComputeCapability(std::move(arch_name)); |
| 65 | ++ const int threadsPerWarp = device_info.threads_per_warp(); |
| 66 | ++ auto cc = device_info.rocm_compute_capability(); |
| 67 | + |
| 68 | + if (is_xla_fusion) { |
| 69 | + pm->addPass(mt_xla::CreateInt4ToPackedInt4RewritePass()); |
| 70 | +diff --git a/xla/backends/gpu/codegen/triton/compilation_pipeline_stub.cc b/xla/backends/gpu/codegen/triton/compilation_pipeline_stub.cc |
| 71 | +index d91acda7f5..ce7517a6b5 100644 |
| 72 | +--- a/xla/backends/gpu/codegen/triton/compilation_pipeline_stub.cc |
| 73 | ++++ b/xla/backends/gpu/codegen/triton/compilation_pipeline_stub.cc |
| 74 | +@@ -23,7 +23,7 @@ namespace xla { |
| 75 | + namespace gpu { |
| 76 | + |
| 77 | + absl::Status CreateTritonPipeline( |
| 78 | +- mlir::OpPassManager* pm, std::string arch_name, int num_warps, int num_ctas, |
| 79 | ++ mlir::OpPassManager* pm, const se::DeviceDescription& device_info, int num_warps, int num_ctas, |
| 80 | + int num_stages, mlir::triton::nvidia_gpu::ClusterInfo& out_cluster_info, |
| 81 | + bool is_xla_fusion) { |
| 82 | + return absl::UnimplementedError("not supported for this build configuration"); |
| 83 | +diff --git a/xla/backends/gpu/codegen/triton/fusion_emitter.cc b/xla/backends/gpu/codegen/triton/fusion_emitter.cc |
| 84 | +index 02644b9dc4..d164ffa9e4 100644 |
| 85 | +--- a/xla/backends/gpu/codegen/triton/fusion_emitter.cc |
| 86 | ++++ b/xla/backends/gpu/codegen/triton/fusion_emitter.cc |
| 87 | +@@ -1544,8 +1544,6 @@ absl::StatusOr<TritonWrapperResult> CompileTritonToLLVM( |
| 88 | + mlir::ModuleOp triton_module, llvm::Module* llvm_module, |
| 89 | + mlir::MLIRContext& mlir_context, bool is_xla_fusion, bool emit_kernel) { |
| 90 | + const auto& cc = device_info.gpu_compute_capability(); |
| 91 | +- std::string arch_name = |
| 92 | +- std::visit([](auto& cc) { return cc.ToString(); }, cc); |
| 93 | + if (std::holds_alternative<se::CudaComputeCapability>(cc)) { |
| 94 | + auto ccCuda = std::get<se::CudaComputeCapability>(cc); |
| 95 | + if (!ccCuda.IsAtLeastAmpere()) { |
| 96 | +@@ -1606,7 +1604,7 @@ absl::StatusOr<TritonWrapperResult> CompileTritonToLLVM( |
| 97 | + pm.addPass(CreateConvertIndexTypePass()); |
| 98 | + |
| 99 | + mlir::triton::nvidia_gpu::ClusterInfo cluster_info; |
| 100 | +- if (!CreateTritonPipeline(&pm, arch_name, block_level_parameters.num_warps, |
| 101 | ++ if (!CreateTritonPipeline(&pm, device_info, block_level_parameters.num_warps, |
| 102 | + block_level_parameters.num_ctas, |
| 103 | + block_level_parameters.num_stages, cluster_info, |
| 104 | + is_xla_fusion) |
| 105 | +diff --git a/xla/backends/gpu/codegen/triton/fusion_emitter_stub_test.cc b/xla/backends/gpu/codegen/triton/fusion_emitter_stub_test.cc |
| 106 | +index 20accf012b..26b0d91fee 100644 |
| 107 | +--- a/xla/backends/gpu/codegen/triton/fusion_emitter_stub_test.cc |
| 108 | ++++ b/xla/backends/gpu/codegen/triton/fusion_emitter_stub_test.cc |
| 109 | +@@ -51,7 +51,7 @@ TEST(TritonStub, CallStubApi) { |
| 110 | + mlir::OpPassManager pm; |
| 111 | + ::mlir::triton::nvidia_gpu::ClusterInfo cluster_info; |
| 112 | + |
| 113 | +- EXPECT_FALSE(CreateTritonPipeline(&pm, "", 1, 1, 1, cluster_info, |
| 114 | ++ EXPECT_FALSE(CreateTritonPipeline(&pm, {}, 1, 1, 1, cluster_info, |
| 115 | + /*is_xla_fusion=*/true) |
| 116 | + .ok()); |
| 117 | + EXPECT_EQ(GetLibdevicePath({}, {}), ""); |
| 118 | +diff --git a/xla/service/gpu/ir_emitter_unnested.cc b/xla/service/gpu/ir_emitter_unnested.cc |
| 119 | +index fcedefa8f3..75d970b7ae 100644 |
| 120 | +--- a/xla/service/gpu/ir_emitter_unnested.cc |
| 121 | ++++ b/xla/service/gpu/ir_emitter_unnested.cc |
| 122 | +@@ -1434,9 +1434,10 @@ absl::Status IrEmitterUnnested::EmitTritonCustomCall( |
| 123 | + KernelArguments::Create(ir_emitter_context_->buffer_assignment(), instr, |
| 124 | + instr->operands(), |
| 125 | + /*dedup=*/false)); |
| 126 | +- auto launch_dimensions = |
| 127 | +- LaunchDimensions(se::BlockDim(call.grid_x, call.grid_y, call.grid_z), |
| 128 | +- se::ThreadDim(call.num_warps * 32)); |
| 129 | ++ auto launch_dimensions = LaunchDimensions( |
| 130 | ++ se::BlockDim(call.grid_x, call.grid_y, call.grid_z), |
| 131 | ++ se::ThreadDim(call.num_warps * |
| 132 | ++ ir_emitter_context_->gpu_device_info().threads_per_warp())); |
| 133 | + |
| 134 | + std::string sanitized_kernel_name = |
| 135 | + GetSanitizedUniqueName(*ir_emitter_context_, kernel_name); |
| 136 | +-- |
| 137 | +2.43.0 |
| 138 | + |
0 commit comments