Skip to content

Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦

C

Merge dev into the DeepSeek V4 CUDA tier (resolve c/Makefile)

JustVuggff30465a67e2
diff --cc c/Makefile
index d2eb7423,27abc4b1..129c46fc
--- a/c/Makefile
+++ b/c/Makefile
@@@ -222,9 -215,17 +222,17 @@@ ifneq ($(IS_WIN),
# '/Wextra'"), which made `make cuda-dll` unbuildable as shipped. -W3 is
# the MSVC warning level (dash form, NOT /W3: MSYS make would mangle the
# slash-form into a filesystem path).
-NVCCFLAGS ?= -O3 -std=c++17 $(CUDA_GENCODE) -Xcompiler=-W3
+NVCCFLAGS ?= -O3 -std=$(NVCC_STD) $(CUDA_GENCODE) -Xcompiler=-W3
else
-NVCCFLAGS ?= -O3 -std=c++17 $(CUDA_GENCODE) -Xcompiler=-Wall,-Wextra
+NVCCFLAGS ?= -O3 -std=$(NVCC_STD) $(CUDA_GENCODE) -Xcompiler=-Wall,-Wextra
+ # glibc >= 2.41 declares the C23 math additions (rsqrt/rsqrtf, sinpi/cospi, ...)
+ # with __THROW -> noexcept(true), clashing with CUDA's crt/math_functions.h
+ # under C++17 (noexcept is part of the function type since C++17). Force-include
+ # a compat header that strips __THROW from the host pass; see
+ # glibc_c23_math_compat.h. MSVC never sees glibc headers, so Linux-only.
+ ifneq ($(LINUX),)
+ NVCCFLAGS += -Xcompiler=-include,$(CURDIR)/glibc_c23_math_compat.h
+ endif
endif
# HIP=1 builds the SAME backend for AMD GPUs via ROCm: backend_cuda.cu is
# compiled unchanged through backend_gpu_compat.h (one source, two vendors,
@@@ -722,27 -693,9 +734,27 @@@ cuda-test: backend_cuda.cu backend_cuda
# as C on purpose: quant.h uses _Thread_local, which nvcc's C++ front end
# rejects, and re-implementing it for the test would defeat the comparison.
$(CC) $(CFLAGS) -c tests/mxfp4_ref.c -o tests/mxfp4_ref.o
- "$(GPUCC)" $(GPUFLAGS) backend_cuda.cu tests/test_mxfp4_cuda.cu tests/mxfp4_ref.o -o mxfp4_cuda_test$(EXE)
+ "$(GPUCC)" $(GPUFLAGS) backend_cuda.cu tests/test_mxfp4_cuda.cu tests/mxfp4_ref.o -o mxfp4_cuda_test$(EXE) $(GPU_OMP_LINK)
./mxfp4_cuda_test$(EXE)
+
+# The DeepSeek V4 kernels on their own: dense, batched attention and routed MoE
+# against the CPU reference in each test. Needs a GPU, so CI compiles it via
+# gpu-compile rather than running it.
+dsv4-cuda-test: tests/test_dsv4_dense_batch_cuda.c tests/test_dsv4_attention_batch_cuda.c tests/test_dsv4_moe_batch_cuda.c backend_cuda_dsv4.h $(DSV4_CUDA_OBJ)
+ $(CC) $(CFLAGS) tests/test_dsv4_dense_batch_cuda.c $(DSV4_CUDA_OBJ) -o dsv4_cuda_test$(EXE) $(LDFLAGS)
+ ./dsv4_cuda_test$(EXE)
+ $(CC) $(CFLAGS) tests/test_dsv4_attention_batch_cuda.c $(DSV4_CUDA_OBJ) -o dsv4_attention_cuda_test$(EXE) $(LDFLAGS)
+ ./dsv4_attention_cuda_test$(EXE)
+ $(CC) $(CFLAGS) tests/test_dsv4_moe_batch_cuda.c $(DSV4_CUDA_OBJ) -o dsv4_moe_cuda_test$(EXE) $(LDFLAGS)
+ ./dsv4_moe_cuda_test$(EXE)
+
+# Pure-CPU unit tests for the two headers the kernels consume. No GPU, no model.
+tests/test_dsv4_mhc$(EXE): tests/test_dsv4_mhc.c dsv4_mhc.h
+ $(CC) $(CFLAGS) tests/test_dsv4_mhc.c -o tests/test_dsv4_mhc$(EXE) $(LDFLAGS)
+
+tests/test_dsv4_quant$(EXE): tests/test_dsv4_quant.c dsv4_quant.h
+ $(CC) $(CFLAGS) tests/test_dsv4_quant.c -o tests/test_dsv4_quant$(EXE) $(LDFLAGS)
# convenience alias: kernel correctness on AMD (same test, hipcc toolchain)
hip-test:
$(MAKE) cuda-test HIP=1