Skip to content

Commit

Permalink
Use xsmm library
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanlucf22 committed Jan 17, 2020
1 parent bdb3719 commit 0f01a39
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ if(NOT HAVE_FABS)
endif()
list(APPEND LINK_LIBRARIES -lm)

find_package(XSMM)

if(XSMM_FOUND)
message(STATUS "Use XSMM")
add_definitions(-DBML_USE_XSMM)
include_directories(${XSMM_INCLUDE_DIRS})
list(APPEND LINK_LIBRARIES ${XSMM_LIBRARY_DIRS}/libxsmm.so)
endif()

if(NOT (BLAS_FOUND OR NOBLAS))
message(FATAL_ERROR "Could not find BLAS library.")
endif()
Expand Down
36 changes: 36 additions & 0 deletions cmake/FindXSMM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# - Find the XSMM library
#
# Usage:
# find_package(XSMM [REQUIRED] [QUIET] )
#
# It sets the following variables:
# XSMM_FOUND ... true if magma is found on the system
# XSMM_LIBRARY_DIRS ... full path to magma library
# XSMM_INCLUDE_DIRS ... magma include directory
# XSMM_LIBRARIES ... magma libraries
#
# The following variables will be checked by the function
# XSMM_USE_STATIC_LIBS ... if true, only static libraries are found
# XSMM_ROOT ... if set, the libraries are exclusively searched
# under this path

#If environment variable XSMM_ROOT is specified, it has same effect as XSMM_ROOT
if( NOT XSMM_ROOT AND NOT $ENV{XSMM_ROOT} STREQUAL "" )
set( XSMM_ROOT $ENV{XSMM_ROOT} )
# set library directories
set(XSMM_LIBRARY_DIRS ${XSMM_ROOT}/lib)
# set include directories
set(XSMM_INCLUDE_DIRS ${XSMM_ROOT}/include)
# set libraries
find_library(
XSMM_LIBRARIES
NAMES "libxsmm"
PATHS ${XSMM_ROOT}
PATH_SUFFIXES "lib"
NO_DEFAULT_PATH
)
set(XSMM_FOUND TRUE)
else()
set(XSMM_FOUND FALSE)
endif()

32 changes: 32 additions & 0 deletions src/C-interface/blas.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <complex.h>

#include "../typed.h"

