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

Typedefs

using ParallelItems

Functions

bool fullTileInPlaceAvailable () noexcept
void subtract (double *out, std::ptrdiff_t out_stride, const double *left, std::ptrdiff_t left_stride, const double *right, std::ptrdiff_t right_stride, std::ptrdiff_t rows, std::ptrdiff_t columns, std::ptrdiff_t depth, bool transpose_right)
void addTransposeProduct (double *out, const double *left, const double *right, std::ptrdiff_t rows, std::ptrdiff_t columns, std::ptrdiff_t depth)
bool factorLower (double *matrix, std::ptrdiff_t order)
void solveLeft (const double *factor, double *rhs, std::ptrdiff_t order, std::ptrdiff_t columns, bool lower)
bool factorLowerGeneral (double *matrix, std::ptrdiff_t stride, std::ptrdiff_t order, ParallelItems run, void *run_context)
void solveLeftGeneral (const double *factor, std::ptrdiff_t factor_stride, bool lower_factor, double *rhs, std::ptrdiff_t rhs_stride, std::ptrdiff_t order, std::ptrdiff_t columns, ParallelItems run, void *run_context)
void solveVectorGeneral (const double *factor, std::ptrdiff_t factor_stride, bool lower_factor, double *rhs, std::ptrdiff_t order)
void assignTransposeGram (const double *b, std::ptrdiff_t b_stride, double *c, std::ptrdiff_t c_stride, std::ptrdiff_t order, ParallelItems run, void *run_context)
void solveRightUpper (const double *factor, double *rhs, std::ptrdiff_t rows, std::ptrdiff_t order)
void addMatrixProduct (double *out, std::ptrdiff_t out_stride, const double *left, std::ptrdiff_t left_stride, const double *right, std::ptrdiff_t right_stride, std::ptrdiff_t rows, std::ptrdiff_t columns, std::ptrdiff_t depth, double scale, bool transpose_left, bool transpose_right)
template<bool TransposeRight = false, class Target, class Left, class Right>
void subtractProduct (Target &&out, const Left &left, const Right &right)

Typedef Documentation

◆ ParallelItems

Initial value:
void (*)(void* context, std::ptrdiff_t count,
void (*item)(void*, std::ptrdiff_t),
void* item_context)

Runs item(item_context, 0) .. item(item_context, count - 1) and returns when all have finished. Items write disjoint memory, so they may run in any order and on any thread.

Definition at line 51 of file CanonicalTileKernels.h.

Function Documentation

◆ addMatrixProduct()

void gpr::linalg::portable_tiles::addMatrixProduct ( double * out,
std::ptrdiff_t out_stride,
const double * left,
std::ptrdiff_t left_stride,
const double * right,
std::ptrdiff_t right_stride,
std::ptrdiff_t rows,
std::ptrdiff_t columns,
std::ptrdiff_t depth,
double scale,
bool transpose_left,
bool transpose_right )

Definition at line 410 of file CanonicalTileKernels.cpp.

416{
417 if (rows <= 0 || columns <= 0 || depth <= 0 || scale == 0.0 ||
418 out == nullptr || left == nullptr || right == nullptr)
419 return;
420 using Stride = Eigen::OuterStride<>;
421 using ConstMap = Eigen::Map<const Eigen::MatrixXd, 0, Stride>;
422 Eigen::Map<Eigen::MatrixXd, 0, Stride> result(out, rows, columns,
423 Stride(out_stride));
424 const auto accumulate = [&](const auto& product) {
425 if (scale == 1.0)
426 result.noalias() += product;
427 else if (scale == -1.0)
428 result.noalias() -= product;
429 else
430 result.noalias() += scale * product;
431 };
432 if (transpose_left && transpose_right) {
433 const ConstMap a(left, depth, rows, Stride(left_stride));
434 const ConstMap b(right, columns, depth, Stride(right_stride));
435 accumulate(a.transpose() * b.transpose());
436 } else if (transpose_left) {
437 const ConstMap a(left, depth, rows, Stride(left_stride));
438 const ConstMap b(right, depth, columns, Stride(right_stride));
439 accumulate(a.transpose() * b);
440 } else if (transpose_right) {
441 const ConstMap a(left, rows, depth, Stride(left_stride));
442 const ConstMap b(right, columns, depth, Stride(right_stride));
443 accumulate(a * b.transpose());
444 } else {
445 const ConstMap a(left, rows, depth, Stride(left_stride));
446 const ConstMap b(right, depth, columns, Stride(right_stride));
447 accumulate(a * b);
448 }
449}
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
void accumulate(const Value &value, Real wk, Real wg, Value &k, Value &g, Value &absolute)

◆ addTransposeProduct()

void gpr::linalg::portable_tiles::addTransposeProduct ( double * out,
const double * left,
const double * right,
std::ptrdiff_t rows,
std::ptrdiff_t columns,
std::ptrdiff_t depth )

