Loading...
Searching...
No Matches
KokkosJointKernel.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Copyright (c) gpridge developers
3#pragma once
4
5#include <Kokkos_Core.hpp>
6#include <cstddef>
7#include <cstdint>
8#include <limits>
9#include <stdexcept>
10#include <string>
11#include <utility>
12
13#include "KokkosAuditedCopy.h"
14
16
17using index_type = std::int64_t;
18
19template <class ExecSpace>
20struct Views {
21 using memory_space = typename ExecSpace::memory_space;
22 using matrix = Kokkos::View<double**, Kokkos::LayoutLeft, memory_space>;
24 Kokkos::View<const double**, Kokkos::LayoutLeft, memory_space>;
25 using vector = Kokkos::View<double*, memory_space>;
26 using const_vector = Kokkos::View<const double*, memory_space>;
27 using ivector = Kokkos::View<int*, memory_space>;
28 using const_ivector = Kokkos::View<const int*, memory_space>;
29 // Squared feature distance per (left geometry, right geometry, type).
30 using table = Kokkos::View<double***, Kokkos::LayoutLeft, memory_space>;
32 Kokkos::View<const double***, Kokkos::LayoutLeft, memory_space>;
33};
34
35// One set of observation rows (training set, test set, ...).
36template <class ExecSpace>
37struct JointRows {
41
42 // Compact molecular rows share one value and three Cartesian slopes per
43 // geometry/pair; observation channels select a signed slope on demand.
45 Kokkos::View<const double***, Kokkos::LayoutLeft,
48
49 // Pair topology of compact molecular rows. A Cartesian slope is nonzero
50 // only for the pairs of its own atom, so an entry need not visit every
51 // pair. atom_pairs lists the pairs of each moving atom between
52 // atom_offsets(a) and atom_offsets(a + 1), ordered by pair type and then
53 // by pair; shared_pair is the pair of two moving atoms, or -1;
54 // pair_types is the type of a pair. In that order the indexed sums add
55 // their terms as the sums over all pairs do; any other order gives the
56 // same sums with different rounding. Empty views select the sums over
57 // all pairs.
60
61 KOKKOS_INLINE_FUNCTION bool indexed() const
62 {
63 return atom_offsets.extent(0) != 0;
64 }
65 KOKKOS_INLINE_FUNCTION int atoms() const
66 {
67 return static_cast<int>(atom_offsets.extent(0)) - 1;
68 }
69
70 KOKKOS_INLINE_FUNCTION double value(index_type row, int pair) const
71 {
72 return q(geometry.extent(0) ? geometry(row) : row, pair);
73 }
74 KOKKOS_INLINE_FUNCTION double derivative(index_type row, int pair) const
75 {
76 if (!geometry.extent(0)) return J(row, pair);
77 const int coordinate = channel(row) - 1;
78 if (coordinate < 0) return 0.0;
79 const int atom = coordinate / 3;
80 const double sign = atom == first(pair) ? 1.0
81 : atom == second(pair) ? -1.0
82 : 0.0;
83 return sign * spatial(geometry(row), pair, coordinate % 3);
84 }
86 {
87 return static_cast<index_type>(channel.extent(0));
88 }
90 {
91 return static_cast<index_type>(q.extent(1));
92 }
93};
94
95// Kernel hyperparameters in their natural (not log) form.
96template <class ExecSpace>
97struct JointHyper {
99 double magnitude = 1.0; // m > 0
100 double energy_constant = 0.0; // c >= 0
101
102 int types() const
103 {
104 return static_cast<int>(inverse_squared_lengths.extent(0));
105 }
106};
107
108// Features grouped by length-scale type: features of type g are
109// perm(offsets(g)) ... perm(offsets(g+1) - 1), in increasing feature order.
110template <class ExecSpace>
117
137
138namespace detail {
139
140inline void require(bool condition, const char* what)
141{
142 if (!condition)
143 throw std::invalid_argument(std::string("gpr::linalg::kokkos_joint: ") +
144 what);
145}
146
147inline index_type checked_product(index_type a, index_type b)
148{
149 require(a >= 0 && b >= 0, "negative extent");
150 require(b == 0 || a <= std::numeric_limits<index_type>::max() / b,
151 "index space overflows int64");
152 return a * b;
153}
154
155template <class ExecSpace>
156void check_rows(const JointRows<ExecSpace>& r)
157{
158 if (r.geometry.extent(0)) {
159 require(r.geometry.extent(0) == r.channel.extent(0) &&
160 r.first.extent(0) == r.q.extent(1) &&
161 r.second.extent(0) == r.q.extent(1) &&
162 r.spatial.extent(0) == r.q.extent(0) &&
163 r.spatial.extent(1) == r.q.extent(1) &&
164 r.spatial.extent(2) == 3,
165 "compact descriptor extents do not match");
166 } else {
167 require(
168 r.J.extent(0) == r.q.extent(0) && r.J.extent(1) == r.q.extent(1),
169 "J extents must equal q extents");
170 require(r.channel.extent(0) == r.q.extent(0),
171 "channel extent must equal number of rows");
172 }
173 require(r.q.extent(1) <=
174 static_cast<std::size_t>(std::numeric_limits<int>::max()),
175 "feature count exceeds int range");
176}
177
178template <class ExecSpace>
179void check_index(const PairTypeIndex<ExecSpace>& idx, index_type n_features,
180 int n_types)
181{
182 require(idx.n_types == n_types &&
183 idx.offsets.extent(0) == static_cast<std::size_t>(n_types) + 1,
184 "PairTypeIndex type count does not match inverse_squared_lengths");
185 require(idx.n_features == n_features &&
186 idx.perm.extent(0) == static_cast<std::size_t>(n_features),
187 "PairTypeIndex feature count does not match rows");
188}
189
190KOKKOS_INLINE_FUNCTION bool finite(double x)
191{
192 return Kokkos::isfinite(x);
193}
194
195struct Sums {
196 double t, A, B, C;
197};
198
199template <class Rows, class IVector, class Vector>
200KOKKOS_INLINE_FUNCTION Sums type_sums(const Rows& left, index_type i,
201 const Rows& right, index_type j,
202 const IVector& offsets,
203 const IVector& perm, const Vector& s,
204 int g)
205{
206 Sums r{0.0, 0.0, 0.0, 0.0};
207 for (int k = offsets(g); k < offsets(g + 1); ++k) {
208 const int p = perm(k);
209 const double d = left.value(i, p) - right.value(j, p);
210 const double ji = left.derivative(i, p), jj = right.derivative(j, p);
211 r.t += d * d;
212 r.A += d * ji;
213 r.B += d * jj;
214 r.C += ji * jj;
215 }
216 const double sg = s(g);
217 r.t *= sg;
218 r.A *= sg;
219 r.B *= sg;
220 r.C *= sg;
221 return r;
222}
223
224template <class Rows, class IVector, class Vector>
225KOKKOS_INLINE_FUNCTION Sums total_sums(const Rows& left, index_type i,
226 const Rows& right, index_type j,
227 const IVector& offsets,
228 const IVector& perm, const Vector& s,
229 int n_types)
230{
231 Sums r{0.0, 0.0, 0.0, 0.0};
232 for (int g = 0; g < n_types; ++g) {
233 const Sums sg = type_sums(left, i, right, j, offsets, perm, s, g);
234 r.t += sg.t;
235 r.A += sg.A;
236 r.B += sg.B;
237 r.C += sg.C;
238 }
239 return r;
240}
241
242// The same sums for rows that carry a pair topology. Every omitted term of
243// type_sums is a product with a zero slope, and the kept terms are added in
244// the same order, so the two functions return the same bits.
245// `total_t(a, b)` is the squared feature distance of left geometry a and
246// right geometry b, `total_a(i, b)` the A sum of left row i against right
247// geometry b and `total_b(j, a)` the B sum of right row j against left
248// geometry a, each already summed over the pair types with their inverse
249// squared lengths (total_table). An entry reads the three and adds the C
250// terms of the pairs its two coordinates share, so its cost does not grow
251// with the number of pairs or of pair types.
252template <class Rows, class Vector, class Matrix>
253KOKKOS_INLINE_FUNCTION Sums indexed_total_sums(const Rows& left, index_type i,
254 const Rows& right, index_type j,
255 const Vector& s,
256 const Matrix& total_t,
257 const Matrix& total_a,
258 const Matrix& total_b)
259{
260 const int ci = left.channel(i) - 1, cj = right.channel(j) - 1;
261 Sums r{total_t(left.geometry(i), right.geometry(j)),
262 ci >= 0 ? total_a(i, right.geometry(j)) : 0.0,
263 cj >= 0 ? total_b(j, left.geometry(i)) : 0.0, 0.0};
264 if (ci >= 0 && cj >= 0) {
265 const int a = ci / 3, b = cj / 3;
266 if (a == b) {
267 // One partial sum per run of a pair type, scaled as it closes.
268 int current = -1;
269 double part = 0.0;
270 for (int k = left.atom_offsets(a); k < left.atom_offsets(a + 1);
271 ++k) {
272 const int p = left.atom_pairs(k);
273 const int g = left.pair_types(p);
274 if (g != current) {
275 if (current >= 0) r.C += part * s(current);
276 current = g;
277 part = 0.0;
278 }
279 part += left.derivative(i, p) * right.derivative(j, p);
280 }
281 if (current >= 0) r.C += part * s(current);
282 } else {
283 // Two different atoms share at most one pair.
284 const int p = left.shared_pair(a * left.atoms() + b);
285 if (p >= 0)
286 r.C = left.derivative(i, p) * right.derivative(j, p) *
287 s(left.pair_types(p));
288 }
289 }
290 return r;
291}
292
293// The group of a pair type: the type itself unless a map is given. A map
294// sends the types that share one length scale to one group, and a table
295// indexed by group holds the sum of the tables of its types.
296template <class IVector>
297KOKKOS_INLINE_FUNCTION int group_of(const IVector& type_group, int g)
298{
299 return type_group.extent(0) != 0 ? type_group(g) : g;
300}
301
302// table(a, b, group) = sum over the pairs of the group's types, type by
303// type and in ascending pair order, of the squared feature difference of
304// left geometry a and right geometry b.
305template <class ExecSpace>
306struct DistanceTableFunctor {
307 using V = Views<ExecSpace>;
308 typename V::const_matrix left, right;
309 typename V::const_ivector offsets, perm, type_group;
310 typename V::table table;
311 index_type n_left;
312 int n_types;
313
314 KOKKOS_INLINE_FUNCTION void operator()(const index_type idx) const
315 {
316 const index_type a = idx % n_left;
317 const index_type b = idx / n_left;
318 for (std::size_t g = 0; g < table.extent(2); ++g)
319 table(a, b, g) = 0.0;
320 for (int g = 0; g < n_types; ++g) {
321 double t = 0.0;
322 for (int k = offsets(g); k < offsets(g + 1); ++k) {
323 const int p = perm(k);
324 const double d = left(a, p) - right(b, p);
325 t += d * d;
326 }
327 table(a, b, group_of(type_group, g)) += t;
328 }
329 }
330};
331
332// table(i, b, g) = sum over the pairs of row i's atom that have type g, in
333// ascending pair order, of (difference of the feature between the row's
334// geometry and geometry b of the other row set) times the row's slope. With
335// `row_is_left` the difference is row minus other, the A sum of type_sums;
336// without it other minus row, the B sum. Energy rows have no slope.
337template <class ExecSpace>
338struct SlopeTableFunctor {
339 using V = Views<ExecSpace>;
340 JointRows<ExecSpace> rows;
341 typename V::const_matrix other;
342 typename V::const_ivector type_group;
343 typename V::table table;
344 index_type n_rows;
345 bool row_is_left;
346
347 KOKKOS_INLINE_FUNCTION void operator()(const index_type idx) const
348 {
349 const index_type i = idx % n_rows;
350 const index_type b = idx / n_rows;
351 const int c = rows.channel(i) - 1;
352 for (std::size_t g = 0; g < table.extent(2); ++g)
353 table(i, b, g) = 0.0;
354 if (c < 0) return;
355 const int atom = c / 3;
356 // One partial sum per run of a pair type, stored as it closes.
357 int current = -1;
358 double sum = 0.0;
359 for (int k = rows.atom_offsets(atom); k < rows.atom_offsets(atom + 1);
360 ++k) {
361 const int p = rows.atom_pairs(k);
362 const int g = rows.pair_types(p);
363 if (g != current) {
364 if (current >= 0)
365 table(i, b, group_of(type_group, current)) += sum;
366 current = g;
367 sum = 0.0;
368 }
369 const double d = row_is_left ? rows.value(i, p) - other(b, p)
370 : other(b, p) - rows.value(i, p);
371 sum += d * rows.derivative(i, p);
372 }
373 if (current >= 0) table(i, b, group_of(type_group, current)) += sum;
374 }
375};
376
377// total(a, b) = sum over the pair types g, ascending, of s(g) times the
378// squared feature difference of left geometry a and right geometry b over
379// the pairs of type g: the per-type distance table summed, without the
380// table.
381template <class ExecSpace>
382struct TotalDistanceFunctor {
383 using V = Views<ExecSpace>;
384 typename V::const_matrix left, right;
385 typename V::const_ivector offsets, perm;
386 typename V::const_vector s;
387 typename V::matrix total;
388 index_type n_left;
389 int n_types;
390
391 KOKKOS_INLINE_FUNCTION void operator()(const index_type idx) const
392 {
393 const index_type a = idx % n_left;
394 const index_type b = idx / n_left;
395 double sum = 0.0;
396 for (int g = 0; g < n_types; ++g) {
397 double t = 0.0;
398 for (int k = offsets(g); k < offsets(g + 1); ++k) {
399 const int p = perm(k);
400 const double d = left(a, p) - right(b, p);
401 t += d * d;
402 }
403 sum += t * s(g);
404 }
405 total(a, b) = sum;
406 }
407};
408
409// total(i, b) = the slope sums of row i against geometry b summed over the
410// pair types with their inverse squared lengths: one partial sum per run of
411// a pair type in the atom's adjacency, scaled as it closes.
412template <class ExecSpace>
413struct TotalSlopeFunctor {
414 using V = Views<ExecSpace>;
415 JointRows<ExecSpace> rows;
416 typename V::const_matrix other;
417 typename V::const_vector s;
418 typename V::matrix total;
419 index_type n_rows;
420 bool row_is_left;
421
422 KOKKOS_INLINE_FUNCTION void operator()(const index_type idx) const
423 {
424 const index_type i = idx % n_rows;
425 const index_type b = idx / n_rows;
426 const int c = rows.channel(i) - 1;
427 double sum = 0.0;
428 if (c >= 0) {
429 const int atom = c / 3;
430 int current = -1;
431 double part = 0.0;
432 for (int k = rows.atom_offsets(atom);
433 k < rows.atom_offsets(atom + 1); ++k) {
434 const int p = rows.atom_pairs(k);
435 const int g = rows.pair_types(p);
436 if (g != current) {
437 if (current >= 0) sum += part * s(current);
438 current = g;
439 part = 0.0;
440 }
441 const double d = row_is_left ? rows.value(i, p) - other(b, p)
442 : other(b, p) - rows.value(i, p);
443 part += d * rows.derivative(i, p);
444 }
445 if (current >= 0) sum += part * s(current);
446 }
447 total(i, b) = sum;
448 }
449};
450
451// Kernel part (without c) of block (ci, cj) from k and the total sums.
452KOKKOS_INLINE_FUNCTION double block(bool di, bool dj, double k, const Sums& u)
453{
454 if (!di && !dj) return k;
455 if (di && !dj) return -2.0 * k * u.A;
456 if (!di && dj) return 2.0 * k * u.B;
457 return k * (2.0 * u.C - 4.0 * u.A * u.B);
458}
459
460// Derivative of block() for perturbations (dk, dA, dB, dC) of its inputs.
461KOKKOS_INLINE_FUNCTION double block_derivative(bool di, bool dj, double k,
462 const Sums& u, double dk,
463 const Sums& du)
464{
465 if (!di && !dj) return dk;
466 if (di && !dj) return -2.0 * (dk * u.A + k * du.A);
467 if (!di && dj) return 2.0 * (dk * u.B + k * du.B);
468 return dk * (2.0 * u.C - 4.0 * u.A * u.B) +
469 k * (2.0 * du.C - 4.0 * (du.A * u.B + u.A * du.B));
470}
471
472template <class ExecSpace>
473struct BuildIndexFunctor {
474 typename Views<ExecSpace>::const_ivector pair_type;
475 typename Views<ExecSpace>::ivector offsets;
476 typename Views<ExecSpace>::ivector perm;
477 int n_types;
478 int n_features;
479
480 KOKKOS_INLINE_FUNCTION void operator()(const int) const
481 {
482 int pos = 0;
483 for (int g = 0; g < n_types; ++g) {
484 offsets(g) = pos;
485 for (int p = 0; p < n_features; ++p)
486 if (pair_type(p) == g) perm(pos++) = p;
487 }
488 offsets(n_types) = pos;
489 // Features with an out-of-range type are not indexed; fill the tail
490 // with valid indices so perm never holds uninitialized values.
491 for (int k = pos; k < n_features; ++k)
492 perm(k) = 0;
493 }
494};
495
496template <class ExecSpace>
497struct AssembleFunctor {
498 using V = Views<ExecSpace>;
499 JointRows<ExecSpace> left, right;
500 typename V::const_ivector offsets, perm;
501 typename V::const_vector s;
502 typename V::const_vector noise; // empty unless training diagonal
503 typename V::matrix K;
504 double m, c, eta;
505 index_type n1;
506 int n_types;
507 bool training;
508 // Empty unless the rows are indexed.
509 typename V::const_matrix total_t, total_a, total_b;
510
511 KOKKOS_INLINE_FUNCTION void operator()(const index_type idx) const
512 {
513 const index_type i = idx % n1;
514 const index_type j = idx / n1;
515 const Sums u =
516 total_t.extent(0) != 0
517 ? indexed_total_sums(left, i, right, j, s, total_t, total_a,
518 total_b)
519 : total_sums(left, i, right, j, offsets, perm, s, n_types);
520 const bool di = left.channel(i) > 0;
521 const bool dj = right.channel(j) > 0;
522 double v = block(di, dj, m * Kokkos::exp(-u.t), u);
523 if (!di && !dj) v += c;
524 if (training && i == j) {
525 v *= 1.0 + eta;
526 if (noise.extent(0) != 0) v += noise(i);
527 }
528 K(i, j) = v;
529 }
530};
531
532template <class ExecSpace>
533struct DiagonalFunctor {
534 using V = Views<ExecSpace>;
535 JointRows<ExecSpace> rows;
536 typename V::const_ivector offsets, perm;
537 typename V::const_vector s;
538 typename V::const_vector noise;
539 typename V::vector diag;
540 double m, c, eta;
541 int n_types;
542
543 KOKKOS_INLINE_FUNCTION void operator()(const index_type i) const
544 {
545 double v;
546 if (rows.channel(i) > 0) {
547 // d = 0 on the diagonal: t = A = B = 0, k = m, K_ii = 2 m C.
548 double C = 0.0;
549 const int atom = (rows.channel(i) - 1) / 3;
550 if (rows.indexed()) {
551 // Only the pairs of this coordinate's atom have a slope:
552 // one partial sum per run of a pair type.
553 int current = -1;
554 double cg = 0.0;
555 for (int k = rows.atom_offsets(atom);
556 k < rows.atom_offsets(atom + 1); ++k) {
557 const int p = rows.atom_pairs(k);
558 const int g = rows.pair_types(p);
559 if (g != current) {
560 if (current >= 0) C += cg * s(current);
561 current = g;
562 cg = 0.0;
563 }
564 const double ji = rows.derivative(i, p);
565 cg += ji * ji;
566 }
567 if (current >= 0) C += cg * s(current);
568 } else {
569 for (int g = 0; g < n_types; ++g) {
570 double cg = 0.0;
571 for (int k = offsets(g); k < offsets(g + 1); ++k) {
572 const double ji = rows.derivative(i, perm(k));
573 cg += ji * ji;
574 }
575 C += cg * s(g);
576 }
577 }
578 v = 2.0 * m * C;
579 } else {
580 v = m + c;
581 }
582 v *= 1.0 + eta;
583 if (noise.extent(0) != 0) v += noise(i);
584 diag(i) = v;
585 }
586};
587
588// Tiled reduction over rows without a pair topology: value r is
589// sum_ij W(i,j) dK_train(i,j)/dtheta_r. Each tile sums a fixed range of
590// entries in index order and the tiles are folded in tile order, so the
591// result does not depend on the thread count.
592// Pair types whose length derivatives one contraction pass reduces.
593inline constexpr int contract_types_per_pass = 30;
594inline constexpr index_type kContractTile = 256;
595
596KOKKOS_INLINE_FUNCTION void compensated_add(double& sum, double& corr,
597 double term)
598{
599 const double next = sum + term;
600 corr += Kokkos::abs(sum) >= Kokkos::abs(term) ? (sum - next) + term
601 : (term - next) + sum;
602 sum = next;
603}
604
605template <class ExecSpace>
606struct ContractTileFunctor {
607 using V = Views<ExecSpace>;
608
609 std::size_t value_count;
610 JointRows<ExecSpace> rows;
611 typename V::const_matrix W;
612 typename V::const_ivector offsets, perm;
613 typename V::const_vector s;
614 typename V::matrix tile_work;
615 double m, c, eta;
616 index_type n, total;
617 int n_types;
618 // One pass reduces the magnitude and constant derivatives (`head`) and
619 // the length derivatives of pair types [g_begin, g_end).
620 bool head;
621 int g_begin, g_end;
622
623 KOKKOS_INLINE_FUNCTION void operator()(const index_type tile) const
624 {
625 for (std::size_t r = 0; r < 2 * value_count; ++r)
626 tile_work(tile, r) = 0.0;
627 const index_type begin = tile * kContractTile;
628 const index_type end =
629 (begin + kContractTile < total) ? (begin + kContractTile) : total;
630 for (index_type idx = begin; idx < end; ++idx) {
631 const index_type i = idx % n;
632 const index_type j = idx / n;
633 double w = W(i, j);
634 if (i == j) w *= 1.0 + eta;
635
636 const Sums u =
637 total_sums(rows, i, rows, j, offsets, perm, s, n_types);
638 const double k = m * Kokkos::exp(-u.t);
639 const bool di = rows.channel(i) > 0;
640 const bool dj = rows.channel(j) > 0;
641
642 const std::size_t first = head ? 2 : 0;
643 if (head) {
644 compensated_add(tile_work(tile, 0),
645 tile_work(tile, value_count),
646 w * block(di, dj, k, u));
647 if (!di && !dj) {
648 compensated_add(tile_work(tile, 1),
649 tile_work(tile, value_count + 1), w * c);
650 }
651 }
652 for (int g = g_begin; g < g_end; ++g) {
653 const Sums ug =
654 type_sums(rows, i, rows, j, offsets, perm, s, g);
655 const Sums du{-2.0 * ug.t, -2.0 * ug.A, -2.0 * ug.B,
656 -2.0 * ug.C};
657 const double dk = 2.0 * ug.t * k;
658 const std::size_t slot =
659 first + static_cast<std::size_t>(g - g_begin);
660 compensated_add(tile_work(tile, slot),
661 tile_work(tile, value_count + slot),
662 w * block_derivative(di, dj, k, u, dk, du));
663 }
664 }
665 for (std::size_t r = 0; r < value_count; ++r)
666 tile_work(tile, r) += tile_work(tile, value_count + r);
667 }
668};
669
670// Contraction over rows with a pair topology.
671//
672// The derivative of an entry with respect to the log length of pair type g
673// is linear in the four sums of that type,
674// alpha t_g + beta A_g + gamma B_g + delta C_g,
675// with coefficients that depend on the entry alone:
676// energy, energy: alpha = 2k
677// slope, energy: alpha = -4k A, beta = 4k
678// energy, slope: alpha = 4k B, gamma = -4k
679// slope, slope: alpha = 2k (2C - 4AB), beta = 8k B,
680// gamma = 8k A, delta = -4k
681// t_g depends on the two geometries, A_g on the row and the other geometry,
682// B_g on the column and the other geometry, and C_g on the pairs the two
683// coordinates share. So the weighted coefficients are summed once over the
684// entries into tables of those shapes, and each type is then a product of
685// the tables with the per-type sums. No entry loops over the types.
686
687// row_index(b, c) is the row of geometry b and channel c, or -1.
688template <class ExecSpace>
689struct RowIndexFunctor {
690 typename Views<ExecSpace>::const_ivector geometry, channel;
691 Kokkos::View<index_type**, Kokkos::LayoutLeft,
693 row_index;
694 KOKKOS_INLINE_FUNCTION void operator()(const index_type i) const
695 {
696 row_index(geometry(i), channel(i)) = i;
697 }
698};
699
700// The parts every contraction functor reads.
701template <class ExecSpace>
702struct ContractInputs {
703 using V = Views<ExecSpace>;
704 JointRows<ExecSpace> rows;
705 typename V::const_matrix W;
706 typename V::const_vector s;
707 typename V::const_matrix total_t, total_a, total_b;
708 Kokkos::View<const index_type**, Kokkos::LayoutLeft,
709 typename V::memory_space>
710 row_index;
711 double m, c, eta;
712 index_type n;
713
714 KOKKOS_INLINE_FUNCTION double weight(index_type i, index_type j) const
715 {
716 return i == j ? W(i, j) * (1.0 + eta) : W(i, j);
717 }
718 KOKKOS_INLINE_FUNCTION Sums sums(index_type i, index_type j) const
719 {
720 return indexed_total_sums(rows, i, rows, j, s, total_t, total_a,
721 total_b);
722 }
723};
724
725// Row i against geometry b: sums over the rows j of that geometry of
726// w alpha, w beta and of the magnitude and constant derivatives.
727template <class ExecSpace>
728struct ContractRowFunctor {
729 using V = Views<ExecSpace>;
730 ContractInputs<ExecSpace> in;
731 typename V::matrix sum_alpha, sum_beta, magnitude, constant; // n x G
732
733 KOKKOS_INLINE_FUNCTION void operator()(const index_type idx) const
734 {
735 const index_type i = idx % in.n;
736 const index_type b = idx / in.n;
737 const bool di = in.rows.channel(i) > 0;
738 double alpha = 0.0, beta = 0.0, m0 = 0.0, c0 = 0.0;
739 for (std::size_t ch = 0; ch < in.row_index.extent(1); ++ch) {
740 const index_type j = in.row_index(b, ch);
741 if (j < 0) continue;
742 const double w = in.weight(i, j);
743 const Sums u = in.sums(i, j);
744 const double k = in.m * Kokkos::exp(-u.t);
745 const bool dj = ch > 0;
746 m0 += w * block(di, dj, k, u);
747 if (!di && !dj) {
748 c0 += w * in.c;
749 alpha += w * (2.0 * k);
750 } else if (di && !dj) {
751 alpha += w * (-4.0 * k * u.A);
752 beta += w * (4.0 * k);
753 } else if (!di && dj) {
754 alpha += w * (4.0 * k * u.B);
755 } else {
756 alpha += w * (2.0 * k * (2.0 * u.C - 4.0 * u.A * u.B));
757 beta += w * (8.0 * k * u.B);
758 }
759 }
760 sum_alpha(i, b) = alpha;
761 sum_beta(i, b) = beta;
762 magnitude(i, b) = m0;
763 constant(i, b) = c0;
764 }
765};
766
767// Column j against geometry a: the sum over the rows i of that geometry of
768// w gamma.
769template <class ExecSpace>
770struct ContractColumnFunctor {
771 using V = Views<ExecSpace>;
772 ContractInputs<ExecSpace> in;
773 typename V::matrix sum_gamma; // n x G
774
775 KOKKOS_INLINE_FUNCTION void operator()(const index_type idx) const
776 {
777 const index_type j = idx % in.n;
778 const index_type a = idx / in.n;
779 double gamma = 0.0;
780 if (in.rows.channel(j) > 0) {
781 for (std::size_t ch = 0; ch < in.row_index.extent(1); ++ch) {
782 const index_type i = in.row_index(a, ch);
783 if (i < 0) continue;
784 const Sums u = in.sums(i, j);
785 const double k = in.m * Kokkos::exp(-u.t);
786 gamma += in.weight(i, j) * (ch > 0 ? 8.0 * k * u.A : -4.0 * k);
787 }
788 }
789 sum_gamma(j, a) = gamma;
790 }
791};
792
793// Slope row i against moving atom y: sums of w delta slope slope over the
794// coordinates of y in every geometry. For y the row's own atom the sums are
795// kept per pair of that atom (own_pair), otherwise the two atoms share one
796// pair (other_atom).
797template <class ExecSpace>
798struct ContractPairFunctor {
799 using V = Views<ExecSpace>;
800 ContractInputs<ExecSpace> in;
801 typename V::matrix own_pair, other_atom;
802
803 KOKKOS_INLINE_FUNCTION void operator()(const index_type idx) const
804 {
805 const index_type i = idx % in.n;
806 const int y = static_cast<int>(idx / in.n);
807 const int ci = in.rows.channel(i) - 1;
808 if (ci < 0) {
809 other_atom(i, y) = 0.0;
810 return;
811 }
812 const int x = ci / 3;
813 const int begin = in.rows.atom_offsets(x);
814 const int end = in.rows.atom_offsets(x + 1);
815 const int shared =
816 x == y ? -1 : in.rows.shared_pair(x * in.rows.atoms() + y);
817 if (x == y)
818 for (int q = begin; q < end; ++q)
819 own_pair(i, q - begin) = 0.0;
820 double other = 0.0;
821 if (x == y || shared >= 0) {
822 for (std::size_t b = 0; b < in.row_index.extent(0); ++b)
823 for (int d = 1; d <= 3; ++d) {
824 const index_type j = in.row_index(b, 3 * y + d);
825 if (j < 0) continue;
826 const Sums u = in.sums(i, j);
827 const double wd =
828 in.weight(i, j) * (-4.0 * in.m * Kokkos::exp(-u.t));
829 if (x == y) {
830 for (int q = begin; q < end; ++q) {
831 const int p = in.rows.atom_pairs(q);
832 own_pair(i, q - begin) += wd *
833 in.rows.derivative(i, p) *
834 in.rows.derivative(j, p);
835 }
836 } else {
837 other += wd * in.rows.derivative(i, shared) *
838 in.rows.derivative(j, shared);
839 }
840 }
841 }
842 other_atom(i, y) = other;
843 }
844};
845
846// by_geometry(a, b) = sum of sum_alpha(i, b) over the rows i of geometry a.
847template <class ExecSpace>
848struct ContractGeometryFunctor {
849 using V = Views<ExecSpace>;
850 typename V::const_ivector geometry;
851 typename V::const_matrix sum_alpha;
852 typename V::matrix by_geometry;
853
854 KOKKOS_INLINE_FUNCTION void operator()(const index_type b) const
855 {
856 for (std::size_t a = 0; a < by_geometry.extent(0); ++a)
857 by_geometry(a, b) = 0.0;
858 for (std::size_t i = 0; i < sum_alpha.extent(0); ++i)
859 by_geometry(geometry(i), b) += sum_alpha(i, b);
860 }
861};
862
863// by_row(i, g): the part of out(2 + g) that belongs to slope row i, its
864// beta and gamma sums against the slope sums of type g and its pair sums
865// for the pairs of that type.
866template <class ExecSpace>
867struct ContractRowTypeFunctor {
868 using V = Views<ExecSpace>;
869 JointRows<ExecSpace> rows;
870 typename V::const_table slope_left, slope_right;
871 typename V::const_matrix sum_beta, sum_gamma, own_pair, other_atom;
872 typename V::const_ivector type_group;
873 typename V::matrix by_row;
874 index_type n;
875
876 KOKKOS_INLINE_FUNCTION void operator()(const index_type idx) const
877 {
878 const index_type i = idx % n;
879 const int g = static_cast<int>(idx / n);
880 double sum = 0.0;
881 const int ci = rows.channel(i) - 1;
882 if (ci >= 0) {
883 for (std::size_t b = 0; b < sum_beta.extent(1); ++b)
884 sum += sum_beta(i, b) * slope_left(i, b, g) +
885 sum_gamma(i, b) * slope_right(i, b, g);
886 const int atom = ci / 3;
887 const int moving = static_cast<int>(other_atom.extent(1));
888 const int begin = rows.atom_offsets(atom);
889 for (int q = begin; q < rows.atom_offsets(atom + 1); ++q) {
890 const int p = rows.atom_pairs(q);
891 if (group_of(type_group, rows.pair_types(p)) != g) continue;
892 sum += own_pair(i, q - begin);
893 const int other =
894 rows.first(p) == atom ? rows.second(p) : rows.first(p);
895 if (other < moving) sum += other_atom(i, other);
896 }
897 }
898 by_row(i, g) = sum;
899 }
900};
901
902// out(2 + g): the geometry table against the distances of pair type g, and
903// the row parts.
904template <class ExecSpace>
905struct ContractTypeFunctor {
906 using V = Views<ExecSpace>;
907 typename V::const_vector s;
908 typename V::const_table distance;
909 typename V::const_matrix by_geometry, by_row;
910 // A type of each group, whose inverse squared length is the group's.
911 typename V::const_ivector group_type;
912 typename V::vector out;
913
914 KOKKOS_INLINE_FUNCTION void operator()(const int g) const
915 {
916 double sum = 0.0;
917 const std::size_t geometries = by_geometry.extent(0);
918 for (std::size_t b = 0; b < geometries; ++b)
919 for (std::size_t a = 0; a < geometries; ++a)
920 sum += by_geometry(a, b) * distance(a, b, g);
921 for (std::size_t i = 0; i < by_row.extent(0); ++i)
922 sum += by_row(i, g);
923 out(2 + g) = s(group_of(group_type, g)) * sum;
924 }
925};
926
927// out(0), out(1): the magnitude and constant derivatives summed over the
928// rows and geometries.
929template <class ExecSpace>
930struct ContractHeadTileFunctor {
931 using V = Views<ExecSpace>;
932 typename V::const_matrix magnitude, constant;
933 typename V::matrix tile_work;
934 index_type n, total;
935
936 KOKKOS_INLINE_FUNCTION void operator()(const index_type tile) const
937 {
938 for (std::size_t r = 0; r < 4; ++r)
939 tile_work(tile, r) = 0.0;
940 const index_type begin = tile * kContractTile;
941 const index_type end =
942 (begin + kContractTile < total) ? (begin + kContractTile) : total;
943 for (index_type idx = begin; idx < end; ++idx) {
944 compensated_add(tile_work(tile, 0), tile_work(tile, 2),
945 magnitude(idx % n, idx / n));
946 compensated_add(tile_work(tile, 1), tile_work(tile, 3),
947 constant(idx % n, idx / n));
948 }
949 tile_work(tile, 0) += tile_work(tile, 2);
950 tile_work(tile, 1) += tile_work(tile, 3);
951 }
952};
953
954// The largest number of pairs of one atom.
955template <class ExecSpace>
956struct DegreeFunctor {
957 typename Views<ExecSpace>::const_ivector offsets;
958 KOKKOS_INLINE_FUNCTION void operator()(const int a, int& largest) const
959 {
960 const int degree = offsets(a + 1) - offsets(a);
961 if (degree > largest) largest = degree;
962 }
963};
964
965template <class ExecSpace>
966struct NoiseContractTileFunctor {
967 using V = Views<ExecSpace>;
968
969 std::size_t value_count;
970 typename V::const_matrix W, dnoise;
971 typename V::matrix tile_work;
972 index_type total;
973
974 KOKKOS_INLINE_FUNCTION void operator()(const index_type tile) const
975 {
976 for (std::size_t r = 0; r < 2 * value_count; ++r)
977 tile_work(tile, r) = 0.0;
978 const index_type begin = tile * kContractTile;
979 const index_type end =
980 (begin + kContractTile < total) ? (begin + kContractTile) : total;
981 for (index_type i = begin; i < end; ++i) {
982 const double w = W(i, i);
983 for (std::size_t r = 0; r < value_count; ++r) {
984 compensated_add(tile_work(tile, r),
985 tile_work(tile, value_count + r),
986 w * dnoise(i, r));
987 }
988 }
989 for (std::size_t r = 0; r < value_count; ++r)
990 tile_work(tile, r) += tile_work(tile, value_count + r);
991 }
992};
993
994template <class ExecSpace>
995struct FoldTileColumnsFunctor {
996 using V = Views<ExecSpace>;
997 typename V::matrix tile_work;
998 typename V::vector out;
999 index_type n_tiles;
1000
1001 KOKKOS_INLINE_FUNCTION void operator()(const std::size_t r) const
1002 {
1003 double sum = 0.0, corr = 0.0;
1004 for (index_type t = 0; t < n_tiles; ++t)
1005 compensated_add(sum, corr, tile_work(t, r));
1006 out(r) = sum + corr;
1007 }
1008};
1009
1010struct Counts {
1011 index_type v[8];
1012};
1013
1014} // namespace detail
1015} // namespace gpr::linalg::kokkos_joint
1016
1017namespace Kokkos {
1018
1019// Sum reduction identity for detail::Counts.
1020template <>
1021struct reduction_identity<gpr::linalg::kokkos_joint::detail::Counts> {
1022 KOKKOS_FORCEINLINE_FUNCTION static gpr::linalg::kokkos_joint::detail::Counts
1023 sum()
1024 {
1025 return gpr::linalg::kokkos_joint::detail::Counts{
1026 {0, 0, 0, 0, 0, 0, 0, 0}};
1027 }
1028};
1029
1030} // namespace Kokkos
1031
1032namespace gpr::linalg::kokkos_joint {
1033namespace detail {
1034
1035KOKKOS_INLINE_FUNCTION Counts& operator+=(Counts& a, const Counts& b)
1036{
1037 for (int r = 0; r < 8; ++r)
1038 a.v[r] += b.v[r];
1039 return a;
1040}
1041
1042// Flattened index space over several arrays; one reduction, one fence.
1043template <class ExecSpace>
1044struct ValidateFunctor {
1045 using V = Views<ExecSpace>;
1046 JointRows<ExecSpace> rows;
1047 typename V::const_ivector channel, pair_type;
1048 typename V::const_vector s;
1049 typename V::const_matrix W;
1050 typename V::const_vector noise;
1051 typename V::const_matrix dnoise;
1052 index_type e_feat, e_chan, e_type, e_len, e_w, e_noise, e_dnoise;
1053 index_type n;
1054 int n_types;
1055
1056 KOKKOS_INLINE_FUNCTION void operator()(index_type idx, Counts& acc) const
1057 {
1058 if (idx < e_feat) {
1059 const index_type i = idx % n, p = idx / n;
1060 if (rows.geometry.extent(0) &&
1061 (rows.geometry(i) < 0 ||
1062 rows.geometry(i) >= rows.q.extent(0))) {
1063 ++acc.v[0];
1064 return;
1065 }
1066 if (!finite(rows.value(i, p))) ++acc.v[0];
1067 if (!finite(rows.derivative(i, p))) ++acc.v[1];
1068 return;
1069 }
1070 idx -= e_feat;
1071 if (idx < e_chan) {
1072 if (channel(idx) < 0) ++acc.v[2];
1073 return;
1074 }
1075 idx -= e_chan;
1076 if (idx < e_type) {
1077 const int g = pair_type(idx);
1078 if (g < 0 || g >= n_types) ++acc.v[3];
1079 return;
1080 }
1081 idx -= e_type;
1082 if (idx < e_len) {
1083 const double x = s(idx);
1084 if (!finite(x) || !(x > 0.0)) ++acc.v[4];
1085 return;
1086 }
1087 idx -= e_len;
1088 if (idx < e_w) {
1089 if (!finite(W(idx % n, idx / n))) ++acc.v[5];
1090 return;
1091 }
1092 idx -= e_w;
1093 if (idx < e_noise) {
1094 const double x = noise(idx);
1095 if (!finite(x) || x < 0.0) ++acc.v[6];
1096 return;
1097 }
1098 idx -= e_noise;
1099 if (idx < e_dnoise) {
1100 if (!finite(dnoise(idx % n, idx / n))) ++acc.v[7];
1101 }
1102 }
1103};
1104
1105inline bool scalars_ok(double m, double c, double eta)
1106{
1107 return Kokkos::isfinite(m) && m > 0.0 && Kokkos::isfinite(c) && c >= 0.0 &&
1108 Kokkos::isfinite(eta) && eta >= 0.0;
1109}
1110
1111template <class ExecSpace>
1112ValidationReport run_validation(const ExecSpace& exec,
1113 ValidateFunctor<ExecSpace> f)
1114{
1115 const index_type total = f.e_feat + f.e_chan + f.e_type + f.e_len + f.e_w +
1116 f.e_noise + f.e_dnoise;
1117 Counts c{};
1118 Kokkos::parallel_reduce(
1119 "gpr::linalg::kokkos_joint::validate",
1120 Kokkos::RangePolicy<ExecSpace, Kokkos::IndexType<index_type>>(exec, 0,
1121 total),
1122 f, Kokkos::Sum<Counts, Kokkos::HostSpace>(c));
1123 exec.fence("gpr::linalg::kokkos_joint::validate");
1124 ValidationReport r;
1125 r.nonfinite_features = c.v[0];
1126 r.nonfinite_jacobian = c.v[1];
1127 r.negative_channels = c.v[2];
1128 r.bad_pair_types = c.v[3];
1129 r.bad_lengths = c.v[4];
1130 r.nonfinite_weights = c.v[5];
1131 r.bad_noise = c.v[6];
1132 r.nonfinite_noise_derivatives = c.v[7];
1133 return r;
1134}
1135
1136} // namespace detail
1137
1138// ---------------------------------------------------------------------------
1139// Setup
1140// ---------------------------------------------------------------------------
1141
1142// Groups features by type on the device (one O(G P) work item; setup cost).
1143// Features whose type is outside [0, n_types) are excluded and are reported by
1144// validate_joint_inputs.
1145template <class ExecSpace>
1147 const ExecSpace& exec,
1148 const typename Views<ExecSpace>::const_ivector& pair_type, int n_types)
1149{
1150 detail::require(n_types >= 0, "negative type count");
1151 detail::require(pair_type.extent(0) <= static_cast<std::size_t>(
1152 std::numeric_limits<int>::max()),
1153 "feature count exceeds int range");
1154 const int P = static_cast<int>(pair_type.extent(0));
1155 typename Views<ExecSpace>::ivector offsets(
1156 Kokkos::view_alloc(exec, Kokkos::WithoutInitializing,
1157 "gpr::linalg::kokkos_joint::offsets"),
1158 static_cast<std::size_t>(n_types) + 1);
1159 typename Views<ExecSpace>::ivector perm(
1160 Kokkos::view_alloc(exec, Kokkos::WithoutInitializing,
1161 "gpr::linalg::kokkos_joint::perm"),
1162 P);
1163 Kokkos::parallel_for("gpr::linalg::kokkos_joint::build_pair_type_index",
1164 Kokkos::RangePolicy<ExecSpace>(exec, 0, 1),
1165 detail::BuildIndexFunctor<ExecSpace>{
1166 pair_type, offsets, perm, n_types, P});
1167 return PairTypeIndex<ExecSpace>{offsets, perm, n_types, P};
1168}
1169
1170// ---------------------------------------------------------------------------
1171// Validation boundary (the only functions that synchronize; they fence `exec`)
1172// ---------------------------------------------------------------------------
1173
1174template <class ExecSpace>
1176 const ExecSpace& exec, const JointRows<ExecSpace>& rows,
1177 const typename Views<ExecSpace>::const_ivector& pair_type,
1178 const JointHyper<ExecSpace>& hyper)
1179{
1180 detail::check_rows(rows);
1181 detail::require(pair_type.extent(0) == rows.q.extent(1),
1182 "pair_type extent must equal feature count");
1183 detail::ValidateFunctor<ExecSpace> f{};
1184 f.rows = rows;
1185 f.channel = rows.channel;
1186 f.pair_type = pair_type;
1187 f.s = hyper.inverse_squared_lengths;
1188 f.n = rows.rows();
1189 f.n_types = hyper.types();
1190 f.e_feat = detail::checked_product(rows.rows(), rows.features());
1191 f.e_chan = rows.rows();
1192 f.e_type = rows.features();
1193 f.e_len = hyper.types();
1194 ValidationReport r = detail::run_validation(exec, f);
1195 r.bad_scalars =
1196 !detail::scalars_ok(hyper.magnitude, hyper.energy_constant, 0.0);
1197 return r;
1198}
1199
1200// Validates W (n x n), eta, optional noise (n or empty) and optional noise
1201// derivatives (n x R or empty).
1202template <class ExecSpace>
1204 const ExecSpace& exec, const typename Views<ExecSpace>::const_matrix& W,
1205 double eta, const typename Views<ExecSpace>::const_vector& noise,
1206 const typename Views<ExecSpace>::const_matrix& dnoise)
1207{
1208 const index_type n = static_cast<index_type>(W.extent(0));
1209 detail::require(W.extent(1) == W.extent(0), "W must be square");
1210 detail::require(noise.extent(0) == 0 || noise.extent(0) == W.extent(0),
1211 "noise extent must be 0 or n");
1212 detail::require(dnoise.extent(0) == 0 || dnoise.extent(0) == W.extent(0),
1213 "noise derivative rows must be 0 or n");
1214 detail::ValidateFunctor<ExecSpace> f{};
1215 f.W = W;
1216 f.noise = noise;
1217 f.dnoise = dnoise;
1218 f.n = n;
1219 f.e_w = detail::checked_product(n, n);
1220 f.e_noise = static_cast<index_type>(noise.extent(0));
1221 f.e_dnoise = dnoise.extent(0) == 0
1222 ? 0
1223 : detail::checked_product(
1224 n, static_cast<index_type>(dnoise.extent(1)));
1225 ValidationReport r = detail::run_validation(exec, f);
1226 r.bad_scalars = !detail::scalars_ok(1.0, 0.0, eta);
1227 return r;
1228}
1229
1230// ---------------------------------------------------------------------------
1231// Pair topology (asynchronous on `exec`)
1232// ---------------------------------------------------------------------------
1233
1234// The squared feature distance of every pair of geometries, per pair type,
1235// for two row sets that carry a pair topology; an empty table otherwise,
1236// which selects the sums over all pairs. One pass of G1 G2 P terms replaces
1237// that sum in each of the n1 n2 matrix entries.
1238template <class ExecSpace>
1240 const ExecSpace& exec, const JointRows<ExecSpace>& rows1,
1241 const JointRows<ExecSpace>& rows2, const PairTypeIndex<ExecSpace>& index,
1242 const typename Views<ExecSpace>::const_ivector& type_group = {},
1243 int n_groups = 0)
1244{
1245 using V = Views<ExecSpace>;
1246 if (!rows1.indexed() || !rows2.indexed() || index.n_types == 0 ||
1247 rows1.geometry.extent(0) == 0 || rows2.geometry.extent(0) == 0)
1248 return typename V::const_table();
1249 detail::require(rows1.atoms() == rows2.atoms() &&
1250 rows1.pair_types.extent(0) == rows1.q.extent(1) &&
1251 rows1.shared_pair.extent(0) ==
1252 static_cast<std::size_t>(rows1.atoms()) *
1253 static_cast<std::size_t>(rows1.atoms()),
1254 "pair topology does not match the rows");
1255 const index_type n_left = static_cast<index_type>(rows1.q.extent(0));
1256 const index_type n_right = static_cast<index_type>(rows2.q.extent(0));
1257 typename V::table table(
1258 Kokkos::view_alloc(exec, Kokkos::WithoutInitializing,
1259 "gpr::linalg::kokkos_joint::distance_table"),
1260 rows1.q.extent(0), rows2.q.extent(0),
1261 static_cast<std::size_t>(type_group.extent(0) != 0 ? n_groups
1262 : index.n_types));
1263 const index_type total = detail::checked_product(n_left, n_right);
1264 if (total != 0)
1265 Kokkos::parallel_for(
1266 "gpr::linalg::kokkos_joint::distance_table",
1267 Kokkos::RangePolicy<ExecSpace, Kokkos::IndexType<index_type>>(
1268 exec, 0, total),
1269 detail::DistanceTableFunctor<ExecSpace>{
1270 rows1.q, rows2.q, index.offsets, index.perm, type_group, table,
1271 n_left, index.n_types});
1272 return table;
1273}
1274
1275// The A sums of `rows` against the geometries of `other` (row_is_left), or
1276// the B sums (otherwise), per pair type; empty when `distances` is, which
1277// is when the rows carry no pair topology. Each has n G' entries per type
1278// and costs the pairs of one atom per entry, where the matrix has n n'.
1279template <class ExecSpace>
1281 const ExecSpace& exec, const JointRows<ExecSpace>& rows,
1282 const JointRows<ExecSpace>& other,
1283 const typename Views<ExecSpace>::const_table& distances, bool row_is_left,
1284 const typename Views<ExecSpace>::const_ivector& type_group = {})
1285{
1286 using V = Views<ExecSpace>;
1287 if (distances.extent(0) == 0) return typename V::const_table();
1288 const index_type n_rows = rows.rows();
1289 const index_type n_other = static_cast<index_type>(other.q.extent(0));
1290 typename V::table table(
1291 Kokkos::view_alloc(exec, Kokkos::WithoutInitializing,
1292 "gpr::linalg::kokkos_joint::slope_table"),
1293 static_cast<std::size_t>(n_rows), other.q.extent(0),
1294 distances.extent(2));
1295 const index_type total = detail::checked_product(n_rows, n_other);
1296 if (total != 0)
1297 Kokkos::parallel_for(
1298 "gpr::linalg::kokkos_joint::slope_table",
1299 Kokkos::RangePolicy<ExecSpace, Kokkos::IndexType<index_type>>(
1300 exec, 0, total),
1301 detail::SlopeTableFunctor<ExecSpace>{rows, other.q, type_group,
1302 table, n_rows, row_is_left});
1303 return table;
1304}
1305
1306// The three totals an assembled entry reads, without the per-type tables:
1307// their memory grows with the number of pair types and an assembly does not
1308// need them. All empty when the rows carry no pair topology.
1309template <class ExecSpace>
1313
1314template <class ExecSpace>
1316 const JointRows<ExecSpace>& rows1,
1317 const JointRows<ExecSpace>& rows2,
1318 const PairTypeIndex<ExecSpace>& index,
1319 const JointHyper<ExecSpace>& hyper)
1320{
1321 using V = Views<ExecSpace>;
1322 using Range = Kokkos::RangePolicy<ExecSpace, Kokkos::IndexType<index_type>>;
1324 if (!rows1.indexed() || !rows2.indexed() || index.n_types == 0 ||
1325 rows1.geometry.extent(0) == 0 || rows2.geometry.extent(0) == 0)
1326 return t;
1327 detail::require(rows1.atoms() == rows2.atoms() &&
1328 rows1.pair_types.extent(0) == rows1.q.extent(1) &&
1329 rows1.shared_pair.extent(0) ==
1330 static_cast<std::size_t>(rows1.atoms()) *
1331 static_cast<std::size_t>(rows1.atoms()),
1332 "pair topology does not match the rows");
1333 const auto without = [&exec](const char* label) {
1334 return Kokkos::view_alloc(exec, Kokkos::WithoutInitializing,
1335 std::string(label));
1336 };
1337 const index_type g1 = static_cast<index_type>(rows1.q.extent(0));
1338 const index_type g2 = static_cast<index_type>(rows2.q.extent(0));
1339 const index_type n1 = rows1.rows(), n2 = rows2.rows();
1340 typename V::matrix distance(without("gpr total distance"),
1341 rows1.q.extent(0), rows2.q.extent(0)),
1342 left(without("gpr total left slope"), static_cast<std::size_t>(n1),
1343 rows2.q.extent(0)),
1344 right(without("gpr total right slope"), static_cast<std::size_t>(n2),
1345 rows1.q.extent(0));
1346 if (detail::checked_product(g1, g2) != 0)
1347 Kokkos::parallel_for(
1348 "gpr::linalg::kokkos_joint::total_distance",
1349 Range(exec, 0, g1 * g2),
1350 detail::TotalDistanceFunctor<ExecSpace>{
1351 rows1.q, rows2.q, index.offsets, index.perm,
1352 hyper.inverse_squared_lengths, distance, g1, index.n_types});
1353 if (detail::checked_product(n1, g2) != 0)
1354 Kokkos::parallel_for(
1355 "gpr::linalg::kokkos_joint::total_left_slope",
1356 Range(exec, 0, n1 * g2),
1357 detail::TotalSlopeFunctor<ExecSpace>{
1358 rows1, rows2.q, hyper.inverse_squared_lengths, left, n1, true});
1359 if (detail::checked_product(n2, g1) != 0)
1360 Kokkos::parallel_for("gpr::linalg::kokkos_joint::total_right_slope",
1361 Range(exec, 0, n2 * g1),
1362 detail::TotalSlopeFunctor<ExecSpace>{
1363 rows2, rows1.q, hyper.inverse_squared_lengths,
1364 right, n2, false});
1365 t.total_t = distance;
1366 t.total_a = left;
1367 t.total_b = right;
1368 return t;
1369}
1370
1371// ---------------------------------------------------------------------------
1372// Assembly (asynchronous on `exec`)
1373// ---------------------------------------------------------------------------
1374
1375// K(i,j) = covariance between rows1 row i and rows2 row j; K is n1 x n2.
1376template <class ExecSpace>
1377void assemble_rectangular(const ExecSpace& exec,
1378 const JointRows<ExecSpace>& rows1,
1379 const JointRows<ExecSpace>& rows2,
1380 const PairTypeIndex<ExecSpace>& index,
1381 const JointHyper<ExecSpace>& hyper,
1382 const typename Views<ExecSpace>::matrix& K)
1383{
1384 detail::check_rows(rows1);
1385 detail::check_rows(rows2);
1386 detail::require(rows1.features() == rows2.features(),
1387 "row sets must have the same feature count");
1388 detail::check_index(index, rows1.features(), hyper.types());
1389 detail::require(K.extent(0) == rows1.rows() && K.extent(1) == rows2.rows(),
1390 "K must be n1 x n2");
1391 const index_type total =
1392 detail::checked_product(rows1.rows(), rows2.rows());
1393 if (total == 0) return;
1394 const auto tables = total_tables(exec, rows1, rows2, index, hyper);
1395 detail::AssembleFunctor<ExecSpace> f{rows1,
1396 rows2,
1397 index.offsets,
1398 index.perm,
1400 {},
1401 K,
1402 hyper.magnitude,
1403 hyper.energy_constant,
1404 0.0,
1405 rows1.rows(),
1406 hyper.types(),
1407 false,
1408 tables.total_t,
1409 tables.total_a,
1410 tables.total_b};
1411 Kokkos::parallel_for(
1412 "gpr::linalg::kokkos_joint::assemble_rectangular",
1413 Kokkos::RangePolicy<ExecSpace, Kokkos::IndexType<index_type>>(exec, 0,
1414 total),
1415 f);
1416}
1417
1418// K_train = K(X,X) + diag(eta K_ii + noise_i); noise may be empty.
1419template <class ExecSpace>
1420void assemble_training(const ExecSpace& exec, const JointRows<ExecSpace>& rows,
1421 const PairTypeIndex<ExecSpace>& index,
1422 const JointHyper<ExecSpace>& hyper, double eta,
1423 const typename Views<ExecSpace>::const_vector& noise,
1424 const typename Views<ExecSpace>::matrix& K)
1425{
1426 detail::check_rows(rows);
1427 detail::check_index(index, rows.features(), hyper.types());
1428 detail::require(K.extent(0) == rows.rows() && K.extent(1) == rows.rows(),
1429 "K must be n x n");
1430 detail::require(noise.extent(0) == 0 || noise.extent(0) == rows.rows(),
1431 "noise extent must be 0 or n");
1432 const index_type total = detail::checked_product(rows.rows(), rows.rows());
1433 if (total == 0) return;
1434 const auto tables = total_tables(exec, rows, rows, index, hyper);
1435 detail::AssembleFunctor<ExecSpace> f{rows,
1436 rows,
1437 index.offsets,
1438 index.perm,
1440 noise,
1441 K,
1442 hyper.magnitude,
1443 hyper.energy_constant,
1444 eta,
1445 rows.rows(),
1446 hyper.types(),
1447 true,
1448 tables.total_t,
1449 tables.total_a,
1450 tables.total_b};
1451 Kokkos::parallel_for(
1452 "gpr::linalg::kokkos_joint::assemble_training",
1453 Kokkos::RangePolicy<ExecSpace, Kokkos::IndexType<index_type>>(exec, 0,
1454 total),
1455 f);
1456}
1457
1458// diag(i) = (1 + eta) K_ii + noise_i (pass eta = 0 and empty noise for the
1459// prior variance). O(n P), no n x n storage.
1460template <class ExecSpace>
1461void assemble_diagonal(const ExecSpace& exec, const JointRows<ExecSpace>& rows,
1462 const PairTypeIndex<ExecSpace>& index,
1463 const JointHyper<ExecSpace>& hyper, double eta,
1464 const typename Views<ExecSpace>::const_vector& noise,
1465 const typename Views<ExecSpace>::vector& diag)
1466{
1467 detail::check_rows(rows);
1468 detail::check_index(index, rows.features(), hyper.types());
1469 detail::require(diag.extent(0) == rows.rows(), "diag must have n entries");
1470 detail::require(noise.extent(0) == 0 || noise.extent(0) == rows.rows(),
1471 "noise extent must be 0 or n");
1472 if (rows.rows() == 0) return;
1473 detail::DiagonalFunctor<ExecSpace> f{
1474 rows, index.offsets, index.perm, hyper.inverse_squared_lengths,
1475 noise, diag, hyper.magnitude, hyper.energy_constant,
1476 eta, hyper.types()};
1477 Kokkos::parallel_for(
1478 "gpr::linalg::kokkos_joint::assemble_diagonal",
1479 Kokkos::RangePolicy<ExecSpace, Kokkos::IndexType<index_type>>(
1480 exec, 0, rows.rows()),
1481 f);
1482}
1483
1484// ---------------------------------------------------------------------------
1485// Weighted derivative contractions (asynchronous on `exec`, no atomics)
1486// ---------------------------------------------------------------------------
1487
1488// out(r) = sum_ij W(i,j) dK_train(i,j)/dtheta_r for
1489// theta = (log m, log c, log l_0, ..., log l_{G-1}); out has 2 + G entries.
1490// The relative nugget contributes eta dK_ii/dtheta_r on the diagonal; the
1491// independent noise is excluded (see contract_noise_derivatives).
1492// The negative log likelihood uses W = (K^{-1} - alpha alpha^T) / 2.
1493template <class ExecSpace>
1495 const ExecSpace& exec, const JointRows<ExecSpace>& rows,
1496 const PairTypeIndex<ExecSpace>& index, const JointHyper<ExecSpace>& hyper,
1497 double eta, const typename Views<ExecSpace>::const_matrix& W,
1498 const typename Views<ExecSpace>::vector& out,
1499 const typename Views<ExecSpace>::const_ivector& type_group = {},
1500 const typename Views<ExecSpace>::const_ivector& group_type = {})
1501{
1502 detail::check_rows(rows);
1503 detail::check_index(index, rows.features(), hyper.types());
1504 detail::require(W.extent(0) == rows.rows() && W.extent(1) == rows.rows(),
1505 "W must be n x n");
1506 // With a group map, pair types that share one length scale are
1507 // contracted together: out has one length entry per group, the sum of
1508 // the entries of its types. The caller holds the lengths equal.
1509 const bool grouped = type_group.extent(0) != 0;
1510 detail::require(!grouped || (type_group.extent(0) ==
1511 static_cast<std::size_t>(hyper.types()) &&
1512 group_type.extent(0) != 0 && rows.indexed()),
1513 "a group map needs one entry per type and indexed rows");
1514 const int n_out =
1515 grouped ? static_cast<int>(group_type.extent(0)) : hyper.types();
1516 const std::size_t count = 2 + static_cast<std::size_t>(n_out);
1517 detail::require(out.extent(0) == count,
1518 "out must have 2 + G entries, G the types or groups");
1519 const index_type total = detail::checked_product(rows.rows(), rows.rows());
1520 const auto tables = total_tables(exec, rows, rows, index, hyper);
1521 if (tables.total_t.extent(0) != 0) {
1522 const auto distance =
1523 distance_table(exec, rows, rows, index, type_group, n_out);
1524 const auto slope_left =
1525 slope_table(exec, rows, rows, distance, true, type_group);
1526 const auto slope_right =
1527 slope_table(exec, rows, rows, distance, false, type_group);
1528 using V = Views<ExecSpace>;
1529 using Range =
1530 Kokkos::RangePolicy<ExecSpace, Kokkos::IndexType<index_type>>;
1531 const index_type n = rows.rows();
1532 const std::size_t geometries = rows.q.extent(0);
1533 int degree = 0;
1534 Kokkos::parallel_reduce(
1535 "gpr::linalg::kokkos_joint::contract_degree",
1536 Kokkos::RangePolicy<ExecSpace>(exec, 0, rows.atoms()),
1537 detail::DegreeFunctor<ExecSpace>{rows.atom_offsets},
1538 Kokkos::Max<int>(degree));
1539 const auto without = [&exec](const char* label) {
1540 return Kokkos::view_alloc(exec, Kokkos::WithoutInitializing,
1541 std::string(label));
1542 };
1543 const std::size_t rows_n = static_cast<std::size_t>(n);
1544 const std::size_t channels =
1545 3 * static_cast<std::size_t>(rows.atoms()) + 1;
1546 Kokkos::View<index_type**, Kokkos::LayoutLeft, typename V::memory_space>
1547 row_index(without("gpr contract row index"), geometries, channels);
1548 ::gpr::linalg::detail::audited_deep_copy(exec, row_index,
1549 index_type(-1));
1550 Kokkos::parallel_for("gpr::linalg::kokkos_joint::contract_row_index",
1551 Range(exec, 0, n),
1552 detail::RowIndexFunctor<ExecSpace>{
1553 rows.geometry, rows.channel, row_index});
1554 typename V::matrix sum_alpha(without("gpr contract alpha"), rows_n,
1555 geometries),
1556 sum_beta(without("gpr contract beta"), rows_n, geometries),
1557 sum_gamma(without("gpr contract gamma"), rows_n, geometries),
1558 magnitude(without("gpr contract magnitude"), rows_n, geometries),
1559 constant(without("gpr contract constant"), rows_n, geometries),
1560 own_pair(without("gpr contract own pair"), rows_n,
1561 static_cast<std::size_t>(degree)),
1562 other_atom(without("gpr contract other atom"), rows_n,
1563 static_cast<std::size_t>(rows.atoms())),
1564 by_geometry(without("gpr contract geometry"), geometries,
1565 geometries);
1566 const detail::ContractInputs<ExecSpace> in{
1567 rows,
1568 W,
1570 tables.total_t,
1571 tables.total_a,
1572 tables.total_b,
1573 row_index,
1574 hyper.magnitude,
1575 hyper.energy_constant,
1576 eta,
1577 n};
1578 const index_type by_row =
1579 detail::checked_product(n, static_cast<index_type>(geometries));
1580 Kokkos::parallel_for("gpr::linalg::kokkos_joint::contract_rows",
1581 Range(exec, 0, by_row),
1582 detail::ContractRowFunctor<ExecSpace>{
1583 in, sum_alpha, sum_beta, magnitude, constant});
1584 Kokkos::parallel_for(
1585 "gpr::linalg::kokkos_joint::contract_columns",
1586 Range(exec, 0, by_row),
1587 detail::ContractColumnFunctor<ExecSpace>{in, sum_gamma});
1588 Kokkos::parallel_for(
1589 "gpr::linalg::kokkos_joint::contract_pairs",
1590 Range(exec, 0,
1591 detail::checked_product(
1592 n, static_cast<index_type>(rows.atoms()))),
1593 detail::ContractPairFunctor<ExecSpace>{in, own_pair, other_atom});
1594 Kokkos::parallel_for(
1595 "gpr::linalg::kokkos_joint::contract_geometries",
1596 Range(exec, 0, static_cast<index_type>(geometries)),
1597 detail::ContractGeometryFunctor<ExecSpace>{rows.geometry, sum_alpha,
1598 by_geometry});
1599 typename V::matrix row_types(without("gpr contract row types"), rows_n,
1600 static_cast<std::size_t>(n_out));
1601 Kokkos::parallel_for(
1602 "gpr::linalg::kokkos_joint::contract_row_types",
1603 Range(exec, 0,
1604 detail::checked_product(n, static_cast<index_type>(n_out))),
1605 detail::ContractRowTypeFunctor<ExecSpace>{
1606 rows, slope_left, slope_right, sum_beta, sum_gamma, own_pair,
1607 other_atom, type_group, row_types, n});
1608 Kokkos::parallel_for("gpr::linalg::kokkos_joint::contract_types",
1609 Kokkos::RangePolicy<ExecSpace>(exec, 0, n_out),
1610 detail::ContractTypeFunctor<ExecSpace>{
1611 hyper.inverse_squared_lengths, distance,
1612 by_geometry, row_types, group_type, out});
1613 const auto head =
1614 Kokkos::subview(out, std::pair<std::size_t, std::size_t>(0, 2));
1615 if (by_row == 0) {
1616 ::gpr::linalg::detail::audited_deep_copy(exec, head, 0.0);
1617 return;
1618 }
1619 const index_type head_tiles =
1620 (by_row + detail::kContractTile - 1) / detail::kContractTile;
1621 typename V::matrix head_work(without("gpr contract head tiles"),
1622 static_cast<std::size_t>(head_tiles), 4);
1623 Kokkos::parallel_for("gpr::linalg::kokkos_joint::contract_head_tiles",
1624 Range(exec, 0, head_tiles),
1625 detail::ContractHeadTileFunctor<ExecSpace>{
1626 magnitude, constant, head_work, n, by_row});
1627 Kokkos::parallel_for("gpr::linalg::kokkos_joint::contract_head_fold",
1628 Kokkos::RangePolicy<ExecSpace>(exec, 0, 2),
1629 detail::FoldTileColumnsFunctor<ExecSpace>{
1630 head_work, head, head_tiles});
1631 return;
1632 }
1633 if (total == 0) {
1634 ::gpr::linalg::detail::audited_deep_copy(exec, out, 0.0);
1635 return;
1636 }
1637 const index_type n_tiles =
1638 (total + detail::kContractTile - 1) / detail::kContractTile;
1639 const std::size_t widest =
1640 count < 2 + static_cast<std::size_t>(detail::contract_types_per_pass)
1641 ? count
1642 : 2 + static_cast<std::size_t>(detail::contract_types_per_pass);
1643 typename Views<ExecSpace>::matrix tile_work(
1644 Kokkos::view_alloc(exec, Kokkos::WithoutInitializing,
1645 "gpr::linalg::kokkos_joint::contract_tiles"),
1646 static_cast<std::size_t>(n_tiles), 2 * widest);
1647 detail::ContractTileFunctor<ExecSpace> f{count,
1648 rows,
1649 W,
1650 index.offsets,
1651 index.perm,
1653 tile_work,
1654 hyper.magnitude,
1655 hyper.energy_constant,
1656 eta,
1657 rows.rows(),
1658 total,
1659 hyper.types(),
1660 true,
1661 0,
1662 0};
1663 // The types are reduced a bounded number at a time, which bounds the
1664 // tile workspace.
1665 const int types = hyper.types();
1666 for (int begin = 0; begin == 0 || begin < types;
1667 begin += detail::contract_types_per_pass) {
1668 const int end = types < begin + detail::contract_types_per_pass
1669 ? types
1670 : begin + detail::contract_types_per_pass;
1671 f.head = begin == 0;
1672 f.g_begin = begin;
1673 f.g_end = end;
1674 const std::size_t first =
1675 f.head ? 0 : 2 + static_cast<std::size_t>(begin);
1676 const std::size_t last = 2 + static_cast<std::size_t>(end);
1677 f.value_count = last - first;
1678 Kokkos::parallel_for(
1679 "gpr::linalg::kokkos_joint::contract_kernel_derivatives_tiles",
1680 Kokkos::RangePolicy<ExecSpace, Kokkos::IndexType<index_type>>(
1681 exec, 0, n_tiles),
1682 f);
1683 Kokkos::parallel_for(
1684 "gpr::linalg::kokkos_joint::contract_kernel_derivatives_fold",
1685 Kokkos::RangePolicy<ExecSpace>(exec, 0, f.value_count),
1686 detail::FoldTileColumnsFunctor<ExecSpace>{
1687 tile_work,
1688 Kokkos::subview(
1689 out, std::pair<std::size_t, std::size_t>(first, last)),
1690 n_tiles});
1691 }
1692}
1693
1694// out(r) = sum_i W(i,i) dnoise(i,r): the independent diagonal noise gradient.
1695template <class ExecSpace>
1697 const ExecSpace& exec, const typename Views<ExecSpace>::const_matrix& W,
1698 const typename Views<ExecSpace>::const_matrix& dnoise,
1699 const typename Views<ExecSpace>::vector& out)
1700{
1701 detail::require(W.extent(0) == W.extent(1), "W must be square");
1702 detail::require(dnoise.extent(0) == W.extent(0), "dnoise must have n rows");
1703 detail::require(out.extent(0) == dnoise.extent(1),
1704 "out must have R entries");
1705 const std::size_t count = out.extent(0);
1706 if (count == 0) return;
1707 const index_type total = static_cast<index_type>(W.extent(0));
1708 if (total == 0) {
1709 ::gpr::linalg::detail::audited_deep_copy(exec, out, 0.0);
1710 return;
1711 }
1712 const index_type n_tiles =
1713 (total + detail::kContractTile - 1) / detail::kContractTile;
1714 typename Views<ExecSpace>::matrix tile_work(
1715 Kokkos::view_alloc(exec, Kokkos::WithoutInitializing,
1716 "gpr::linalg::kokkos_joint::noise_tiles"),
1717 static_cast<std::size_t>(n_tiles), 2 * count);
1718 detail::NoiseContractTileFunctor<ExecSpace> f{count, W, dnoise, tile_work,
1719 total};
1720 Kokkos::parallel_for(
1721 "gpr::linalg::kokkos_joint::contract_noise_derivatives_tiles",
1722 Kokkos::RangePolicy<ExecSpace, Kokkos::IndexType<index_type>>(exec, 0,
1723 n_tiles),
1724 f);
1725 Kokkos::parallel_for(
1726 "gpr::linalg::kokkos_joint::contract_noise_derivatives_fold",
1727 Kokkos::RangePolicy<ExecSpace>(exec, 0, count),
1728 detail::FoldTileColumnsFunctor<ExecSpace>{tile_work, out, n_tiles});
1729}
1730
1731} // namespace gpr::linalg::kokkos_joint
@ x
Definition Enums.h:28
@ y
Definition Enums.h:28
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
PairTypeIndex< ExecSpace > build_pair_type_index(const ExecSpace &exec, const typename Views< ExecSpace >::const_ivector &pair_type, int n_types)
void assemble_rectangular(const ExecSpace &exec, const JointRows< ExecSpace > &rows1, const JointRows< ExecSpace > &rows2, const PairTypeIndex< ExecSpace > &index, const JointHyper< ExecSpace > &hyper, const typename Views< ExecSpace >::matrix &K)
void assemble_training(const ExecSpace &exec, const JointRows< ExecSpace > &rows, const PairTypeIndex< ExecSpace > &index, const JointHyper< ExecSpace > &hyper, double eta, const typename Views< ExecSpace >::const_vector &noise, const typename Views< ExecSpace >::matrix &K)
Views< ExecSpace >::const_table distance_table(const ExecSpace &exec, const JointRows< ExecSpace > &rows1, const JointRows< ExecSpace > &rows2, const PairTypeIndex< ExecSpace > &index, const typename Views< ExecSpace >::const_ivector &type_group={}, int n_groups=0)
void contract_noise_derivatives(const ExecSpace &exec, const typename Views< ExecSpace >::const_matrix &W, const typename Views< ExecSpace >::const_matrix &dnoise, const typename Views< ExecSpace >::vector &out)
void contract_kernel_derivatives(const ExecSpace &exec, const JointRows< ExecSpace > &rows, const PairTypeIndex< ExecSpace > &index, const JointHyper< ExecSpace > &hyper, double eta, const typename Views< ExecSpace >::const_matrix &W, const typename Views< ExecSpace >::vector &out, const typename Views< ExecSpace >::const_ivector &type_group={}, const typename Views< ExecSpace >::const_ivector &group_type={})
void assemble_diagonal(const ExecSpace &exec, const JointRows< ExecSpace > &rows, const PairTypeIndex< ExecSpace > &index, const JointHyper< ExecSpace > &hyper, double eta, const typename Views< ExecSpace >::const_vector &noise, const typename Views< ExecSpace >::vector &diag)
Views< ExecSpace >::const_table slope_table(const ExecSpace &exec, const JointRows< ExecSpace > &rows, const JointRows< ExecSpace > &other, const typename Views< ExecSpace >::const_table &distances, bool row_is_left, const typename Views< ExecSpace >::const_ivector &type_group={})
TotalTables< ExecSpace > total_tables(const ExecSpace &exec, const JointRows< ExecSpace > &rows1, const JointRows< ExecSpace > &rows2, const PairTypeIndex< ExecSpace > &index, const JointHyper< ExecSpace > &hyper)
ValidationReport validate_joint_inputs(const ExecSpace &exec, const JointRows< ExecSpace > &rows, const typename Views< ExecSpace >::const_ivector &pair_type, const JointHyper< ExecSpace > &hyper)
ValidationReport validate_contraction_inputs(const ExecSpace &exec, const typename Views< ExecSpace >::const_matrix &W, double eta, const typename Views< ExecSpace >::const_vector &noise, const typename Views< ExecSpace >::const_matrix &dnoise)
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.
Definition Macros.h:16
Views< ExecSpace >::const_vector inverse_squared_lengths
Views< ExecSpace >::const_ivector pair_types
Views< ExecSpace >::const_ivector channel
Views< ExecSpace >::const_ivector atom_offsets
Views< ExecSpace >::const_ivector geometry
KOKKOS_INLINE_FUNCTION bool indexed() const
Views< ExecSpace >::const_ivector shared_pair
Views< ExecSpace >::const_matrix q
KOKKOS_INLINE_FUNCTION double value(index_type row, int pair) const
KOKKOS_INLINE_FUNCTION int atoms() const
KOKKOS_INLINE_FUNCTION double derivative(index_type row, int pair) const
Views< ExecSpace >::const_matrix J
Views< ExecSpace >::const_ivector first
Kokkos::View< const double ***, Kokkos::LayoutLeft, typename Views< ExecSpace >::memory_space > spatial
Views< ExecSpace >::const_ivector atom_pairs
Views< ExecSpace >::const_ivector second
Views< ExecSpace >::const_ivector perm
Views< ExecSpace >::const_ivector offsets
Views< ExecSpace >::const_matrix total_a
Views< ExecSpace >::const_matrix total_t
Views< ExecSpace >::const_matrix total_b
Kokkos::View< const int *, memory_space > const_ivector
Kokkos::View< double *, memory_space > vector
typename ExecSpace::memory_space memory_space
Kokkos::View< const double *, memory_space > const_vector
Kokkos::View< const double ***, Kokkos::LayoutLeft, memory_space > const_table
Kokkos::View< int *, memory_space > ivector
Kokkos::View< double **, Kokkos::LayoutLeft, memory_space > matrix
Kokkos::View< double ***, Kokkos::LayoutLeft, memory_space > table
Kokkos::View< const double **, Kokkos::LayoutLeft, memory_space > const_matrix