einsums::packed_gemm::stream_contract#
Note
Generated from the C++ headers by apiary --emit-cpp-docs-json.
Defined in header Einsums/PackedGemm/Stream.hpp.
-
template<typename T>
void stream_contract(const T *s, const StreamLayout &s_layout, const std::vector<StreamTerm<T>> &terms, const std::vector<int> &partition_axes)# Evaluate every term with one read of \(S\), in storage order.
A contraction in which one operand supplies every index and the other operands are small is memory-bandwidth bound: its cost is one read of \(S\). This walks \(S\) once, fastest axis innermost, and adds each element’s contribution to every term’s output, so \(N\) terms over one tensor cost one read of it instead of \(N\).
The team is sized to the work: a stream too short to pay for forking threads runs serially and writes every output in place. A parallel walk accumulates outputs in per-thread private buffers and reduces them at the end, unless
partition_axesnames axes of \(S\) the walk may split between threads instead: the kernel partitions one of them (preferring an axis with a block for every thread, then the largest stride), and each term whose output carries that axis writes its own disjoint slice directly. Terms sharing an output must put the axis in the same place in it: one on the rows and another on the columns would hand each thread crossing stripes, so such a term is privatized instead. Every term whose output does not carry the chosen axis is privatized too, so the caller must keep those outputs small enough for a copy per thread to stay in cache.Each output’s
c_pfis applied once, before any accumulation, even when \(S\) is empty. The work is split over the threads the parallel region actually receives, so a call from inside another parallel region, where the region does not fork, runs correctly on one thread.Added in version 2.0.0.
- Parameters:
s – The streamed tensor’s data.
s_layout – Its geometry.
terms – The contractions to evaluate. No output may overlap \(S\), a small operand, or another output.
partition_axes – Axes of \(S\) the walk may partition for direct writes; empty to privatize every output.
- Throws:
std::invalid_argument – If a term’s axis maps do not match \(S\)’s rank, or a term after the first on an output has a
c_pfother than 1.