void C_SSCAL(
const int *n,
const float *a,
Expand Down Expand Up @@ -108,4 +110,34 @@ void C_ZAXPY(
double complex * y,
const int *incy);

void XSMM(
C_SGEMM) (
const char *transa,
const char *transb,
const int *m,
const int *n,
const int *k,
const float *alpha,
const float *a,
const int *lda,
const float *b,
const int *ldb,
const float *beta,
float *c,
const int *ldc);
void XSMM(
C_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);
#endif
8 changes: 4 additions & 4 deletions src/C-interface/ellblock/bml_multiply_ellblock_typed.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ void *TYPED_FUNC(
#if 1
REAL_T alpha = (REAL_T) 1.;
REAL_T beta = (REAL_T) 1.;
TYPED_FUNC(bml_gemm) ("N", "N", &bsize[kb], &bsize[ib],
&bsize[jb], &alpha, X_value_right,
&bsize[kb], X_value_left, &bsize[jb],
&beta, x, &bsize[kb]);
TYPED_FUNC(bml_xsmm_gemm) ("N", "N", &bsize[kb], &bsize[ib],
&bsize[jb], &alpha, X_value_right,
&bsize[kb], X_value_left,
&bsize[jb], &beta, x, &bsize[kb]);
#else
for (int ii = 0; ii < bsize[ib]; ii++)
for (int jj = 0; jj < bsize[kb]; jj++)
Expand Down
30 changes: 30 additions & 0 deletions src/internal-blas/bml_gemm.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,33 @@ void TYPED_FUNC(
#endif
#endif
}

void TYPED_FUNC(
bml_xsmm_gemm) (
const char *transa,
const char *transb,
const int *m,
const int *n,
const int *k,
const REAL_T * alpha,
const REAL_T * a,
const int *lda,
const REAL_T * b,
const int *ldb,
const REAL_T * beta,
REAL_T * c,
const int *ldc)
{
#ifdef BML_INTERNAL_GEMM
TYPED_FUNC(bml_gemm_internal) (transa, transb, m, n, k, alpha, a,
lda, b, ldb, beta, c, ldc);
#else

#ifndef BML_USE_XSMM
LOG_ERROR("No XSMM library");
#else
XSMM(C_BLAS(GEMM)) (transa, transb, m, n, k, alpha, a,
lda, b, ldb, beta, c, ldc);
#endif
#endif
}
57 changes: 57 additions & 0 deletions src/internal-blas/bml_gemm.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,61 @@ void bml_gemm_double_complex(
double complex * c,
const int *ldc);

void bml_xsmm_gemm_single_real(
const char *transa,
const char *transb,
const int *m,
const int *n,
const int *k,
const float *alpha,
const float *a,
const int *lda,
const float *b,
const int *ldb,
const float *beta,
float *c,
const int *ldc);
void bml_xsmm_gemm_double_real(
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);
void bml_xsmm_gemm_single_complex(
const char *transa,
const char *transb,
const int *m,
const int *n,
const int *k,
const float complex * alpha,
const float complex * a,
const int *lda,
const float complex * b,
const int *ldb,
const float complex * beta,
float complex * c,
const int *ldc);
void bml_xsmm_gemm_double_complex(
const char *transa,
const char *transb,
const int *m,
const int *n,
const int *k,
const double complex * alpha,
const double complex * a,
const int *lda,
const double complex * b,
const int *ldb,
const double complex * beta,
double complex * c,
const int *ldc);

#endif
5 changes: 5 additions & 0 deletions src/typed.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define MATRIX_PRECISION single_real
#define BLAS_PREFIX S
#define MAGMA_PREFIX s
#define XSMM_PREFIX libxsmm_
#define REAL_PART(x) (x)
#define IMAGINARY_PART(x) (0)
#define COMPLEX_CONJUGATE(x) (x)
Expand All @@ -32,6 +33,7 @@
#define MATRIX_PRECISION double_real
#define BLAS_PREFIX D
#define MAGMA_PREFIX d
#define XSMM_PREFIX libxsmm_
#define REAL_PART(x) (x)
#define IMAGINARY_PART(x) (0)
#define COMPLEX_CONJUGATE(x) (x)
Expand All @@ -43,6 +45,7 @@
#define MATRIX_PRECISION single_complex
#define BLAS_PREFIX C
#define MAGMA_PREFIX c
#define XSMM_PREFIX
#define REAL_PART(x) (crealf(x))
#define IMAGINARY_PART(x) (cimagf(x))
#define COMPLEX_CONJUGATE(x) (conjf(x))
Expand All @@ -54,6 +57,7 @@
#define MATRIX_PRECISION double_complex
#define BLAS_PREFIX Z
#define MAGMA_PREFIX z
#define XSMM_PREFIX
#define REAL_PART(x) (creal(x))
#define IMAGINARY_PART(x) (cimag(x))
#define COMPLEX_CONJUGATE(x) (conj(x))
Expand All @@ -71,6 +75,7 @@

#define TYPED_FUNC(a) CONCAT_(a, FUNC_SUFFIX)
#define C_BLAS(a) CONCAT_(C, CONCAT(BLAS_PREFIX , a))
#define XSMM(a) CONCAT(XSMM_PREFIX , a)
#define MAGMACOMPLEX(a) CONCAT_(MAGMA, CONCAT_(BLAS_PREFIX, a))
#define MAGMA(a) CONCAT_(magma, CONCAT(MAGMA_PREFIX , a))
#define MAGMAGPU(a) CONCAT_(magma, CONCAT(MAGMA_PREFIX , CONCAT_(a, gpu)))
Expand Down

0 comments on commit 0f01a39

Please sign in to comment.