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,
78 int batch_order[ntasks];
82 for (
int itask = 0; itask < ntasks; ++itask) {
87 buckets[
i] += buckets[
i - 1];
90 for (
int itask = 0; itask < ntasks; ++itask) {
93 batch_order[buckets[
i]] = itask;
96 for (
int itask = 0; itask < ntasks; ++itask) {
97 batch_order[itask] = itask;
101#if defined(__LIBXSMM)
103 const int flags = LIBXSMM_GEMM_FLAG_TRANS_B;
104 const int prefetch = DBM_LIBXSMM_PREFETCH;
105 int kernel_m = 0, kernel_n = 0, kernel_k = 0;
106#if (LIBXSMM_GEMM_PREFETCH_NONE != DBM_LIBXSMM_PREFETCH)
107 double *data_a_next = NULL, *data_b_next = NULL, *data_c_next = NULL;
109#if LIBXSMM_VERSION2(1, 17) < LIBXSMM_VERSION_NUMBER
110 libxsmm_gemmfunction kernel_func = NULL;
112 libxsmm_dmmfunction kernel_func = NULL;
113 const double beta = 1.0;
119 for (
int itask = 0; itask < ntasks; ++itask) {
121 task_next = batch[batch_order[(itask + 1) < ntasks ? (itask + 1) : itask]];
123#if defined(__LIBXSMM)
125 (task.
m != kernel_m || task.
n != kernel_n || task.
k != kernel_k)) {
126 if (LIBXSMM_SMM(task.
m, task.
n, task.
m, 1 ,
128#if LIBXSMM_VERSION2(1, 17) < LIBXSMM_VERSION_NUMBER
129 const libxsmm_gemm_shape shape = libxsmm_create_gemm_shape(
130 task.
m, task.
n, task.
k, task.
m , task.
n ,
131 task.
m , LIBXSMM_DATATYPE_F64 ,
132 LIBXSMM_DATATYPE_F64 , LIBXSMM_DATATYPE_F64 ,
133 LIBXSMM_DATATYPE_F64 );
135 (LIBXSMM_FEQ(1.0, alpha)
136 ? libxsmm_dispatch_gemm(shape, (libxsmm_bitfield)flags,
137 (libxsmm_bitfield)prefetch)
140 kernel_func = libxsmm_dmmdispatch(task.
m, task.
n, task.
k, NULL ,
141 NULL , NULL , &alpha,
142 &beta, &flags, &prefetch);
157#if defined(__LIBXSMM)
158 if (kernel_func != NULL) {
159#if LIBXSMM_VERSION2(1, 17) < LIBXSMM_VERSION_NUMBER
160 libxsmm_gemm_param gemm_param;
161 gemm_param.a.primary = data_a;
162 gemm_param.b.primary = data_b;
163 gemm_param.c.primary = data_c;
164#if (LIBXSMM_GEMM_PREFETCH_NONE != DBM_LIBXSMM_PREFETCH)
165 gemm_param.a.quaternary = pack_a->
data + task_next.
offset_a;
166 gemm_param.b.quaternary = pack_b->
data + task_next.
offset_b;
167 gemm_param.c.quaternary = shard_c->
data + task_next.
offset_c;
169 kernel_func(&gemm_param);
170#elif (LIBXSMM_GEMM_PREFETCH_NONE != DBM_LIBXSMM_PREFETCH)
171 kernel_func(data_a, data_b, data_c, pack_a->
data + task_next.
offset_a,
175 kernel_func(data_a, data_b, data_c);
180 dbm_dgemm(
'N',
'T', task.
m, task.
n, task.
k, alpha, data_a, task.
m, data_b,
181 task.
n, 1.0, data_c, task.
m);
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 dbm_multiply_cpu_process_batch(int ntasks, const dbm_task_t batch[ntasks], double alpha, const dbm_pack_t *pack_a, const dbm_pack_t *pack_b, dbm_shard_t *shard_c, int options)
Internal routine for executing the tasks in given batch on the CPU.
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.