Skip to content
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

Make some computations in DFTK GPU-compatible #712

Merged
merged 98 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 91 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
e17fb59
LOBPCG with GPU support (CUDA). Does not yet support preconditionning
GVigne Jul 6, 2022
e80f5b6
Merge branch 'master' into gpu_hpc
GVigne Jul 8, 2022
ed15b32
MWE for self_consistent_field with GPU support (CUDA). Only works wit…
GVigne Jul 18, 2022
19bfa69
Fix package version conflicts while merging
GVigne Jul 18, 2022
f4748ac
Stop using BlockArrays and use a custom BlockVector for GPU compatibi…
GVigne Jul 20, 2022
94f1d2a
GPU support for AtomicLocal term
GVigne Jul 22, 2022
60d8041
First GPU implementation of the non local term + LOBPCG enhancement
GVigne Jul 25, 2022
fb6484a
Merge branch 'master' into gpu_hpc
GVigne Jul 25, 2022
cf1dc3c
add timed examples
mfherbst Jul 25, 2022
11b85f0
Change some code organisation after PR's feedback
GVigne Jul 28, 2022
abb99f4
Code organisation and performance optimisation after PR's feedback
GVigne Jul 28, 2022
a89171a
Code refactoring following PR's feedback
GVigne Aug 2, 2022
44bcb61
PWB is now parametric on the array type: this also fixes type issues
GVigne Aug 9, 2022
646b44c
Update workarounds: remove iszero and isone, add eigen
GVigne Aug 16, 2022
76c697d
Rename block_mul into * + build e on GPU
GVigne Aug 22, 2022
bd684d7
Modify the change of basis functions to be GPU compatible
GVigne Aug 23, 2022
f02c954
Merge branch 'master' into gpu_hpc
GVigne Aug 23, 2022
15d1324
Keep this branch synced with LOBPCG_GPU
GVigne Aug 23, 2022
62d9f79
Add the Hartree term
GVigne Aug 23, 2022
19100cf
Remove CUDA dependency from ortho_qr
GVigne Aug 23, 2022
1184ec1
Bugfix when plotting bandstructure + typo fixes
GVigne Aug 29, 2022
833928b
Make all mixings except Chi0 mixing GPu compatible
GVigne Aug 30, 2022
e12f35b
Prettier way to overload eigen for CuArrays
GVigne Sep 1, 2022
a0c4066
Update comments + remove unnecessary code
GVigne Sep 6, 2022
9cdff93
Update the GPU example
GVigne Sep 6, 2022
20b7b10
Put the Gvectors for each kpoint on the GPU
GVigne Sep 7, 2022
a2d811b
Bugfix after launching the tests
GVigne Sep 7, 2022
8ee55a4
Put the occupation on GPU
GVigne Sep 7, 2022
7909720
Merge branch 'master' into gpu_hpc
GVigne Sep 7, 2022
b700d1c
GPU compatibility for Anderson acceleration
GVigne Oct 5, 2022
981e7a1
Remove unnecessary dependencies
GVigne Oct 6, 2022
272ff85
Merge commit '7bd07e3cbbe847ad71eb2f7f2524d1ff70e47b5b' into gpu_hpc
GVigne Oct 6, 2022
c8af93d
Merge commit 'b83c3cc3c3b3f551970aa8bda1379203f6797669' into gpu_hpc
GVigne Oct 6, 2022
acd4bef
Merge commit '3448b533d3486278bda44689963c72d5168e83fa' into gpu_hpc
GVigne Oct 6, 2022
06b07cc
Merge commit 'a96f551ed78a47f6cbd5280fedf08f6a7443d31e' into gpu_hpc
GVigne Oct 6, 2022
8b294da
Merge commit 'd28391e6ffb366168fc43ea61e5cac9d04b252e3' into gpu_hpc
GVigne Oct 6, 2022
b5b0d09
Merge commit '3ce3b2c5e84f728d12b8e74792ecd31c24ddd5e0' into gpu_hpc
GVigne Oct 6, 2022
9177e8b
Merge commit '353c11f1871adffae8bcbad9aadb95faa929f718' into gpu_hpc
GVigne Oct 6, 2022
5c3b620
Crude bugfix for the nbands algorithm
GVigne Oct 6, 2022
bf77db2
Less CPU-GPU transfers in guess_density + whitespaces
GVigne Oct 6, 2022
ce05d66
Merge branch 'master' into gpu_hpc
GVigne Oct 11, 2022
0c8067e
Whitespaces, typos + stick to the same conventions
GVigne Oct 11, 2022
95fe043
Merge branch 'master' into gpu_hpc
GVigne Oct 13, 2022
b511225
Removed unnecessary imports
GVigne Oct 14, 2022
28e05e7
WIP: solve dependency issues
GVigne Oct 14, 2022
1c5a5b5
Adapt the workarounds for forward differentiation to the new API
GVigne Oct 14, 2022
06eb5b6
WIP: remove TaskLocalRNG for julia versions < 1.6
GVigne Oct 14, 2022
de28ac4
Better fallback for TaskLocalRng for Julia < 1.6
GVigne Oct 14, 2022
866d6bf
Change build_fft_plans in fft_generic.jl to take arrays as arguments
GVigne Oct 14, 2022
2008199
Merge branch 'master' into gpu_hpc
GVigne Oct 17, 2022
7ad1744
Fixes
mfherbst Oct 17, 2022
278a001
Merge commit '175937aaff610da98b5606f06dbaf62029af31e0' into gpu_hpc
GVigne Oct 24, 2022
a3e9acc
Merge commit '9381bf4e250f633673958e9f90c47faffc8a7144' into gpu_hpc
GVigne Oct 24, 2022
682dbde
Merge commit '3b1bffff7f116ad239fbea17cae1acc150213736' into gpu_hpc
GVigne Oct 24, 2022
ca75332
Merge commit '5f24d3dbde5aa71f4c3367f0ba5558fefd22dada' into gpu_hpc
GVigne Oct 24, 2022
f6e45b9
Fix tests
GVigne Oct 24, 2022
bd4e315
Update examples/gpu.jl
mfherbst Oct 26, 2022
a339a4d
Fix CPU performance bug when using FFTs
GVigne Oct 28, 2022
695263a
WIP: remove the AT type in PWB
GVigne Nov 2, 2022
7afc5fd
WIP: copy_like also takes Type arguments
GVigne Nov 2, 2022
2563c58
Remove AT parameter from PWB
GVigne Nov 2, 2022
2d17ebc
Merge commit '6e6d523b4780f43cc534153bd1de929907295bf4' into gpu_hpc
GVigne Nov 2, 2022
8088d67
Merge branch 'master' into gpu_hpc
GVigne Nov 2, 2022
d9d9da1
Add Kpoints's array type as a parametric type in PWB
GVigne Nov 3, 2022
0a69e2c
Fix serialization test
GVigne Nov 3, 2022
b4e6fd5
Merge branch 'master' into gpu_hpc
mfherbst Nov 5, 2022
ecfd306
Fix example
mfherbst Nov 5, 2022
3401d79
Merge branch 'master' into gpu_hpc
mfherbst Nov 5, 2022
4c45977
Simplify coordinate transformation routines
mfherbst Nov 8, 2022
5e4d37a
More refactoring ... barely tested, might fail
mfherbst Nov 8, 2022
6dc6c82
Fixes
mfherbst Nov 8, 2022
a6fe22b
Remove array_type and use AbstractArchitecture structure instead
GVigne Nov 9, 2022
6e12d3a
Merge branch 'master' into gpu_hpc
GVigne Nov 9, 2022
866598c
Fixes
GVigne Nov 9, 2022
0bcd3d1
Fix failing tests
GVigne Nov 9, 2022
d13fa56
Code clarification and better comments
GVigne Nov 15, 2022
085ca99
Refactoring/code cleanup
GVigne Nov 15, 2022
9d72ba0
Merge branch 'master' into gpu_hpc
GVigne Nov 15, 2022
8c6ac54
Replace sum(abs2(...)) by norm2 function
GVigne Nov 16, 2022
a02cd21
Bugfix: extend norm2 to any array
GVigne Nov 16, 2022
0d845fc
Merge branch 'master' into gpu_hpc
GVigne Nov 16, 2022
349b8f1
Remove convert_like and add to_device
GVigne Nov 17, 2022
778712d
Update comments and docstring
GVigne Nov 17, 2022
c39ee19
Enforce the use of to_cpu instead of Array when doing GPU-CPU transfers
GVigne Nov 17, 2022
4501bd9
Small polishing
mfherbst Nov 18, 2022
60506b9
Formatting, updating comments and small nits
GVigne Nov 21, 2022
147c81d
Remove architecture argument from G_vectors + infer type in kinetic_e…
GVigne Nov 21, 2022
da1ac09
Merge branch 'gpu_hpc' of github.com:GVigne/DFTK.jl into gpu_hpc
GVigne Nov 21, 2022
8a40af5
Inline _closure_matmatmul
GVigne Nov 21, 2022
5ee546b
Rename closures and small changes to ortho_qr and build_kpoints
GVigne Nov 21, 2022
b7b611a
Hard-code CPU architecture
mfherbst Nov 21, 2022
fbe675d
Merge branch 'master' into gpu_hpc
mfherbst Nov 22, 2022
d7be3a6
Reformat basis
mfherbst Nov 22, 2022
482d3b2
Docs concurrency
mfherbst Nov 22, 2022
7070487
Value type instead of real type.
mfherbst Nov 22, 2022
cf3fbf8
Minor nits: broadcast norm2, more type inference
GVigne Nov 22, 2022
dec0653
Merge branch 'gpu_hpc' of github.com:GVigne/DFTK.jl into gpu_hpc
GVigne Nov 22, 2022
ff0d9b0
Update xc.jl
mfherbst Nov 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProgressMeter = "92933f4c-e287-5a05-a399-4b506db050ca"
PseudoPotentialIO = "cb339c56-07fa-4cb2-923a-142469552264"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Roots = "f2b01f46-fcfa-551c-844a-d8ac1e96c665"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand Down
19 changes: 19 additions & 0 deletions examples/gpu.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using DFTK
using CUDA

a = 10.26 # Silicon lattice constant in Bohr
lattice = a / 2 * [[0 1 1.];
[1 0 1.];
[1 1 0.]]
Si = ElementPsp(:Si, psp=load_psp("hgh/lda/Si-q4"))
atoms = [Si, Si]
positions = [ones(3)/8, -ones(3)/8]
model = model_DFT(lattice, atoms, positions, []; temperature=1e-3)

# If available, use CUDA to store DFT quantities and perform main computations
architecture = has_cuda() ? DFTK.GPU(CuArray) : DFTK.CPU()

basis = PlaneWaveBasis(model; Ecut=30, kgrid=(1, 1, 1), architecture)
scfres = self_consistent_field(basis; tol=1e-3,
solver=scf_damping_solver(),
mixing=KerkerMixing())
4 changes: 4 additions & 0 deletions src/DFTK.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ using spglib_jll
using Unitful
using UnitfulAtomic
using ForwardDiff
using AbstractFFTs
using GPUArraysCore
using Random
using ChainRulesCore

export Vec3
Expand All @@ -31,6 +34,7 @@ include("common/mpi.jl")
include("common/threading.jl")
include("common/printing.jl")
include("common/cis2pi.jl")
include("architecture.jl")
include("common/zeros_like.jl")
include("common/norm.jl")