Definition at line 276 of file CanonicalTileKernels.cpp.

279{
280 using ConstMap = Eigen::Map<const Eigen::MatrixXd, Eigen::Aligned64>;
281 Eigen::Map<Eigen::MatrixXd, Eigen::Aligned64> result(out, rows, columns);
282 const ConstMap a(left, depth, rows), b(right, depth, columns);
283 result.noalias() += a.transpose() * b;
284}

◆ assignTransposeGram()

void gpr::linalg::portable_tiles::assignTransposeGram ( const double * b,
std::ptrdiff_t b_stride,
double * c,
std::ptrdiff_t c_stride,
std::ptrdiff_t order,
ParallelItems run,
void * run_context )

Definition at line 375 of file CanonicalTileKernels.cpp.

378{
379 if (order <= 0 || b == nullptr || c == nullptr) return;
380 using Stride = Eigen::OuterStride<>;
381 const Eigen::Map<const Eigen::MatrixXd, 0, Stride> left(b, order, order,
382 Stride(b_stride));
383 Eigen::Map<Eigen::MatrixXd, 0, Stride> gram(c, order, order,
384 Stride(c_stride));
385 if (run == nullptr || order < kMinParallelOrder) {
386 gram.noalias() = left.transpose() * left;
387 return;
388 }
389 // Column ranges of one product: a range of two or more columns stays on
390 // the blocked kernel (one column would take the matrix-vector path).
391 const std::vector<Index> starts = alignedStarts(order, Traits::nr);
392 auto item = [&](Index i) {
393 const Index first = starts[i], width = starts[i + 1] - starts[i];
394 gram.middleCols(first, width).noalias() =
395 left.transpose() * left.middleCols(first, width);
396 };
397 Items(run, run_context)(static_cast<Index>(starts.size()) - 1, item);
398}

◆ factorLower()

bool gpr::linalg::portable_tiles::factorLower ( double * matrix,
std::ptrdiff_t order )

Definition at line 286 of file CanonicalTileKernels.cpp.

287{
288 Eigen::Map<Eigen::MatrixXd, Eigen::Aligned64> block(matrix, order, order);
289 Eigen::LLT<Eigen::Ref<Eigen::MatrixXd>> factor(block);
290 return factor.info() == Eigen::Success;
291}

◆ factorLowerGeneral()

bool gpr::linalg::portable_tiles::factorLowerGeneral ( double * matrix,
std::ptrdiff_t stride,
std::ptrdiff_t order,
ParallelItems run,
void * run_context )

Definition at line 305 of file CanonicalTileKernels.cpp.

308{
309 if (order < 0 || (order > 0 && (matrix == nullptr || stride < order)))
310 return false;
311 if (order == 0) return true;
312 const auto factorise = [&](DenseRef lower) {
313 if (run == nullptr) {
314 Eigen::LLT<DenseRef, Eigen::Lower> factor(lower);
315 return factor.info() == Eigen::Success;
316 }
317 return blockedLowerLLT(lower, Items(run, run_context)) == -1;
318 };
319 // A contiguous column-major buffer is factored in place. Eigen's lower
320 // LLT reads and writes only that triangle, so a zero-filled copy is the
321 // same factor and an extra allocation.
322 if (stride == order) {
323 Eigen::Map<Eigen::MatrixXd> mapped(matrix, order, order);
324 return factorise(mapped);
325 }
326 using Stride = Eigen::OuterStride<>;
327 Eigen::Map<Eigen::MatrixXd, 0, Stride> mapped(matrix, order, order,
328 Stride(stride));
329 thread_local Eigen::MatrixXd dense;
330 dense.resize(order, order);
331 dense.setZero();
332 dense.triangularView<Eigen::Lower>() =
333 mapped.triangularView<Eigen::Lower>();
334 if (!factorise(dense)) return false;
335 mapped.triangularView<Eigen::Lower>() =
336 dense.triangularView<Eigen::Lower>();
337 return true;
338}

◆ fullTileInPlaceAvailable()

bool gpr::linalg::portable_tiles::fullTileInPlaceAvailable ( )
noexcept

Whether full packed operands can update a strided result in place with the same arithmetic as a packed result.

Definition at line 251 of file CanonicalTileKernels.cpp.

252{
254}
bool wideTileProductAvailable() noexcept
Definition TileProduct.h:17

◆ solveLeft()

void gpr::linalg::portable_tiles::solveLeft ( const double * factor,
double * rhs,
std::ptrdiff_t order,
std::ptrdiff_t columns,
bool lower )

Definition at line 293 of file CanonicalTileKernels.cpp.

295{
296 const Eigen::Map<const Eigen::MatrixXd, Eigen::Aligned64> diagonal(
297 factor, order, order);
298 Eigen::Map<Eigen::MatrixXd, Eigen::Aligned64> result(rhs, order, columns);
299 if (lower)
300 diagonal.triangularView<Eigen::Lower>().solveInPlace(result);
301 else
302 diagonal.triangularView<Eigen::Upper>().solveInPlace(result);
303}

