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

Bad performance #1

Open
maleadt opened this issue Mar 6, 2024 · 0 comments
Open

Bad performance #1

maleadt opened this issue Mar 6, 2024 · 0 comments

Comments

@maleadt
Copy link
Owner

maleadt commented Mar 6, 2024

Apparently this doesn't result in the expected speed-ups. Unsure why: JuliaGPU/GPUArrays.jl#454 (comment)

Simply providing the cartesian index statically like so is sufficient, at least with Metal's back-end compiler:

struct StaticCartesianIndices{N, I} end

StaticCartesianIndices(iter::CartesianIndices{N}) where {N} =
    StaticCartesianIndices{N, iter.indices}()
StaticCartesianIndices(x) = StaticCartesianIndices(CartesianIndices(x))

Base.CartesianIndices(iter::StaticCartesianIndices{N, I}) where {N, I} =
    CartesianIndices{N, typeof(I)}(I)

Base.@propagate_inbounds Base.getindex(I::StaticCartesianIndices, i::Int) =
    CartesianIndices(I)[i]
Base.length(I::StaticCartesianIndices) = length(CartesianIndices(I))

function Base.show(io::IO, I::StaticCartesianIndices)
    print(io, "Static")
    show(io, CartesianIndices(I))
end

Only relying on LLVM isn't sufficient, see JuliaGPU/GPUArrays.jl#454 (comment) and JuliaGPU/GPUArrays.jl#454 (comment)

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

No branches or pull requests

1 participant