5#ifndef GPR_LINALG_SCALAR_GEBP_KERNEL_H_
6#define GPR_LINALG_SCALAR_GEBP_KERNEL_H_
25#if defined(__cplusplus) && __has_include(<Eigen/Core>)
29#if defined(EIGEN_DONT_VECTORIZE) && EIGEN_WORLD_VERSION == 3 && \
30 EIGEN_MAJOR_VERSION == 4 && (defined(__GNUC__) || defined(__clang__))
34#define GPR_SCALAR_GEBP_KERNEL 1
38namespace gpr_scalar_gebp {
43template <
int Rows,
typename DataMapper>
44EIGEN_ALWAYS_INLINE
void panelRows(
const DataMapper& res,
const double* blockA,
45 const double* blB,
double alpha, Index i,
46 Index j2, Index strideA, Index offsetA,
47 Index peeled_kc, Index depth)
49 const double* blA[Rows];
50 Lanes4 C[Rows], D[Rows];
51 for (
int r = 0; r < Rows; ++r) {
52 blA[r] = &blockA[(i + r) * strideA + offsetA];
53 C[r] = Lanes4{0.0, 0.0, 0.0, 0.0};
54 D[r] = Lanes4{0.0, 0.0, 0.0, 0.0};
56 for (Index k = 0; k < peeled_kc; k += 2) {
58 std::memcpy(&b0, &blB[4 * k],
sizeof(b0));
59 std::memcpy(&b1, &blB[4 * (k + 1)],
sizeof(b1));
60 for (
int r = 0; r < Rows; ++r) {
61 const Lanes4 t0 = blA[r][k] * b0;
63 const Lanes4 t1 = blA[r][k + 1] * b1;
67 for (
int r = 0; r < Rows; ++r)
69 for (Index k = peeled_kc; k < depth; ++k) {
71 std::memcpy(&b, &blB[4 * k],
sizeof(b));
72 for (
int r = 0; r < Rows; ++r) {
73 const Lanes4 t = blA[r][k] * b;
77 for (
int r = 0; r < Rows; ++r) {
78 for (
int c = 0; c < 4; ++c) {
79 double& entry = res(i + r, j2 + c);
80 const double scaled = C[r][c] * alpha;
81 entry = scaled + entry;
89template <
bool ConjugateLhs,
bool ConjugateRhs>
90struct gebp_kernel<double, double,
Index,
91 blas_data_mapper<double,
Index, ColMajor, Unaligned, 1>, 1,
92 4, ConjugateLhs, ConjugateRhs> {
93 typedef blas_data_mapper<double, Index, ColMajor, Unaligned, 1> DataMapper;
96 void operator()(
const DataMapper& res,
const double* blockA,
97 const double* blockB, Index rows, Index depth, Index cols,
98 double alpha, Index strideA = -1, Index strideB = -1,
99 Index offsetA = 0, Index offsetB = 0)
101 using gpr_scalar_gebp::panelRows;
102 if (strideA == -1) strideA = depth;
103 if (strideB == -1) strideB = depth;
104 const Index packet_cols4 = (cols / 4) * 4;
105 const Index peeled_kc = depth & ~Index(7);
106 constexpr int kRows = 4;
107 const Index peeled_rows = (rows / kRows) * kRows;
109 for (Index j2 = 0; j2 < packet_cols4; j2 += 4) {
110 const double* blB = &blockB[j2 * strideB + offsetB * 4];
112 for (; i < peeled_rows; i += kRows)
113 panelRows<kRows>(res, blockA, blB, alpha, i, j2, strideA,
114 offsetA, peeled_kc, depth);
115 for (; i < rows; ++i)
116 panelRows<1>(res, blockA, blB, alpha, i, j2, strideA, offsetA,
120 for (Index j2 = packet_cols4; j2 < cols; ++j2) {
121 const double* blB = &blockB[j2 * strideB + offsetB];
122 for (Index i = 0; i < rows; ++i) {
123 const double* blA = &blockA[i * strideA + offsetA];
125 for (Index k = 0; k < depth; ++k) {
126 const double t = blA[k] * blB[k];
129 double& entry = res(i, j2);
130 const double scaled = C0 * alpha;
131 entry = scaled + entry;
__attribute__((visibility("default"))) void *gpr_training_product_create_v1(char *error
Kokkos::IndexType< std::size_t > Index