Uh oh!
There was an error while loading. Please reload this page.
Make seed! and extract_jacobian! gpu-friendly - #472
Conversation
Interestingly, when trying ip = Iterators.product(ydual, 1:n)
out_reshaped .=map(rc->partials(T, rc[1], rc[2]), ip)I can see in the GPU stack trace: ERROR: GPU compilation of kernel broadcast_kernel(CUDA.CuKernelContext, CuDeviceArray{Float32,2,1}, Base.Broadcast.Broadcasted{Nothing,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}},typeof(identity),Tuple{Base.Broadcast.Extruded{Array{Float32,2},Tuple{Bool,Bool},Tuple{Int64,Int64}}}}, Int64) failed
KernelError: passing and using non-bitstype argument
Argument 4 to your kernel function is of type Base.Broadcast.Broadcasted{Nothing,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}},typeof(identity),Tuple{Base.Broadcast.Extruded{Array{Float32,2},Tuple{Bool,Bool},Tuple{Int64,Int64}}}}, which is not isbits:.args is of type Tuple{Base.Broadcast.Extruded{Array{Float32,2},Tuple{Bool,Bool},Tuple{Int64,Int64}}} which is not isbits.
.1 is of type Base.Broadcast.Extruded{Array{Float32,2},Tuple{Bool,Bool},Tuple{Int64,Int64}} which is not isbits.
.x is of type Array{Float32,2} which is not isbits.that the array in Not sure who to ping here |
Uh oh!
There was an error while loading. Please reload this page.
a08d02d to
b6e6984CompareAlright, I worked out the issue with using ForwardDiff, BenchmarkTools
x =rand(1000);
cfg = ForwardDiff.GradientConfig(nothing, x);
@btime ForwardDiff.seed!($(cfg.duals), $x, $(cfg.seeds));Results in 0 allocations, and using CUDA, ForwardDiff, Test;
CUDA.allowscalar(false);
functionf!(F, x)
t =Tuple(x)
F_nt =ntuple(Val(length(F))) do i
i==1&& (F_i = (t[1] +3) * (t[2]^3-7) +18)
i==2&& (F_i =sin(t[2] *exp(t[1]) -1))
F_i
end
F .= F_nt
end;
x_initial = CUDA.CuArray(Float32[0.1; 1.2]);
# x_initial = Float32[0.1; 1.2];
J =similar(x_initial, (length(x_initial),length(x_initial)));
F =similar(x_initial);
Ja =[-5.27213.3921.256271.04689]
ForwardDiff.jacobian!(J, f!, F, x_initial);
@testall(Array(J) .≈ Ja)passes. |
Uh oh!
There was an error while loading. Please reload this page.
b6e6984 to
f39a36bCompareseeds! and extract_jacobian! gpu-friendlyseed! and extract_jacobian! gpu-friendlyOk, looks like Travis is passing. Some of AppVeyor is, too, but it looks like Windows has not consistently passed in CI. |
simonbyrne
commented
Nov 11, 2020
This would be a good candidate for the julialang GPU CI. |
charleskawczynski
commented
Nov 16, 2020
bump |
oxinabox
left a comment
There was a problem hiding this comment.
LGTM, though some small comments about naming thing and using vec for reshaping to a vector.
This might be a tiny bit slower than it is now for extract_jacobian_chunk!,
but i think it probably optimized out, at least in 1.5, and that is not perforance critical anyway, so if this gets us GPU support than that is a win.
Please bump the version number as a non-breaking change.
Strong agreement re: setting up JuliaGPU tests, but I won't block the PR over that.
Once these things are addressed I will merge.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
f39a36b to
b4cb1acComparecharleskawczynski
commented
Nov 17, 2020
I changed to
I bumped |
KristofferC
commented
Nov 17, 2020
How did the benchmark show 0 allocations when views and broadcasting were missed in some places? Where those not benchmarked? Would be good to ensure all the stuff changed here has been benchmarked and confirmed not to allocate. |
Where were views/broadcasts missing? I agree that adding a test would be nice. I'll see if I can add that somewhere. The only piece I checked locally was julia>using ForwardDiff, BenchmarkTools
julia> x =rand(1000);
julia> cfg = ForwardDiff.GradientConfig(nothing, x);
julia>@btime ForwardDiff.seed!($(cfg.duals), $x, $(cfg.seeds));
54.821 ns (0 allocations:0 bytes) |
KristofferC
commented
Nov 17, 2020
I though e.g #472 (comment) would have caused allocations. |
charleskawczynski
commented
Nov 17, 2020
I must have had the view in the For good measure, I added |
Ah, glad I added the tests, I just realized that I missed one method (the |
Alright, now all of the |
f303aea to
a5b9e7fComparecharleskawczynski
commented
Nov 17, 2020
Ok, I also squashed. I think this should be ready to go. |
Allocation tests are failing on julia 1.4 and 1.0. The failure on nightly is unrelated and is fixed by |
| x = rand(1000) | ||
| cfg = ForwardDiff.GradientConfig(nothing, x) | ||
| balloc = @ballocated ForwardDiff.seed!($(cfg.duals), $x, $(cfg.seeds)) |
There was a problem hiding this comment.
Doesn't just @allocated work?
There was a problem hiding this comment.
I tried, but I wasn't able to interpolate with @allocated, so it results in non-zero allocations.
There was a problem hiding this comment.
Actually, it looks like we can use @allocated, we'll just need to duplicate the calls and remove the getproperty/getindex in the calls:
@testset"Test seed! allocations"begin
x =rand(1000)
cfg = ForwardDiff.GradientConfig(nothing, x)
duals = cfg.duals
seeds = cfg.seeds
seed = cfg.seeds[1]
alloc =@allocated ForwardDiff.seed!(duals, x, seeds)
alloc =@allocated ForwardDiff.seed!(duals, x, seeds)
@test alloc ==0
alloc =@allocated ForwardDiff.seed!(duals, x, seed)
alloc =@allocated ForwardDiff.seed!(duals, x, seed)
@test alloc ==0
index =1
alloc =@allocated ForwardDiff.seed!(duals, x, index, seeds)
alloc =@allocated ForwardDiff.seed!(duals, x, index, seeds)
@test alloc ==0
index =1
alloc =@allocated ForwardDiff.seed!(duals, x, index, seed)
alloc =@allocated ForwardDiff.seed!(duals, x, index, seed)
@test alloc ==0endLet me know which one is preferred
There was a problem hiding this comment.
I think that originally (in e.g. 1.0) julia tried to excluded compilation from the output of @allocated, but that proved unreliable, and so that was removed in 1.4 (ish?).
In response to that I added @ballocated to BenchmarkTools that just pulled the allocations out of the fastest run according to @benchmark (which will naturally not be the one that included the timing).
I think @ballocated is nicer than duplicating personally, but I will defer to others.
There was a problem hiding this comment.
I agree that @ballocated seems nicer, but I'll also defer to others as this is my first PR to this repo.
There was a problem hiding this comment.
@ballocated doesn't really make sense to me. You run the function thousands of time and then pick out the lowest one. For functions that don't allocate, that will be the second run. So why run the function 998 more times? Seems like it will just slow down the test suite.
There was a problem hiding this comment.
Ok, I'll switch to the code snippet above
charleskawczynski
commented
Nov 18, 2020
Ah, good point. I'll update to test on 1.5 and above. |
23ed88e to
46bd294Comparecharleskawczynski
commented
Nov 27, 2020
Bump |
46bd294 to
3b6f62bCompareUse broadcast/macro consistently Fix jac Add AllocationsTest.jl
3b6f62b to
e0be439Comparecharleskawczynski
commented
Nov 30, 2020
Rebased and re-bumped the version. |
Per @vchuravy's suggestion to open a new PR: Now that JuliaLang/julia#14955 is resolved, this PR revives the work of #353 and #406.