Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/SETTINGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ version made it the default.
| `STRATA_PF_XMX` | text | Intel Arc | v0.2.16 | [INTEL.md](INTEL.md), [release-notes-0.2.0.md](release-notes-0.2.0.md) |
| `STRATA_PIPELINE_ADAPT_ASYNC` | number | NVIDIA and AMD | v0.2.16 | - |
| `STRATA_PLE_AUTO_MMAP` | number | NVIDIA and AMD, Intel Arc | v0.2.16 | [DETAILS.md](DETAILS.md) |
| `STRATA_POLY_BELL` | on / off | NVIDIA | - | - |
| `STRATA_POLY_BELL` | on / off | NVIDIA and AMD | - | [inkling.md](models/inkling.md) |
| `STRATA_POLY_EXPERT_TILES` | on / off | NVIDIA and AMD | - | [inkling.md](models/inkling.md) |
| `STRATA_POLY_HIP_GROUPED` | on / off | NVIDIA and AMD | - | - |
| `STRATA_POLY_NV4_TILE` | on / off | NVIDIA and AMD | - | - |
Expand Down
5 changes: 4 additions & 1 deletion docs/models/inkling.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,10 @@ every expert on the CPU the answers match an RTX 2070 Super's: on the RX 7900 XT
64 of 64 steps after a 302-token prompt, and at 15 to 16 of 16 after 2,048 tokens. On RDNA4 the prompt's FP16 products
go through hipBLASLt, which rounds them differently: after one 2,048-token prompt that is unusually sensitive, the RX
9070 XT's answers differed from CUDA's more than the RX 7900 XT's, and with `ROCBLAS_USE_HIPBLASLT=0` as much as the
RX 7900 XT's; after 302 and 8,192 tokens they match CUDA's. Use an NVIDIA card or a Mac for now.
RX 7900 XT's; after 302 and 8,192 tokens they match CUDA's. With some experts in RAM a decode token is routed on
the card, which hands the experts it lacks to the CPU through the doorbell, as on NVIDIA: no wait for the host at
each layer. The card's routing rounds a little differently from the host's; `STRATA_POLY_BELL=0` routes on the host
as before. Use an NVIDIA card or a Mac for now.

Not run yet: an AMD card on native Linux or Windows, `--expert-gpu` on two cards (built but not run), `--layer-split`
on two unequal cards (below; it has run on two RTX 2070 Super), UD-Q4_K_XL on the 8 GB card and UD-Q4_K_XL on a Mac.
Expand Down
7 changes: 7 additions & 0 deletions engine/cmake/strata_poly.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ if(STRATA_BUILD_POLY AND STRATA_NATIVE_EXPERTS AND (STRATA_ENABLE_CUDA OR STRATA
target_include_directories(poly_route_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
${_strata_gpu_include_directories})
target_link_libraries(poly_route_test PRIVATE ${_strata_gpu_blas_target} ${_strata_gpu_runtime_target})
# the doorbell between a running card and the host (bell_ring(), bell_add()); needs a card (77 without one)
add_executable(poly_bell_test src/poly/bell_test.cu src/poly/kernels.cu)
target_include_directories(poly_bell_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
${_strata_gpu_include_directories})
target_link_libraries(poly_bell_test PRIVATE ${_strata_gpu_blas_target} ${_strata_gpu_runtime_target})
add_test(NAME poly_bell_test COMMAND poly_bell_test)
set_tests_properties(poly_bell_test PROPERTIES SKIP_RETURN_CODE 77 TIMEOUT 300)
# the fused residual sum, RMS norm and Q8_1 quantization against the three launches; needs a card, run by hand
add_executable(poly_norm_q8_test src/poly/norm_q8_test.cu src/poly/kernels.cu)
target_include_directories(poly_norm_q8_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include
Expand Down
2 changes: 1 addition & 1 deletion engine/include/strata/poly/kernels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ struct ExpertBell {
};
/// One token's picks ids[0..n_used) with weights w at layer `layer`: the ones whose slots[] entry is null, at a place
/// under skip_from, go into the bell, x (n floats) into hx, and the bell rings (seq[0] counts the rings; seq[1] is
/// this one, or 0 when there is none). One block. CUDA only.
/// this one, or 0 when there is none). One block. CUDA and HIP.
void bell_ring(const void* const* slots, const int32_t* ids, const float* w, int n_used, int skip_from, int layer,
const float* x, float* hx, int n, ExpertBell* bell, uint32_t* seq, void* stream);
/// Where seq[1] is a ring: wait until the bell's ack is that ring (or abort is set), then acc += hy (n floats).
Expand Down
54 changes: 54 additions & 0 deletions engine/src/poly/bell.cuh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// src/poly/bell.cuh - the card's side of the doorbell (ExpertBell, kernels.hpp): its loads and stores of the words
// the host writes and reads while a kernel runs, and its wait between two looks. CUDA keeps its volatile accesses
// and __threadfence_system(), as before. On HIP the words are read and written with system-scope atomics (a
// kernel on an RX 9070 XT under WSL2 saw the host's writes to pinned memory live this way, and the host its writes:
// a round trip of 1.3 to 2.8 us), and the bell's memory is coherent (Engine::hmalloc(): hipHostMallocCoherent), so
// no cache between the card and the host holds a stale copy.
#pragma once

#include "strata/poly/kernels.hpp"

#include <cstdint>

namespace strata::poly {

/// The word *p as the host last wrote it.
__device__ __forceinline__ uint32_t bell_peek(const volatile uint32_t* p) {
#if defined(__HIP_DEVICE_COMPILE__)
return __hip_atomic_load(const_cast<uint32_t*>(p), __ATOMIC_RELAXED, __HIP_MEMORY_SCOPE_SYSTEM);
#else
return *p;
#endif
}

/// *p = v for the host to see; what this thread wrote before (and fenced at system scope) is the host's first.
__device__ __forceinline__ void bell_poke(volatile uint32_t* p, uint32_t v) {
#if defined(__HIP_DEVICE_COMPILE__)
__hip_atomic_store(const_cast<uint32_t*>(p), v, __ATOMIC_RELEASE, __HIP_MEMORY_SCOPE_SYSTEM);
#else
*p = v;
#endif
}

/// A pause between two looks at the bell, so that a waiting block does not keep the memory path busy (a spinning
/// card draws power that a laptop's CPU, computing the experts meanwhile, would rather have): 0.5 us on CUDA; on AMD
/// s_sleep 8, 8 x 64 clocks (~0.2 us at 2.5 GHz).
__device__ __forceinline__ void bell_pause() {
#if defined(__HIP_DEVICE_COMPILE__)
__builtin_amdgcn_s_sleep(8);
#elif defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 700
__nanosleep(500);
#endif
}

/// One thread: wait until the bell's ack is ring r or the host gave up (abort). The caller's block then meets at a
/// barrier and fences at system scope before it reads what the host wrote.
__device__ __forceinline__ void bell_wait(const ExpertBell* bell, uint32_t r) {
while (bell_peek(&bell->ack) != r && !bell_peek(&bell->abort)) bell_pause();
#if defined(__HIP_DEVICE_COMPILE__)
// the acquire that pairs with the host's release before its ack: the host's sum is this thread's to share
__builtin_amdgcn_fence(__ATOMIC_ACQUIRE, "");
#endif
}

} // namespace strata::poly
Loading
Loading