Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/target/codegen_hip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ void CodeGenTileLangHIP::PrintVecElemLoad(const std::string &vec, DataType t,
os << "((half2*)(&(" << vec << "." << access[i / 2] << ")))->"
<< access[i % 2];
} else if (t.is_bfloat16()) {
os << "((nv_bfloat162*)(&(" << vec << "." << access[i / 2] << ")))->"
os << "((bfloat16x2*)(&(" << vec << "." << access[i / 2] << ")))->"
<< access[i % 2];
Comment on lines +483 to 484
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While this change from nv_bfloat162 to bfloat16x2 is correct for HIP, there's an underlying issue with vector element loading for 2-element vectors.

For a bfloat16 vector with 2 lanes, PrintType generates a scalar uint type for the vector variable vec. The current code then attempts to access a member (e.g., .x) of this scalar uint (vec << "." << access[i / 2]), which is incorrect and will cause compilation errors in the generated code.

The logic should handle 2-lane vectors (represented as a scalar uint) differently from wider vectors (e.g., uint2, uint4). For the 2-lane case, the address of the scalar vec should be cast directly, without member access.

A similar issue exists for float16 vectors on lines 480-481.

Suggested change
os << "((bfloat16x2*)(&(" << vec << "." << access[i / 2] << ")))->"
<< access[i % 2];
os << "((bfloat16x2*)(&(" << (t.lanes() == 2 ? vec : (vec + "." + access[i / 2])) << ")))->"
<< access[i % 2];

} else if (t.lanes() > 4 && t.lanes() <= 8) {
std::string type_name;
Expand Down
2 changes: 1 addition & 1 deletion src/tl_templates/hip/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ using half_t = float16_t;
using bfloat16_t = hip_bfloat16;

struct bfloat16x2 {
bfloat16_t data[2];
bfloat16_t x, y;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This change to bfloat16x2 is correct to support member access like .x and .y. For consistency, you should consider updating bfloat16x4, bfloat16x8, and bfloat16x16 to also use named members (x, y, z, w, etc.) or nested structs instead of a data array. This would make the API for these vector-like structs more uniform and easier to use.

};

struct bfloat16x4 {
Expand Down
1 change: 1 addition & 0 deletions testing/python/amd/test_tilelang_gemm_mfma_intrinsic.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def tl_matmul(
A_shared_shape = (block_K, block_M) if a_transposed else (block_M, block_K)
B_shared_shape = (block_N, block_K) if b_transposed else (block_K, block_N)
C_shared_shape = (
block_M // micro_size_x,
block_N // micro_size_y,
micro_size_x,
micro_size_y,
Expand Down
Loading