Comments (2)
Confirmed to not be due to scalar indexing:
using Flux, SparseDiffTools, BenchmarkTools, CuArrays, ForwardDiff, LinearAlgebra, Random
CuArrays.allowscalar(false)
N = 10
T = Float32
A = rand(T, N,N)
cuA = A |> gpu
function f!(out, A)
out .= A .+ A .* A .+ 1f0
end
krn(x) = x + x*x + 1f0
function f!(out, A::CuMatrix{Float32})
out .= krn.(A)
end
function f(A)
return A .+ A .* A .+ 1f0
end
function f(A::CuMatrix{Float32})
return krn.(A)
end
J = rand(T, N^2, N^2)
@info "test cpu (inplace)"
cache = SparseDiffTools.ForwardColorJacCache(f!,A, dx = similar(A))
SparseDiffTools.forwarddiff_color_jacobian!(J, f!, A, cache)
(N<5) && @info "test ∇f cpu inplace: $(J)"
(N>5) && @btime SparseDiffTools.forwarddiff_color_jacobian!($J, $f!, $A, $cache)
@info "test cpu (out of place)"
cacheoos = SparseDiffTools.ForwardColorJacCache(f,A, dx = similar(A))
J = SparseDiffTools.forwarddiff_color_jacobian(f, A, cacheoos)
(N<5) && @info "test ∇f cpu oop: $(J)"
(N>5) && @btime SparseDiffTools.forwarddiff_color_jacobian($f, $A, $cacheoos)
@info "test gpu (inplace)"
cuJ = J |> gpu
cucache = SparseDiffTools.ForwardColorJacCache(f!,cuA, dx = similar(cuA))
SparseDiffTools.forwarddiff_color_jacobian!(cuJ, f!, cuA, cucache)
(N<5) && @info "test ∇f gpu inplace: $(cuJ)"
(N>5) && @btime SparseDiffTools.forwarddiff_color_jacobian!($cuJ, $f!, $cuA, $cucache)
@info "test gpu (outofplace)"
cucacheoop = SparseDiffTools.ForwardColorJacCache(f,cuA, dx = similar(cuA))
cuJ = SparseDiffTools.forwarddiff_color_jacobian(f, cuA, cucacheoop)
(N<5) && @info "test ∇f gpu oop: $(cuJ)"
(N>5) && @btime SparseDiffTools.forwarddiff_color_jacobian($f, $cuA, $cucacheoop)
The problem is likely the fact that https://github.com/JuliaDiff/SparseDiffTools.jl/blob/v1.8.0/src/differentiation/compute_jacobian_ad.jl#L123-L126 produces too many kernels. It's somewhat tied up with #106 and the upstream issue https://github.com/JuliaGPU/CuArrays.jl/issues/571
from sparsedifftools.jl.
#115 makes this much faster. I'll leave this open because it's not perfect (it now mutates), but the speed boost will essentially make this issue go away for most people.
from sparsedifftools.jl.
Related Issues (20)
- Support for structured sparsity in sparse hessian
- `BandedMatrix` sparsity computes only diagonal elements HOT 2
- Unable to compute sparse jacobian for reaction system (UndefVarError: m not defined) HOT 2
- tril
- Documentation offline HOT 2
- Todos for v2 HOT 4
- Doc badge leads to 403 Forbidden HOT 1
- needs comprehensive testing HOT 1
- ForwardColorJacCache error using partition by rows coloration HOT 4
- Release v2 HOT 2
- Typo in VecJac opnorm argument
- Invalid test group specified in CI
- Test failure related to StaticArrays and ArrayInterface HOT 2
- Code cleanup after #232
- Docs currently failing to load HOT 2
- Extend JacVec to have a speedy solution also for matrix multiplication?
- SparseDiffTools broken w/ Julia 1.8.5
- Incorrect kwarg, this should error or fail HOT 1
- Failed get_tag breaking gpu ode solve with Krylov_GMRES() linear solver
- Floating point arithmetic 101 - it doesn't add up! aka Don't touch user input without telling them the rules
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sparsedifftools.jl.