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

tests: make the GPU test suite build and pass under HIP on gfx1151

huppiflupp97cd7620cf0e
diff --git a/c/Makefile b/c/Makefile
index aad7fd6a..8dc63004 100644
--- a/c/Makefile
+++ b/c/Makefile
@@ -979,8 +979,8 @@ cuda-test: backend_cuda.cu backend_cuda.h backend_gpu_compat.h tests/test_backen
# Getting that wrong would leave OpenMP symbols in the object while the link
# below no longer pulls the runtime, and CI could not catch it because CI
# never runs cuda-test. -Xclang appears nowhere else in CFLAGS.
- $(CC) $(filter-out -Xclang -fopenmp,$(CFLAGS)) -fno-openmp -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) $(GPU_TEST_LIBS)
+ $(CC) $(filter-out -Xclang -fopenmp,$(CFLAGS)) -fno-openmp -fPIC -c tests/mxfp4_ref.c -o tests/mxfp4_ref.o
+ "$(GPUCC)" $(GPUFLAGS) backend_cuda.cu tests/test_mxfp4_cuda.cu -x none tests/mxfp4_ref.o -o mxfp4_cuda_test$(EXE) $(GPU_TEST_LIBS)
./mxfp4_cuda_test$(EXE)
# Allocator footprint (#687): what a cudaMalloc really takes off the card,
# which is what the expert tier has to be charged rather than the logical
diff --git a/c/backend_gpu_compat.h b/c/backend_gpu_compat.h
index dbbd07ff..04b64dc6 100644
--- a/c/backend_gpu_compat.h
+++ b/c/backend_gpu_compat.h
@@ -67,6 +67,7 @@ namespace nvcuda { namespace wmma = ::rocwmma; }
#define cudaDeviceProp hipDeviceProp_t
#define cudaGetDeviceProperties hipGetDeviceProperties
#define cudaMalloc hipMalloc
+#define cudaMallocManaged hipMallocManaged
#define cudaFree hipFree
#define cudaMemcpy hipMemcpy
#define cudaMemcpy2D hipMemcpy2D
diff --git a/c/tests/bench_dsv4_deepgemm.cu b/c/tests/bench_dsv4_deepgemm.cu
index 1607cf69..49af2156 100644
--- a/c/tests/bench_dsv4_deepgemm.cu
+++ b/c/tests/bench_dsv4_deepgemm.cu
@@ -1,6 +1,8 @@
#include <cuda.h>
#include <cuda_bf16.h>
-#include <cuda_runtime.h>
+#if !defined(__HIPCC__)
+#include <cuda_runtime.h> /* under HIP, backend_gpu_compat.h (via backend_cuda.cu) provides these */
+#endif
#include <cstdio>
#include <cstdlib>
diff --git a/c/tests/bench_dsv4_mxfp8.cu b/c/tests/bench_dsv4_mxfp8.cu
index 209433ee..c072719a 100644
--- a/c/tests/bench_dsv4_mxfp8.cu
+++ b/c/tests/bench_dsv4_mxfp8.cu
@@ -1,4 +1,6 @@
-#include <cuda_runtime.h>
+#if !defined(__HIPCC__)
+#include <cuda_runtime.h> /* under HIP, backend_gpu_compat.h (via backend_cuda.cu) provides these */
+#endif
#include <cuda_fp8.h>
#include <cublasLt.h>
#include <cstdio>
diff --git a/c/tests/test_alloc_footprint_cuda.cu b/c/tests/test_alloc_footprint_cuda.cu
index bb973ca9..79c6d921 100644
--- a/c/tests/test_alloc_footprint_cuda.cu
+++ b/c/tests/test_alloc_footprint_cuda.cu
@@ -16,6 +16,9 @@
#include <cstdlib>
#include <vector>
#include "../backend_cuda.h"
+#if defined(__HIPCC__)
+#include "../backend_gpu_compat.h" /* separate TU: needs the CUDA->HIP mapping itself */
+#endif
static int failures = 0;
diff --git a/c/tests/test_fp8_cuda.cu b/c/tests/test_fp8_cuda.cu
index 6c98c51e..87ccecc2 100644
--- a/c/tests/test_fp8_cuda.cu
+++ b/c/tests/test_fp8_cuda.cu
@@ -27,7 +27,9 @@
#include <cstdlib>
#include <cstring>
#include <cmath>
-#include <cuda_runtime.h>
+#if !defined(__HIPCC__)
+#include <cuda_runtime.h> /* under HIP, backend_gpu_compat.h (via backend_cuda.cu) provides these */
+#endif
#include "../backend_cuda.cu"
diff --git a/c/tests/test_grouped_g4_cuda.cu b/c/tests/test_grouped_g4_cuda.cu
index 9acb82da..5821cae3 100644
--- a/c/tests/test_grouped_g4_cuda.cu
+++ b/c/tests/test_grouped_g4_cuda.cu
@@ -22,7 +22,9 @@
#include <cstdlib>
#include <cstring>
#include <cmath>
-#include <cuda_runtime.h>
+#if !defined(__HIPCC__)
+#include <cuda_runtime.h> /* under HIP, backend_gpu_compat.h (via backend_cuda.cu) provides these */
+#endif
#include "../backend_cuda.cu"
diff --git a/c/tests/test_mxfp4_cuda.cu b/c/tests/test_mxfp4_cuda.cu
index 48c1dddb..6604560d 100644
--- a/c/tests/test_mxfp4_cuda.cu
+++ b/c/tests/test_mxfp4_cuda.cu
@@ -25,7 +25,12 @@
#include <cstdlib>
#include <cstring>
#include <cmath>
+#if defined(__HIPCC__)
+#include "../backend_gpu_compat.h" /* this TU links against a separately compiled backend_cuda.cu,
+ so it needs the CUDA->HIP mapping itself */
+#else
#include <cuda_runtime.h>
+#endif
/* quant.h is C (it uses _Thread_local, which nvcc's C++ front end rejects), so
* the reference is compiled separately as C and reached through this one
@@ -68,8 +73,8 @@ static void compare_case(const char *what, const float *y_cpu, const float *y_gp
if (std::isnan(a) != std::isnan(b)) bad++;
continue;
}
- if (isinf(a) || isinf(b)) { /* exponent 255: both must agree it is inf */
- if (isinf(a) != isinf(b) || (isinf(a) && ((a > 0) != (b > 0)))) bad++;
+ if (std::isinf(a) || std::isinf(b)) { /* exponent 255: both must agree it is inf */
+ if (std::isinf(a) != std::isinf(b) || (std::isinf(a) && ((a > 0) != (b > 0)))) bad++;
continue;
}
double den = fabs(a) > 1e-6 ? fabs(a) : 1e-6;
diff --git a/c/tests/test_router_cuda.cu b/c/tests/test_router_cuda.cu
index 4e714a6a..8f2ec4d5 100644
--- a/c/tests/test_router_cuda.cu
+++ b/c/tests/test_router_cuda.cu
@@ -14,7 +14,9 @@
#include <cstdlib>
#include <cstring>
#include <cmath>
-#include <cuda_runtime.h>
+#if !defined(__HIPCC__)
+#include <cuda_runtime.h> /* under HIP, backend_gpu_compat.h (via backend_cuda.cu) provides these */
+#endif
/* pull in the kernel definitions (same idiom as the CPU tests' #include "../colibri.c") */
#include "../backend_cuda.cu"