JuliaGPU / JuliaGPU/KernelAbstractions.jl

creation of a subarray for function calls results in an error with throw_checksize_error

Open
#275 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
523
Forks
88
Avg merge
1d 11h
Merged PRs (30d)
25

Description

Here's the mwe:
```
using Test
using CUDA
using CUDAKernels
using KernelAbstractions

function check(input, tid)
end

@kernel function f_test_kernel!(input)
tid = @index(Global, Linear)
check(input[:], tid)

end

function f_test!(input; numcores = 4, numthreads = 256)

if isa(input, Array)
kernel! = f_test_kernel!(CPU(), numcores)
else
kernel! = f_test_kernel!(CUDADevice(), numthreads)
end

kernel!(input, ndrange=size(input))
end
```

Gotta be honest, I am not sure if this behavior should be allowed, but I could imagine a case where people want to index along different subarray or something. I think there are almost always workarounds for this that make more sense in parallel.

As a note, `input[:] = 0` should probably also be disallowed for a similar reason; however, if we want to support this type of behavior, we could create an override for the checksize error. The issue is that it allocates a string for the error:

```
@noinline throw_checksize_error(A, sz) = throw(DimensionMismatch("output array is the wrong size; expected $sz, got $(size(A))"))
```

I am leaving this as an issue because it's not pressing to fix for me, but I figured someone should mention it.

For the record, I did try something like this:

```
#@inline Cassette.overdub(::$Ctx, ::Core.Typeof(Base.throw_checksize_error), args...) = throw(DimensionMismatch("output array is the wrong size; expected $args[2], got $(size(args[1]))"))
```

But it didn't work

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by running the supplied MWE around f_test_kernel!, check(input[:], tid), and Base.throw_checksize_error. Determine whether subarray creation and input[:] assignment should be supported in kernels or rejected, then inspect the resulting size-check path and add coverage for the chosen behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
hpc
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.