JuliaGPU / CLArrays.jl

OpenCL-backed GPU Arrays
Other
62 stars 12 forks source link

Fast way of populating matrices? #28

Closed dlfivefifty closed 6 years ago

dlfivefifty commented 6 years ago

I'm trying to set entries of a CLArray to a constant but it's much slower than just creating a new Array and converting it:

julia> A = CLArray{Float32}(100);

julia> @time A[:] .= 1;
  0.021409 seconds (522 allocations: 17.656 KiB)

julia> @time A[:] = 1;
  0.022855 seconds (505 allocations: 17.359 KiB)

julia> function foo(A)
       A[:] = 1
       end
foo (generic function with 1 method)

julia> @time foo(A);
  0.022989 seconds (505 allocations: 17.359 KiB)

julia> @time convert(CLArray, ones(Float32,100))
  0.000824 seconds (107 allocations: 4.484 KiB)
SimonDanisch commented 6 years ago

ah, that might hit a slow path...Did you check with GPUArrays.allowslow(false)?

dlfivefifty commented 6 years ago
julia> A[:] = 1
ERROR: setindex! is disabled
Stacktrace:
 [1] assertslow(::String) at /Users/sheehanolver/.julia/v0.6/GPUArrays/src/indexing.jl:6
 [2] setindex! at /Users/sheehanolver/.julia/v0.6/GPUArrays/src/indexing.jl:30 [inlined]
 [3] setindex!(::CLArrays.CLArray{Float32,1}, ::Int64, ::Int64) at /Users/sheehanolver/.julia/v0.6/GPUArrays/src/indexing.jl:34
 [4] macro expansion at ./multidimensional.jl:558 [inlined]
 [5] macro expansion at ./cartesian.jl:64 [inlined]
 [6] macro expansion at ./multidimensional.jl:556 [inlined]
 [7] _unsafe_setindex!(::IndexLinear, ::CLArrays.CLArray{Float32,1}, ::Int64, ::Base.Slice{Base.OneTo{Int64}}) at ./multidimensional.jl:549
 [8] macro expansion at ./multidimensional.jl:541 [inlined]
 [9] _setindex! at ./multidimensional.jl:537 [inlined]
 [10] setindex!(::CLArrays.CLArray{Float32,1}, ::Int64, ::Colon) at ./abstractarray.jl:968