39static inline void dbm_dgemm(
const char transa,
const char transb,
const int m,
40 const int n,
const int k,
const double alpha,
41 const double *a,
const int lda,
const double *b,
42 const int ldb,
const double beta,
double *c,
45 dgemm_(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c,
71 const int ntasks,
const dbm_task_t batch[ntasks],
const double alpha,
83 for (
int itask = 0; itask < ntasks; ++itask) {
88 buckets[
i] += buckets[
i - 1];
91 int batch_order[ntasks];
92 for (
int itask = 0; itask < ntasks; ++itask) {
95 batch_order[buckets[
i]] = itask;
99 const int flags = LIBXSMM_GEMM_FLAG_TRANS_B;
100 const int prefetch = DBM_LIBXSMM_PREFETCH;
101 int kernel_m = 0, kernel_n = 0, kernel_k = 0;
104#if (LIBXSMM_GEMM_PREFETCH_NONE != DBM_LIBXSMM_PREFETCH)
105 double *data_a_next = NULL, *data_b_next = NULL, *data_c_next = NULL;
107#if LIBXSMM_VERSION2(1, 17) < LIBXSMM_VERSION_NUMBER
108 libxsmm_gemmfunction kernel_func = NULL;
110 libxsmm_dmmfunction kernel_func = NULL;
111 const double beta = 1.0;
115 for (
int itask = 0; itask < ntasks; ++itask) {
117 task_next = batch[batch_order[(itask + 1) < ntasks ? (itask + 1) : itask]];
119 if (task.
m != kernel_m || task.
n != kernel_n || task.
k != kernel_k) {
120 if (LIBXSMM_SMM(task.
m, task.
n, task.
m, 1 ,
122#if LIBXSMM_VERSION2(1, 17) < LIBXSMM_VERSION_NUMBER
123 const libxsmm_gemm_shape shape = libxsmm_create_gemm_shape(
124 task.
m, task.
n, task.
k, task.
m , task.
n ,
125 task.
m , LIBXSMM_DATATYPE_F64 ,
126 LIBXSMM_DATATYPE_F64 , LIBXSMM_DATATYPE_F64 ,
127 LIBXSMM_DATATYPE_F64 );
129 (LIBXSMM_FEQ(1.0, alpha)
130 ? libxsmm_dispatch_gemm(shape, (libxsmm_bitfield)flags,
131 (libxsmm_bitfield)prefetch)
134 kernel_func = libxsmm_dmmdispatch(task.
m, task.
n, task.
k, NULL ,
135 NULL , NULL , &alpha,
136 &beta, &flags, &prefetch);
151 if (kernel_func != NULL) {
152#if LIBXSMM_VERSION2(1, 17) < LIBXSMM_VERSION_NUMBER
153 libxsmm_gemm_param gemm_param;
154 gemm_param.a.primary = data_a;
155 gemm_param.b.primary = data_b;
156 gemm_param.c.primary = data_c;
157#if (LIBXSMM_GEMM_PREFETCH_NONE != DBM_LIBXSMM_PREFETCH)
158 gemm_param.a.quaternary = pack_a->
data + task_next.
offset_a;
159 gemm_param.b.quaternary = pack_b->
data + task_next.
offset_b;
160 gemm_param.c.quaternary = shard_c->
data + task_next.
offset_c;
162 kernel_func(&gemm_param);
163#elif (LIBXSMM_GEMM_PREFETCH_NONE != DBM_LIBXSMM_PREFETCH)
164 kernel_func(data_a, data_b, data_c, pack_a->
data + task_next.
offset_a,
168 kernel_func(data_a, data_b, data_c);
171 dbm_dgemm(
'N',
'T', task.
m, task.
n, task.
k, alpha, data_a, task.
m, data_b,
172 task.
n, 1.0, data_c, task.
m);
177 for (
int itask = 0; itask < ntasks; ++itask) {
182 dbm_dgemm(
'N',
'T', task.
m, task.
n, task.
k, alpha, data_a, task.
m, data_b,
183 task.
n, 1.0, data_c, task.
m);
void dbm_multiply_cpu_process_batch(const int ntasks, const dbm_task_t batch[ntasks], const double alpha, const dbm_pack_t *pack_a, const dbm_pack_t *pack_b, dbm_shard_t *shard_c)
Private hash function based on Szudzik's elegant pairing. Using unsigned int to return a positive num...
static void dbm_dgemm(const char transa, const char transb, const int m, const int n, const int k, const double alpha, const double *a, const int lda, const double *b, const int ldb, const double beta, double *c, const int ldc)
Private convenient wrapper to hide Fortran nature of dgemm_.
void dgemm_(const char *transa, const char *transb, const int *m, const int *n, const int *k, const double *alpha, const double *a, const int *lda, const double *b, const int *ldb, const double *beta, double *c, const int *ldc)
Prototype for BLAS dgemm.
static unsigned int hash(const unsigned int row, const unsigned int col)
Private hash function based on Cantor pairing function. https://en.wikipedia.org/wiki/Pairing_functio...