Archived
tests: lora_test and r4d_emu_lora over one shared case matrix
lora_cases.h holds the matrix (M 1/3/17/64/130, R 16/32/48, S 4, K and N 64/256/1000, a bf16 or E4M3 with a 128-column scale, y bf16/f32, f16/f32/E5M2/i8 once; a, a_scale and y as column slices; slots -1, -5, 0..3 and S) and the checks: base rows untouched by bytes (a sentinel NaN in t, -0 in y), adapter rows against an f64 sum within (K + 2) 2^-24 sum|terms| (shrink) and half an ulp of y plus 4 (R + 2) 2^-24 (|y| + |scale| sum|terms|) (expand). lora_test runs libref and libavx at every ISA level through rad_plugin_open (libavx builds its fp8 decode table there). r4d_emu_lora runs libr4d's source on the SIMT emulator beside ref_host.cpp and libref, expand bit for bit.
This commit is contained in:
1 parent
979b54e091
commit
51293b269c
6 files changed
+567
-14
No files matched your search
+23
-13
@@ -356,13 +356,14 @@ endif()
|
||||
# ================================================================== libr4d's kernels, on the host
|
||||
#
|
||||
# Some libr4d ops (the sandwich-norm joins, expert_scale) have no libref oracle by design
|
||||
# (docs/OPS.md), so rad-kbench never checks them. r4d_emu runs the source of five units written
|
||||
# (docs/OPS.md), so rad-kbench never checks them. r4d_emu runs the source of six units written
|
||||
# against r4d_launch.h on the host: the windowed paged attention, pair_argmax, the joins,
|
||||
# expert_scale and the QSA block selection, whose four kernels a card-less build otherwise never
|
||||
# runs. emu/hip/hip_runtime.h supplies the HIP names, each GPU thread is a fiber, and
|
||||
# __syncthreads and cross-lane ops are barriers (one not reached uniformly is reported as a
|
||||
# deadlock). Checked against ports of libref's ref_attn_paged and ref_qsa_select, the host
|
||||
# arithmetic in ref_host.cpp, and, for the joins, the unfused chain bit for bit.
|
||||
# expert_scale, the QSA block selection, whose four kernels a card-less build otherwise never
|
||||
# runs, and the runtime-LoRA pair. emu/hip/hip_runtime.h supplies the HIP names, each GPU thread
|
||||
# is a fiber, and __syncthreads and cross-lane ops are barriers (one not reached uniformly is
|
||||
# reported as a deadlock). Checked against ports of libref's ref_attn_paged and ref_qsa_select,
|
||||
# the host arithmetic in ref_host.cpp, for the joins the unfused chain bit for bit, and for the
|
||||
# LoRA pair libref itself when the test can load it.
|
||||
#
|
||||
# Requires clang (ext_vector_type) and x86-64 (SysV fiber switch in inline assembly). With a clang
|
||||
# C++ compiler the .hip files build here as C++ (`-x c++`; the property is per directory, so
|
||||
@@ -374,8 +375,8 @@ set(R4D_DIR ${CMAKE_SOURCE_DIR}/libr4d)
|
||||
set(R4D_EMU ${CMAKE_CURRENT_SOURCE_DIR}/r4d_emu)
|
||||
set(R4D_EMU_HIP ${R4D_DIR}/r4d_attn_paged_window.hip ${R4D_DIR}/r4d_pair_argmax_f32.hip
|
||||
${R4D_DIR}/r4d_norm_join_bf16.hip ${R4D_DIR}/r4d_expert_scale_bf16.hip
|
||||
${R4D_DIR}/r4d_qsa_select_bf16.hip)
|
||||
set(R4D_EMU_TESTS attn pick norm escale qsa)
|
||||
${R4D_DIR}/r4d_qsa_select_bf16.hip ${R4D_DIR}/r4d_lora_bf16.hip)
|
||||
set(R4D_EMU_TESTS attn pick norm escale qsa lora)
|
||||
set(R4D_EMU_BUILT OFF)
|
||||
if(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64)$")
|
||||
# No fiber switch for this ISA.
|
||||
@@ -388,7 +389,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT RAD_ASAN AND NOT RAD_TSAN)
|
||||
target_compile_options(r4d_emu_kernels PRIVATE -ffp-contract=off -Wno-psabi)
|
||||
foreach(t ${R4D_EMU_TESTS})
|
||||
add_executable(r4d_emu_${t} ${R4D_EMU}/test_${t}.cpp)
|
||||
target_link_libraries(r4d_emu_${t} PRIVATE r4d_emu_kernels)
|
||||
target_link_libraries(r4d_emu_${t} PRIVATE r4d_emu_kernels ${CMAKE_DL_LIBS})
|
||||
target_compile_options(r4d_emu_${t} PRIVATE -ffp-contract=off -Wno-psabi)
|
||||
set_target_properties(r4d_emu_${t} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/tests)
|
||||
endforeach()
|
||||
@@ -411,7 +412,7 @@ else()
|
||||
set(objs "")
|
||||
foreach(src ${R4D_EMU_HIP} ${R4D_EMU}/ref_host.cpp ${R4D_EMU}/emu/emu.cpp
|
||||
${R4D_EMU}/test_attn.cpp ${R4D_EMU}/test_pick.cpp ${R4D_EMU}/test_norm.cpp
|
||||
${R4D_EMU}/test_escale.cpp ${R4D_EMU}/test_qsa.cpp)
|
||||
${R4D_EMU}/test_escale.cpp ${R4D_EMU}/test_qsa.cpp ${R4D_EMU}/test_lora.cpp)
|
||||
get_filename_component(stem ${src} NAME_WE)
|
||||
set(lang "")
|
||||
if(src MATCHES "\\.hip$")
|
||||
@@ -428,11 +429,16 @@ else()
|
||||
list(APPEND objs ${dir}/${stem}.o)
|
||||
endif()
|
||||
endforeach()
|
||||
# test_lora opens libref with dlopen to hold the emulated kernels to it.
|
||||
set(dl "")
|
||||
foreach(l ${CMAKE_DL_LIBS})
|
||||
list(APPEND dl -l${l})
|
||||
endforeach()
|
||||
set(exes "")
|
||||
foreach(t ${R4D_EMU_TESTS})
|
||||
set(exe ${CMAKE_BINARY_DIR}/tests/r4d_emu_${t})
|
||||
add_custom_command(OUTPUT ${exe}
|
||||
COMMAND ${R4D_EMU_CXX} ${dir}/test_${t}.o ${objs} -o ${exe}
|
||||
COMMAND ${R4D_EMU_CXX} ${dir}/test_${t}.o ${objs} ${dl} -o ${exe}
|
||||
DEPENDS ${dir}/test_${t}.o ${objs}
|
||||
COMMENT "Linking r4d_emu_${t}"
|
||||
VERBATIM)
|
||||
@@ -443,7 +449,7 @@ else()
|
||||
endif()
|
||||
endif()
|
||||
if(R4D_EMU_BUILT)
|
||||
foreach(t pick norm escale qsa)
|
||||
foreach(t pick norm escale qsa lora)
|
||||
add_test(NAME r4d_emu_${t} COMMAND ${CMAKE_BINARY_DIR}/tests/r4d_emu_${t})
|
||||
endforeach()
|
||||
# The attention cases take about 11 s, 7 of them in the two long prefills on the WMMA kernel,
|
||||
@@ -453,8 +459,12 @@ if(R4D_EMU_BUILT)
|
||||
COMMAND ${CMAKE_BINARY_DIR}/tests/r4d_emu_attn --shard ${k}/3)
|
||||
endforeach()
|
||||
set_tests_properties(r4d_emu_attn_shard0 r4d_emu_attn_shard1 r4d_emu_attn_shard2 r4d_emu_pick
|
||||
r4d_emu_norm r4d_emu_escale r4d_emu_qsa
|
||||
r4d_emu_norm r4d_emu_escale r4d_emu_qsa r4d_emu_lora
|
||||
PROPERTIES LABELS "r4d_emu" TIMEOUT ${RAD_TEST_TIMEOUT})
|
||||
# The LoRA pair has a libref oracle, and the test holds the emulated kernels to it when it can
|
||||
# load one -- expand bit for bit, shrink to its bound.
|
||||
set_tests_properties(r4d_emu_lora PROPERTIES
|
||||
ENVIRONMENT "RADIANCE_HOME=${CMAKE_BINARY_DIR}/radiance_home")
|
||||
# A seeded random sweep, mostly prefill shapes on the WMMA kernel, which the emulator runs at
|
||||
# about 2 s a case: `slow`. `r4d_emu_attn sweep 200` is a longer run by hand, a superset of it.
|
||||
add_test(NAME r4d_emu_attn_sweep COMMAND ${CMAKE_BINARY_DIR}/tests/r4d_emu_attn sweep 40)
|
||||
|
||||
Reference in new issue
Block a user