Archived
radiance 1.7.0
- every model serves without a GPU: libavx covers every op, so `--kernels libavx` alone serves every shipped container - Qwen3-ASR (zivius): speech to text on /v1/audio/transcriptions and live over /v1/realtime - /v1/messages works with Claude Code as it ships (gearwave00001) - a long agent conversation keeps its cached history when the client rewrites its last turn (manueloverride) - a stream's first event goes out with the first token, so llama-benchy measures prefill right - opt-in --prefill-interleave (Smellyyyy, baKon) and --prefill-span (keptn42) - four-rank TP releases the link early; four-rank selftests and docs/TP4.md (goodman-b) - NVFP4 and FP8 compressed-tensors imports (devmilan); tools/rad-export for finetunes and LoRA adapters (baKon) - many fixes, among them lost tokens on stop strings under concurrency, keep-alive, MiniCPM5 tool arguments and the CPU's vision and audio encoders - plugin ABI 17 and changed op schemas: out-of-tree plugins must be rebuilt
This commit is contained in:
1 parent
b068190326
commit
1e968f6e1d
739 files changed
+128447
-84632
No files matched your search
+110
-220
@@ -1,8 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
# VERSION is what /version reports and what a client checks compatibility against. It is NOT the
|
||||
# ABI version -- that lives in abi/rad_abi.h and is read out of the header below, because
|
||||
# a plugin contract and a server release do not move together.
|
||||
project(radiance VERSION 1.6.0 LANGUAGES C CXX)
|
||||
# VERSION is the server release that /version reports. The plugin ABI version is separate and is
|
||||
# read from abi/rad_abi.h below.
|
||||
project(radiance VERSION 1.7.0 LANGUAGES C CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
@@ -13,35 +12,30 @@ if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE RelWithDebInfo)
|
||||
endif()
|
||||
|
||||
# NOT option(): option() is boolean-only, so a default of AUTO collapses to OFF and the detection
|
||||
# below never runs -- a machine with cards then silently builds the host backend. Tri-state wants a
|
||||
# cache STRING.
|
||||
# A cache STRING, not option(): option() is boolean, so AUTO would collapse to OFF and skip
|
||||
# detection.
|
||||
set(RAD_WITH_HIP "AUTO" CACHE STRING "ON | OFF | AUTO -- build the HIP backend and device kernels")
|
||||
set_property(CACHE RAD_WITH_HIP PROPERTY STRINGS ON OFF AUTO)
|
||||
set(RAD_WITH_FFMPEG "AUTO" CACHE STRING "ON | OFF | AUTO -- decode image, video and audio parts with libavformat/libavcodec/libswscale/libswresample")
|
||||
set(RAD_WITH_FFMPEG "AUTO" CACHE STRING
|
||||
"ON | OFF | AUTO -- decode image, video and audio parts with libavformat/libavcodec/libswscale/libswresample")
|
||||
set_property(CACHE RAD_WITH_FFMPEG PROPERTY STRINGS ON OFF AUTO)
|
||||
option(RAD_BUILD_TESTS "Build the test suite" ON)
|
||||
option(RAD_ASAN "Build with AddressSanitizer" OFF)
|
||||
# Whether the HIP compiler's VOPD pairing is repeatable. LLVM 24's is not unless it carries the
|
||||
# fix the image builds (docker/llvm-vopd-pairing.patch); without this the build turns pairing off
|
||||
# on LLVM 24, see rad_hip_repeatable in cmake/RadAddPlugin.cmake.
|
||||
option(RAD_ASAN "Build host code with AddressSanitizer and UBSan" OFF)
|
||||
option(RAD_TSAN "Build host code with ThreadSanitizer" OFF)
|
||||
# LLVM 24's VOPD pairing is not repeatable unless patched (docker/llvm-vopd-pairing.patch); when
|
||||
# OFF, pairing is disabled on LLVM 24. See rad_hip_repeatable in cmake/RadAddPlugin.cmake.
|
||||
option(RAD_HIP_VOPD_REPEATABLE "The HIP compiler's VOPD pairing is repeatable (the image's LLVM 24 is)" OFF)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------- HIP detection
|
||||
# RAD_GPU_TARGETS is the set of offload architectures device kernels are compiled for. The project
|
||||
# does not fix it and holds no opinion about which cards are acceptable: a kernel library is a
|
||||
# plugin, so which hardware the engine can serve is decided by which kernel plugins are installed,
|
||||
# not here (spec §2.1). Leaving it unset means "ask this machine", through the enumerator the ROCm
|
||||
# toolchain ships.
|
||||
# RAD_GPU_TARGETS lists the offload architectures device kernels are compiled for. Which cards the
|
||||
# engine serves is decided by the installed kernel plugins, not here (spec §18). Unset means
|
||||
# enumerate this machine's devices with the ROCm toolchain.
|
||||
#
|
||||
# A kernel library that covers only some architectures narrows the list for itself with
|
||||
# rad_plugin_gpu_targets() and skips its own build when the intersection is empty. That is how
|
||||
# libr4d, which is RDNA4-only, coexists with a target list that may name anything, and it is the
|
||||
# same mechanism a library for another card uses from out of tree.
|
||||
# A kernel library covering only some architectures narrows the list with rad_plugin_gpu_targets()
|
||||
# and skips itself when the intersection is empty (libr4d is RDNA4-only).
|
||||
#
|
||||
# With no ROCm at all the host backend is built. That is a supported configuration and not a
|
||||
# degraded one: everything except device kernels is exercised by it.
|
||||
# Without ROCm the host backend is built, a supported configuration that exercises everything
|
||||
# except device kernels.
|
||||
set(RAD_HIP_FOUND OFF)
|
||||
if(NOT RAD_WITH_HIP STREQUAL "OFF")
|
||||
find_program(RAD_HIPCC hipcc HINTS /opt/rocm/bin /opt/rocm/llvm/bin ENV ROCM_PATH)
|
||||
@@ -54,10 +48,8 @@ if(NOT RAD_WITH_HIP STREQUAL "OFF")
|
||||
endif()
|
||||
|
||||
if(RAD_HIP_FOUND AND NOT DEFINED RAD_GPU_TARGETS)
|
||||
# amdgpu-arch and offload-arch each print one architecture per visible device. EVERY device is
|
||||
# listed, integrated graphics included, and that is the right input: a plugin filters the list
|
||||
# down to what it serves, so an architecture no library covers costs a skipped plugin rather
|
||||
# than a refused configure.
|
||||
# amdgpu-arch / offload-arch print one architecture per visible device, integrated graphics
|
||||
# included. Plugins filter the list to what they serve.
|
||||
find_program(RAD_ARCH_TOOL NAMES amdgpu-arch offload-arch
|
||||
HINTS /opt/rocm/bin /opt/rocm/llvm/bin ENV ROCM_PATH)
|
||||
if(RAD_ARCH_TOOL)
|
||||
@@ -71,12 +63,11 @@ if(RAD_HIP_FOUND AND NOT DEFINED RAD_GPU_TARGETS)
|
||||
endif()
|
||||
endif()
|
||||
if(NOT RAD_GPU_TARGETS)
|
||||
# A toolchain with no card attached is an ordinary build machine. Guessing an architecture here
|
||||
# would emit kernels for hardware nobody named, so the device build is declined and the way to
|
||||
# ask for it anyway is spelled out.
|
||||
# No card attached: do not guess an architecture. Decline the device build and say how to
|
||||
# request one.
|
||||
set(RAD_HIP_FOUND OFF)
|
||||
message(WARNING
|
||||
"radiance: hipcc was found but no AMD GPU could be enumerated, so this build has NO device "
|
||||
"radiance: hipcc was found but no AMD GPU could be enumerated, so this build has no device "
|
||||
"kernels. To cross-compile them anyway, name the architectures: -DRAD_GPU_TARGETS=gfx1201 "
|
||||
"(semicolon-separated for several).")
|
||||
endif()
|
||||
@@ -88,88 +79,66 @@ elseif(RAD_WITH_HIP STREQUAL "OFF")
|
||||
message(STATUS "radiance: HIP backend OFF by request -- host backend only")
|
||||
elseif(NOT RAD_HIPCC)
|
||||
message(WARNING
|
||||
"radiance: HIP backend OFF -- hipcc was not found, so this build has NO device kernels.\n"
|
||||
" That is correct on a machine without ROCm and WRONG on one with cards. Looked in "
|
||||
"/opt/rocm/bin, /opt/rocm/llvm/bin and \.")
|
||||
"radiance: HIP backend OFF -- hipcc was not found, so this build has no device kernels.\n"
|
||||
" Expected on a machine without ROCm, wrong on one with cards. Looked in /opt/rocm/bin, "
|
||||
"/opt/rocm/llvm/bin and $ROCM_PATH.")
|
||||
endif()
|
||||
|
||||
# HOST CODE ONLY, AND THAT IS NOT A COMPROMISE -- IT IS THE WHOLE AVAILABLE SURFACE.
|
||||
# ASan + UBSan for host code only. AMD's amdgcn ASan needs xnack+ for its page-fault-based shadow,
|
||||
# and RDNA has no xnack, so the generator expressions keep the flags off HIP. Device kernels rely on
|
||||
# rad-kbench's red zones instead: a poisoned margin around every operand and scratch allocation,
|
||||
# checked after the launch, which catches out-of-bounds writes.
|
||||
#
|
||||
# AMD ships an amdgcn AddressSanitizer (/opt/rocm/amdgcn/bitcode/asanrtl.bc) and it cannot run
|
||||
# on an RDNA card: its shadow is page-fault based, which needs xnack+, and RDNA does not implement
|
||||
# xnack -- rocminfo reports `XNACK enabled: NO`. Handing -fsanitize=address to the HIP
|
||||
# compilation therefore buys a device binary that cannot work, so the generator expression keeps
|
||||
# it off the HIP language entirely. What device kernels get instead is rad-kbench's red zones: a
|
||||
# poisoned margin either side of every operand and every scratch allocation, verified after the
|
||||
# launch. That catches the out-of-bounds WRITE, which is the one that corrupts a neighbour.
|
||||
#
|
||||
# What this DOES cover is everything else, which is most of the project: the core, the tools,
|
||||
# libref in full, and every host-side launch wrapper in libr4d. UBSan comes with it because the
|
||||
# two share a build and the interesting reports here -- a signed shift, a misaligned load, an
|
||||
# enum out of range -- are UBSan's, not ASan's.
|
||||
# TSan, likewise host code only, for the threaded host paths (scheduler, server, stager, tokenizer
|
||||
# cache). libgomp is not instrumented, so tests run it with one thread (tests/CMakeLists.txt).
|
||||
if(RAD_ASAN AND RAD_TSAN)
|
||||
message(FATAL_ERROR "RAD_ASAN and RAD_TSAN cannot be combined; use a build directory for each.")
|
||||
endif()
|
||||
if(RAD_ASAN)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=address,undefined>
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-fno-omit-frame-pointer>
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-fno-sanitize-recover=all>)
|
||||
add_link_options(-fsanitize=address,undefined)
|
||||
endif()
|
||||
if(RAD_TSAN)
|
||||
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fsanitize=thread>
|
||||
$<$<COMPILE_LANGUAGE:CXX>:-fno-omit-frame-pointer>)
|
||||
add_link_options(-fsanitize=thread)
|
||||
endif()
|
||||
|
||||
add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers)
|
||||
|
||||
# GNUInstallDirs before the ABI, not after it, because the ABI target's INSTALL_INTERFACE include
|
||||
# path is spelled in CMAKE_INSTALL_INCLUDEDIR and an undefined variable there expands to nothing --
|
||||
# which is not an error, it is an exported target whose include directory is the install prefix
|
||||
# itself, so every consumer's `#include "rad_abi.h"` misses by one directory level.
|
||||
# Before the ABI: its INSTALL_INTERFACE path uses CMAKE_INSTALL_INCLUDEDIR, which would otherwise
|
||||
# expand to nothing and silently export the wrong include directory.
|
||||
include(GNUInstallDirs)
|
||||
|
||||
# ---------------------------------------------------------------- the ABI
|
||||
# Header-only. The ONLY thing plugins compile against.
|
||||
# Header-only, and the only thing plugins compile against.
|
||||
add_library(rad_abi INTERFACE)
|
||||
# radiance::abi is the name plugins link, in-tree and out. It is an ALIAS here and an imported
|
||||
# target in the installed package, and the two are spelled identically on purpose: rad_add_plugin
|
||||
# has ONE body (cmake/RadAddPlugin.cmake) and it cannot branch on which world it is running in.
|
||||
# Plugins link radiance::abi: an ALIAS here, an imported target when installed, so rad_add_plugin
|
||||
# (cmake/RadAddPlugin.cmake) needs one body for both.
|
||||
add_library(radiance::abi ALIAS rad_abi)
|
||||
set_target_properties(rad_abi PROPERTIES EXPORT_NAME abi)
|
||||
# CMAKE_INSTALL_FULL_DATADIR and not a literal "share": it is <prefix>/share under every default,
|
||||
# and it moves together with the destination the plugins are actually installed to. Those two
|
||||
# disagreeing is a prefix that looks complete and whose loader finds nothing.
|
||||
# CMAKE_INSTALL_FULL_DATADIR, not a literal "share", so it follows the plugin install destination.
|
||||
set(RAD_DEFAULT_HOME "${CMAKE_INSTALL_FULL_DATADIR}/radiance" CACHE STRING "default $RADIANCE_HOME")
|
||||
target_include_directories(rad_abi INTERFACE
|
||||
# abi/ AND NOT THE REPO ROOT, which is the whole reason the headers sit in a directory of their
|
||||
# own rather than being included as `abi/rad_abi.h` from the top. A plugin links this target and
|
||||
# gets exactly the headers in abi/ on its include path -- not core/, not arch/, not the tree. An
|
||||
# ABI a plugin can see past is not a boundary.
|
||||
#
|
||||
# BUILD_INTERFACE/INSTALL_INTERFACE rather than one bare path, because this target is exported:
|
||||
# a bare ${CMAKE_CURRENT_SOURCE_DIR}/abi is a hard error out of install(EXPORT) ("path which is
|
||||
# prefixed in the source directory"), and the export is the whole point -- an interface target
|
||||
# that cannot leave the tree is the defect, not the fix.
|
||||
#
|
||||
# The spelling is the same in both worlds: `#include "rad_abi.h"` in-tree and installed, because
|
||||
# rad_add_plugin has ONE body and cannot branch on which world it is running in.
|
||||
# abi/, not the repo root, so a plugin sees only the ABI headers, never core/ or arch/.
|
||||
# Generator expressions because the target is exported, and install(EXPORT) rejects a source
|
||||
# path. Plugins write `#include "rad_abi.h"` both in-tree and installed.
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/abi>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/radiance>)
|
||||
target_compile_definitions(rad_abi INTERFACE RAD_DEFAULT_HOME="${RAD_DEFAULT_HOME}")
|
||||
|
||||
if(RAD_HIP_FOUND)
|
||||
target_compile_definitions(rad_abi INTERFACE RAD_HAVE_HIP=1)
|
||||
# core/device/hip.cpp is compiled by the ORDINARY C++ compiler -- only plugins go through
|
||||
# hipcc -- so it needs the HIP headers on the include path explicitly. hipcc supplies them to
|
||||
# itself, which is why this is invisible until the first non-plugin translation unit includes
|
||||
# hip_runtime.h.
|
||||
# Host translation units such as core/device/hip.cpp use the ordinary C++ compiler and need the
|
||||
# HIP headers explicitly.
|
||||
#
|
||||
# SYSTEM, AND NOT AS A MATTER OF TASTE. hipcc has this same directory on its own path as a
|
||||
# SYSTEM include, where a warning inside it is suppressed. Naming it again as an ordinary -I
|
||||
# puts the user-include copy first and the headers stop being system headers -- for every
|
||||
# plugin, because this is an INTERFACE property of rad_abi and every plugin links it. One ROCm
|
||||
# header alone (amd_device_functions.h: `__fns`, `__fns64`, unused) then warns in every
|
||||
# translation unit that includes it, which is a large share of the build output and none of it
|
||||
# ours. A build whose warnings are mostly somebody else's is a build where nobody reads the
|
||||
# warnings.
|
||||
# SYSTEM: hipcc already has this directory as a system include. A plain -I would take precedence
|
||||
# and make ROCm headers warn in every plugin (rad_abi is an INTERFACE dependency of all of them).
|
||||
#
|
||||
# BUILD_INTERFACE only: the path is this machine's, and an exported target carrying it fails to
|
||||
# configure wherever ROCm sits elsewhere. The installed package config finds the headers again on
|
||||
# the consumer's machine (cmake/radiance-config.cmake.in).
|
||||
# BUILD_INTERFACE only: the path is this machine's. The installed package config finds the
|
||||
# headers on the consumer's machine (cmake/radiance-config.cmake.in).
|
||||
get_filename_component(RAD_ROCM_BIN "${RAD_HIPCC}" DIRECTORY)
|
||||
get_filename_component(RAD_ROCM_ROOT "${RAD_ROCM_BIN}" DIRECTORY)
|
||||
if(EXISTS "${RAD_ROCM_ROOT}/include/hip/hip_runtime.h")
|
||||
@@ -190,16 +159,12 @@ endif()
|
||||
set(RAD_PLUGIN_OUT ${CMAKE_BINARY_DIR}/radiance_home)
|
||||
file(MAKE_DIRECTORY ${RAD_PLUGIN_OUT}/kernels ${RAD_PLUGIN_OUT}/architectures)
|
||||
|
||||
# THE RECORDED KERNEL FIXTURE, COPIED INTO THE BUILD'S HOME.
|
||||
#
|
||||
# data/kernels.rkb is checked in and is what makes `rad-kbench` runnable with no model present: it
|
||||
# holds the geometries, the seeds the inputs are drawn from and libref's answers reduced to a norm
|
||||
# and a sample. Copied rather than pointed at, because $RADIANCE_HOME is what the tool looks in and
|
||||
# an installed prefix has no source tree beside it. Recording a new one is
|
||||
# Recorded kernel fixtures, copied into the build's $RADIANCE_HOME (where rad-kbench looks; an
|
||||
# installed prefix has no source tree). data/kernels.rkb lets rad-kbench run with no model: it holds
|
||||
# geometries, input seeds and libref's answers reduced to a norm and a sample. Re-record with a 27B
|
||||
# container:
|
||||
#
|
||||
# rad-kbench -m <model.rad> --max-cases 1 --record data/kernels.rkb
|
||||
#
|
||||
# and that is the only step that needs a 27B container on the machine.
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/data/kernels.rkb)
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/data/kernels.rkb
|
||||
${RAD_PLUGIN_OUT}/kernels.rkb COPYONLY)
|
||||
@@ -207,13 +172,9 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/data/kernels.rkb)
|
||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/radiance)
|
||||
endif()
|
||||
|
||||
|
||||
# THE SECOND FIXTURE, AND WHY THERE ARE TWO. A recording is of ONE container -- it holds that
|
||||
# model's declared geometries -- and no single container in scope declares the whole vocabulary.
|
||||
# The 27B is dense, has a DFlash2 drafter and gqa 6; the 35B-A3B is routed (moe_gemm_q,
|
||||
# router_topk, moe_scatter, moe_gather, scale_rows), has an MTP head and gqa 8. Recording only one
|
||||
# leaves five ops and a whole attention dispatch with no replay coverage at all, so a kernel that
|
||||
# no locally available model exercises would regress unseen. Recording a new one is
|
||||
# A recording covers one container's geometries, and no single model declares the whole vocabulary.
|
||||
# The 27B is dense with a DFlash2 drafter and gqa 6; the 35B-A3B is routed (moe_gemm_q,
|
||||
# router_topk, moe_scatter, moe_gather, scale_rows) with an MTP head and gqa 8. Re-record with
|
||||
#
|
||||
# rad-kbench -m <model.rad> --max-cases 1 --record data/kernels_moe.rkb
|
||||
#
|
||||
@@ -223,87 +184,41 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/data/kernels_moe.rkb)
|
||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/kernels_moe.rkb
|
||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/radiance)
|
||||
endif()
|
||||
# THE DOWNLOADER `radiance --model <owner/name>` RUNS (core/hf_model.cpp). The engine finds it at
|
||||
# <bin>/../libexec/radiance/, so the build puts a copy at the same place under the build tree and
|
||||
# a binary run from either tree finds it without a path to configure.
|
||||
# The downloader behind `radiance --model <owner/name>` (core/hf_model.cpp). The engine looks in
|
||||
# <bin>/../libexec/radiance/, so the build tree mirrors that layout.
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/hfget.sh
|
||||
${CMAKE_BINARY_DIR}/libexec/radiance/hfget.sh COPYONLY)
|
||||
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/scripts/hfget.sh
|
||||
DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/radiance)
|
||||
|
||||
# rad_add_plugin() and rad_hipify() live in cmake/RadAddPlugin.cmake because the installed package
|
||||
# config includes that same file: a third party building a plugin from their own repository needs
|
||||
# the function, and a second copy of it in the package config would drift from this one. The file
|
||||
# documents the variables it expects; every one of them is set above.
|
||||
# rad-export (a finetune to a .rad with the stock model's recipe) runs on the host, beside the
|
||||
# trainer. It is installed with the tools so the image hands it out
|
||||
# (`docker run --entrypoint busybox <image> cat /opt/radiance/bin/rad-export`), though the image
|
||||
# has no Python to run it.
|
||||
install(PROGRAMS ${CMAKE_CURRENT_SOURCE_DIR}/tools/rad-export
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
# rad_add_plugin() and rad_hipify(), shared with the installed package config. The variables it
|
||||
# expects are all set above.
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/RadAddPlugin.cmake)
|
||||
|
||||
if(RAD_HIP_FOUND)
|
||||
string(TOUPPER "${CMAKE_BUILD_TYPE}" RAD_CFG_UPPER)
|
||||
# NOT `set(CMAKE_CXX_COMPILER hipcc)`. The C++ compiler is fixed by project() and assigning it
|
||||
# afterwards is silently ignored -- device sources then reach the host C++ compiler with
|
||||
# --offload-arch, an error that reads like a bad flag rather than a bad compiler.
|
||||
#
|
||||
# CMake has had a HIP language since 3.21. Device sources are marked LANGUAGE HIP and the rest of
|
||||
# the tree stays on the ordinary C++ compiler, which is what we want: only kernels need hipcc.
|
||||
# CMake refuses hipcc as CMAKE_HIP_COMPILER by design ("use Clang directly"), so this is ROCm's
|
||||
# own clang++. That needs the address-space cast in libr4d/r4d_common.h: ROCm 7.2 / LLVM 22
|
||||
# tightened __builtin_amdgcn_global_load_tr_b128_v8i16 to require a global address space, and
|
||||
# the builtin fails identically under hipcc and clang++ without it.
|
||||
# The HIP language (CMake >= 3.21): device sources are LANGUAGE HIP and everything else stays on
|
||||
# the C++ compiler. Do not set CMAKE_CXX_COMPILER to hipcc; after project() it is silently
|
||||
# ignored. CMake refuses hipcc as CMAKE_HIP_COMPILER, so this is ROCm's clang++. ROCm 7.2 /
|
||||
# LLVM 22 requires a global address space for __builtin_amdgcn_global_load_tr_b128_v8i16, hence
|
||||
# the cast in libr4d/r4d_common.h.
|
||||
enable_language(HIP)
|
||||
rad_hip_rule_fixes()
|
||||
|
||||
# AND CMAKE EMITS NO DEPENDENCY FLAGS FOR HIP, which is the same shape of omission as the two
|
||||
# below and by far the most dangerous of the three, because it does not fail -- it silently
|
||||
# builds the wrong thing.
|
||||
# Device optimisation level for every config. Depending on its version, CMake leaves
|
||||
# CMAKE_HIP_FLAGS_<CONFIG> empty (device code at -O0 with asserts) or, from CMake 4.4, pre-fills
|
||||
# the host-style '-O2 -g -DNDEBUG'. At -O0 decode reads weights at ~7 GB/s on a ~640 GB/s card.
|
||||
# -O3 for kernels; no -g on the device, where it slows compiles and inhibits scheduling.
|
||||
#
|
||||
# `CMAKE_DEPFILE_FLAGS_<LANG>` is set by the compiler modules for C and CXX and is EMPTY for HIP.
|
||||
# Ninja's HIP rule still declares `depfile = $DEP_FILE` and `deps = gcc`, so it WAITS for a
|
||||
# depfile the command was never told to write, and records nothing:
|
||||
#
|
||||
# $ ninja -t deps libr4d/CMakeFiles/libr4d.dir/r4d_model_bf16.hip.o
|
||||
# ...hip.o: #deps 0, deps mtime ... (VALID)
|
||||
#
|
||||
# Zero. No header is a dependency of any .hip object, so editing a header libr4d includes --
|
||||
# r4d_emit.h, r4d_common.h, r4d_fp8_wmma.h, or the ABI itself -- recompiles nothing and RELINKS
|
||||
# the plugin around stale objects. The library then exports one signature and the engine calls
|
||||
# another -- a hook called with more arguments than it takes, which segfaults inside the plugin
|
||||
# with a stack that blames the kernel -- and every test after the edit runs objects that predate
|
||||
# it.
|
||||
#
|
||||
# It is a one-line omission with no upper bound on what it can hide, so it is fixed here rather
|
||||
# than worked around with `touch`.
|
||||
if(NOT CMAKE_DEPFILE_FLAGS_HIP)
|
||||
set(CMAKE_DEPFILE_FLAGS_HIP "-MD -MT <DEP_TARGET> -MF <DEP_FILE>")
|
||||
endif()
|
||||
|
||||
# AND CMAKE DOES NOT SUPPLY A SYSTEM-INCLUDE FLAG FOR HIP EITHER, which is the same shape of
|
||||
# omission as the optimisation level below and just as quiet. `CMAKE_INCLUDE_SYSTEM_FLAG_<LANG>`
|
||||
# is set by the compiler modules for C and CXX and is EMPTY for HIP, and CMake's fallback when it
|
||||
# is empty is a plain `-I` -- so every SYSTEM include directory reaches a .hip translation unit as
|
||||
# an ordinary user include and every warning inside it becomes ours. Without this, ONE
|
||||
# target_include_directories(... SYSTEM ...) call reaches a CXX source as
|
||||
# `-isystem /opt/rocm/include` and a .hip source as `-I/opt/rocm/include` -- so this is not
|
||||
# something an author can get right at the call site. It is set once, here, for every HIP target
|
||||
# in the tree, vendor/ included.
|
||||
set(CMAKE_INCLUDE_SYSTEM_FLAG_HIP "-isystem ")
|
||||
|
||||
# OPTIMISATION LEVEL, SET HERE FOR EVERY CONFIG BECAUSE CMAKE DOES NOT SUPPLY A USABLE ONE FOR
|
||||
# HIP. Depending on the CMake version `CMAKE_HIP_FLAGS_<CONFIG>` is either EMPTY -- every device
|
||||
# kernel compiles at -O0 with asserts live while the host half gets -O2 -g -DNDEBUG -- or, from
|
||||
# CMake 4.4's HIP toolchain on, pre-filled with the host-style '-O2 -g -DNDEBUG'. Nothing in the
|
||||
# build says so either way: an absent flag reads as the default, a pre-filled one as a choice.
|
||||
#
|
||||
# It is the whole performance story. At -O0 decode reads weights at about 7 GB/s against a card
|
||||
# that does ~640, and no kernel change can fix a build that does not optimise the kernel. -O3 and
|
||||
# not -O2 because these are the kernels; -g is deliberately NOT carried onto the device side,
|
||||
# where it costs compile time and inhibits scheduling for a symbol table no profiler here reads.
|
||||
#
|
||||
# THE ASSIGNMENT IS UNCONDITIONAL. A guard such as `if(NOT CMAKE_HIP_FLAGS_${cfg})` cannot tell a
|
||||
# toolchain default from an operator's choice: on a CMake that pre-fills the variable it sees a
|
||||
# value and leaves every device kernel at -O2 with debug info, and a build tree whose cache still
|
||||
# holds -O3 from an older CMake hides that until its next fresh configure drops it, with no
|
||||
# signal in the build output. An operator who genuinely wants other device flags says so BY NAME
|
||||
# through RAD_HIP_FLAGS_<CONFIG>. A deliberate override is a thing someone typed; a toolchain
|
||||
# default that happens to be non-empty is not, and the two must not be spelled the same way.
|
||||
# The assignment is unconditional (FORCE) because a guard cannot tell a toolchain default from an
|
||||
# operator's choice. Override by name with RAD_HIP_FLAGS_<CONFIG>.
|
||||
foreach(cfg DEBUG RELEASE RELWITHDEBINFO MINSIZEREL)
|
||||
if(cfg STREQUAL "DEBUG")
|
||||
set(lvl "-O0 -g")
|
||||
@@ -328,10 +243,9 @@ endif()
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
# ---------------------------------------------------------------- media decoding
|
||||
# An image, video or audio part of a request is decoded by libavformat/libavcodec and converted by
|
||||
# libswscale or libswresample (core/mm/media.cpp). Without them the engine builds and serves text, and refuses a
|
||||
# media part by name -- the same tri-state as HIP, because a machine that has the libraries should
|
||||
# not silently build without them.
|
||||
# Image, video and audio request parts are decoded by libavformat/libavcodec and converted by
|
||||
# libswscale/libswresample (core/mm/media.cpp). Without them the engine serves text and refuses media
|
||||
# parts. Tri-state like HIP, so a machine with the libraries does not silently build without them.
|
||||
set(RAD_FFMPEG_FOUND OFF)
|
||||
if(NOT RAD_WITH_FFMPEG STREQUAL "OFF")
|
||||
find_package(PkgConfig QUIET)
|
||||
@@ -350,11 +264,8 @@ endif()
|
||||
|
||||
add_subdirectory(vendor)
|
||||
add_subdirectory(core)
|
||||
# THE KERNEL PLUGINS, one directory each, at the root, with no `kernels/` grouping: a plugin's
|
||||
# kernels, row table, layouts and launch adapter all live in its own directory, so it reads as a
|
||||
# plugin built on abi/ rather than something the engine assembles. Each links rad_abi and nothing
|
||||
# else, from one directory, exactly like a plugin written out of tree. That is the acceptance test,
|
||||
# and this is the layout that states it.
|
||||
# Kernel plugins, one root directory each. Each holds its kernels, row table and layouts and links
|
||||
# only rad_abi, exactly like a plugin written out of tree.
|
||||
add_subdirectory(libref)
|
||||
# libquant: the built-in quantisers, the third plugin kind (spec §4.5). Host C++, built everywhere:
|
||||
# rad-convert drives it and the oracle decodes through it.
|
||||
@@ -362,13 +273,10 @@ add_subdirectory(libquant)
|
||||
if(RAD_HIP_FOUND AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/libr4d/CMakeLists.txt)
|
||||
add_subdirectory(libr4d)
|
||||
endif()
|
||||
# libavx: the conventional op vocabulary in hand-written x86 SIMD, runtime-dispatched by CPU
|
||||
# feature -- the production HOST kernels, built wherever libref is, on x86-64. An op the placement
|
||||
# puts on the host needs a host kernel that is not the oracle (rad_gate_reference_kernels refuses
|
||||
# to serve on libref), and a model whose table is too large for the card -- the n-gram
|
||||
# embedding's gather -- puts one there every step. It is not behind an option for that reason: a
|
||||
# build without it cannot serve such a model. It also builds standalone (`cmake -S libavx -B
|
||||
# build-avx`) on a box with no ROCm.
|
||||
# libavx: the production host kernels (x86 SIMD, dispatched by CPU feature), built on every x86-64.
|
||||
# Not optional: host-placed ops need a kernel other than the oracle (rad_gate_reference_kernels
|
||||
# refuses libref), and a table too large for the card, such as the n-gram embedding's gather, runs
|
||||
# on the host every step. Also builds standalone without ROCm (`cmake -S libavx -B build-avx`).
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(x86_64|AMD64|amd64)$")
|
||||
add_subdirectory(libavx)
|
||||
endif()
|
||||
@@ -380,55 +288,39 @@ if(RAD_BUILD_TESTS)
|
||||
endif()
|
||||
|
||||
# ---------------------------------------------------------------- the installed package
|
||||
# Everything below is ADDITIVE: it changes nothing about what gets built or where the build tree
|
||||
# puts it. It is what makes `find_package(radiance)` work: the ABI headers -- the entire documented
|
||||
# contract with a plugin -- and the package config are installed, so an out-of-tree plugin compiles
|
||||
# against an installed prefix rather than a hand-copied abi/. Without it the plugin boundary is
|
||||
# real inside the tree and imaginary outside it.
|
||||
# Install-only rules for `find_package(radiance)`; they do not affect the build tree.
|
||||
#
|
||||
# (a) the ABI headers. They are self-contained -- they include each other and C standard headers,
|
||||
# and nothing else -- so the directory installs as a unit with no filtering beyond the
|
||||
# extension. arch/common/ is installed by arch/CMakeLists.txt, which owns those files.
|
||||
#
|
||||
# Under include/radiance/ rather than loose in include/: a prefix of /usr shares that directory with
|
||||
# every other package, and rad_*.h and arch/ are names someone else can have. The include spelling
|
||||
# does not change -- the target's include path is the radiance/ directory itself.
|
||||
# (a) The ABI headers, which include only each other and C standard headers. arch/common/ is
|
||||
# installed by arch/CMakeLists.txt. Under include/radiance/ to avoid clashes in shared prefixes such
|
||||
# as /usr; the include spelling is unchanged because the target's include path is radiance/ itself.
|
||||
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/abi/
|
||||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/radiance
|
||||
FILES_MATCHING PATTERN "*.h")
|
||||
|
||||
# (b) the ABI target itself, as radiance::abi. An INTERFACE library has no artifact to install, but
|
||||
# it carries the include path, RAD_DEFAULT_HOME, RAD_HAVE_HIP and the ROCm include directory -- and
|
||||
# those are exactly the flags a plugin has to be compiled with to be loadable by this engine, so
|
||||
# exporting the target is what stops an out-of-tree author reconstructing them by reading our
|
||||
# CMakeLists and getting one of them wrong.
|
||||
# (b) The ABI target as radiance::abi. It carries the include path, RAD_DEFAULT_HOME and RAD_HAVE_HIP,
|
||||
# the flags a plugin must be compiled with to load in this engine.
|
||||
install(TARGETS rad_abi EXPORT radianceTargets)
|
||||
install(EXPORT radianceTargets
|
||||
NAMESPACE radiance::
|
||||
FILE radianceTargets.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/radiance)
|
||||
|
||||
# (c) the package config. The version IS the ABI version, read out of the header rather than written
|
||||
# down a second time here: the loader refuses any plugin that does not report exactly
|
||||
# RAD_ABI_VERSION (core/plugin/loader.cpp), so a package version that could drift from the header
|
||||
# would let find_package(radiance 3) accept an installation whose plugins the consumer cannot load.
|
||||
# SameMajorVersion, with the ABI as the major, is that same exact-match rule expressed to CMake.
|
||||
# (c) The package config. Its version is the ABI version, read from the header: the loader requires
|
||||
# an exact RAD_ABI_VERSION match (core/plugin/loader.cpp), which SameMajorVersion with the ABI as
|
||||
# the major expresses to CMake.
|
||||
file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/abi/rad_abi.h" RAD_ABI_VERSION_LINE
|
||||
REGEX "^#define[ \t]+RAD_ABI_VERSION[ \t]")
|
||||
string(REGEX MATCH "[0-9]+" RAD_ABI_VERSION "${RAD_ABI_VERSION_LINE}")
|
||||
if(NOT RAD_ABI_VERSION)
|
||||
message(FATAL_ERROR
|
||||
"could not read RAD_ABI_VERSION out of abi/rad_abi.h. That number is the whole "
|
||||
"compatibility contract with a plugin; a build that cannot find it must not ship a package "
|
||||
"config that claims one.")
|
||||
"could not read RAD_ABI_VERSION out of abi/rad_abi.h; the package config cannot state the "
|
||||
"plugin compatibility it is built for without it.")
|
||||
endif()
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
# PATH_VARS, so the config resolves these against wherever the package was actually found rather
|
||||
# than against the prefix it was configured with. A staged install (DESTDIR) or a moved tree would
|
||||
# otherwise hand a consumer absolute paths into a directory that no longer exists, and the symptom
|
||||
# is a plugin that compiles and installs into nothing.
|
||||
# PATH_VARS, so the config resolves these relative to where the package is found, which keeps
|
||||
# staged (DESTDIR) and relocated installs working.
|
||||
set(RAD_HOME_RELDIR "${CMAKE_INSTALL_DATADIR}/radiance")
|
||||
set(RAD_INCLUDE_RELDIR "${CMAKE_INSTALL_INCLUDEDIR}/radiance")
|
||||
configure_package_config_file(
|
||||
@@ -444,14 +336,12 @@ write_basic_package_version_file(
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_BINARY_DIR}/radiance-config.cmake
|
||||
${CMAKE_CURRENT_BINARY_DIR}/radiance-config-version.cmake
|
||||
# The function itself, not a copy of it: the config includes this exact file, so the rule
|
||||
# that decides what a plugin links and where it lands is one file for both worlds.
|
||||
# The config includes this exact file, so there is one copy for both builds.
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/RadAddPlugin.cmake
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/radiance)
|
||||
|
||||
# (d) the license and the notices. Apache-2.0 asks that both travel with every copy, and the MIT
|
||||
# License asks the same of each bundled component's text, so they install beside the binaries and
|
||||
# anything built from the install (the Docker image) carries them.
|
||||
# (d) License and notices. Apache-2.0 and the bundled components' licenses require them to travel
|
||||
# with every copy, including images built from the install.
|
||||
install(FILES LICENSE NOTICE DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
||||
install(FILES vendor/llama/LICENSE
|
||||
DESTINATION ${CMAKE_INSTALL_DOCDIR}/third_party RENAME llama.cpp.LICENSE)
|
||||
|
||||
Reference in new issue
Block a user