-
Notifications
You must be signed in to change notification settings - Fork 110
Port stress/response calculations to the GPU #1187
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
Changes from 6 commits
5168fdb
0e1597f
25d26f7
f881486
10b206b
033c3f3
5bf18c3
c753c5f
8300e55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,9 +31,9 @@ end | |
| function LinearAlgebra.mul!(y::AbstractArray{<:Union{Complex{<:Dual}}}, | ||
| p::AbstractFFTs.Plan, | ||
| x::AbstractArray{<:Union{Complex{<:Dual}}}) | ||
| copyto!(y, p*x) | ||
| copyto!(y, _mul(p, x)) | ||
| end | ||
| function Base.:*(p::AbstractFFTs.Plan, x::AbstractArray{<:Complex{<:Dual{Tg}}}) where {Tg} | ||
| function _mul(p::AbstractFFTs.Plan, x::AbstractArray{<:Complex{<:Dual{Tg}}}) where {Tg} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again this feels strange and is surprising to me. Why did you need this ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this workaround, the GPU compiler throws an
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, this we need to understand. @niklasschmitz I recall we anyway only needed this because on the AbstractFFT side this was not properly supported. Could it be that now it is and we can drop our type piracy workaround alltogether ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
CUDA.jl overloads
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So it's a bug in CUDA.jl, effectively ? Their typing is too broad as it covers Duals, which they don't support ?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's my understanding, yes.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Once there is an issue opened and referenced here (please |
||
| # TODO do we want x::AbstractArray{<:Dual{T}} too? | ||
| xtil = p * ForwardDiff.value.(x) | ||
| dxtils = ntuple(ForwardDiff.npartials(eltype(x))) do n | ||
|
|
@@ -46,6 +46,8 @@ function Base.:*(p::AbstractFFTs.Plan, x::AbstractArray{<:Complex{<:Dual{Tg}}}) | |
| ) | ||
| end | ||
| end | ||
| Base.:*(p::AbstractFFTs.Plan, x::AbstractArray{<:Complex{<:Dual}}) = _mul(p, x) | ||
| Base.:*(p::DummyInplace, x::AbstractArray{<:Union{Complex{<:Dual}}}) = copyto!(x, _mul(p.fft, x)) | ||
|
|
||
| function build_fft_plans!(tmp::AbstractArray{Complex{T}}) where {T<:Dual} | ||
| opFFT = AbstractFFTs.plan_fft(tmp) | ||
|
|
@@ -230,9 +232,9 @@ end | |
|
|
||
|
|
||
| @timing "self_consistent_field ForwardDiff" function self_consistent_field( | ||
| basis_dual::PlaneWaveBasis{T}; | ||
| basis_dual::PlaneWaveBasis{<:Dual{Tg,V,N}}; | ||
| response=ResponseOptions(), | ||
| kwargs...) where {T <: Dual} | ||
| kwargs...) where {Tg,V,N} | ||
| # Note: No guarantees on this interface yet. | ||
|
|
||
| # Primal pass | ||
|
|
@@ -251,28 +253,28 @@ end | |
| end | ||
| # Implicit differentiation | ||
| response.verbose && println("Solving response problem") | ||
| δresults = ntuple(ForwardDiff.npartials(T)) do α | ||
| δresults = ntuple(N) do α | ||
| δHextψ = [ForwardDiff.partials.(δHextψk, α) for δHextψk in Hψ_dual] | ||
| δtemperature = ForwardDiff.partials(basis_dual.model.temperature, α) | ||
| solve_ΩplusK_split(scfres, δHextψ; δtemperature, | ||
| tol=last(scfres.history_Δρ), response.verbose) | ||
| end | ||
|
|
||
| # Convert and combine | ||
| DT = Dual{ForwardDiff.tagtype(T)} | ||
| ψ = map(scfres.ψ, getfield.(δresults, :δψ)...) do ψk, δψk... | ||
| map(ψk, δψk...) do ψnk, δψnk... | ||
| Complex(DT(real(ψnk), real.(δψnk)), | ||
| DT(imag(ψnk), imag.(δψnk))) | ||
| Complex(Dual{Tg}(real(ψnk), real.(δψnk)), | ||
| Dual{Tg}(imag(ψnk), imag.(δψnk))) | ||
| end | ||
| end | ||
| eigenvalues = map(scfres.eigenvalues, getfield.(δresults, :δeigenvalues)...) do εk, δεk... | ||
| map((εnk, δεnk...) -> DT(εnk, δεnk), εk, δεk...) | ||
| map((εnk, δεnk...) -> Dual{Tg}(εnk, δεnk), εk, δεk...) | ||
|
mfherbst marked this conversation as resolved.
|
||
| end | ||
| occupation = map(scfres.occupation, getfield.(δresults, :δoccupation)...) do occk, δocck... | ||
| map((occnk, δoccnk...) -> DT(occnk, δoccnk), occk, δocck...) | ||
| occk_cpu = to_cpu(occk) | ||
| to_device(basis_dual.architecture, map(Dual{Tg}, occk_cpu, δocck...)) | ||
| end | ||
| εF = DT(scfres.εF, getfield.(δresults, :δεF)...) | ||
| εF = Dual{Tg}(scfres.εF, getfield.(δresults, :δεF)...) | ||
|
|
||
| # For strain, basis_dual contributes an explicit lattice contribution which | ||
| # is not contained in δresults, so we need to recompute ρ here | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.