Expand Down
39 changes: 29 additions & 10 deletions src/Model.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,25 @@ Examples of covectors are forces.
Reciprocal vectors are a special case: they are covectors, but conventionally have an
additional factor of 2π in their definition, so they transform rather with 2π times the
inverse lattice transpose: q_cart = 2π lattice' \ q_red = recip_lattice * q_red.

For each of the function there is a one-argument version (returning a function to do the
transformation) and a two-argument version applying the transformation to a passed vector.
=#
vector_red_to_cart(model::Model, rred) = model.lattice * rred
vector_cart_to_red(model::Model, rcart) = model.inv_lattice * rcart
covector_red_to_cart(model::Model, fred) = model.inv_lattice' * fred
covector_cart_to_red(model::Model, fcart) = model.lattice' * fcart
recip_vector_red_to_cart(model::Model, qred) = model.recip_lattice * qred
recip_vector_cart_to_red(model::Model, qcart) = model.inv_recip_lattice * qcart
@inline _gen_matmul(mat) = vec -> mat * vec

vector_red_to_cart(model::Model) = _gen_matmul(model.lattice)
vector_cart_to_red(model::Model) = _gen_matmul(model.inv_lattice)
covector_red_to_cart(model::Model) = _gen_matmul(model.inv_lattice')
covector_cart_to_red(model::Model) = _gen_matmul(model.lattice')
recip_vector_red_to_cart(model::Model) = _gen_matmul(model.recip_lattice)
recip_vector_cart_to_red(model::Model) = _gen_matmul(model.inv_recip_lattice)

vector_red_to_cart(model::Model, vec) = vector_red_to_cart(model)(vec)
mfherbst marked this conversation as resolved.
Show resolved Hide resolved
vector_cart_to_red(model::Model, vec) = vector_cart_to_red(model)(vec)
covector_red_to_cart(model::Model, vec) = covector_red_to_cart(model)(vec)
covector_cart_to_red(model::Model, vec) = covector_cart_to_red(model)(vec)
recip_vector_red_to_cart(model::Model, vec) = recip_vector_red_to_cart(model)(vec)
recip_vector_cart_to_red(model::Model, vec) = recip_vector_cart_to_red(model)(vec)

#=
Transformations on vectors and covectors are matrices and comatrices.
Expand All @@ -300,7 +312,14 @@ s_cart = L s_red = L A_red r_red = L A_red L⁻¹ r_cart, thus A_cart = L A_red
Examples of matrices are the symmetries in real space (W)
Examples of comatrices are the symmetries in reciprocal space (S)
=#
matrix_red_to_cart(model::Model, Ared) = model.lattice * Ared * model.inv_lattice
matrix_cart_to_red(model::Model, Acart) = model.inv_lattice * Acart * model.lattice
comatrix_red_to_cart(model::Model, Bred) = model.inv_lattice' * Bred * model.lattice'
comatrix_cart_to_red(model::Model, Bcart) = model.lattice' * Bcart * model.inv_lattice'
@inline _gen_matmatmul(M, Minv) = mat -> M * mat * Minv

matrix_red_to_cart(model::Model) = _gen_matmatmul(model.lattice, model.inv_lattice)
matrix_cart_to_red(model::Model) = _gen_matmatmul(model.inv_lattice, model.lattice)
comatrix_red_to_cart(model::Model) = _gen_matmatmul(model.inv_lattice', model.lattice')
comatrix_cart_to_red(model::Model) = _gen_matmatmul(model.lattice', model.inv_lattice')

matrix_red_to_cart(model::Model, Ared) = matrix_red_to_cart(model)(Ared)
matrix_cart_to_red(model::Model, Acart) = matrix_cart_to_red(model)(Acart)
comatrix_red_to_cart(model::Model, Bred) = comatrix_red_to_cart(model)(Bred)
comatrix_cart_to_red(model::Model, Bcart) = comatrix_cart_to_red(model)(Bcart)
Loading