Nektar++
Loading...
Searching...
No Matches
libXSMMDispatchWrapper.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: libXSMMDispatchWrapper.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#pragma once
36
38
39#if __has_include("libxsmm.h")
40#include <libxsmm.h>
41#else
43#define LIBXSMM_PREFETCH_NONE 0
44template <typename TData> class libxsmm_mmfunction
45{
46public:
47 libxsmm_mmfunction([[maybe_unused]] const int flag, const int m,
48 const int n, const int k, const TData alpha,
49 const TData beta, [[maybe_unused]] const int prefetch)
50 : m(m), n(n), k(k), alpha(alpha), beta(beta)
51 {
52 }
53
54 // Without libxsmm the product goes through the BLAS library the build
55 // links.
56 void operator()(const TData *a, const TData *b, TData *c)
57 {
58 Blas::Gemm('N', 'N', m, n, k, alpha, a, m, b, k, beta, c, m);
59 }
60
61 operator const void *() const
62 {
63 return this;
64 }
65
66private:
67 int m;
68 int n;
69 int k;
70 TData alpha;
71 TData beta;
72};
73#endif
74
75template <typename TData> struct LibxsmmDispatchWrapper
76{
78
79 static inline KernelFunc dispatch(
80 const int m, const int n, const int k, const TData alpha,
81 const TData beta, const int flags = 0,
82 const int prefetch = LIBXSMM_PREFETCH_NONE)
83 {
84 ASSERTL0(alpha == 1.0, "libxsmm: alpha must be equal to 1.0");
85 ASSERTL0(beta == 0.0 || beta == 1.0,
86 "libxsmm: beta must be equal to 0.0 or 1.0");
87
88 KernelFunc kernel(flags, m, n, k, alpha, beta, prefetch);
89 ASSERTL0(kernel, "libxsmm: kernel dispatch failed");
90 return kernel;
91 }
92};
#define ASSERTL0(condition, msg)
void operator()(const TData *a, const TData *b, TData *c)
libxsmm_mmfunction(const int flag, const int m, const int n, const int k, const TData alpha, const TData beta, const int prefetch)
#define LIBXSMM_PREFETCH_NONE
static void Gemm(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)
BLAS level 3: Matrix-matrix multiply C = A x B where op(A)[m x k], op(B)[k x n], C[m x n] DGEMM perfo...
Definition Blas.hpp:227
static KernelFunc dispatch(const int m, const int n, const int k, const TData alpha, const TData beta, const int flags=0, const int prefetch=LIBXSMM_PREFETCH_NONE)