Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
9f2ca41
fall back to ptx, follow kernel pointers, stop hoarding the fatbin
Zaneham Sep 16, 2026
0656d99
an object that calls, an extent that counts, and a namespace that pic…
Zaneham Sep 17, 2026
5a985bd
ldmatrix reaches SASS as LDSM, and the rest of inline asm says why not
Zaneham Sep 17, 2026
e39e8fb
a header nobody can find gets a warning with a name on it
Zaneham Sep 17, 2026
f7501ca
assert traps on the device and falls through to the system header eve…
Zaneham Sep 17, 2026
2d2f254
kath cuda stops quietly dropping the flags you gave it
Zaneham Sep 17, 2026
5d2869a
a branch on two literals only ever had one arm
Zaneham Sep 17, 2026
c91de00
a shared kernel names its own section and rounds up to sixteen
Zaneham Sep 17, 2026
97e4ce0
a ternary is control flow the moment its arms do something
Zaneham Sep 17, 2026
1e7c940
a functor is a call too, and forty kernels were missing because of it
Zaneham Sep 17, 2026
d1a2df8
nvptx: a uint3 is twelve bytes, not four
Zaneham Sep 18, 2026
3efe4d4
nvptx: alignment is a walk, not a stack, and four bools make a word
Zaneham Sep 18, 2026
57e7718
bir: a pointer keeps the address space of the value it came from
Zaneham Sep 19, 2026
513a52f
bir: a constexpr local that folds is a constant, not a call
Zaneham Sep 19, 2026
873ea7d
inline: take back the comments the ratchet counted
Zaneham Sep 19, 2026
674223a
bir: two integers of different width meet at the wider one
Zaneham Sep 19, 2026
6b667b9
sass: a predicated branch ends a block wherever it sits
Zaneham Sep 19, 2026
89dab4d
bir: a launch scan types a wrapper's locals under its bindings
Zaneham Sep 19, 2026
9617488
nvptx: an aggregate phi carries an address and copies at the merge
Zaneham Sep 19, 2026
47d7bf0
hgen: a 64-bit template argument is spelt int64_t, for now
Zaneham Sep 19, 2026
a4a9f75
bir: an address space follows a pointer through select and phi
Zaneham Sep 19, 2026
f3b0114
tdf: fission follows a param through its spill slot
Zaneham Sep 21, 2026
eb07af1
bir: a ternary does not run the arm it did not take, if the arm reads…
Zaneham Sep 21, 2026
05274ff
nvptx: a 64-bit integer constant is built from its halves
Zaneham Sep 21, 2026
f374594
bir: p += n, p -= n, p++ and p-- step a pointer by elements
Zaneham Sep 21, 2026
0bb375e
bir: say why pstep is there, where the next person will look
Zaneham Sep 21, 2026
33bd874
nvptx: a signed byte is extended from bit 7, not bit 15
Zaneham Sep 22, 2026
0b2129f
bir: a vector constructor converts each argument to its field
Zaneham Sep 22, 2026
71630ea
bir: the constructor's conversion goes in before the store that reads it
Zaneham Sep 22, 2026
1714507
bir: a deduced argument may be *(T *)p as well as p[i]
Zaneham Sep 22, 2026
0cb9afa
bir: a short or a char promotes to int before it meets an operator
Zaneham Sep 22, 2026
cace292
bir: a launch wrapper's local that Booth cannot name is skipped, not …
Zaneham Sep 22, 2026
0c2e5bf
bir: a template handed out as a function pointer still gets its kerne…
Zaneham Sep 23, 2026
ba02700
a function pointer keeps its parameter list, so a template returned t…
Zaneham Sep 23, 2026
c991124
sass: P1 is the wide compares' scratch, so no value may live there
Zaneham Sep 23, 2026
ae66cb4
an alias template of a function pointer keeps its params too, so ggml…
Zaneham Sep 24, 2026
523d258
HOLY FUCK
Zaneham Sep 24, 2026
3e3d857
the tensor cores were in there the whole time
Zaneham Oct 26, 2026
a6f9603
you were meant to be the chosen launcher! (Param shadowing and launch…
Zaneham Oct 26, 2026
28b0175
girl I'm tired lmao (no MLIR for now will work on it later)
Zaneham Oct 26, 2026
51ad4b3
newer gcc read my bitset more carefully than I did
Zaneham Oct 26, 2026
3f2233c
I meant to release this all a month ago but got carried away
Zaneham Oct 26, 2026
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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -186,3 +186,7 @@ tdf_flag_out.txt
# Mutation harness scratch copy. Removed on exit, but an interrupted run
# can leave it behind.
/.mutscratch/

src/mlir/
tests/mlir/
tests/tmlir.c
80 changes: 80 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,86 @@
Booth — Changelog
=================

## Unreleased

### Backends

- `--nvidia-cubin` puts every kernel of a module into the one cubin, so
ggml-cuda files with several kernels no longer stop at E600
(Zane Hambly, 2026-10-26)

- `--nvidia-cubin` lowers local loads and stores, half and bfloat16
conversions, rounding, votes, membar, nanosleep, 16-bit parameters and
constant divisors, and sizes each kernel's registers from its own counts
(Zane Hambly, 2026-10-26)

- `--nvidia-cubin` holds a register only where its value is live, places join
barriers by the blocks a region covers, and lowers wmma load, store and mma
to scalar SASS, so topk-moe and lightning-indexer build (Zane Hambly,
2026-10-26)

- `--nvidia-cubin` lowers cvta.local and cvta.global, so cumsum and quantize
get as far as their vprintf call (Zane Hambly, 2026-10-26)

- `--nvidia-cubin` spills values to the local frame when a kernel needs more
registers than SASS has, so mmvq gets past E603 (Zane Hambly, 2026-10-26)

- `--cuda-host` and `--cuda-exe` emit the host half of a CUDA compile, so kath
builds a whole program the way nvcc does: the source back out with the device
definitions removed, each launch through `__cudaPushCallConfiguration` and a
stub calling `cudaLaunchKernel`, the kernels registered from a constructor out
of a fatbin carrying both the cubin and the PTX, and the system C++ compiler
driven to link it. Clean-room `cuda.h`, `cuda_runtime.h`, `cuda_fp16.h`,
`cuda_bf16.h` and `cublas_v2.h` under `runtime/include` (Zane Hambly,
2026-10-26)

- `--cuda-host` writes each kernel's stub where the kernel stood and keys a
launch on the instantiation rather than its position, so a kernel launched
from inside a host template or through a macro reaches the right one, and it
spells enum, struct, vector and function template arguments, so ggml-cuda
files get through the host pass (Zane Hambly, 2026-10-26)

- `--cuda-host` writes out a variadic template argument pack, spells a function
template-id argument rather than the symbol it lowered to, keeps a launch
whose callee ends in `>>`, registers up to 4096 kernels and refuses with E622
above that instead of falling silent, and `kath cuda` finds Booth's own
`runtime/include` from the binary rather than the working directory, so
binbcast and cpy get through (Zane Hambly, 2026-10-26)
- `--cuda-host` carries const on the BIR type itself, so a kernel taking
`const float *` registers the instantiation its launch actually names
rather than one spelled without the qualifier (Zane Hambly, 2026-10-26)

- `kath cuda -c` compiles one `.cu` to one relocatable object rather than a
whole program, with `-fPIC` for a shared library, each object carrying its
own fatbin and registration constructor the way nvcc does, so many
translation units link into one library (Zane Hambly, 2026-10-26)

- `kath cuda` takes `-Idir` written up against the flag as well as `-I dir`,
rather than dropping it and compiling with the include path missing
- `--cuda-host` leaves a declaration where it deleted a device function, so
host code naming one as a template argument still resolves, expands an
argument pack in the stub body, keeps default arguments, tells a commented
out parameter name from a type, and the clean-room headers gain
`cudaFuncSetAttribute`, the host-mapped allocation flags, occupancy without
the flags suffix, `cudaDataType_t`, the cuBLAS side, fill, diag, compute and
algo enums with `cublasStrsmBatched` and the `GemmEx` family, and a minimal
`cooperative_groups.h`, so 63 of the 67 ggml-cuda files compile to objects
(Zane Hambly, 2026-10-26)

### Frontend

- Explicit template instantiation, `template void f<args>(params);` with
`extern template` as its declaration form, deduces and instantiates down the
same path as an implicit one, and a launch through a function-pointer local
resolves to the kernel it holds, so ggml-cuda's template-instance files get
through the device and host passes (Zane Hambly, 2026-10-26)

- `--cuda-host` strips `__device__`, `__global__`, `__host__` and
`__forceinline__` wherever they survive into host output, and leaves an angle
include a directive rather than inlining Booth's own headers over the one g++
will read, while `kath cuda` now hands every `-I` to every stage instead of
only the last, so the emitted C++ compiles (Zane Hambly, 2026-10-26)

## Booth 0.6.0

### Runtime
Expand Down
60 changes: 7 additions & 53 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ CFLAGS = -std=c99 -MMD -MP -Wall -Wextra -pedantic -O2 \
-Wdouble-promotion -Wswitch-enum -Wwrite-strings \
-D_FORTIFY_SOURCE=2 -fstack-protector-strong -fPIE $(CF_PROT) \
$(GCC_ONLY) \
-Isrc -Isrc/fe -Isrc/ir -Isrc/tdf -Isrc/backend -Isrc/amdgpu -Isrc/tensix -Isrc/nvidia -Isrc/metal -Isrc/intel -Isrc/triton -Isrc/cpu -Isrc/build -Isrc/exec -Iruntime/include \
-Isrc -Isrc/fe -Isrc/ir -Isrc/tdf -Isrc/backend -Isrc/amdgpu -Isrc/tensix -Isrc/nvidia -Isrc/metal -Isrc/intel -Isrc/triton -Isrc/cpu -Isrc/build -Isrc/exec -Isrc/host -Iruntime/include \
$(COVFLAGS)
LDFLAGS = -pie
LIBS = -lm
Expand Down Expand Up @@ -76,53 +76,11 @@ SOURCES = src/main.c src/kauri_impl.c \
src/metal/emit.c src/metal/metal_be.c \
src/intel/emit.c src/intel/intel_be.c \
src/triton/lex.c src/triton/parse.c src/triton/sema.c src/triton/lower.c \
src/mlir/mlir_fe.c src/mlir/lower.c \
src/exec/execs.c src/exec/cpu_exec.c src/exec/booth_run.c src/exec/verbs.c \
src/host/hgen.c \
runtime/host/cuda/nv_rt.c runtime/host/cuda/nv_exec.c

# Certik's pure-C MLIR reader, vendored under src/mlir/vendor. It carries his
# corec base library and a syscall shim per host, so only one of the three
# platform files is ever built.
#
# c2x rather than c99 because corec's format.h dispatches on _Generic and
# needs __VA_OPT__, and the ~100 format() call sites through it are not worth
# rewriting. -Wno-switch-enum because these switch over a 140-value op enum
# with a default label and upstream keeps adding ops. Nothing else in the
# warning set is relaxed. PLATFORM_SKIP_ENTRY leaves main to Booth,
# COREC_STDLIB_PROVIDES_MEM stops corec defining memcpy and memset when a real
# libc is already doing it.
VDIR = src/mlir/vendor
VPLAT = platform_windows.c
ifeq ($(UNAME_S),Linux)
VPLAT = platform_linux.c
endif
ifeq ($(UNAME_S),Darwin)
VPLAT = platform_macos.c
endif
VSOURCES = $(VDIR)/tokenizer.c $(VDIR)/mlir_parser.c $(VDIR)/op_parsers.c \
$(VDIR)/mlir_api_impl.c $(VDIR)/mlir_op_names.c \
$(VDIR)/mlir_classic_printer.c $(VDIR)/mlir_lift_cf_to_scf.c \
$(VDIR)/base/io.c $(VDIR)/base/buddy.c $(VDIR)/base/arena.c \
$(VDIR)/base/scratch.c $(VDIR)/base/format.c $(VDIR)/base/math.c \
$(VDIR)/base/string.c $(VDIR)/base/strbuf.c $(VDIR)/base/mem.c \
$(VDIR)/base/numconv.c $(VDIR)/base/assert.c $(VDIR)/base/exit.c \
$(VDIR)/platform/$(VPLAT)
# Simply expanded, so the target-specific assignment below is a plain string
# rather than something that re-expands CFLAGS into itself.
VCFLAGS := $(subst -std=c99,-std=c2x,$(CFLAGS)) -Wno-switch-enum \
-DPLATFORM_SKIP_ENTRY -DCOREC_STDLIB_PROVIDES_MEM -I$(VDIR)

OBJECTS = $(SOURCES:%.c=$(OBJDIR)/%.o) $(VSOURCES:%.c=$(OBJDIR)/%.o)

# Everything under src/mlir compiles on VCFLAGS, vendored or not. mlir_fe.c and
# lower.c are ours but they speak corec types, so they want the same flags.
# A target-specific variable rather than a pattern rule, because two patterns
# match these objects and make 3.81, which is what macOS ships, does not
# resolve that the way make 4 does. It took the generic rule and the build lost
# its include path.
MLOBJECTS = $(VSOURCES:%.c=$(OBJDIR)/%.o) \
$(OBJDIR)/src/mlir/mlir_fe.o $(OBJDIR)/src/mlir/lower.o
$(MLOBJECTS): CFLAGS := $(VCFLAGS)
OBJECTS = $(SOURCES:%.c=$(OBJDIR)/%.o)
TARGET = kath

# Host programs that link a vendor driver at run time: the examples and the
Expand All @@ -143,7 +101,7 @@ $(OBJDIR)/%.o: %.c
# ---- Test Suite ----
TCFLAGS = -std=c99 -MMD -MP -D_POSIX_C_SOURCE=200809L -Wall -Wextra -O0 -g \
-Isrc -Isrc/fe -Isrc/ir -Isrc/tdf -Isrc/backend -Isrc/amdgpu -Isrc/tensix -Isrc/nvidia -Isrc/metal -Isrc/intel -Isrc/triton -Isrc/cpu -Isrc/build -Isrc/exec \
-Isrc/mlir -Iruntime/include $(COVFLAGS)
-Iruntime/include $(COVFLAGS)
TSRC = tests/tmain.c tests/tsmoke.c tests/tcomp.c tests/tenc.c \
tests/tasy.c \
tests/ttabs.c tests/ttypes.c tests/terrs.c tests/tphase.c \
Expand All @@ -170,7 +128,6 @@ TSRC = tests/tmain.c tests/tsmoke.c tests/tcomp.c tests/tenc.c \
tests/tbackend.c \
tests/tordr.c \
tests/trpi.c \
tests/tmlir.c \
tests/tbir.c \
tests/tocm.c \
tests/tpack.c \
Expand All @@ -179,7 +136,7 @@ TSRC = tests/tmain.c tests/tsmoke.c tests/tcomp.c tests/tenc.c \
tests/ttpl.c \
tests/tvec.c \
tests/tref.c tests/ttyc.c tests/tcpp.c \
tests/tmof.c tests/tasm.c
tests/tmof.c tests/tasm.c tests/thost.c

TOBJS = $(TSRC:%.c=$(OBJDIR)/%.o)
COBJS = $(OBJDIR)/src/kauri_impl.o $(OBJDIR)/src/ir/bir.o $(OBJDIR)/src/ir/bir_print.o $(OBJDIR)/src/ir/bir_lower.o $(OBJDIR)/src/ir/bir_mem2reg.o $(OBJDIR)/src/ir/bir_cfold.o $(OBJDIR)/src/ir/bir_dce.o $(OBJDIR)/src/ir/bir_struct.o $(OBJDIR)/src/ir/bir_insert.o $(OBJDIR)/src/ir/bir_sroa.o $(OBJDIR)/src/ir/bir_inline.o \
Expand All @@ -190,6 +147,7 @@ COBJS = $(OBJDIR)/src/kauri_impl.o $(OBJDIR)/src/ir/bir.o $(OBJDIR)/src/ir/bir
$(OBJDIR)/src/fe/bc_err.o $(OBJDIR)/src/fe/lexer.o $(OBJDIR)/src/fe/parser.o $(OBJDIR)/src/fe/preproc.o $(OBJDIR)/src/fe/sema.o \
$(OBJDIR)/runtime/host/bc_abend.o $(HOSTRT) \
$(OBJDIR)/src/backend/backends.o \
$(OBJDIR)/src/host/hgen.o \
$(OBJDIR)/src/amdgpu/amd_be.o $(OBJDIR)/src/nvidia/nv_be.o \
$(OBJDIR)/src/tensix/tensix_be.o $(OBJDIR)/src/cpu/cpu_be.o \
$(OBJDIR)/src/metal/metal_be.o $(OBJDIR)/src/intel/intel_be.o \
Expand All @@ -198,8 +156,7 @@ COBJS = $(OBJDIR)/src/kauri_impl.o $(OBJDIR)/src/ir/bir.o $(OBJDIR)/src/ir/bir
$(OBJDIR)/src/cpu/cpu_emit.o $(OBJDIR)/src/cpu/cpu_elf.o \
$(OBJDIR)/src/cpu/rv64_emit.o $(OBJDIR)/src/cpu/rv64_elf.o \
$(OBJDIR)/src/tensix/isel.o $(OBJDIR)/src/tensix/coarsen.o $(OBJDIR)/src/tensix/datamov.o \
$(OBJDIR)/src/metal/emit.o $(OBJDIR)/src/intel/emit.o \
$(OBJDIR)/src/mlir/mlir_fe.o $(OBJDIR)/src/mlir/lower.o $(VSOURCES:%.c=$(OBJDIR)/%.o)
$(OBJDIR)/src/metal/emit.o $(OBJDIR)/src/intel/emit.o

rules:
@sh tests/rules.sh
Expand Down Expand Up @@ -311,11 +268,8 @@ coverage:
-./trunner --all
@command -v gcovr >/dev/null 2>&1 || { echo "gcovr not found. pip install gcovr"; exit 1; }
@mkdir -p coverage-html
@# gcovr snuffles through the object dir like a skaven after warp tokens, so vendored data has to be gone rather than filtered.
find $(COVDIR)/src/mlir \( -name '*.gcda' -o -name '*.gcno' \) -delete 2>/dev/null || true
gcovr --root . --object-directory $(COVDIR) \
--filter 'src/' --filter 'runtime/' \
--exclude 'src/mlir/vendor/' \
--exclude-unreachable-branches \
--print-summary --txt coverage.txt --html-details coverage-html/index.html
rm -f $(TARGET) $(TARGET).exe trunner trunner.exe
Expand Down
2 changes: 0 additions & 2 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ The following CUDA features compile to working GFX9/GFX10/GFX11/GFX12 machine co
- Struct pass-by-value
- Triton tile shape inference: rank-0/1/2 shape annotation on every expression, constexpr default propagation (`BLOCK: tl.constexpr = 256` resolves to `vec[256]`), numpy-style broadcasting, `[:, None]` / `[None, :]` reshape patterns
- Triton matmul on the CPU: `tl.dot` lowers and runs via `--cpu`, with a runtime K-loop so the contraction can be any size. Rank-2 tiles materialise and unroll
- MLIR frontend (`--mlir`): `func.func`, `return`, `arith.constant`, the `arith` binops, compares and conversions lower to BIR and run through the same pipeline as CUDA and Triton. `--mlir --pp` reprints what was read
- OCaml frontend: kernels are ordinary OCaml functions, type-checked by `ocamlc` against an abstract-typed `Kernel` module, lowered from the `.cmt` by `kcomp` and read back through `--bir-in`. Global and block-shared arrays of any element type, counted loops, `ref` accumulators, `if`/`else`, barriers, atomics, `let[@device]` functions, and twelve transcendentals. All six backends
- BIR text frontend (`--bir-in`): a module printed by `--ir` reads back in, so a compiler outside this tree can target Booth without linking against it
- x86-64 CPU backend (`--cpu`): CUDA and Triton kernels compile to a host object and run with no GPU. SIMT becomes a thread loop. Stack-everything codegen, no register allocator yet
Expand All @@ -58,7 +57,6 @@ Being honest about limitations is important. Here's what's missing:
- Triton `tl.dot` on the matrix cores. `mma.sync` and MFMA are in and checked against llvm-mc byte for byte, but a rank-2 tile still materialises and unrolls into scalar FMAs on every backend, which is correct and very large rather than a refusal. Reaching the matrix path from Triton is an execution-model change, not a missing encoding
- Loop-carried reassignment in a Triton kernel. Rewriting a name across a `for` back-edge needs a phi at the loop head and only the counter gets one, so an accumulator refuses with E141 rather than quietly reading its pre-loop value every trip
- CPU backend is correct-first: stack-everything codegen, no register allocator yet, single block per call, and `tl.load` masks aren't honoured (so keep the launch's nthreads equal to the element count). It runs; it isn't fast.
- MLIR beyond `func`, `return` and `arith`. No `memref`, `scf` or `gpu` dialect, and a function body with more than one block is refused rather than flattened. Nothing marks an MLIR function as a kernel, so it lowers as a device function: `--cpu` and `--rv64` emit real code, `--metal` counts it as a kernel, and `--amdgpu-bin` and `--nvidia-ptx` report zero kernels and write an empty container
- OCaml kernels have no `while` and no early exit, no `f64`, no warp shuffles, and no atomic `min` or `max`. BIR carries one opcode for each of those two and the NVIDIA and AMD backends read it with opposite signedness, so they stay out of reach until the IR can say which is meant
- `--bir-in` reads the subset the frontends emit, not all of BIR. Round-tripping the sample corpus is 45 of 103; an opcode or type it does not know is named and refused rather than skipped
- Soft-float for the Tenstorrent native RV32IM path. The runtime exists and validates against host FPU; wiring it into `--rv-elf` is a sitting's work away.
Expand Down
4 changes: 0 additions & 4 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,13 @@ Booth takes seven inputs. They all meet at BIR and go down the same pipeline.
| HIP | `--hip`, or a `.hip` file | Macro layer over the CUDA path |
| Triton | `--triton` | Python subset, `tl.*`, `tl.dot` on the CPU backend |
| Fortran | via LFortran | `do concurrent`, elementwise, SLATEC-checked in CI |
| MLIR | `--mlir` | `func`, `return` and `arith`. No LLVM in the path |
| OCaml | via `kcomp` | Kernels as typed OCaml functions |
| BIR text | `--bir-in` | What `--ir` prints, read back in |

What each still owes:

- **Triton** — rank-2 tiles refuse on GPU targets with E099. `tl.load` masks are
not honoured on the CPU backend.
- **MLIR** — no `memref`, `scf` or `gpu` dialect. A function body with more than
one block is refused rather than flattened, and nothing marks an MLIR function
as a kernel, so it lowers as a device function.
- **OCaml** — no `while` and no early exit, no `f64`, no warp shuffles, and no
atomic min or max until the IR question above is settled.
- **Fortran** — This is more LFortran work than on Booth as Fortran already has GPU support through `do concurrent`. I'm working on the LFortran compiler at the moment to shore up some support around legacy f77 Fortran and also send a patch upstream so I can get Fortran compiling to GPUs properly rather than the limited subset.
Expand Down
44 changes: 14 additions & 30 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ The compiled binary is `kath` (after Kathleen Booth); the project is Booth. They
./kath build <file> -o out.o # compile only
./kath doctor # report devices and toolchain, then self-test

# Compile a .cu the way nvcc would: device code into a fatbin, host code
# through your C++ compiler, one object out
./kath cuda -c -fPIC kernel.cu -o kernel.o

# When the cubin backend refuses a kernel, that unit's fatbin carries PTX
# alone and the fallback says so on stderr. On by default, and Latimer runs
# PTX where it finds no SASS.
./kath cuda -c kernel.cu -o kernel.o --ptx-fallback

