Skip to content

Throw a KernelError for non-singleton type arguments - #954

Merged
maleadt merged 1 commit into
mainfrom
tb/type-arg-error
Sep 25, 2026
Merged

maleadt merged 1 commit into
mainfrom
tb/type-arg-error

Conversation

@maleadt

@maleadt maleadt commented Sep 25, 2026

Copy link
Copy Markdown
Member

On Julia 1.13 and earlier, Core.Compiler.isconstType(Type{T}) is only true when T has a unique representation. That excludes unions and UnionAlls, so a kernel argument like Type{Union{Missing, Bool}} or Type{Vector} falls through check_invocation to fieldcount, which throws:

ERROR: ArgumentError: type does not have a definite number of fields
  [1] fieldcount(t::Any)
  [2] check_invocation(job::GPUCompiler.CompilerJob)

Such an argument can't work there anyway, because Julia's codegen passes it as a boxed host pointer. This PR reports it as a KernelError:

KernelError: passing a non-singleton type argument

Argument 3 to your kernel function is the type Vector, which
cannot be passed to a GPU kernel on this version of Julia.
Pass `Val(Vector)` instead, or a value of that type.

On Julia with Core.TypeEgal (JuliaLang/julia#62001), methodinstance already turns these into TypeEgal{T} singletons, so the check never fires there. The test covers both cases.

This came up in JuliaGPU/KernelAbstractions.jl#791, where the POCL back-end's zeros(::POCLBackend, Union{Missing, Bool}, ...) passed the element type to a kernel. That is fixed on the KA side in JuliaGPU/KernelAbstractions.jl#795.

Before `Core.TypeEgal`, `Type{T}` is only a singleton when `T` has a unique
representation, so an argument like `Type{Union{Missing, Bool}}` or `Type{Vector}`
fell through to `fieldcount`, which threw an unhelpful `ArgumentError`. Report it as a
`KernelError` suggesting `Val(T)` instead.
@maleadt
maleadt merged commit 87076e0 into main Sep 25, 2026
30 of 33 checks passed
@maleadt
maleadt deleted the tb/type-arg-error branch September 25, 2026 13:22
@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.41%. Comparing base (8496909) to head (bf13c3e).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #954   +/-   ##
=======================================
  Coverage   86.41%   86.41%           
=======================================
  Files          29       29           
  Lines        5674     5676    +2     
=======================================
+ Hits         4903     4905    +2     
  Misses        771      771           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

maleadt added a commit that referenced this pull request Oct 7, 2026
* Use identity comparison during type mangling (#910)

(cherry picked from commit 1c5bef9)

* Mangle a `Vararg` whose length is still a `TypeVar` (#921)

(cherry picked from commit 370be42)

* Throw a KernelError for non-singleton type arguments (#954)

(cherry picked from commit 87076e0)

* Look up the global logger's level in the latest world (#977)

(cherry picked from commit c2f106b)

* PTX: Restore FMA contraction. (#881)

(cherry picked from commit 96fb6f6)

* [SPIRV] add workaround for khronos translator (#879)

Co-authored-by: Tim Besard <tim.besard@gmail.com>
(cherry picked from commit 081c892)

* Handle allocation failure when boxing (#919)

(cherry picked from commit ea53814)

* Fix invalid IR from small type tags on Julia 1.10 and 1.11 (#972)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit b0dd255)

* SPIR-V: lower llvm.minimum and llvm.maximum (#937)

(cherry picked from commit 8eecfc8)

* Metal: lower `llvm.sin` and `llvm.cos` to AIR (#967)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

(cherry picked from commit cc26075)

* Metal: lower bare LLVM fences to air.atomic.fence (#932)

(cherry picked from commit cae55dd)

* Metal: expand `llvm.powi` into multiplies (#946)

[1.x: re-expressed in 1.23's worklist style, without #941's helpers.]

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 0d06ee4)

* Metal: expand vector reductions into scalar chains (#962)

[1.x: re-expressed in 1.23's worklist style, without #941's helpers.]

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 9f0d0b8)

---------

Co-authored-by: Joachim Brand <j.brand@massey.ac.nz>
Co-authored-by: Valentin Churavy <v.churavy@gmail.com>
Co-authored-by: Simeon David Schaub <simeon@schaub.rocks>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Tim Esselens <tim.esselens@gmail.com>
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