phono3py-gpu 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- phono3py_gpu/__init__.py +19 -0
- phono3py_gpu/_wte.py +521 -0
- phono3py_gpu/backend.py +65 -0
- phono3py_gpu/batching.py +211 -0
- phono3py_gpu/collision.py +432 -0
- phono3py_gpu/eigensolver.py +222 -0
- phono3py_gpu/factory.py +353 -0
- phono3py_gpu/fourier.py +474 -0
- phono3py_gpu/harmonic.py +258 -0
- phono3py_gpu/initialization.py +50 -0
- phono3py_gpu/integration.py +183 -0
- phono3py_gpu/interaction.py +270 -0
- phono3py_gpu/isotope.py +116 -0
- phono3py_gpu/kappa.py +39 -0
- phono3py_gpu/kernels/collision.cu +11 -0
- phono3py_gpu/kernels/degeneracy.cu +36 -0
- phono3py_gpu/kernels/interaction.cu +89 -0
- phono3py_gpu/kernels/isotope.cu +28 -0
- phono3py_gpu/kernels/scattering.cu +85 -0
- phono3py_gpu/kernels/tetrahedron.cu +801 -0
- phono3py_gpu/multigpu.py +347 -0
- phono3py_gpu/scattering.py +449 -0
- phono3py_gpu/velocity.py +175 -0
- phono3py_gpu-1.0.0.dist-info/METADATA +151 -0
- phono3py_gpu-1.0.0.dist-info/RECORD +32 -0
- phono3py_gpu-1.0.0.dist-info/WHEEL +5 -0
- phono3py_gpu-1.0.0.dist-info/entry_points.txt +2 -0
- phono3py_gpu-1.0.0.dist-info/licenses/LICENSE +26 -0
- phono3py_gpu-1.0.0.dist-info/licenses/LICENSE.phono3py +26 -0
- phono3py_gpu-1.0.0.dist-info/licenses/LICENSE.phonopy +26 -0
- phono3py_gpu-1.0.0.dist-info/licenses/LICENSE.wte +28 -0
- phono3py_gpu-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
"""FP64 distributed symmetric eigensolve through CUDA's cuSOLVERMg C API.
|
|
2
|
+
|
|
3
|
+
The host matrix keeps phono3py's public storage contract. Device matrices use
|
|
4
|
+
one-dimensional block-cyclic columns; no device stores the full dense matrix.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import atexit
|
|
8
|
+
import ctypes as ct
|
|
9
|
+
from functools import lru_cache
|
|
10
|
+
|
|
11
|
+
import numpy as np
|
|
12
|
+
|
|
13
|
+
from phono3py_gpu.backend import cupy, host
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@lru_cache(maxsize=1)
|
|
17
|
+
def _library():
|
|
18
|
+
lib = ct.CDLL("libcusolverMg.so.11")
|
|
19
|
+
p, i, integer64 = ct.c_void_p, ct.c_int, ct.c_int64
|
|
20
|
+
signatures = {
|
|
21
|
+
"Create": [ct.POINTER(p)],
|
|
22
|
+
"Destroy": [p],
|
|
23
|
+
"DeviceSelect": [p, i, ct.POINTER(i)],
|
|
24
|
+
"CreateDeviceGrid": [ct.POINTER(p), i, i, ct.POINTER(i), i],
|
|
25
|
+
"DestroyGrid": [p],
|
|
26
|
+
"CreateMatrixDesc": [
|
|
27
|
+
ct.POINTER(p),
|
|
28
|
+
integer64,
|
|
29
|
+
integer64,
|
|
30
|
+
integer64,
|
|
31
|
+
integer64,
|
|
32
|
+
i,
|
|
33
|
+
p,
|
|
34
|
+
],
|
|
35
|
+
"DestroyMatrixDesc": [p],
|
|
36
|
+
}
|
|
37
|
+
common = [p, i, i, i, ct.POINTER(p), i, i, p, p, i, i]
|
|
38
|
+
signatures["Syevd_bufferSize"] = common + [ct.POINTER(integer64)]
|
|
39
|
+
signatures["Syevd"] = common + [ct.POINTER(p), integer64, ct.POINTER(i)]
|
|
40
|
+
for name, arguments in signatures.items():
|
|
41
|
+
function = getattr(lib, "cusolverMg" + name)
|
|
42
|
+
function.argtypes, function.restype = arguments, i
|
|
43
|
+
return lib
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _call(name, *arguments):
|
|
47
|
+
status = getattr(_library(), "cusolverMg" + name)(*arguments)
|
|
48
|
+
if status:
|
|
49
|
+
raise RuntimeError(f"cusolverMg{name} failed with status {status}.")
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _pointers(arrays):
|
|
53
|
+
return (ct.c_void_p * len(arrays))(*(a.data.ptr for a in arrays))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@lru_cache(maxsize=None)
|
|
57
|
+
def _handle(devices):
|
|
58
|
+
# Keep CUDA library handles alive across sigma/temperature steps, as CuPy
|
|
59
|
+
# does for its dense solvers. CUDA 12.4 Mg fails after destroy/recreate.
|
|
60
|
+
handle = ct.c_void_p()
|
|
61
|
+
_call("Create", ct.byref(handle))
|
|
62
|
+
ids = (ct.c_int * len(devices))(*devices)
|
|
63
|
+
_call("DeviceSelect", handle, len(devices), ids)
|
|
64
|
+
atexit.register(_library().cusolverMgDestroy, handle)
|
|
65
|
+
return handle
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
class DistributedEigh:
|
|
69
|
+
"""Own distributed eigenvectors until the pseudo-inverse contractions finish."""
|
|
70
|
+
|
|
71
|
+
def __init__(self, matrix, devices, block=256):
|
|
72
|
+
cp = cupy()
|
|
73
|
+
if matrix.dtype != np.float64 or matrix.shape[0] != matrix.shape[1]:
|
|
74
|
+
raise ValueError("cuSOLVERMg expects a real FP64 square matrix.")
|
|
75
|
+
self.devices = devices
|
|
76
|
+
self.n = n = len(matrix)
|
|
77
|
+
self.block = block
|
|
78
|
+
self.values = np.empty(n)
|
|
79
|
+
self.shards, self.columns = [], []
|
|
80
|
+
self.pool = cp.cuda.MemoryPool()
|
|
81
|
+
grid, desc = ct.c_void_p(), ct.c_void_p()
|
|
82
|
+
gpu_ids = (ct.c_int * len(devices))(*devices)
|
|
83
|
+
current = cp.cuda.runtime.getDevice()
|
|
84
|
+
try:
|
|
85
|
+
cp.cuda.Device(devices[0]).use()
|
|
86
|
+
handle = _handle(tuple(devices))
|
|
87
|
+
_call("CreateDeviceGrid", ct.byref(grid), 1, len(devices), gpu_ids, 0)
|
|
88
|
+
_call("CreateMatrixDesc", ct.byref(desc), n, n, n, block, 1, grid)
|
|
89
|
+
for rank, device in enumerate(devices):
|
|
90
|
+
starts = range(rank * block, n, len(devices) * block)
|
|
91
|
+
columns = (
|
|
92
|
+
np.concatenate([np.arange(s, min(s + block, n)) for s in starts])
|
|
93
|
+
if len(starts)
|
|
94
|
+
else np.empty(0, dtype=int)
|
|
95
|
+
)
|
|
96
|
+
with cp.cuda.Device(device), cp.cuda.using_allocator(self.pool.malloc):
|
|
97
|
+
shard = cp.zeros((n, max(1, len(starts)) * block), order="F")
|
|
98
|
+
for local, start in enumerate(starts):
|
|
99
|
+
width = min(block, n - start)
|
|
100
|
+
shard[:, local * block : local * block + width] = cp.asarray(
|
|
101
|
+
matrix[:, start : start + width]
|
|
102
|
+
)
|
|
103
|
+
cp.cuda.get_current_stream().synchronize()
|
|
104
|
+
self.shards.append(shard)
|
|
105
|
+
self.columns.append(columns)
|
|
106
|
+
common = (
|
|
107
|
+
handle,
|
|
108
|
+
1,
|
|
109
|
+
0,
|
|
110
|
+
n,
|
|
111
|
+
_pointers(self.shards),
|
|
112
|
+
1,
|
|
113
|
+
1,
|
|
114
|
+
desc,
|
|
115
|
+
ct.c_void_p(self.values.ctypes.data),
|
|
116
|
+
1,
|
|
117
|
+
1,
|
|
118
|
+
)
|
|
119
|
+
size, info = ct.c_int64(), ct.c_int()
|
|
120
|
+
_call("Syevd_bufferSize", *common, ct.byref(size))
|
|
121
|
+
self.workspace_bytes_per_device = size.value * 8
|
|
122
|
+
workspace = []
|
|
123
|
+
for device in devices:
|
|
124
|
+
with cp.cuda.Device(device), cp.cuda.using_allocator(self.pool.malloc):
|
|
125
|
+
self.pool.free_all_blocks()
|
|
126
|
+
free, _ = cp.cuda.runtime.memGetInfo()
|
|
127
|
+
if size.value * 8 > free:
|
|
128
|
+
raise MemoryError(
|
|
129
|
+
f"cuSOLVERMg needs {size.value * 8 / 2**30:.2f} GiB "
|
|
130
|
+
f"workspace on GPU {device}; "
|
|
131
|
+
f"{free / 2**30:.2f} GiB free."
|
|
132
|
+
)
|
|
133
|
+
workspace.append(cp.empty(size.value, dtype=cp.float64))
|
|
134
|
+
status = _library().cusolverMgSyevd(
|
|
135
|
+
*common, _pointers(workspace), size, ct.byref(info)
|
|
136
|
+
)
|
|
137
|
+
for device in devices:
|
|
138
|
+
cp.cuda.Device(device).synchronize()
|
|
139
|
+
if status or info.value:
|
|
140
|
+
raise np.linalg.LinAlgError(
|
|
141
|
+
f"cuSOLVERMg syevd status={status}, info={info.value}, "
|
|
142
|
+
f"dimension={n}, block={block}."
|
|
143
|
+
)
|
|
144
|
+
workspace.clear()
|
|
145
|
+
for device in devices:
|
|
146
|
+
with cp.cuda.Device(device):
|
|
147
|
+
self.pool.free_all_blocks()
|
|
148
|
+
finally:
|
|
149
|
+
if desc.value:
|
|
150
|
+
_call("DestroyMatrixDesc", desc)
|
|
151
|
+
if grid.value:
|
|
152
|
+
_call("DestroyGrid", grid)
|
|
153
|
+
cp.cuda.Device(current).use()
|
|
154
|
+
|
|
155
|
+
def write_vectors(self, output, transpose=False):
|
|
156
|
+
cp = cupy()
|
|
157
|
+
for rank, device in enumerate(self.devices):
|
|
158
|
+
with cp.cuda.Device(device):
|
|
159
|
+
for local, start in enumerate(
|
|
160
|
+
range(rank * self.block, self.n, len(self.devices) * self.block)
|
|
161
|
+
):
|
|
162
|
+
width = min(self.block, self.n - start)
|
|
163
|
+
tile = host(
|
|
164
|
+
self.shards[rank][
|
|
165
|
+
:, local * self.block : local * self.block + width
|
|
166
|
+
]
|
|
167
|
+
)
|
|
168
|
+
if transpose:
|
|
169
|
+
output[start : start + width] = tile.T
|
|
170
|
+
else:
|
|
171
|
+
output[:, start : start + width] = tile
|
|
172
|
+
|
|
173
|
+
def inverse_values(self, cutoff, method=0):
|
|
174
|
+
valid = (np.abs(self.values) if method == 0 else self.values) > cutoff
|
|
175
|
+
inverse = np.zeros_like(self.values)
|
|
176
|
+
inverse[valid] = 1 / self.values[valid]
|
|
177
|
+
return inverse
|
|
178
|
+
|
|
179
|
+
def solve(self, x, inverse):
|
|
180
|
+
cp = cupy()
|
|
181
|
+
partials = []
|
|
182
|
+
for device, shard, columns in zip(
|
|
183
|
+
self.devices, self.shards, self.columns, strict=True
|
|
184
|
+
):
|
|
185
|
+
with cp.cuda.Device(device):
|
|
186
|
+
v = shard[:, : len(columns)]
|
|
187
|
+
scale = cp.asarray(inverse[columns])
|
|
188
|
+
if x.ndim == 2:
|
|
189
|
+
scale = scale[:, None]
|
|
190
|
+
partials.append(v @ ((v.T @ cp.asarray(x)) * scale))
|
|
191
|
+
result = np.zeros_like(x)
|
|
192
|
+
for device, partial in zip(self.devices, partials, strict=True):
|
|
193
|
+
with cp.cuda.Device(device):
|
|
194
|
+
result += host(partial)
|
|
195
|
+
return result
|
|
196
|
+
|
|
197
|
+
def write_inverse(self, output, inverse):
|
|
198
|
+
cp = cupy()
|
|
199
|
+
for start in range(0, self.n, self.block):
|
|
200
|
+
stop = min(start + self.block, self.n)
|
|
201
|
+
partials = []
|
|
202
|
+
for device, shard, columns in zip(
|
|
203
|
+
self.devices, self.shards, self.columns, strict=True
|
|
204
|
+
):
|
|
205
|
+
with cp.cuda.Device(device):
|
|
206
|
+
v = shard[:, : len(columns)]
|
|
207
|
+
partials.append(
|
|
208
|
+
(v[start:stop] * cp.asarray(inverse[columns])) @ v.T
|
|
209
|
+
)
|
|
210
|
+
output[start:stop] = 0
|
|
211
|
+
for device, partial in zip(self.devices, partials, strict=True):
|
|
212
|
+
with cp.cuda.Device(device):
|
|
213
|
+
output[start:stop] += host(partial)
|
|
214
|
+
|
|
215
|
+
def close(self):
|
|
216
|
+
cp = cupy()
|
|
217
|
+
for device in self.devices:
|
|
218
|
+
cp.cuda.Device(device).synchronize()
|
|
219
|
+
self.shards.clear()
|
|
220
|
+
for device in self.devices:
|
|
221
|
+
with cp.cuda.Device(device):
|
|
222
|
+
self.pool.free_all_blocks()
|
phono3py_gpu/factory.py
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
2
|
+
"""Adapter for phono3py's calculator factory.
|
|
3
|
+
|
|
4
|
+
Assembly follows upstream factory.py; public metadata and I/O are inherited.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
|
|
11
|
+
import numpy as np
|
|
12
|
+
from phono3py.conductivity.build_components import (
|
|
13
|
+
CalculatorConfig,
|
|
14
|
+
build_lbte_kappa_settings,
|
|
15
|
+
build_rot_grid_points,
|
|
16
|
+
build_rta_kappa_settings,
|
|
17
|
+
)
|
|
18
|
+
from phono3py.conductivity.calculators import LBTECalculator, RTACalculator
|
|
19
|
+
from phono3py.conductivity.factory import _get_lbte_grid_point_indices
|
|
20
|
+
from phono3py.conductivity.kappa_solvers import LBTEKappaSolver
|
|
21
|
+
from phono3py.phonon3.collision_matrix import CollisionMatrix
|
|
22
|
+
from phono3py.phonon3.interaction import Interaction
|
|
23
|
+
|
|
24
|
+
from phono3py_gpu._wte import GPUWignerLBTEKappaSolver, GPUWignerRTAKappaSolver
|
|
25
|
+
from phono3py_gpu.backend import batch_size, cupy, report_devices
|
|
26
|
+
from phono3py_gpu.batching import compute_q_batch
|
|
27
|
+
from phono3py_gpu.collision import create_collision_matrix_kernel
|
|
28
|
+
from phono3py_gpu.harmonic import prepare_phonons
|
|
29
|
+
from phono3py_gpu.interaction import InteractionKernel
|
|
30
|
+
from phono3py_gpu.kappa import GPURTAKappaSolver
|
|
31
|
+
from phono3py_gpu.multigpu import devices
|
|
32
|
+
from phono3py_gpu.multigpu import iterate as iterate_multi_gpu
|
|
33
|
+
from phono3py_gpu.scattering import (
|
|
34
|
+
GPUCollisionSolver,
|
|
35
|
+
GPUScatteringSolver,
|
|
36
|
+
collision_layout,
|
|
37
|
+
)
|
|
38
|
+
from phono3py_gpu.velocity import GPUHeatCapacitySolver, GPUVelocitySolver
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class GPUCalculatorMixin:
|
|
42
|
+
def __init__(self, *args, **kwargs):
|
|
43
|
+
super().__init__(*args, **kwargs)
|
|
44
|
+
if self._isotope_solver is not None:
|
|
45
|
+
from phono3py_gpu.isotope import GPUIsotopeSolver
|
|
46
|
+
|
|
47
|
+
solver = (
|
|
48
|
+
self._collision_solver
|
|
49
|
+
if isinstance(self, LBTECalculator)
|
|
50
|
+
else self._scattering_solver
|
|
51
|
+
)
|
|
52
|
+
self._isotope_solver = GPUIsotopeSolver(
|
|
53
|
+
self._isotope_solver.isotope,
|
|
54
|
+
self._kappa_settings.sigmas,
|
|
55
|
+
log_level=self._log_level,
|
|
56
|
+
device_phonons=(solver.engine.frequencies, solver.engine.eigenvectors),
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
def _build_grid_point_aggregates(self):
|
|
60
|
+
if self._velocity_solver.velocity_operator is not None:
|
|
61
|
+
self._kappa_solver.velocity_operator = (
|
|
62
|
+
self._velocity_solver.velocity_operator
|
|
63
|
+
)
|
|
64
|
+
return super()._build_grid_point_aggregates()
|
|
65
|
+
|
|
66
|
+
def _iterate_grid_points(self, on_grid_point):
|
|
67
|
+
"""Opt-in q batching; stateful file paths retain upstream iteration."""
|
|
68
|
+
requested = int(os.environ.get("PHONO3PY_GPU_Q_BATCH_SIZE", "1"))
|
|
69
|
+
collision = isinstance(self, LBTECalculator)
|
|
70
|
+
solver = self._collision_solver if collision else self._scattering_solver
|
|
71
|
+
self.q_batch_stats = dict(q_batches=0, triplet_batches=0, max_q_per_launch=0)
|
|
72
|
+
solver.q_batch_stats = self.q_batch_stats
|
|
73
|
+
self.multi_gpu_stats = None
|
|
74
|
+
reason = ""
|
|
75
|
+
if self._pp.nac_q_direction is not None:
|
|
76
|
+
reason = "directional NAC"
|
|
77
|
+
elif collision and on_grid_point is not None:
|
|
78
|
+
reason = "per-q output or callback"
|
|
79
|
+
elif solver._read_pp:
|
|
80
|
+
reason = "reading PP"
|
|
81
|
+
elif solver._is_full_pp:
|
|
82
|
+
reason = "full PP requested"
|
|
83
|
+
elif not collision and self._read_gamma:
|
|
84
|
+
reason = "reading linewidths"
|
|
85
|
+
elif not collision and solver._requires_full_gamma_path():
|
|
86
|
+
reason = "per-q scattering options"
|
|
87
|
+
method = "WTE" if self._velocity_solver.wte else "BTE"
|
|
88
|
+
stage = f"{method}-{'LBTE' if collision else 'RTA'} scattering"
|
|
89
|
+
ids = devices()
|
|
90
|
+
indices = list(self._get_grid_point_indices())
|
|
91
|
+
if collision and indices:
|
|
92
|
+
self._pp.delete_interaction_strength()
|
|
93
|
+
if not reason and indices:
|
|
94
|
+
if collision and (len(ids) > 1 or requested > 1):
|
|
95
|
+
_, _, shape, _ = collision_layout(solver)
|
|
96
|
+
bytes_per_q = int(np.prod(shape)) * len(solver._temperatures) * 8
|
|
97
|
+
requested = batch_size(bytes_per_q, maximum=max(1, requested))
|
|
98
|
+
groups = (len(indices) + max(1, requested) - 1) // max(1, requested)
|
|
99
|
+
ids = ids[:groups]
|
|
100
|
+
if len(ids) > 1 and not reason and indices:
|
|
101
|
+
iterate_multi_gpu(
|
|
102
|
+
self, solver, ids, indices, max(1, requested), collision, on_grid_point
|
|
103
|
+
)
|
|
104
|
+
if self._log_level:
|
|
105
|
+
per_device = self.multi_gpu_stats["per_device"]
|
|
106
|
+
used = [dev for dev in ids if per_device[dev]["q_points"]]
|
|
107
|
+
report_devices(stage, used)
|
|
108
|
+
return
|
|
109
|
+
if self._log_level and indices:
|
|
110
|
+
if collision or not self._read_gamma or solver.use_ave_pp:
|
|
111
|
+
note = f" of {len(ids)} visible GPUs ({reason})" if len(ids) > 1 else ""
|
|
112
|
+
report_devices(stage, ids[:1], note)
|
|
113
|
+
if requested <= 1 or reason:
|
|
114
|
+
if requested > 1 and self._log_level:
|
|
115
|
+
print("phono3py-gpu: using the per-q path for the requested options.")
|
|
116
|
+
if collision:
|
|
117
|
+
return self._iterate_lbte_points(indices, on_grid_point)
|
|
118
|
+
return super()._iterate_grid_points(on_grid_point)
|
|
119
|
+
for start in range(0, len(indices), requested):
|
|
120
|
+
selected = indices[start : start + requested]
|
|
121
|
+
gps = self._kappa_settings.grid_points[selected]
|
|
122
|
+
if self._log_level:
|
|
123
|
+
print("phono3py-gpu: GPU batch: %d q points." % len(gps), flush=True)
|
|
124
|
+
results = compute_q_batch(
|
|
125
|
+
solver,
|
|
126
|
+
gps,
|
|
127
|
+
collision=collision,
|
|
128
|
+
last_batch=start + len(selected) == len(indices),
|
|
129
|
+
)
|
|
130
|
+
self.q_batch_stats["q_batches"] += 1
|
|
131
|
+
for offset, (index, result) in enumerate(
|
|
132
|
+
zip(selected, results, strict=True)
|
|
133
|
+
):
|
|
134
|
+
index = int(index)
|
|
135
|
+
if collision:
|
|
136
|
+
self._gamma[:, :, index] = result.gamma
|
|
137
|
+
self._kappa_solver.store(index, result)
|
|
138
|
+
else:
|
|
139
|
+
self._store_scattering_result(
|
|
140
|
+
index, result["result"], result["gamma_N"], result["gamma_U"]
|
|
141
|
+
)
|
|
142
|
+
self._gamma_detail_at_q = None
|
|
143
|
+
solver._gamma_N, solver._gamma_U = (
|
|
144
|
+
result["gamma_N"],
|
|
145
|
+
result["gamma_U"],
|
|
146
|
+
)
|
|
147
|
+
self._pp._triplets_at_q = result["triplets"]
|
|
148
|
+
self._pp._weights_at_q = result["weights"]
|
|
149
|
+
self._grid_point_count = start + offset + 1
|
|
150
|
+
if self._log_level:
|
|
151
|
+
if collision:
|
|
152
|
+
self._show_log(index, self._gv[index])
|
|
153
|
+
else:
|
|
154
|
+
self._show_log(index, self._gv[index], None)
|
|
155
|
+
if on_grid_point is not None:
|
|
156
|
+
on_grid_point(index)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class GPURTACalculator(GPUCalculatorMixin, RTACalculator):
|
|
160
|
+
def _finalize(self):
|
|
161
|
+
if self._log_level:
|
|
162
|
+
stage = (
|
|
163
|
+
"WTE-RTA mode contributions"
|
|
164
|
+
if self._velocity_solver.wte
|
|
165
|
+
else "BTE-RTA conductivity sum"
|
|
166
|
+
)
|
|
167
|
+
report_devices(stage, [cupy().cuda.runtime.getDevice()])
|
|
168
|
+
super()._finalize()
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
class GPULBTECalculator(GPUCalculatorMixin, LBTECalculator):
|
|
172
|
+
def _iterate_lbte_points(self, indices, on_grid_point):
|
|
173
|
+
"""Expose each callback's PP, retaining only the final requested snapshot."""
|
|
174
|
+
solver = self._collision_solver
|
|
175
|
+
retain_final = solver.retain_pp
|
|
176
|
+
try:
|
|
177
|
+
for count, index in enumerate(indices, 1):
|
|
178
|
+
keep = retain_final and count == len(indices)
|
|
179
|
+
solver.retain_pp = keep or on_grid_point is not None
|
|
180
|
+
index = int(index)
|
|
181
|
+
self._compute_at_grid_point(index)
|
|
182
|
+
self._grid_point_count = count
|
|
183
|
+
if on_grid_point is not None:
|
|
184
|
+
on_grid_point(index)
|
|
185
|
+
if not keep:
|
|
186
|
+
self._pp.delete_interaction_strength()
|
|
187
|
+
finally:
|
|
188
|
+
solver.retain_pp = retain_final
|
|
189
|
+
if not retain_final:
|
|
190
|
+
self._pp.delete_interaction_strength()
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def _validate_wte(interaction, wte):
|
|
194
|
+
if wte and len(interaction.band_indices) != 3 * len(interaction.primitive):
|
|
195
|
+
raise ValueError("WTE requires every phonon branch, as in phono3py-wte.")
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def make_rta(
|
|
199
|
+
interaction: Interaction,
|
|
200
|
+
config: CalculatorConfig,
|
|
201
|
+
wte: bool = False,
|
|
202
|
+
) -> RTACalculator:
|
|
203
|
+
"""Build an RTACalculator from variant component factories."""
|
|
204
|
+
cupy().cuda.Device(devices()[0]).use()
|
|
205
|
+
harmonic, f, e = prepare_phonons(interaction)
|
|
206
|
+
engine = InteractionKernel(interaction, f, e)
|
|
207
|
+
_validate_wte(interaction, wte)
|
|
208
|
+
kappa_settings = build_rta_kappa_settings(interaction, config)
|
|
209
|
+
scattering_solver = GPUScatteringSolver(
|
|
210
|
+
interaction,
|
|
211
|
+
engine=engine,
|
|
212
|
+
sigmas=config.sigmas,
|
|
213
|
+
temperatures=config.temperatures,
|
|
214
|
+
sigma_cutoff=config.sigma_cutoff,
|
|
215
|
+
is_full_pp=config.is_full_pp,
|
|
216
|
+
use_ave_pp=config.use_ave_pp,
|
|
217
|
+
read_pp=config.read_pp,
|
|
218
|
+
store_pp=config.store_pp,
|
|
219
|
+
pp_filename=config.pp_filename,
|
|
220
|
+
is_N_U=config.is_N_U,
|
|
221
|
+
is_gamma_detail=config.is_gamma_detail,
|
|
222
|
+
log_level=config.log_level,
|
|
223
|
+
lang=config.lang,
|
|
224
|
+
)
|
|
225
|
+
velocity_solver = GPUVelocitySolver(
|
|
226
|
+
interaction,
|
|
227
|
+
harmonic=harmonic,
|
|
228
|
+
wte=wte,
|
|
229
|
+
is_kappa_star=kappa_settings.is_kappa_star,
|
|
230
|
+
gv_delta_q=kappa_settings.gv_delta_q,
|
|
231
|
+
log_level=config.log_level,
|
|
232
|
+
)
|
|
233
|
+
cv_solver = GPUHeatCapacitySolver(interaction, kappa_settings.temperatures)
|
|
234
|
+
kappa_solver = (
|
|
235
|
+
GPUWignerRTAKappaSolver(
|
|
236
|
+
kappa_settings,
|
|
237
|
+
interaction.phonons.frequencies,
|
|
238
|
+
interaction.primitive.volume,
|
|
239
|
+
log_level=config.log_level,
|
|
240
|
+
)
|
|
241
|
+
if wte
|
|
242
|
+
else GPURTAKappaSolver(
|
|
243
|
+
kappa_settings,
|
|
244
|
+
interaction.phonons.frequencies,
|
|
245
|
+
log_level=config.log_level,
|
|
246
|
+
)
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
return GPURTACalculator(
|
|
250
|
+
interaction,
|
|
251
|
+
velocity_solver=velocity_solver,
|
|
252
|
+
cv_solver=cv_solver,
|
|
253
|
+
scattering_solver=scattering_solver,
|
|
254
|
+
kappa_solver=kappa_solver,
|
|
255
|
+
kappa_settings=kappa_settings,
|
|
256
|
+
is_isotope=config.is_isotope,
|
|
257
|
+
mass_variances=config.mass_variances,
|
|
258
|
+
is_N_U=config.is_N_U,
|
|
259
|
+
is_gamma_detail=config.is_gamma_detail,
|
|
260
|
+
sigma_cutoff_width=config.sigma_cutoff,
|
|
261
|
+
log_level=config.log_level,
|
|
262
|
+
lang=config.lang,
|
|
263
|
+
rust_gp_batch_size=config.rust_gp_batch_size,
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def make_lbte(
|
|
268
|
+
interaction: Interaction,
|
|
269
|
+
config: CalculatorConfig,
|
|
270
|
+
wte: bool = False,
|
|
271
|
+
) -> LBTECalculator:
|
|
272
|
+
"""Build an LBTECalculator from variant component factories."""
|
|
273
|
+
cupy().cuda.Device(devices()[0]).use()
|
|
274
|
+
harmonic, f, e = prepare_phonons(interaction)
|
|
275
|
+
engine = InteractionKernel(interaction, f, e)
|
|
276
|
+
_validate_wte(interaction, wte)
|
|
277
|
+
kappa_settings = build_lbte_kappa_settings(interaction, config)
|
|
278
|
+
grid_point_indices = _get_lbte_grid_point_indices(
|
|
279
|
+
kappa_settings.grid_points, config.grid_points
|
|
280
|
+
)
|
|
281
|
+
assert interaction.phonons is not None
|
|
282
|
+
frequencies = interaction.phonons.frequencies
|
|
283
|
+
rot_grid_points = build_rot_grid_points(kappa_settings)
|
|
284
|
+
collision = CollisionMatrix(
|
|
285
|
+
interaction,
|
|
286
|
+
rot_grid_points=rot_grid_points,
|
|
287
|
+
is_kappa_star=config.is_kappa_star,
|
|
288
|
+
log_level=config.log_level,
|
|
289
|
+
lang=config.lang,
|
|
290
|
+
)
|
|
291
|
+
collision_solver = GPUCollisionSolver(
|
|
292
|
+
interaction,
|
|
293
|
+
collision,
|
|
294
|
+
engine=engine,
|
|
295
|
+
retain_pp=os.environ.get("PHONO3PY_GPU_RETAIN_PP", "0") != "0",
|
|
296
|
+
sigmas=config.sigmas,
|
|
297
|
+
sigma_cutoff=config.sigma_cutoff,
|
|
298
|
+
temperatures=config.temperatures,
|
|
299
|
+
is_full_pp=config.is_full_pp,
|
|
300
|
+
read_pp=config.read_pp,
|
|
301
|
+
pp_filename=config.pp_filename,
|
|
302
|
+
log_level=config.log_level,
|
|
303
|
+
)
|
|
304
|
+
colmat_kernel = create_collision_matrix_kernel(
|
|
305
|
+
wte=wte,
|
|
306
|
+
kappa_settings=kappa_settings,
|
|
307
|
+
frequencies=frequencies,
|
|
308
|
+
degenerate_ids=interaction.phonons.degenerate_ids,
|
|
309
|
+
rot_grid_points=rot_grid_points,
|
|
310
|
+
pinv_cutoff=config.pinv_cutoff,
|
|
311
|
+
pinv_solver=config.pinv_solver,
|
|
312
|
+
pinv_method=config.pinv_method,
|
|
313
|
+
lang=config.lang,
|
|
314
|
+
log_level=config.log_level,
|
|
315
|
+
is_one_gp_colmat=grid_point_indices is not None,
|
|
316
|
+
)
|
|
317
|
+
velocity_solver = GPUVelocitySolver(
|
|
318
|
+
interaction,
|
|
319
|
+
harmonic=harmonic,
|
|
320
|
+
wte=wte,
|
|
321
|
+
is_kappa_star=kappa_settings.is_kappa_star,
|
|
322
|
+
gv_delta_q=kappa_settings.gv_delta_q,
|
|
323
|
+
log_level=config.log_level,
|
|
324
|
+
)
|
|
325
|
+
cv_solver = GPUHeatCapacitySolver(interaction, kappa_settings.temperatures)
|
|
326
|
+
kappa_solver = (
|
|
327
|
+
GPUWignerLBTEKappaSolver(
|
|
328
|
+
colmat_kernel,
|
|
329
|
+
kappa_settings,
|
|
330
|
+
frequencies,
|
|
331
|
+
interaction.primitive.volume,
|
|
332
|
+
is_reducible_collision_matrix=kappa_settings.is_reducible_collision_matrix,
|
|
333
|
+
log_level=config.log_level,
|
|
334
|
+
)
|
|
335
|
+
if wte
|
|
336
|
+
else LBTEKappaSolver(colmat_kernel, kappa_settings, config.log_level)
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
return GPULBTECalculator(
|
|
340
|
+
interaction,
|
|
341
|
+
velocity_solver=velocity_solver,
|
|
342
|
+
cv_solver=cv_solver,
|
|
343
|
+
collision_solver=collision_solver,
|
|
344
|
+
kappa_solver=kappa_solver,
|
|
345
|
+
kappa_settings=kappa_settings,
|
|
346
|
+
is_isotope=config.is_isotope,
|
|
347
|
+
mass_variances=config.mass_variances,
|
|
348
|
+
is_full_pp=config.is_full_pp,
|
|
349
|
+
sigma_cutoff_width=config.sigma_cutoff,
|
|
350
|
+
log_level=config.log_level,
|
|
351
|
+
lang=config.lang,
|
|
352
|
+
grid_point_indices=grid_point_indices,
|
|
353
|
+
)
|