# Turn it off and a refused unit is a hard failure again. That is how you
# enumerate every gap in the SASS backend across a whole build.
./kath cuda -c kernel.cu -o kernel.o --no-ptx-fallback

# Compile to AMD GPU binary (RDNA 3, default)
./kath --amdgpu-bin kernel.cu -o kernel.hsaco

Expand Down Expand Up @@ -106,7 +119,7 @@ Hand `kath` more than one `.cu` and each is compiled on its own, then linked int

Each file gets a fresh preprocessor, lexer, parser and sema, so a macro, typedef or struct in one cannot reach the next, and two files may each keep their own `static` helper of the same name without either calling the other's. Anything not marked `static` is one symbol the whole program shares, so a `__device__` function, a `__constant__` global, or an `inline` function arriving from a header several files include, all give you one copy rather than one per file. Two files defining the same non-`inline` symbol is E126 rather than a quiet decision about which one wins.

Symbols become visible in the order you list the files, so a `__device__` function has to be defined in a file earlier on the command line than the one calling it. The other way round comes back as E105, unknown function. The other frontends read one document each, so `--triton`, `--mlir` and `--bir-in` still take a single file and will say so if given more.
Symbols become visible in the order you list the files, so a `__device__` function has to be defined in a file earlier on the command line than the one calling it. The other way round comes back as E105, unknown function. The other frontends read one document each, so `--triton` and `--bir-in` still take a single file and will say so if given more.

