Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve CUDA kernels #1128

Open
simonbyrne opened this issue Feb 23, 2023 · 1 comment
Open

Improve CUDA kernels #1128

simonbyrne opened this issue Feb 23, 2023 · 1 comment
Assignees

Comments

@simonbyrne
Copy link
Member

simonbyrne commented Feb 23, 2023

Using fortran style 1D indexing on the parent, with any required assertions done upstream, might be easiest for some kernels. E.g.:

function Base.copyto!(
    dest::IJFH{S, Nij},
    bc::Union{IJFH{S, Nij, A}, Base.Broadcast.Broadcasted{IJFHStyle{Nij, A}}},
) where {S, Nij, A <: CUDA.CuArray}
    nitems = length(parent(dest))
    max_threads = 256 # can be higher if conditions permit
    nthreads = min(max_threads, nitems)
    nblocks = cld(nitems, nthreads)
    pdest, pbc = parent(dest), parent(bc)
    CUDA.@cuda threads = (nthreads) blocks = (nblocks) knl_copyto!(pdest, pbc)
    return dest
end

function knl_copyto!(dest, src)
    nitems = length(dest)
    gidx = threadIdx().x + (blockIdx().x - 1) * blockDim().x

    if gidx < nitems
        @inbounds dest[gidx] = p_src[gidx]
    end
    return nothing
end

Originally posted by @sriharshakandala in #767 (comment)

@sriharshakandala sriharshakandala self-assigned this Apr 4, 2023
@sriharshakandala sriharshakandala linked a pull request Apr 4, 2023 that will close this issue
4 tasks
@sriharshakandala
Copy link
Member

sriharshakandala commented Feb 26, 2024

We can try

cartidx = CartesianIndices(dest)[gidx]

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 a pull request may close this issue.

2 participants