Skip to content

Commit 5b08503

Browse files
jeffdailymeta-codesync[bot]
authored andcommitted
plumb per-build wave-size flags from CMake into codegen (#6103)
Summary: X-link: https://github.com/facebookresearch/FBGEMM/pull/3008 Add the CMake-to-codegen plumbing that a later change uses to emit only the wave-size-specific kernel instantiations and host dispatch tables a given ROCm wheel needs. `cmake/Hip.cmake` derives `FBGEMM_HAS_WAVE32` / `FBGEMM_HAS_WAVE64` from `PYTORCH_ROCM_ARCH` (gfx9* is wave64; gfx10/11/12 is wave32), `CMakeLists.txt` forwards them to the gen scripts as `--has_wave32` / `--has_wave64`, and `scripts_argsparse.py` parses them. This change is pure plumbing: the flags are parsed but not yet consumed by the Jinja templates, so generated code is byte-identical to before on every build configuration. The consumer lands in the next PR in the chain. Splitting the plumbing out lets it be reviewed and landed without touching any generated kernel output. Fourth in the chain splitting #5804 into reviewable pieces; stacked on #6037. Authored with assistance from Claude (Anthropic). Pull Request resolved: #6103 Reviewed By: cthi Differential Revision: D114618233 Pulled By: q10 fbshipit-source-id: 306b374d49e7dcfd0b3b3513520001d2d5afe1dc
1 parent 204fc30 commit 5b08503

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

fbgemm_gpu/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,15 @@ endif()
182182
set(CMAKE_CODEGEN_DIR ${CMAKE_CURRENT_SOURCE_DIR}/codegen)
183183

184184
macro(RUN_GEN_SCRIPT SCRIPT)
185+
set(rocm_flag)
185186
if(FBGEMM_BUILD_VARIANT STREQUAL BUILD_VARIANT_ROCM)
186-
set(rocm_flag --is_rocm)
187+
list(APPEND rocm_flag --is_rocm)
188+
if(FBGEMM_HAS_WAVE32)
189+
list(APPEND rocm_flag --has_wave32)
190+
endif()
191+
if(FBGEMM_HAS_WAVE64)
192+
list(APPEND rocm_flag --has_wave64)
193+
endif()
187194
endif()
188195

189196
BLOCK_PRINT(

fbgemm_gpu/cmake/Hip.cmake

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ if(PYTORCH_ROCM_ARCH STREQUAL "")
3434
endif()
3535
message("Building FBGEMM for GPU arch: ${PYTORCH_ROCM_ARCH}")
3636

37+
# Derive the wave-size set in scope for this build from PYTORCH_ROCM_ARCH.
38+
# gfx9* archs (CDNA: gfx90a, gfx940/941/942, gfx950) run wave64; gfx10/11/12
39+
# archs (RDNA3/4: gfx1100, gfx1200, ...) run wave32. The codegen uses these
40+
# to emit only the host-side dispatch branches needed by this wheel, so
41+
# single-arch wheels stay free of the wrong wave's bracket table.
42+
set(FBGEMM_HAS_WAVE32 OFF)
43+
set(FBGEMM_HAS_WAVE64 OFF)
44+
foreach(fbgemm_rocm_arch ${PYTORCH_ROCM_ARCH})
45+
if(fbgemm_rocm_arch MATCHES "^gfx9")
46+
set(FBGEMM_HAS_WAVE64 ON)
47+
else()
48+
set(FBGEMM_HAS_WAVE32 ON)
49+
endif()
50+
endforeach()
51+
message("FBGEMM wave-size set: WAVE32=${FBGEMM_HAS_WAVE32} WAVE64=${FBGEMM_HAS_WAVE64}")
52+
3753
ADD_DEFINITIONS(-DNDEBUG)
3854
# USE_ROCM flag is used inside FBGEMM_GPU C++ code
3955
ADD_DEFINITIONS(-DUSE_ROCM)

fbgemm_gpu/codegen/genscript/scripts_argsparse.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
)
2222
parser.add_argument("--opensource", action="store_false", dest="is_fbcode")
2323
parser.add_argument("--is_rocm", action="store_true")
24+
# CMake-derived wave-size set for the current ROCm build. CUDA builds ignore
25+
# these (always wave32). Both unset on a ROCm build defaults to wave64-only
26+
# to preserve pre-port behavior.
27+
parser.add_argument("--has_wave32", action="store_true")
28+
parser.add_argument("--has_wave64", action="store_true")
2429

2530
args: argparse.Namespace
2631
_: list[str]

0 commit comments

Comments
 (0)