## Runtime Launcher

Expand Down Expand Up @@ -297,32 +310,3 @@ abstract. Both take a literal, not an expression.
This is not OCaml running on a GPU. It is OCaml as the language you write the
kernel in. There is no GC, no closure at runtime, no exception and no
polymorphism on the device. CUDA C is not C either so it does track (gpu's are weird)..

## MLIR

`--mlir` reads MLIR text. The reader is Ondřej Čertík's, vendored under
`src/mlir/vendor`, and there is no LLVM in the path.

```bash
# Lower MLIR and compile it, same as any other frontend
./kath --mlir kernel.mlir --cpu -o kernel.o
./kath --mlir kernel.mlir --rv64 -o kernel.o

# Dump the BIR the lowering produced
./kath --mlir --ir kernel.mlir

# Reprint what was read instead of lowering it, for telling a misreading
# from a bad file
./kath --mlir --pp kernel.mlir
```

Accepted today: `func.func` with named arguments, `return`, `arith.constant`,
every `arith` integer and float binop, `arith.cmpi` and `arith.cmpf`, and the
`arith` conversions. Anything else is named on stderr and the whole lowering
fails, because an op skipped quietly is a kernel that compiles and computes
something different.

Nothing in MLIR marks a function as a kernel yet, so everything lowers as a
device function. `--cpu` and `--rv64` give you real code; the GPU backends will
take the file and then report zero kernels, which is an honest answer until
the `gpu` dialect arrives.
Loading
Loading