JuliaGPU / JuliaGPU/KernelAbstractions.jl

Unroll factor compilation not available for Val values

Open
#665 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
523
Forks
88
Avg merge
1d 11h
Merged PRs (30d)
25

Description

I am trying to do the following:

using KernelAbstractions, CUDA
using KernelAbstractions.Extras: @unroll
backend = CUDABackend()

@kernel function add1_kernel!(A, ::Val{VALSPERTHREAD} = Val(4), ::Val{UNROLLFACTOR} = Val(4)) where {VALSPERTHREAD, UNROLLFACTOR}
    I = @index(Global,Linear)
    @unroll UNROLLFACTOR for i in 0:VALSPERTHREAD-1
        @inbounds A[I*4+i] = A[I*4+i]+1
    end
end

function myadd!(A)
    backend = get_backend(A)
    kernel = add1_kernel!(backend)
    kernel(A, ndrange = (Int(length(A)/4)))
    return
end

A = KernelAbstractions.zeros(backend, Float32, 64)
myadd!(A)
KernelAbstractions.synchronize(backend)

And getting an error:

ERROR: LoadError: Syntax error: `@unroll N expr` needs a constant integer N
Stacktrace:
 [1] error(s::String)
   @ Base .\error.jl:35
 [2] var"@unroll"(__source__::LineNumberNode, __module__::Module, N::Any, expr::Any)
   @ KernelAbstractions.Extras.LoopInfo C:\Users\evely\.julia\packages\KernelAbstractions\lGrz7\src\extras\loopinfo.jl:60
in expression starting at C:\Users\evely\NextLATuner\juliakernels\unrollparam.jl:7
in expression starting at C:\Users\evely\NextLATuner\juliakernels\unrollparam.jl:5

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example with the CUDA backend and read src/extras/loopinfo.jl around the @unroll implementation and its constant-integer check. Determine how Val parameters reach the macro, then add support if appropriate and verify that the shown kernel compiles and runs without the syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.