mcabbott / SliceMap.jl

Same-same but different
Other
31 stars 3 forks source link

mapcols return CPU arrays with GPU input #4

Open baggepinnen opened 4 years ago

baggepinnen commented 4 years ago
julia> using SliceMap, Flux

julia> mapcols(norm, gpu(Flux.param(randn(2,2))))
Tracked 1×2 Array{Float32,2}:
 1.98362  0.443408

julia> mapcols(norm, gpu(randn(2,2)))
1×2 Array{Float32,2}:
 0.891582  3.15292

Possibly because norm returns a scalar?

mcabbott commented 4 years ago

Yes, for scalars I called surevec(x) = [x] before reducing, which made an Array always.

I tried two things on master to improve things. The first made a small CuArray from each scalar instead, and then reduce(hcat, …) made a CuArray. But then the gradient wants to take first() of each of them, which gives a warning. The second was just to return map(f, eachcol(M)) pretty much. But then I realised that’s also an ordinary array. Surely there is a good solution to this.

mcabbott commented 4 years ago

Related thread: https://discourse.julialang.org/t/map-performance-with-cuarrays/33497/10

Are there functions for which some variant of f.(eachcol(cu(x))) does make sense? i.e. for which mapping over slices of a CuArray is useful & fast?