In @kernelattn/fwd.cu , given the alignment assertions of the inputs, is it possible…
- User
In @kernel_attn/fwd.cu , given the alignment assertions of the inputs, is it possible that
i + ROCWMMA_K < kevaluates to false?--- Content from referenced files ---
Content from @kernel_attn/fwd.cu:
#ifndef NO_PYTORCH #include <torch/csrc/stable/accelerator.h> #include <torch/csrc/stable/c/shim.h> #include <torch/csrc/stable/library.h> #include <torch/csrc/stable/tensor.h> #endif
#include <hip/hip_runtime.h>
#include #include
using bfloat16_t = uint16_t;
typedef uint16_t bf16x16_t attribute((ext_vector_type(16))); typedef float fp32x8_t attribute((ext_vector_type(8))); typedef uint16_t fp16x16_t attribute((ext_vector_type(16))); typedef float fp32x16_t attribute((ext_vector_type(16)));
#define HALF16(pointer) (reinterpret_cast<const fp16x16_t*>(&(pointer))[0]) #define FLOAT8(pointer) (reinterpret_cast<const fp32x8_t*>(&(pointer))[0]) #define HALF16W(pointer) (reinterpret_cast<fp16x16_t*>(&(pointer))[0]) #define FLOAT8W(pointer) (reinterpret_cast<fp32x8_t*>(&(pointer))[0])
device forceinline uint16_t fp32_to_bf16(const float f) { const uint32_t u = reinterpret_cast<const uint32_t>(&f); return static_cast<uint16_t>(u >> 16); }
device forceinline float bf16_to_fp32(uint16_t bf) { const uint32_t u = static_cast<uint32_t>(bf) << 16; return reinterpret_cast<const float>(&u); }
constexpr int ROCWMMA_M = 16; constexpr int ROCWMMA_N = 16; constexpr int ROCWMMA_K = 16; constexpr int WAVE_SIZE = 32;
// C = A @ B^T (Q @ K^T) template device void mul_A_BT( const bfloat16_t* restrict const A, // Q [Br, d] const bfloat16_t* restrict const B, // K [Bc, d] bfloat16_t* restrict const C, // Si [Br, Bc] const int lda, const int ldb, const int ldc, const int m, const int n, const int k, const float scale) { bf16x16_t fragA[2]; bf16x16_t fragB[2];
code Assistant
Yes, it is possible, but only in one specific case depending on which function is executing.
The check
i + ROCWMMA_K < kappears in two functions, and the variablekrepresents different dimensions in each:-
In
mul_A_BT(kcorresponds tod): No, it will never be false. Whenfwd_kernelcallsmul_A_BT, it passesdas thekargument. The PyTorch binding assertsSTD_TORCH_CHECK(d % 32 == 0), meaningkis always a multiple of 32. Since the loop incrementsiby32(ROCWMMA_K * 2),iwill be at mostk - 32. Therefore,i + 16 < kis alwaystrue. -
In
mul_add_A_B(kcorresponds toBc): Yes, it evaluates to false forBc = 16. Whenfwd_kernelcallsmul_add_A_B, it passesBcas thekargument. Looking at , there is a configuration specifically designed for testing tiny sizes: . For this configuration, , so . On the first iteration, , and the condition becomes , which evaluates to .
-