[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

Better handling of slices f(A[i,:]) etc. #20

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Better handling of slices f(A[i,:]) etc. #20

wants to merge 5 commits into from

Conversation

mcabbott
Copy link
Owner

Somewhat unexpectedly, some mapslices-like things already work:

julia> f(scalar, row, num) = sum(row .+ num)/scalar;

julia> s = 2; m = rand(Int8, 4,4); a = rand(1:9, 4);

julia> @tullio z[_,r] := f(s, m[r,:], a[r])
1×4 Array{Float64,2}:
 -25.5  -6.0  9.0  182.0

julia> @tullio z[_,r] := f(s, m[r,:], a[r])  threads=false verbose=true
[ Info: running KernelAbstractions CPU actor
1×4 Array{Float64,2}:
 -25.5  -6.0  9.0  182.0

julia> f.(s, eachrow(m), a)'
1×4 Adjoint{Float64,Array{Float64,1}}:
 -25.5  -6.0  9.0  182.0

Perhaps following https://github.com/SciML/DiffEqGPU.jl/blob/master/src/DiffEqGPU.jl they can be made to work on the GPU too.

And perhaps there should be tests & slightly better support for such things, e.g. to avoid this:

julia> m2 = similar(m, Int);

julia> @tullio m2[:,i] = cumsum(m[i,:])
ERROR: LoadError: unable to infer range of index :

@mcabbott
Copy link
Owner Author
mcabbott commented Jul 30, 2020

Kernel that works on CPU only: @tullio z[r] := sum(m[r,:]) now gives this:

@kernel function kern(res::AbstractArray{T}, @Const(m), @Const(ax_r), @Const(keep), @Const(final)) where T
    (r,) = @index(Global, NTuple)
    @views begin
        res[r] = if isnothing(keep)
            sum(m[r, :])
        else
            res[r] + sum(m[r, :])
        end
    end
end

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