Skip to content

Conversation

@chengjunlu
Copy link
Contributor

Reland the block store lowering changes with fix of an issue in block store.

@chengjunlu chengjunlu requested a review from whitneywhtsang July 9, 2025 02:48
@chengjunlu chengjunlu force-pushed the chengjun/re_land_block_store branch from 261e487 to ed0a771 Compare July 9, 2025 02:56
@chengjunlu chengjunlu force-pushed the chengjun/re_land_block_store branch 3 times, most recently from fac026c to 26ab3b4 Compare July 9, 2025 08:39
@etiotto etiotto requested review from Copilot and etiotto July 9, 2025 21:55
@etiotto
Copy link
Contributor

etiotto commented Jul 9, 2025

This PR looks too large. We will work on slitting it.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR relands the 2D block store lowering changes, fixes a block store issue, and enhances StoreOp conversion with LinearLayout-based tile size computation.

  • Introduces getBlockIOTileSize and extends isMemoryRowMajor to handle StoreOp
  • Unifies and refactors StoreOp lowering into a single matchAndRewrite, supporting both block pointers and regular pointers via a new Matrix2DBlockStoreOp
  • Updates tests (blockptr_store.mlir) for expected 2D block store patterns and adds new kernel cases; adds a new env var in GetEnv.hpp

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
LoadStoreOpToLLVM.cpp Added includes, getBlockIOTileSize, extended StoreOp lowering
test/TritonIntelGPU/blockptr_store.mlir Updated expected checks, added new block store test scenarios
include/triton/Tools/Sys/GetEnv.hpp Added TRITON_INTEL_ENABLE_BLOCK_IO_STORE_ON_REGULAR_PTR to set

Comment on lines +394 to +396
llvm_unreachable(("Could not find the input dim:" + inDim +
", on the ll:" + ll.toString())
.c_str());
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing c_str() of a temporary std::string into llvm_unreachable risks a dangling pointer. Construct the message in a local std::string variable or use llvm::formatv to ensure the string data remains valid.

Suggested change
llvm_unreachable(("Could not find the input dim:" + inDim +
", on the ll:" + ll.toString())
.c_str());
std::string errorMessage = "Could not find the input dim:" + inDim +
", on the ll:" + ll.toString();
llvm_unreachable(errorMessage.c_str());

Copilot uses AI. Check for mistakes.
size_t rank = tensorShape.size();
// 2D block store supports 64 bytes per row at most.
unsigned totalBytesPerRowPerMatrix = tileWidth * elemSizeInBits / 8;
if (totalBytesPerRowPerMatrix > 64)
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The literal 64 appears as a magic number here. Consider defining a named constant (e.g. kMaxBytesPerRow) to clarify its meaning and ease future updates.

Suggested change
if (totalBytesPerRowPerMatrix > 64)
if (totalBytesPerRowPerMatrix > kMaxBytesPerRow)

Copilot uses AI. Check for mistakes.

// Only lower StoreOp with dpas layout encoding.
if (!hasDpasEncoding(tensorType))
matchAndRewrite(triton::StoreOp op, OpAdaptor adaptor,
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] This matchAndRewrite function has grown quite large. Consider refactoring block-pointer and regular-pointer handling into separate helper methods to improve readability and testability.

Copilot uses AI. Check for mistakes.
Comment on lines +2636 to +2637
assert(!llMask && "The masks is expected to be used with regular tensor "
"pointer type, but got a block pointer type.");
Copy link

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using assert for input validation can crash in release builds. Prefer returning failure() with an informative diagnostic rather than aborting, so consumers get a graceful rewrite failure.

Suggested change
assert(!llMask && "The masks is expected to be used with regular tensor "
"pointer type, but got a block pointer type.");
if (llMask) {
rewriter.emitError(loc, "The masks are expected to be used with regular tensor "
"pointer type, but got a block pointer type.");
return failure();
}

Copilot uses AI. Check for mistakes.
@chengjunlu
Copy link
Contributor Author

I created a new PR #4666 to enable the block store for regular pointer first.

@whitneywhtsang
Copy link
Contributor

Created #4667 for some easier changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants