Skip to content

Commit 0da219f

Browse files
committed
[hipblaslt] modify the batch offset value as in elements.
1 parent e097805 commit 0da219f

5 files changed

Lines changed: 59 additions & 25 deletions

File tree

projects/hipblaslt/clients/common/include/testing_matmul_batch_offset.hpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void testing_matmul_batch_offset_impl(const Arguments& arg)
6262

6363
int32_t batch_count = arg.batch_count;
6464

65-
// Batch offsets (from YAML - assumed to be in BYTES)
65+
// Batch offsets (from YAML - in ELEMENTS)
6666
int64_t offset_a = arg.batch_offset_a;
6767
int64_t offset_b = arg.batch_offset_b;
6868
int64_t offset_c = arg.batch_offset_c;
@@ -86,22 +86,16 @@ void testing_matmul_batch_offset_impl(const Arguments& arg)
8686
size_t size_C_sub = size_t(ldc) * size_t(N);
8787
size_t size_D_sub = size_t(ldd) * size_t(N);
8888

89-
// Convert byte offsets to element offsets
90-
// Note: offsets must be aligned to element size
91-
size_t offset_a_elem = offset_a / sizeof(Ti);
92-
size_t offset_b_elem = offset_b / sizeof(Ti);
93-
size_t offset_c_elem = offset_c / sizeof(To);
94-
size_t offset_d_elem = offset_d / sizeof(To);
95-
9689
// Full buffer sizes: [offset padding] + [matrix data]
9790
// The offset padding comes FIRST because:
9891
// - Pointer array points to buffer BASE
9992
// - Kernel adds offset to BASE to get actual data location
10093
// - So actual data is at BASE + offset
101-
size_t size_A_full = offset_a_elem + size_A_sub;
102-
size_t size_B_full = offset_b_elem + size_B_sub;
103-
size_t size_C_full = offset_c_elem + size_C_sub;
104-
size_t size_D_full = offset_d_elem + size_D_sub;
94+
// Offsets are already in elements (the API takes element offsets).
95+
size_t size_A_full = offset_a + size_A_sub;
96+
size_t size_B_full = offset_b + size_B_sub;
97+
size_t size_C_full = offset_c + size_C_sub;
98+
size_t size_D_full = offset_d + size_D_sub;
10599

106100
// Allocate host memory for full buffers
107101
host_vector<Ti> h_A_full(size_A_full * batch_count);
@@ -116,9 +110,9 @@ void testing_matmul_batch_offset_impl(const Arguments& arg)
116110
for(int b = 0; b < batch_count; b++)
117111
{
118112
// Initialize each batch's sub-matrix at the offset location
119-
Ti* A_batch = h_A_full.data() + b * size_A_full + offset_a_elem;
120-
Ti* B_batch = h_B_full.data() + b * size_B_full + offset_b_elem;
121-
To* C_batch = h_C_full.data() + b * size_C_full + offset_c_elem;
113+
Ti* A_batch = h_A_full.data() + b * size_A_full + offset_a;
114+
Ti* B_batch = h_B_full.data() + b * size_B_full + offset_b;
115+
To* C_batch = h_C_full.data() + b * size_C_full + offset_c;
122116

123117
// Simple initialization: A and B with small integers
124118
for(int64_t j = 0; j < A_col; j++)
@@ -308,9 +302,9 @@ void testing_matmul_batch_offset_impl(const Arguments& arg)
308302
for(int b = 0; b < batch_count; b++)
309303
{
310304
// Get pointers to sub-matrices (with element offset applied)
311-
Ti* A_sub = h_A_full.data() + b * size_A_full + offset_a_elem;
312-
Ti* B_sub = h_B_full.data() + b * size_B_full + offset_b_elem;
313-
To* C_sub = h_C_full.data() + b * size_C_full + offset_c_elem;
305+
Ti* A_sub = h_A_full.data() + b * size_A_full + offset_a;
306+
Ti* B_sub = h_B_full.data() + b * size_B_full + offset_b;
307+
To* C_sub = h_C_full.data() + b * size_C_full + offset_c;
314308
To* D_sub = h_D_gold.data() + b * size_D_sub;
315309

316310
// Simple GEMM: D = alpha * A * B + beta * C
@@ -346,7 +340,7 @@ void testing_matmul_batch_offset_impl(const Arguments& arg)
346340
for(int b = 0; b < batch_count; b++)
347341
{
348342
// GPU result is at (base + offset) within each batch's buffer
349-
To* result_gpu = h_D_full.data() + b * size_D_full + offset_d_elem;
343+
To* result_gpu = h_D_full.data() + b * size_D_full + offset_d;
350344
To* result_cpu = h_D_gold.data() + b * size_D_sub;
351345

352346
for(size_t i = 0; i < size_D_sub; i++)

projects/hipblaslt/library/include/hipblaslt/hipblaslt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ typedef enum {
177177
/** Matrix Offset.
178178
*
179179
* For ``General Batched GEMM``, we can support for users to access a sub-matrix of
180-
* the original matrix by adding an ``offset`` value from the base address.
180+
* the original matrix by adding an ``offset`` value (in elements) from the base address.
181181
* Note that for non-batched or Strided Batch GEMM case, we can directly apply
182182
* the offset value by using the strided-offset value.
183183
*/

projects/hipblaslt/library/src/amd_detail/include/auxiliary.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ constexpr const char* hip_datatype_to_string(hipDataType type)
158158
return "invalid";
159159
}
160160

161+
// Returns true for sub-byte MX-style data types (fp6/fp4).
162+
// Used to reject features that require byte-addressable elements.
163+
HIPBLASLT_EXPORT
164+
constexpr bool hip_datatype_is_mxtype(hipDataType type)
165+
{
166+
switch(type)
167+
{
168+
case HIP_R_6F_E2M3:
169+
case HIP_R_6F_E3M2:
170+
case HIP_R_4F_E2M1:
171+
return true;
172+
default:
173+
return false;
174+
}
175+
}
176+
161177
// return precision string for hipDataType
162178
HIPBLASLT_EXPORT
163179
constexpr const char* hipblas_computetype_to_string(hipblasComputeType_t type)

projects/hipblaslt/library/src/amd_detail/rocblaslt/src/include/rocblaslt_mat_utils.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,19 @@ inline rocblaslt_status validateMatmulArgs(int64_t m,
229229
return rocblaslt_status_invalid_size;
230230
}
231231

232+
// Batch offsets are expressed in elements and converted to bytes; sub-byte
233+
// (MX) data types are not byte-addressable, so a nonzero offset is unsupported.
234+
if((batch_offset_a != 0 && hip_datatype_is_mxtype(type_a))
235+
|| (batch_offset_b != 0 && hip_datatype_is_mxtype(type_b))
236+
|| (batch_offset_c != 0 && hip_datatype_is_mxtype(type_c))
237+
|| (batch_offset_d != 0 && hip_datatype_is_mxtype(type_d)))
238+
{
239+
#ifndef CODE_COVERAGE
240+
std::cerr << "matrix offset is not supported for sub-byte (MX) data types" << std::endl;
241+
#endif
242+
return rocblaslt_status_not_implemented;
243+
}
244+
232245
// number of batches of matrics A,B,C,D must be the same and positive
233246
if(num_batches_a != num_batches_b || num_batches_a != num_batches_c
234247
|| num_batches_a != num_batches_d || num_batches_a < 1)

projects/hipblaslt/library/src/amd_detail/rocblaslt/src/tensile_host.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2394,11 +2394,22 @@ namespace
23942394
inputs.batchC = reinterpret_cast<void const* const*>(prob.batch_C);
23952395
inputs.batchD = reinterpret_cast<void* const*>(prob.batch_D);
23962396

2397-
// set the batched offset of A, B, C, and D.
2398-
inputs.batchOffsetA = prob.batch_offset_a;
2399-
inputs.batchOffsetB = prob.batch_offset_b;
2400-
inputs.batchOffsetC = prob.batch_offset_c;
2401-
inputs.batchOffsetD = prob.batch_offset_d;
2397+
// The batch offsets are specified by the user in elements; convert them to
2398+
// bytes here so the kernel/assembly can add them straight to byte addresses.
2399+
// Only data types whose element size is at least one byte are supported
2400+
// (sub-byte types such as fp4/fp6 are rejected during argument validation).
2401+
inputs.batchOffsetA
2402+
= prob.batch_offset_a
2403+
* size_t(TensileLite::DataTypeInfo::Get(hip2TensileType(prob.a_type)).elementSize);
2404+
inputs.batchOffsetB
2405+
= prob.batch_offset_b
2406+
* size_t(TensileLite::DataTypeInfo::Get(hip2TensileType(prob.b_type)).elementSize);
2407+
inputs.batchOffsetC
2408+
= prob.batch_offset_c
2409+
* size_t(TensileLite::DataTypeInfo::Get(hip2TensileType(prob.c_type)).elementSize);
2410+
inputs.batchOffsetD
2411+
= prob.batch_offset_d
2412+
* size_t(TensileLite::DataTypeInfo::Get(hip2TensileType(prob.d_type)).elementSize);
24022413

24032414
// Set the GSU workspace
24042415
inputs.ws = prob.workspace;

0 commit comments

Comments
 (0)