d-SEAMS
Install
Output
Methods
Docs
Engine & CLI
Python
Rust
Julia
R
Lua / Fennel
Fortran
PLUMED
linkcell
Wiki
Cite
GitHub
seams-core
v2.14.0
libyodaLib, the C++ engine of d-SEAMS
Toggle main menu visibility
Loading...
Searching...
No Matches
ozaki.hpp
Go to the documentation of this file.
1
#ifndef SEAMS_OZAKI_H_
2
#define SEAMS_OZAKI_H_
3
4
// Emulated products for the short dots and the one tiny GEMM in d-SEAMS.
5
//
6
// Ozaki scheme I splits a floating-point vector into slices whose products
7
// are exact in FP64 (Ozaki, Ogita and Oishi, Numer. Algorithms 59, 95, 2012).
8
// Ozaki scheme II replaces that slicing by an integer matrix product modulo
9
// several coprime moduli and a Chinese-remainder reconstruction (Ozaki,
10
// Uchino and Imamura, arXiv:2504.08009, 2025). The INT8 products use
11
// AVX-512 VNNI or AMX-INT8 when the shape fills a tile; shorter products
12
// use an INT32 accumulator, which is exact for the lengths that occur here.
13
//
14
// TwoProd / TwoSum and pairwise summation are the error-free transformations
15
// of Dekker, Knuth, and Ogita, Rump and Oishi (SIAM J. Sci. Comput. 26,
16
// 2005). Pairwise summation is the reduction whose error Higham bounds by
17
// gamma_{ceil(log2 n)} (Accuracy and Stability of Numerical Algorithms,
18
// SIAM, 2002). It does not depend on a left-to-right fold.
19
20
#include <complex>
21
#include <cstddef>
22
#include <vector>
23
24
namespace
seams::product
{
25
26
enum class
Mode
{
27
Fp64
= 0,
28
Dot2
= 1,
29
OzakiI
= 2,
30
OzakiII
= 3,
31
};
32
33
enum class
Reduction
{
34
Left
= 0,
35
Pairwise
= 1,
36
Neumaier
= 2,
37
};
38
39
enum class
Int8Backend
{
40
Auto
= 0,
41
Scalar
= 1,
42
Vnni
= 2,
43
Amx
= 3,
44
};
45
46
struct
RealDot
{
47
double
value
;
48
double
bound
;
49
bool
certified
;
50
int
work
;
51
const
char
*
backend
;
52
};
53
54
struct
ComplexDot
{
55
double
re
;
56
double
im
;
57
double
normA
;
58
double
normB
;
59
double
boundRe
;
60
double
boundIm
;
61
double
boundNormA
;
62
double
boundNormB
;
63
bool
certified
;
64
const
char
*
backend
;
65
};
66
67
Mode
mode
();
68
void
setMode
(
Mode
m);
69
const
char
*
modeName
(
Mode
m);
70
71
Reduction
reduction
();
72
void
setReduction
(
Reduction
r);
73
const
char
*
reductionName
(
Reduction
r);
74
75
bool
amxAvailable
();
76
bool
vnniAvailable
();
77
78
void
twoSum
(
double
a,
double
b,
double
&s,
double
&e);
79
void
twoProd
(
double
a,
double
b,
double
&hi,
double
&lo);
80
81
double
pairwiseSum
(
const
double
*x,
int
n);
82
double
neumaierSum
(
const
double
*x,
int
n);
83
double
leftSum
(
const
double
*x,
int
n);
84
double
reduce
(
const
double
*x,
int
n,
Reduction
r);
85
86
// Absolute error bound for pairwise summation of n finite terms whose
87
// absolute values sum to absSum (Higham's gamma_ceil(log2 n) bound,
88
// rounded upward).
89
double
pairwiseBound
(
int
n,
long
double
absSum);
90
91
RealDot
realDot
(
const
double
*x,
const
double
*y,
int
n,
Mode
m);
92
93
ComplexDot
complexDot
(
const
std::complex<double> *a,
94
const
std::complex<double> *b,
int
n,
Mode
m);
95
96
// c = Re(a ยท conj(b)) / (|a| |b|), with an absolute certificate.
97
struct
Cij
{
98
double
value
;
99
double
bound
;
100
bool
certified
;
101
const
char
*
backend
;
102
};
103
104
Cij
bondCorrelation
(
const
std::complex<double> *a,
const
std::complex<double> *b,
105
int
n,
Mode
m);
106
107
// Mean of the finite entries, in input order. Left matches a plain
108
// accumulator; pairwise and Neumaier do not depend on a chain of +=.
109
double
meanOfFinite
(
const
double
*x,
int
n,
Reduction
r);
110
111
// Row-major C = A(m x k) * B(k x n). bounds may be null. On Ozaki-II each
112
// bounds[i*n+j] is an absolute certificate. Fp64 leaves bounds at 0 when
113
// the pointer is non-null (no certificate for the rounded GEMM).
114
struct
GemmInfo
{
115
bool
ok
;
116
const
char
*
backend
;
117
int
moduli
;
118
int
sliceWidth
;
119
};
120
121
GemmInfo
gemm
(
int
m,
int
n,
int
k,
const
double
*A,
int
lda,
const
double
*B,
122
int
ldb,
double
*C,
int
ldc,
Mode
mode
,
double
*bounds,
123
Int8Backend
backend =
Int8Backend::Auto
);
124
125
// INT8 C += A * B, row-major, int32 accumulator. Used to check the tiles.
126
// Returns false when the backend cannot run this shape.
127
bool
int8Gemm
(
int
m,
int
n,
int
k,
const
signed
char
*A,
int
lda,
128
const
signed
char
*B,
int
ldb,
int
*C,
int
ldc,
129
Int8Backend
backend);
130
131
}
// namespace seams::product
132
133
#endif
seams::product
Definition
ozaki.hpp:24
seams::product::meanOfFinite
double meanOfFinite(const double *x, int n, Reduction r)
seams::product::complexDot
ComplexDot complexDot(const std::complex< double > *a, const std::complex< double > *b, int n, Mode m)
seams::product::realDot
RealDot realDot(const double *x, const double *y, int n, Mode m)
seams::product::pairwiseSum
double pairwiseSum(const double *x, int n)
seams::product::setReduction
void setReduction(Reduction r)
seams::product::pairwiseBound
double pairwiseBound(int n, long double absSum)
seams::product::Reduction
Reduction
Definition
ozaki.hpp:33
seams::product::Reduction::Pairwise
@ Pairwise
Definition
ozaki.hpp:35
seams::product::Reduction::Neumaier
@ Neumaier
Definition
ozaki.hpp:36
seams::product::Reduction::Left
@ Left
Definition
ozaki.hpp:34
seams::product::mode
Mode mode()
seams::product::reduce
double reduce(const double *x, int n, Reduction r)
seams::product::leftSum
double leftSum(const double *x, int n)
seams::product::amxAvailable
bool amxAvailable()
seams::product::int8Gemm
bool int8Gemm(int m, int n, int k, const signed char *A, int lda, const signed char *B, int ldb, int *C, int ldc, Int8Backend backend)
seams::product::reduction
Reduction reduction()
seams::product::neumaierSum
double neumaierSum(const double *x, int n)
seams::product::reductionName
const char * reductionName(Reduction r)
seams::product::Mode
Mode
Definition
ozaki.hpp:26
seams::product::Mode::Dot2
@ Dot2
Definition
ozaki.hpp:28
seams::product::Mode::OzakiI
@ OzakiI
Definition
ozaki.hpp:29
seams::product::Mode::Fp64
@ Fp64
Definition
ozaki.hpp:27
seams::product::Mode::OzakiII
@ OzakiII
Definition
ozaki.hpp:30
seams::product::twoSum
void twoSum(double a, double b, double &s, double &e)
seams::product::modeName
const char * modeName(Mode m)
seams::product::setMode
void setMode(Mode m)
seams::product::gemm
GemmInfo gemm(int m, int n, int k, const double *A, int lda, const double *B, int ldb, double *C, int ldc, Mode mode, double *bounds, Int8Backend backend=Int8Backend::Auto)
seams::product::twoProd
void twoProd(double a, double b, double &hi, double &lo)
seams::product::bondCorrelation
Cij bondCorrelation(const std::complex< double > *a, const std::complex< double > *b, int n, Mode m)
seams::product::Int8Backend
Int8Backend
Definition
ozaki.hpp:39
seams::product::Int8Backend::Auto
@ Auto
Definition
ozaki.hpp:40
seams::product::Int8Backend::Vnni
@ Vnni
Definition
ozaki.hpp:42
seams::product::Int8Backend::Amx
@ Amx
Definition
ozaki.hpp:43
seams::product::Int8Backend::Scalar
@ Scalar
Definition
ozaki.hpp:41
seams::product::vnniAvailable
bool vnniAvailable()
seams::product::Cij
Definition
ozaki.hpp:97
seams::product::Cij::certified
bool certified
Definition
ozaki.hpp:100
seams::product::Cij::value
double value
Definition
ozaki.hpp:98
seams::product::Cij::backend
const char * backend
Definition
ozaki.hpp:101
seams::product::Cij::bound
double bound
Definition
ozaki.hpp:99
seams::product::ComplexDot
Definition
ozaki.hpp:54
seams::product::ComplexDot::normA
double normA
Definition
ozaki.hpp:57
seams::product::ComplexDot::boundNormA
double boundNormA
Definition
ozaki.hpp:61
seams::product::ComplexDot::certified
bool certified
Definition
ozaki.hpp:63
seams::product::ComplexDot::re
double re
Definition
ozaki.hpp:55
seams::product::ComplexDot::normB
double normB
Definition
ozaki.hpp:58
seams::product::ComplexDot::im
double im
Definition
ozaki.hpp:56
seams::product::ComplexDot::backend
const char * backend
Definition
ozaki.hpp:64
seams::product::ComplexDot::boundNormB
double boundNormB
Definition
ozaki.hpp:62
seams::product::ComplexDot::boundIm
double boundIm
Definition
ozaki.hpp:60
seams::product::ComplexDot::boundRe
double boundRe
Definition
ozaki.hpp:59
seams::product::GemmInfo
Definition
ozaki.hpp:114
seams::product::GemmInfo::sliceWidth
int sliceWidth
Definition
ozaki.hpp:118
seams::product::GemmInfo::ok
bool ok
Definition
ozaki.hpp:115
seams::product::GemmInfo::moduli
int moduli
Definition
ozaki.hpp:117
seams::product::GemmInfo::backend
const char * backend
Definition
ozaki.hpp:116
seams::product::RealDot
Definition
ozaki.hpp:46
seams::product::RealDot::certified
bool certified
Definition
ozaki.hpp:49
seams::product::RealDot::backend
const char * backend
Definition
ozaki.hpp:51
seams::product::RealDot::bound
double bound
Definition
ozaki.hpp:48
seams::product::RealDot::work
int work
Definition
ozaki.hpp:50
seams::product::RealDot::value
double value
Definition
ozaki.hpp:47
src
include
internal
ozaki.hpp