Loading...
Searching...
No Matches
gpr::linalg::kokkos_joint Namespace Reference

Classes

struct  Views
struct  JointRows
struct  JointHyper
struct  PairTypeIndex
struct  ValidationReport
struct  TotalTables

Typedefs

using index_type = std::int64_t

Functions

template<class ExecSpace>
PairTypeIndex< ExecSpace > build_pair_type_index (const ExecSpace &exec, const typename Views< ExecSpace >::const_ivector &pair_type, int n_types)
template<class ExecSpace>
ValidationReport validate_joint_inputs (const ExecSpace &exec, const JointRows< ExecSpace > &rows, const typename Views< ExecSpace >::const_ivector &pair_type, const JointHyper< ExecSpace > &hyper)
template<class ExecSpace>
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)
template<class ExecSpace>
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)
template<class ExecSpace>
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={})
template<class ExecSpace>
TotalTables< ExecSpace > total_tables (const ExecSpace &exec, const JointRows< ExecSpace > &rows1, const JointRows< ExecSpace > &rows2, const PairTypeIndex< ExecSpace > &index, const JointHyper< ExecSpace > &hyper)
template<class ExecSpace>
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)
template<class ExecSpace>
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)
template<class ExecSpace>
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)
template<class ExecSpace>
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={})
template<class ExecSpace>
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)

Typedef Documentation

◆ index_type

Definition at line 17 of file KokkosJointKernel.h.

Function Documentation

◆ assemble_diagonal()

template<class ExecSpace>
void gpr::linalg::kokkos_joint::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 )

Definition at line 1461 of file KokkosJointKernel.h.

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}
Views< ExecSpace >::const_vector inverse_squared_lengths
Views< ExecSpace >::const_ivector perm
Views< ExecSpace >::const_ivector offsets

◆ assemble_rectangular()

template<class ExecSpace>
void gpr::linalg::kokkos_joint::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 )

Definition at line 1377 of file KokkosJointKernel.h.

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}
TotalTables< ExecSpace > total_tables(const ExecSpace &exec, const JointRows< ExecSpace > &rows1, const JointRows< ExecSpace > &rows2, const PairTypeIndex< ExecSpace > &index, const JointHyper< ExecSpace > &hyper)

◆ assemble_training()

template<class ExecSpace>
void gpr::linalg::kokkos_joint::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 )

Definition at line 1420 of file KokkosJointKernel.h.

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}

◆ build_pair_type_index()

template<class ExecSpace>
PairTypeIndex< ExecSpace > gpr::linalg::kokkos_joint::build_pair_type_index ( const ExecSpace & exec,
const typename Views< ExecSpace >::const_ivector & pair_type,
int n_types )

Definition at line 1146 of file KokkosJointKernel.h.

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}
Kokkos::View< int *, memory_space > ivector

◆ contract_kernel_derivatives()

template<class ExecSpace>
void gpr::linalg::kokkos_joint::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 = {} )

Definition at line 1494 of file KokkosJointKernel.h.

1499 {},
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}
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
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)
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={})
Views< ExecSpace >::const_ivector channel
Views< ExecSpace >::const_ivector geometry
KOKKOS_INLINE_FUNCTION bool indexed() const
Views< ExecSpace >::const_matrix q
KOKKOS_INLINE_FUNCTION int atoms() const
Kokkos::View< const int *, memory_space > const_ivector
Kokkos::View< double **, Kokkos::LayoutLeft, memory_space > matrix

◆ contract_noise_derivatives()

template<class ExecSpace>
void gpr::linalg::kokkos_joint::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 )

Definition at line 1696 of file KokkosJointKernel.h.

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}

◆ distance_table()

template<class ExecSpace>
Views< ExecSpace >::const_table gpr::linalg::kokkos_joint::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 )

Definition at line 1239 of file KokkosJointKernel.h.

1242 {},
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}
Views< ExecSpace >::const_ivector pair_types
Views< ExecSpace >::const_ivector shared_pair

◆ slope_table()

template<class ExecSpace>
Views< ExecSpace >::const_table gpr::linalg::kokkos_joint::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 = {} )

Definition at line 1280 of file KokkosJointKernel.h.

1284 {})
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}

◆ total_tables()

template<class ExecSpace>
TotalTables< ExecSpace > gpr::linalg::kokkos_joint::total_tables ( const ExecSpace & exec,
const JointRows< ExecSpace > & rows1,
const JointRows< ExecSpace > & rows2,
const PairTypeIndex< ExecSpace > & index,
const JointHyper< ExecSpace > & hyper )

Definition at line 1315 of file KokkosJointKernel.h.

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}
Views< ExecSpace >::const_matrix total_a
Views< ExecSpace >::const_matrix total_t
Views< ExecSpace >::const_matrix total_b

◆ validate_contraction_inputs()

template<class ExecSpace>
ValidationReport gpr::linalg::kokkos_joint::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 )

Definition at line 1203 of file KokkosJointKernel.h.

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}

◆ validate_joint_inputs()

template<class ExecSpace>
ValidationReport gpr::linalg::kokkos_joint::validate_joint_inputs ( const ExecSpace & exec,
const JointRows< ExecSpace > & rows,
const typename Views< ExecSpace >::const_ivector & pair_type,
const JointHyper< ExecSpace > & hyper )

Definition at line 1175 of file KokkosJointKernel.h.

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}