FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
matvecmult_bcsr_dense_mkl.cpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6// includes, FEAT
8#include <kernel/lafem/arch/matvecmult_bcsr_dense.hpp>
10
11FEAT_DISABLE_WARNINGS
12#include <mkl.h>
13#include <mkl_spblas.h>
14FEAT_RESTORE_WARNINGS
15
16namespace FEAT::LAFEM::Arch
17{
18 // the code below casts Index* to MKL_INT*
19 static_assert(sizeof(Index) == sizeof(MKL_INT), "size mismatch between MKL_INT and FEAT::Index");
20
21 void MatVecMultBCSRDense::exec_mkl_impl(float * r, const float alpha, const float * const x, const float * const y, const float * const val, const Index * const col_idx, const Index * const row_ptr, const Index rows, const Index cols, const Index, const int block_size, const bool transposed)
22 {
23 MKL_INT mrows = (MKL_INT)rows;
24 MKL_INT mcolumns = (MKL_INT)cols;
25 MKL_INT mblocksize = (MKL_INT)block_size;
26 MKL_INT mcopysize = (transposed ? mcolumns : mrows) * mblocksize;
27
28 if(y == nullptr)
29 Memory::memset_main(r, 0, sizeof(float) * std::size_t(mcopysize));
30 else if(r != y)
31 {
32 MKL_INT one = 1;
33 scopy(&mcopysize, y, &one, r, &one);
34 }
35
36 float beta = 1.0f;
37
38#ifndef FEAT_USE_MKL_LEGACY_SPMV
39
40 sparse_operation_t opt = (transposed ? SPARSE_OPERATION_TRANSPOSE : SPARSE_OPERATION_NON_TRANSPOSE);
41
42 sparse_matrix_t A;
43 FEAT_DISABLE_WARNINGS
44 mkl_sparse_s_create_bsr(&A, SPARSE_INDEX_BASE_ZERO, SPARSE_LAYOUT_ROW_MAJOR, mrows, mcolumns, mblocksize, (MKL_INT*)row_ptr, (MKL_INT*)(row_ptr + 1), (MKL_INT*)col_idx, (float*) val);
45 FEAT_RESTORE_WARNINGS
46 matrix_descr md;
47 md.type = SPARSE_MATRIX_TYPE_GENERAL;
48 mkl_sparse_s_mv(opt, alpha, A, md, x, beta, r);
49 mkl_sparse_destroy(A);
50
51#else
52
53 char trans = (transposed ? 'T' : 'N');
54 char matdescra[6];
55 matdescra[0] = 'G';
56 matdescra[1] = 0; //ingored by mkl, but valgrind complains otherwise
57 matdescra[2] = 0; //ingored by mkl, but valgrind complains otherwise
58 matdescra[3] = 'C';
59
60 FEAT_DISABLE_WARNINGS
61 mkl_sbsrmv(&trans, &mrows, &mcolumns, &mblocksize, (const float*)&alpha, matdescra, (const float*) val, (const MKL_INT*)col_idx, (const MKL_INT*)row_ptr, (const MKL_INT*)(row_ptr) + 1, (const float*)x, (const float*)&beta, r);
62 FEAT_RESTORE_WARNINGS
63
64#endif
65 }
66
67 void MatVecMultBCSRDense::exec_mkl_impl(double * r, const double alpha, const double * const x, const double * const y, const double * const val, const Index * const col_idx, const Index * const row_ptr, const Index rows, const Index cols, const Index, const int block_size, const bool transposed)
68 {
69 MKL_INT mrows = (MKL_INT)rows;
70 MKL_INT mcolumns = (MKL_INT)cols;
71 MKL_INT mblocksize = (MKL_INT)block_size;
72 MKL_INT mcopysize = (transposed ? mcolumns : mrows) * mblocksize;
73
74 if(y == nullptr)
75 Memory::memset_main(r, 0, sizeof(double) * std::size_t(mcopysize));
76 else if(r != y)
77 {
78 MKL_INT one = 1;
79 dcopy(&mcopysize, y, &one, r, &one);
80 }
81
82 double beta = 1.0;
83
84#ifndef FEAT_USE_MKL_LEGACY_SPMV
85
86 sparse_operation_t opt = (transposed ? SPARSE_OPERATION_TRANSPOSE : SPARSE_OPERATION_NON_TRANSPOSE);
87
88 sparse_matrix_t A;
89 FEAT_DISABLE_WARNINGS
90 mkl_sparse_d_create_bsr(&A, SPARSE_INDEX_BASE_ZERO, SPARSE_LAYOUT_ROW_MAJOR, mrows, mcolumns, mblocksize, (MKL_INT*)row_ptr, (MKL_INT*)(row_ptr + 1), (MKL_INT*)col_idx, (double*) val);
91 FEAT_RESTORE_WARNINGS
92 matrix_descr md;
93 md.type = SPARSE_MATRIX_TYPE_GENERAL;
94 mkl_sparse_d_mv(opt, alpha, A, md, x, beta, r);
95 mkl_sparse_destroy(A);
96
97#else
98
99 char trans = (transposed ? 'T' : 'N');
100 char matdescra[6];
101 matdescra[0] = 'G';
102 matdescra[1] = 0; //ingored by mkl, but valgrind complains otherwise
103 matdescra[2] = 0; //ingored by mkl, but valgrind complains otherwise
104 matdescra[3] = 'C';
105
106 FEAT_DISABLE_WARNINGS
107 mkl_dbsrmv(&trans, &mrows, &mcolumns, &mblocksize, (const double*)&alpha, matdescra, (const double*) val, (const MKL_INT*)col_ind, (const MKL_INT*)row_ptr, (const MKL_INT*)(row_ptr) + 1, (const double*)x, (const double*)&beta, r);
108 FEAT_RESTORE_WARNINGS
109
110#endif
111 }
112} // namespace FEAT::LAFEM::Arch
FEAT Kernel base header.
void memset_main(void *ptr, int value, std::size_t bytes)
Formats all bytes of a memory block in main memory to a given value.
std::uint64_t Index
Index data type.