forked from codeplaysoftware/portBLAS
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gemv.cpp
61 lines (51 loc) · 1.93 KB
/
gemv.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "sycl_blas.hpp"
#include <CL/sycl.hpp>
#include "util.hpp"
int main(int argc, char** argv) {
/* Create a SYCL queue with the default device selector */
cl::sycl::queue q = cl::sycl::queue(cl::sycl::default_selector());
/* Create a SYCL-BLAS sb_handle and get the policy handler */
blas::SB_Handle sb_handle(q);
/* Arguments of the Gemm operation.
* Note: these matrix dimensions are too small to get a performance gain by
* using SYCL-BLAS, but they are convenient for this sample */
const size_t m = 7;
const size_t n = 7;
const size_t lda = 12;
const size_t incx = 2;
const size_t incy = 3;
const float alpha = 1.5;
const float beta = 0.5;
/* Create the matrix and vectors */
const size_t lx = (n - 1) * incx + 1;
const size_t ly = (m - 1) * incy + 1;
std::vector<float> A = std::vector<float>(lda * n);
std::vector<float> X = std::vector<float>(lx);
std::vector<float> Y = std::vector<float>(ly);
/* Fill the matrices with random values */
fill_matrix(A, m, n, lda);
fill_vector(X, n, incx);
fill_vector(Y, m, incy);
/* Print the matrices before the GEMV operation */
std::cout << "A:\n";
print_matrix(A, m, n, lda);
std::cout << "---\nX:\n";
print_vector(X, n, incx);
std::cout << "---\nY (before):\n";
print_vector(Y, m, incy);
/* Execute the GEMV operation
* Note: you can also use explicit copies, see the GEMM sample
*/
std::cout << "---\nExecuting Y = " << alpha << "*A*X + " << beta << "*Y\n";
{
auto a_gpu = blas::make_sycl_iterator_buffer<float>(A, lda * n);
auto x_gpu = blas::make_sycl_iterator_buffer<float>(X, lx);
auto y_gpu = blas::make_sycl_iterator_buffer<float>(Y, ly);
auto event = blas::_gemv(sb_handle, 'n', m, n, alpha, a_gpu, lda, x_gpu,
incx, beta, y_gpu, incy);
}
/* Print the result after the GEMM operation */
std::cout << "---\nY (after):" << std::endl;
print_vector(Y, m, incy);
return 0;
}