-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Triton] Fix a bug while lowering to LLVM for block_k=16 when the inp…
…ut types involve an 8-bit. This change is porting in this [PR](triton-lang/triton#4768). PiperOrigin-RevId: 695275077
- Loading branch information
1 parent
3c2a6e7
commit 4a4d7af
Showing
4 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- a/lib/Conversion/TritonGPUToLLVM/ElementwiseOpToLLVM.cpp | ||
+++ b/lib/Conversion/TritonGPUToLLVM/ElementwiseOpToLLVM.cpp | ||
@@ -46,6 +46,7 @@ SmallVector<Value> reorderValues(const S | ||
return values; | ||
auto inEncoding = dyn_cast<DotOperandEncodingAttr>(inTensorTy.getEncoding()); | ||
auto ouEncoding = dyn_cast<DotOperandEncodingAttr>(ouTensorTy.getEncoding()); | ||
+ auto in_shape = inTensorTy.getShape(); | ||
assert(inEncoding == ouEncoding); | ||
if (!inEncoding) | ||
return values; | ||
@@ -101,6 +102,11 @@ SmallVector<Value> reorderValues(const S | ||
// | ||
// [0, 1], [4, 5], [2, 3], [6, 7], [8, 9], [12, 13], [10, 11], [14, 15] | ||
SmallVector<Value> ret; | ||
+ | ||
+ // In the corner cases (1) where in_shape[0] == 16 and getOpIdx() == | ||
+ // 1, and (2) where in_shape[1] == 16 and getOpIdx == 0, extra elements will | ||
+ // be loaded. It is necessary to discard these additional elements. | ||
+ bool loadsExtraElements = in_shape[1 - inEncoding.getOpIdx()] == 16; | ||
for (unsigned i = 0; i < values.size(); i += 16) { | ||
ret.push_back(values[i]); | ||
ret.push_back(values[i + 1]); | ||
@@ -110,6 +116,8 @@ SmallVector<Value> reorderValues(const S | ||
ret.push_back(values[i + 3]); | ||
ret.push_back(values[i + 6]); | ||
ret.push_back(values[i + 7]); | ||
+ if (loadsExtraElements) | ||
+ continue; | ||
ret.push_back(values[i + 8]); | ||
ret.push_back(values[i + 9]); | ||
ret.push_back(values[i + 12]); | ||
new file mode 100644 | ||
--- /dev/null | ||
+++ b/test/Conversion/tritongpu_to_llvm_ampere.mlir | ||
@@ -0,0 +1,23 @@ | ||
+// RUN: triton-opt %s -split-input-file --allocate-shared-memory --convert-triton-gpu-to-llvm=compute-capability=80 2>&1 | FileCheck %s | ||
+ | ||
+#mma = #triton_gpu.nvidia_mma<{versionMajor = 2, versionMinor = 0, warpsPerCTA = [2, 2], instrShape = [16, 8]}> | ||
+module attributes {"triton_gpu.num-ctas" = 1 : i32, "triton_gpu.num-warps" = 4 : i32, triton_gpu.shared = 3072 : i32, triton_gpu.target = "cuda:80", "triton_gpu.threads-per-warp" = 32 : i32} { | ||
+ tt.func public @ampere_s8_to_fp16_conversion_opIdx1(%1 : tensor<16x32xi8, #triton_gpu.dot_op<{opIdx = 1, parent = #mma, kWidth = 4}>>) attributes {noinline = false} { | ||
+ // CHECK-LABEL: ampere_s8_to_fp16_conversion_opIdx1 | ||
+ // CHECK: llvm.sitofp %{{.*}} : i8 to f16 | ||
+ %2 = arith.sitofp %1 : tensor<16x32xi8, #triton_gpu.dot_op<{opIdx = 1, parent = #mma, kWidth = 4}>> to tensor<16x32xf16, #triton_gpu.dot_op<{opIdx = 1, parent = #mma, kWidth = 4}>> | ||
+ tt.return | ||
+ } | ||
+} | ||
+ | ||
+// ----- | ||
+ | ||
+#mma = #triton_gpu.nvidia_mma<{versionMajor = 2, versionMinor = 0, warpsPerCTA = [2, 2], instrShape = [16, 8]}> | ||
+module attributes {"triton_gpu.num-ctas" = 1 : i32, "triton_gpu.num-warps" = 4 : i32, triton_gpu.shared = 3072 : i32, triton_gpu.target = "cuda:80", "triton_gpu.threads-per-warp" = 32 : i32} { | ||
+ tt.func public @ampere_s8_to_fp16_conversion_opIdx0(%1 : tensor<32x16xi8, #triton_gpu.dot_op<{opIdx = 0, parent = #mma, kWidth = 4}>>) attributes {noinline = false} { | ||
+ // CHECK-LABEL: @ampere_s8_to_fp16_conversion_opIdx0 | ||
+ // CHECK: llvm.sitofp %{{.*}} : i8 to f16 | ||
+ %2 = arith.sitofp %1 : tensor<32x16xi8, #triton_gpu.dot_op<{opIdx = 0 , parent = #mma, kWidth = 4}>> to tensor<32x16xf16, #triton_gpu.dot_op<{opIdx = 0, parent = #mma, kWidth = 4}>> | ||
+ tt.return | ||
+ } | ||
+} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters