forked from apache/mxnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use mkl sparse matrix to improve performance (apache#14492)
* use mkl sparse matrix to improve performance * fix build fail issue * add 3rdparty/sparse matrix in Makefile * add macro for variable * fix lib not find error * fix gpu R test error * fix Mac build error * add lib/libsparse_matrix.so to CI * fix indentation * retrigger CI
- Loading branch information
1 parent
1c49e40
commit c437d5b
Showing
6 changed files
with
175 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
CC = g++ | ||
C = gcc | ||
MKLROOT = /opt/intel/mkl | ||
|
||
ifneq ($(USE_INTEL_PATH),) | ||
MKLROOT = $(USE_INTEL_PATH)/mkl | ||
endif | ||
|
||
CFLAGS = -fpic -O2 -I/opt/intel/mkl/include -c -Wall -Werror -DMKL_ILP64 -m64 -std=c++11 | ||
LDFLAGS = -Wl,--start-group -L${MKLROOT}/../compiler/lib/intel64 ${MKLROOT}/lib/intel64/libmkl_intel_ilp64.a ${MKLROOT}/lib/intel64/libmkl_intel_thread.a ${MKLROOT}/lib/intel64/libmkl_core.a -Wl,--end-group -liomp5 -lpthread -lm -ldl | ||
|
||
default: libsparse_matrix.so | ||
|
||
libsparse_matrix.so: sparse_matrix.o | ||
$(CC) -shared -o libsparse_matrix.so sparse_matrix.o $(LDFLAGS) | ||
|
||
sparse_matrix.o: sparse_matrix.cc sparse_matrix.h | ||
$(CC) $(CFLAGS) sparse_matrix.cc | ||
|
||
clean: | ||
$(RM) libsparse_matrix.so *.o *~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#include <iostream> | ||
#include <string> | ||
#include <fstream> | ||
#include <mkl_spblas.h> | ||
#include "sparse_matrix.h" | ||
|
||
|
||
|
||
bool mkl_DotCsrDnsDns(SP_INT64* rows_start, SP_INT64* col_indx, | ||
float* values, float* X, float* y, | ||
int rows, int cols, int X_columns) | ||
{ | ||
|
||
sparse_index_base_t indexing = SPARSE_INDEX_BASE_ZERO; | ||
sparse_status_t status; | ||
sparse_matrix_t A = NULL; | ||
sparse_layout_t layout = SPARSE_LAYOUT_ROW_MAJOR; | ||
float one, zero; | ||
one = (float)1.0; | ||
zero = (float)0.0; | ||
|
||
MKL_INT* rows_end = rows_start + 1; | ||
status = mkl_sparse_s_create_csr(&A, indexing, rows, cols, rows_start, rows_end, col_indx, values); | ||
|
||
if (status != SPARSE_STATUS_SUCCESS) | ||
{ | ||
std::cout << "mkl_sparse_s_create_csr status :" << status << std::endl; | ||
return false; | ||
} | ||
sparse_operation_t operation = SPARSE_OPERATION_NON_TRANSPOSE; | ||
struct matrix_descr descrA; | ||
descrA.type = SPARSE_MATRIX_TYPE_GENERAL; | ||
|
||
status = mkl_sparse_s_mm(operation, one, A, descrA, layout, X, X_columns, X_columns, zero, y, X_columns); | ||
if (status != SPARSE_STATUS_SUCCESS) | ||
{ | ||
std::cout << "mkl_sparse_s_create_csr status :" << status << std::endl; | ||
return false; | ||
} | ||
|
||
mkl_sparse_destroy(A); | ||
|
||
return true; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#ifndef MXNET_OPERATOR_SPARSE_MATRIX_INL_H_ | ||
#define MXNET_OPERATOR_SPARSE_MATRIX_INL_H_ | ||
|
||
|
||
#if (!defined(__INTEL_COMPILER)) & defined(_MSC_VER) | ||
#define SP_INT64 __int64 | ||
#define SP_UINT64 unsigned __int64 | ||
#else | ||
#define SP_INT64 long long int | ||
#define SP_UINT64 unsigned long long int | ||
#endif | ||
|
||
|
||
#if defined _WIN32 || defined __CYGWIN__ | ||
#ifdef BUILDING_DLL | ||
#ifdef __GNUC__ | ||
#define SPM_API_PUBLIC __attribute__ ((dllexport)) | ||
#else | ||
#define SPM_API_PUBLIC __declspec(dllexport) // Note: actually gcc seems to also supports this syntax. | ||
#endif | ||
#else | ||
#ifdef __GNUC__ | ||
#define SPM_API_PUBLIC __attribute__ ((dllimport)) | ||
#else | ||
#define SPM_API_PUBLIC __declspec(dllimport) // Note: actually gcc seems to also supports this syntax. | ||
#endif | ||
#endif | ||
#define SPM_API_LOCAL | ||
#else | ||
#if __GNUC__ >= 4 | ||
#define SPM_API_PUBLIC __attribute__ ((visibility ("default"))) | ||
#define SPM_API_LOCAL __attribute__ ((visibility ("hidden"))) | ||
#else | ||
#define SPM_API_PUBLIC | ||
#define SPM_API_LOCAL | ||
#endif | ||
#endif | ||
|
||
|
||
|
||
extern "C" | ||
{ | ||
extern SPM_API_PUBLIC bool mkl_DotCsrDnsDns(SP_INT64* rows_start, SP_INT64* col_indx, | ||
float* values, float* X, float* y, int rows, int cols, int X_columns); | ||
|
||
} | ||
|
||
#endif //MXNET_OPERATOR_SPARSE_MATRIX_INL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters