-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
77 lines (57 loc) · 1.69 KB
/
test.cpp
File metadata and controls
77 lines (57 loc) · 1.69 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// STDLIB
#include <cassert>
#include <iostream>
#include <vector>
// CUDA
#include <cuda.h>
#include <cuda_runtime.h>
// LOCAL
#include "eigen_blas.h"
#include "blas.cu.h"
#include "util.h"
int main()
{
using namespace Util;
int rows, cols;
rows = 64;
cols = 32;
auto x = random_vec (rows);
auto y = random_vec (rows);
float alpha = 2.0;
float *x_d = copy_to_cuda (x);
float *y_d = copy_to_cuda (y);
EigenImpl::axpy (rows, alpha, x.data (), y.data ());
CudaImpl::axpy (rows, alpha, x_d, y_d);
auto y_h = copy_from_cuda (y_d, rows);
cudaFree (x_d);
cudaFree (y_d);
assert (("axpy test", compare (y, y_h)));
auto A = random_vec (rows * cols);
y = random_vec (rows);
x = random_vec (cols);
float beta = 0.5;
float* A_d = copy_to_cuda (A);
x_d = copy_to_cuda (x);
y_d = copy_to_cuda (y);
EigenImpl::gemv (rows, cols, alpha, A.data (), x.data (), beta, y.data ());
CudaImpl::gemv (rows, cols, alpha, A_d, x_d, beta, y_d);
y_h = copy_from_cuda (y_d, rows);
cudaFree (x_d);
cudaFree (y_d);
cudaFree (A_d);
assert (("gemv test", compare (y, y_h)));
A = random_vec (rows * cols);
auto B = random_vec (cols * cols);
auto C = random_vec (rows * cols);
A_d = copy_to_cuda (A);
float* B_d = copy_to_cuda (B);
float* C_d = copy_to_cuda (C);
EigenImpl::gemm (rows, cols, cols, alpha, A.data (), B.data (), beta, C.data ());
CudaImpl::gemm (rows, cols, cols, alpha, A_d, B_d, beta, C_d);
auto C_h = copy_from_cuda (C_d, rows * cols);
cudaFree (A_d);
cudaFree (B_d);
cudaFree (C_d);
assert(("gemm test", compare (C, C_h)));
std::cout << "Tests passed\n";
}