◆ solveLeftGeneral()

void gpr::linalg::portable_tiles::solveLeftGeneral ( const double * factor,
std::ptrdiff_t factor_stride,
bool lower_factor,
double * rhs,
std::ptrdiff_t rhs_stride,
std::ptrdiff_t order,
std::ptrdiff_t columns,
ParallelItems run,
void * run_context )

Definition at line 340 of file CanonicalTileKernels.cpp.

344{
345 if (order <= 0 || columns <= 0 || factor == nullptr || rhs == nullptr)
346 return;
347 using Stride = Eigen::OuterStride<>;
348 const Eigen::Map<const Eigen::MatrixXd, 0, Stride> triangular(
349 factor, order, order, Stride(factor_stride));
350 Eigen::Map<Eigen::MatrixXd, 0, Stride> result(rhs, order, columns,
351 Stride(rhs_stride));
352 const Items items(run, run_context);
353 if (lower_factor)
354 solveColumns(triangular.triangularView<Eigen::Lower>(), result, items);
355 else
356 solveColumns(triangular.transpose().triangularView<Eigen::Upper>(),
357 result, items);
358}

◆ solveRightUpper()

void gpr::linalg::portable_tiles::solveRightUpper ( const double * factor,
double * rhs,
std::ptrdiff_t rows,
std::ptrdiff_t order )

Definition at line 400 of file CanonicalTileKernels.cpp.

402{
403 const Eigen::Map<const Eigen::MatrixXd, Eigen::Aligned64> diagonal(
404 factor, order, order);
405 Eigen::Map<Eigen::MatrixXd, Eigen::Aligned64> result(rhs, rows, order);
406 diagonal.triangularView<Eigen::Upper>().solveInPlace<Eigen::OnTheRight>(
407 result);
408}

◆ solveVectorGeneral()

void gpr::linalg::portable_tiles::solveVectorGeneral ( const double * factor,
std::ptrdiff_t factor_stride,
bool lower_factor,
double * rhs,
std::ptrdiff_t order )

Solves for one right-hand side held as a vector. Eigen picks its triangular-solve kernel from the compile-time shape of the right-hand side: a vector runs the matrix-vector sweep, a one-column matrix runs the blocked matrix kernel, and the two round differently.

Definition at line 360 of file CanonicalTileKernels.cpp.

362{
363 if (order <= 0 || factor == nullptr || rhs == nullptr) return;
364 using Stride = Eigen::OuterStride<>;
365 const Eigen::Map<const Eigen::MatrixXd, 0, Stride> triangular(
366 factor, order, order, Stride(factor_stride));
367 Eigen::Map<Eigen::VectorXd> result(rhs, order);
368 if (lower_factor)
369 triangular.triangularView<Eigen::Lower>().solveInPlace(result);
370 else
371 triangular.transpose().triangularView<Eigen::Upper>().solveInPlace(
372 result);
373}

◆ subtract()

void gpr::linalg::portable_tiles::subtract ( double * out,
std::ptrdiff_t out_stride,
const double * left,
std::ptrdiff_t left_stride,
const double * right,
std::ptrdiff_t right_stride,
std::ptrdiff_t rows,
std::ptrdiff_t columns,
std::ptrdiff_t depth,
bool transpose_right )

Definition at line 256 of file CanonicalTileKernels.cpp.

261{
262 using Stride = Eigen::OuterStride<>;
263 using ConstMap = Eigen::Map<const Eigen::MatrixXd, 0, Stride>;
264 Eigen::Map<Eigen::MatrixXd, 0, Stride> result(out, rows, columns,
265 Stride(out_stride));
266 const ConstMap a(left, rows, depth, Stride(left_stride));
267 if (transpose_right) {
268 const ConstMap b(right, columns, depth, Stride(right_stride));
270 } else {
271 const ConstMap b(right, depth, columns, Stride(right_stride));
272 canonical::subtractTileProduct(result, a, b);
273 }
274}
void subtractTileProduct(Target &&out, const Left &left, const Right &right)

◆ subtractProduct()

template<bool TransposeRight = false, class Target, class Left, class Right>
void gpr::linalg::portable_tiles::subtractProduct ( Target && out,
const Left & left,
const Right & right )
inline

Definition at line 95 of file CanonicalTileKernels.h.

96{
97 subtract(out.data(), out.outerStride(), left.data(), left.outerStride(),
98 right.data(), right.outerStride(), out.rows(), out.cols(),
99 left.cols(), TransposeRight);
100}
void subtract(double *out, std::ptrdiff_t out_stride, const double *left, std::ptrdiff_t left_stride, const double *right, std::ptrdiff_t right_stride, std::ptrdiff_t rows, std::ptrdiff_t columns, std::ptrdiff_t depth, bool transpose_right)