Skip to content
Merged
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
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build & Test

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: make
- name: Test
run: make test

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: make
- name: Test
run: make test

windows:
runs-on: windows-latest
defaults:
run:
shell: msys2 {0}
steps:
- uses: actions/checkout@v4
- uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
install: mingw-w64-x86_64-gcc make
- name: Build
run: make
- name: Test
run: make test
22 changes: 20 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,25 @@ $(TARGET): $(OBJECTS)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

# ---- Test Suite ----
TCFLAGS = -std=c99 -Wall -Wextra -O0 -g -Isrc -Isrc/fe -Isrc/ir -Isrc/amdgpu
TSRC = tests/tmain.c tests/tsmoke.c tests/tcomp.c tests/tenc.c \
tests/ttabs.c tests/ttypes.c tests/terrs.c tests/tphase.c
TOBJS = $(TSRC:.c=.o)
COBJS = src/ir/bir.o src/ir/bir_print.o src/ir/bir_lower.o src/ir/bir_mem2reg.o \
src/amdgpu/encode.o src/amdgpu/enc_tab.o src/amdgpu/isel.o src/amdgpu/emit.o \
src/fe/lexer.o src/fe/parser.o src/fe/preproc.o src/fe/sema.o

test: $(TARGET) trunner
./trunner --all

trunner: $(TOBJS) $(COBJS)
$(CC) $(TCFLAGS) -o $@ $^

tests/%.o: tests/%.c
$(CC) $(TCFLAGS) -c $< -o $@

clean:
rm -f $(OBJECTS) $(TARGET) $(TARGET).exe
rm -f $(OBJECTS) $(TARGET) $(TARGET).exe trunner trunner.exe $(TOBJS)

.PHONY: all clean
.PHONY: all clean test
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ This is what happens when you look at NVIDIA's walled garden and think "how hard

**UPDATE: RDNA 2, 3 and 4 now supported.** `--gfx1030` / `--gfx1100` / `--gfx1200`

**UPDATE: HSA runtime launcher added.** Compile kernels and dispatch them on real AMD hardware — no HIP, no hipcc. See [Runtime Launcher](#runtime-launcher).

## What It Does

Takes CUDA C source code, the same `.cu` files you'd feed to `nvcc`, and compiles them to AMD RDNA 2 (gfx1030), RDNA 3 (gfx1100) and RDNA 4 (gfx1200) binaries. No LLVM. No HIP translation layer. No "convert your CUDA to something else first." Just a lexer, a parser, an IR, and a hand-written instruction selection backend that would make a compiler textbook weep.
Expand Down
58 changes: 58 additions & 0 deletions tests/tcomp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* tcomp.c -- compile matrix
* Every .cu file, every target. The brute-force approach to confidence. */

#include "tharns.h"

static char obuf[TH_BUFSZ];

/* ---- Helpers ---- */

static const char *targets[] = { "--gfx1030", "", "--gfx1200" };
static const char *tnames[] = { "gfx1030", "gfx1100", "gfx1200" };

static int compile_cu(const char *cu, const char *extra)
{
char cmd[TH_BUFSZ];
const char *out = "test_out.hsaco";

for (int t = 0; t < 3; t++) {
snprintf(cmd, TH_BUFSZ,
BC_BIN " --amdgpu-bin %s %s %s -o %s",
targets[t], extra, cu, out);
int rc = th_run(cmd, obuf, TH_BUFSZ);
if (rc != 0) {
printf(" target %s failed: %s\n", tnames[t], obuf);
return -1;
}
if (!th_exist(out)) {
printf(" target %s: output missing\n", tnames[t]);
return -1;
}
remove(out);
}
return 0;
}

/* ---- compile: individual .cu files ---- */

#define COMP_TEST(name, cu, extra) \
static void name(void) { \
CHECK(compile_cu(cu, extra) == 0); \
PASS(); \
} \
TH_REG("compile", name)

COMP_TEST(cmp_vecadd, "tests/vector_add.cu", "")
COMP_TEST(cmp_canon, "tests/canonical.cu", "")
COMP_TEST(cmp_feat, "tests/cuda_features.cu", "")
COMP_TEST(cmp_tier12, "tests/test_tier12.cu", "")
COMP_TEST(cmp_notgpt, "tests/notgpt.cu", "")
COMP_TEST(cmp_stress, "tests/stress.cu", "")
COMP_TEST(cmp_math, "tests/mymathhomework.cu", "")
COMP_TEST(cmp_launch, "tests/test_launch_bounds.cu", "")
COMP_TEST(cmp_coop, "tests/test_coop_groups.cu", "")
COMP_TEST(cmp_preproc, "tests/test_preproc.cu", "")
COMP_TEST(cmp_includ, "tests/test_include.cu", "-I tests")
COMP_TEST(cmp_tmpl, "tests/templates.cu", "")
COMP_TEST(cmp_unsign, "tests/test_unsigned.cu", "")
COMP_TEST(cmp_shr2d, "tests/test_shared2d.cu", "")
Loading
Loading