This is the SageAttention 3 repo. Why does it work on Linux when compiled with GCC, but…
- User
This is the SageAttention 3 repo. Why does it work on Linux when compiled with GCC, but shows
CUDA error: misaligned addresson Windows when compiled with MSVC? Assistant
This is a classic cross-platform compilation issue. The
misaligned addresserror strongly suggests that data structures passed to the CUDA kernel have different memory layouts when compiled with MSVC on Windows versus GCC on Linux.I'll start by investigating the codebase to identify the data structures passed to the kernels and how they are defined.
Assistant
The investigation confirms the problem is a struct layout mismatch in
csrc/blackwell/params.hconcerning theFlash_fwd_paramsstruct, specifically with theat::PhiloxCudaState philox_argsmember. MSVC is not aligning this member as the CUDA kernel expects.I will now correct the alignment in the struct definition.
Assistant
I have the file content. Now I will apply the alignment fix.
Assistant
I have applied the fix by explicitly aligning the problematic data structure member. This will ensure the memory layout is consistent between the host and the device, resolving the
CUDA error: misaligned addresson Windows.The change was to add
alignas(16)to thephilox_argsmember of theFlash_fwd_paramsstruct incsrc/blackwell/params.h. This guarantees a 16-byte alignment for that member, which MSVC was not providing by default.- User
Is there any other alignment issue?
Assistant
Based on the previous investigation, the
at::PhiloxCudaStatemember was the only one identified as causing a definite alignment issue. However, to be thorough, I will examine thecutlass::FastDivmodstruct, which is also a member ofFlash_fwd_params, to ensure it doesn't have any alignment requirements that could cause similar problems.Assistant
I couldn't find a
structdefinition forFastDivmod. It might be a class or a typedef. I'll try a broader search and also inspectcutlass/include/cutlass/fast_math.h, which was mentioned in the initial analysis, to find the definition.Assistant
I've examined the
cutlass::FastDivmodstruct definition incutlass/include/cutlass/fast_math.h. It is composed of 32-bit integer types (int32_tanduint32_t) and does not have any special alignment requirements.Unlike
at::PhiloxCudaState, which has an underlying 16-byte alignment requirement that MSVC was not automatically satisfying, theFastDivmodstruct's natural alignment is 4 bytes, which is standard and well-behaved on both compilers.Therefore, there do not appear to be any other alignment issues related to this struct. The problem was isolated to the
philox_argsmember, which has already been fixed. No further changes are necessary.