Skip to content

Commit a188e13

Browse files
committed
[BACKEND][PPU] Apply formatting to INT8 AIU changes
1 parent b20e5b2 commit a188e13

3 files changed

Lines changed: 22 additions & 40 deletions

File tree

third_party/ppu/lib/TritonPPUGPUToLLVM/AIUUtility.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,17 +257,15 @@ DenseMap<unsigned, Value> getPPUAIUV1SwizzledSharedPtrs(
257257
Value sliceStartPtr =
258258
b.gep(dstPtrTy, resElemTy, dstPtrBase, sliceStartOffset);
259259

260-
Value idxColInnerSlice =
261-
b.urem(idxColInnerCube, b.i32_val(sliceElems));
260+
Value idxColInnerSlice = b.urem(idxColInnerCube, b.i32_val(sliceElems));
262261
// new swizzled row index inside slice, swizzled slice shape is (cubeW/4,
263262
// 64)
264263
Value rowSwizzleID = b.udiv(idxRowInnerCube, b.i32_val(4));
265264
// new linear slice index inside slice, slice shape is (cubeW/4, 64)
266265
Value idxColSlicelinear = b.urem(
267266
b.add(b.mul(idxRowInnerCube, b.i32_val(sliceElems)), idxColInnerSlice),
268267
b.i32_val(128 / elemBytes));
269-
Value colSliceID =
270-
b.udiv(idxColSlicelinear, b.i32_val(16 / elemBytes));
268+
Value colSliceID = b.udiv(idxColSlicelinear, b.i32_val(16 / elemBytes));
271269

272270
// rotated length: (((sliceID>1)|(sliceID<1))&0x3) << 1
273271
// sliceID 0, 1, 2, 3 ---> rotated length: 0, 4, 2, 6
@@ -284,13 +282,12 @@ DenseMap<unsigned, Value> getPPUAIUV1SwizzledSharedPtrs(
284282
Value colRotID = b.sub(b.i32_val(7), colRotBitPos);
285283
Value colSwizzleID = b.xor_(colRotID, b.urem(rowSwizzleID, b.i32_val(2)));
286284

287-
Value swizzleOffset = b.add(
288-
b.mul(rowSwizzleID, b.i32_val(128 / elemBytes)),
289-
b.mul(colSwizzleID, b.i32_val(16 / elemBytes)));
285+
Value swizzleOffset = b.add(b.mul(rowSwizzleID, b.i32_val(128 / elemBytes)),
286+
b.mul(colSwizzleID, b.i32_val(16 / elemBytes)));
290287

291288
// for minVec is not equal to outVec
292-
swizzleOffset = b.or_(
293-
swizzleOffset, b.urem(idxCol, b.i32_val(16 / elemBytes)));
289+
swizzleOffset =
290+
b.or_(swizzleOffset, b.urem(idxCol, b.i32_val(16 / elemBytes)));
294291
ret[elemIdx] = b.gep(dstPtrTy, resElemTy, sliceStartPtr, swizzleOffset);
295292
}
296293

third_party/ppu/lib/TritonPPUGPUToLLVM/ConvertLayoutOpToLLVM/SharedToDotOperandPPUAIUV1.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,19 @@ loadX4B8(ConversionPatternRewriter &rewriter, Location loc, Value smemBase,
5454
llvm::report_fatal_error(
5555
"PPU0010 B8 AIU dot requires native A-row/B-col layout");
5656
Value bytePtr = b.bitcast(smemBase, ptr_ty(rewriter.getContext(), 3));
57-
Value topLeftIndex =
58-
b.add(b.mul(startCoordY, blockLineStride), startCoordX);
57+
Value topLeftIndex = b.add(b.mul(startCoordY, blockLineStride), startCoordX);
5958
Value sliceId = b.udiv(channelOffset, b.i32_val(32));
6059
Value sliceOffset = b.mul(sliceId, b.mul(blockLineStride, b.i32_val(32)));
61-
bytePtr = b.gep(ptr_ty(rewriter.getContext(), 3), i8_ty,
62-
bytePtr, sliceOffset);
60+
bytePtr =
61+
b.gep(ptr_ty(rewriter.getContext(), 3), i8_ty, bytePtr, sliceOffset);
6362
Value sBase = b.or_(
6463
b.shl(b.and_(sliceId, b.i32_val(3)), b.i32_val(27)),
6564
b.or_(b.shl(b.and_(blockLineStride, b.i32_val(0x7ff)), b.i32_val(16)),
6665
b.and_(topLeftIndex, b.i32_val(0xffff))));
6766
auto resultTy = vec_ty(i32_ty, 4);
68-
Value loaded = callIntrinsic(rewriter, loc,
69-
"llvm.ppu.tsm.ld.swizzle.b32x4.p3i8",
70-
resultTy, {bytePtr, b.i32_val(1), sBase});
67+
Value loaded =
68+
callIntrinsic(rewriter, loc, "llvm.ppu.tsm.ld.swizzle.b32x4.p3i8",
69+
resultTy, {bytePtr, b.i32_val(1), sBase});
7170
Value r0 = b.extract_element(i32_ty, loaded, b.i32_val(0));
7271
Value r1 = b.extract_element(i32_ty, loaded, b.i32_val(1));
7372
Value r2 = b.extract_element(i32_ty, loaded, b.i32_val(2));

third_party/ppu/python/test/unit/tle/test_tle_aiu_async_load.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,7 @@ def test_aiu_promotion_dtypes(dtype):
171171
assert "aiu_load" in compiled.asm["ttir"]
172172
_assert_no_tle_residue(compiled)
173173
if dtype == "fp32":
174-
aiu_instructions = [
175-
line for line in compiled.asm["llir"].splitlines()
176-
if "ppu.cp.async.aiu" in line
177-
]
174+
aiu_instructions = [line for line in compiled.asm["llir"].splitlines() if "ppu.cp.async.aiu" in line]
178175
assert aiu_instructions
179176
assert all(".b16" in line for line in aiu_instructions)
180177
assert all(".b8" not in line for line in aiu_instructions)
@@ -196,9 +193,7 @@ def test_int8_aiu_load_device_correctness():
196193
expected = torch.arange(32 * 32, device="cuda", dtype=torch.int32)
197194
expected = expected.remainder(127).to(torch.int8).reshape(32, 32)
198195
actual = torch.empty_like(expected)
199-
_typed_aiu_load[(1,)](
200-
expected, actual, 32, 32, 32, 32, num_warps=4, num_stages=1
201-
)
196+
_typed_aiu_load[(1, )](expected, actual, 32, 32, 32, 32, num_warps=4, num_stages=1)
202197
torch.cuda.synchronize()
203198
torch.testing.assert_close(actual.cpu(), expected.cpu(), rtol=0, atol=0)
204199

@@ -302,12 +297,10 @@ def _int8_gemm_aiu_kernel(
302297
):
303298
pid_m = tl.program_id(0)
304299
pid_n = tl.program_id(1)
305-
a_bp = tl.make_block_ptr(a_ptr, shape=(M, K), strides=(K, 1),
306-
offsets=(pid_m * BLOCK_M, 0),
300+
a_bp = tl.make_block_ptr(a_ptr, shape=(M, K), strides=(K, 1), offsets=(pid_m * BLOCK_M, 0),
307301
block_shape=(BLOCK_M, BLOCK_K), order=(1, 0))
308302
# b_ptr is physically contiguous [N, K], logically column-major [K, N].
309-
b_bp = tl.make_block_ptr(b_ptr, shape=(K, N), strides=(1, K),
310-
offsets=(0, pid_n * BLOCK_N),
303+
b_bp = tl.make_block_ptr(b_ptr, shape=(K, N), strides=(1, K), offsets=(0, pid_n * BLOCK_N),
311304
block_shape=(BLOCK_K, BLOCK_N), order=(0, 1))
312305
acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.int32)
313306
for _ in range(0, K, BLOCK_K):
@@ -318,8 +311,7 @@ def _int8_gemm_aiu_kernel(
318311
b_bp = tl.advance(b_bp, (BLOCK_K, 0))
319312
offs_m = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)
320313
offs_n = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)
321-
tl.store(c_ptr + N * offs_m[:, None] + offs_n[None, :], acc,
322-
mask=(offs_m[:, None] < M) & (offs_n[None, :] < N))
314+
tl.store(c_ptr + N * offs_m[:, None] + offs_n[None, :], acc, mask=(offs_m[:, None] < M) & (offs_n[None, :] < N))
323315

324316

325317
@_skip_no_sdk
@@ -345,9 +337,7 @@ def test_int8_gemm_uses_v1_b8_aiu_load_and_int8_mma():
345337
@pytest.mark.skipif(not torch.cuda.is_available(), reason="PPU device not available")
346338
@pytest.mark.parametrize(
347339
"m,n,k,bm,bn,bk,num_warps",
348-
[(16, 16, 32, 16, 16, 32, 1),
349-
(16, 32, 64, 16, 32, 64, 1),
350-
(64, 64, 64, 64, 64, 64, 4),
340+
[(16, 16, 32, 16, 16, 32, 1), (16, 32, 64, 16, 32, 64, 1), (64, 64, 64, 64, 64, 64, 4),
351341
(128, 128, 128, 64, 64, 64, 4)],
352342
)
353343
def test_int8_gemm_aiu_device_correctness(m, n, k, bm, bn, bk, num_warps):
@@ -356,8 +346,7 @@ def test_int8_gemm_aiu_device_correctness(m, n, k, bm, bn, bk, num_warps):
356346
b = torch.randint(-8, 9, (n, k), device="cuda", dtype=torch.int8)
357347
actual = torch.empty((m, n), device="cuda", dtype=torch.int32)
358348
grid = (triton.cdiv(m, bm), triton.cdiv(n, bn))
359-
_int8_gemm_aiu_kernel[grid](a, b, actual, m, n, k, bm, bn, bk,
360-
num_warps=num_warps, num_stages=1)
349+
_int8_gemm_aiu_kernel[grid](a, b, actual, m, n, k, bm, bn, bk, num_warps=num_warps, num_stages=1)
361350
torch.cuda.synchronize()
362351
expected = a.cpu().to(torch.int32) @ b.cpu().to(torch.int32).T
363352
torch.testing.assert_close(actual.cpu(), expected, rtol=0, atol=0)
@@ -445,8 +434,7 @@ def kernel(a_ptr, c_ptr, M: tl.constexpr, K: tl.constexpr, BLOCK_M: tl.constexpr
445434
mask=(offs_m[:, None] < M) & (offs_k[None, :] < K))
446435

447436
compiled = _compile(kernel, {"a_ptr": "*fp16", "c_ptr": "*fp16"},
448-
{"M": 512, "K": 512, "BLOCK_M": 64, "BLOCK_K": 64},
449-
options={"num_stages": num_stages})
437+
{"M": 512, "K": 512, "BLOCK_M": 64, "BLOCK_K": 64}, options={"num_stages": num_stages})
450438
_assert_stages_exist(compiled)
451439
assert "aiu_load" in compiled.asm["ttir"]
452440
_assert_no_tle_residue(compiled)
@@ -467,12 +455,10 @@ def kernel(a_ptr, c_ptr, M: tl.constexpr, K: tl.constexpr, BLOCK_M: tl.constexpr
467455
a_bp = tl.advance(a_bp, (0, BLOCK_K))
468456
offs_m = pid * BLOCK_M + tl.arange(0, BLOCK_M)
469457
offs_k = tl.arange(0, BLOCK_K)
470-
tl.store(c_ptr + K * offs_m[:, None] + offs_k[None, :], acc,
471-
mask=(offs_m[:, None] < M) & (offs_k[None, :] < K))
458+
tl.store(c_ptr + K * offs_m[:, None] + offs_k[None, :], acc, mask=(offs_m[:, None] < M) & (offs_k[None, :] < K))
472459

473460
compiled = _compile_through_llir(kernel, {"a_ptr": "*i8", "c_ptr": "*i32"},
474-
{"M": 512, "K": 512, "BLOCK_M": 64, "BLOCK_K": 64},
475-
options={"num_stages": 2})
461+
{"M": 512, "K": 512, "BLOCK_M": 64, "BLOCK_K": 64}, options={"num_stages": 2})
476462
_assert_stages_exist(compiled)
477463
assert "aiu_load" in compiled.asm["ttir"]
478464
_assert_no_tle_residue(compiled)

0 commit comments

Comments
 (0)