Skip to content

Add a static assertion macro#880

Merged
maleadt merged 3 commits into
mainfrom
tb/static_assert
Jul 15, 2026
Merged

Add a static assertion macro#880
maleadt merged 3 commits into
mainfrom
tb/static_assert

Conversation

@maleadt

@maleadt maleadt commented Jul 15, 2026

Copy link
Copy Markdown
Member

Makes it easy to write functions that only work in certain situations:

julia> using GPUCompiler
julia> include("examples/kernel.jl")

julia> kernel() = GPUCompiler.@static_assert false "you need true"

julia> main()
ERROR: InvalidIRError: compiling MethodInstance for kernel() resulted in invalid LLVM IR
Reason: static assertion failed (you need true)
Stacktrace:
 [1] macro expansion
   @ ~/.julia/packages/LLVM/zkwaZ/src/interop/base.jl:39
 [2] macro expansion
   @ ~/Julia/pkg/GPUCompiler/src/static_assert.jl:19
 [3] kernel
   @ ./REPL[5]:1

julia> kernel() = GPUCompiler.@static_assert true "you need true"

julia> main()
works fine

Also, a drive-by breaking change, removing the PTX version emission. I plan on moving that to CUDA.jl and using the static assertion functionality from here, which isn't a problem as we haven't released a CUDA.jl version compatible with GPUCompiler 2.x yet.

@maleadt
maleadt merged commit 4a4be52 into main Jul 15, 2026
29 of 30 checks passed
@maleadt
maleadt deleted the tb/static_assert branch July 15, 2026 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant