This repository has been archived by the owner on Jul 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
stream_kernels_vec.cl
executable file
·77 lines (61 loc) · 1.81 KB
/
stream_kernels_vec.cl
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
/**
Kernel implementations for the STRAM benchmark which utilize vector types
instead of the unroll pragma.
Also manual unrolling is done in the copy and scalar kernel.
*/
#if (QUARTUS_MAJOR_VERSION <= 18)
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
#endif
#ifndef STREAM_TYPE
#define STREAM_TYPE double
#endif
#ifndef UNROLL_COUNT
#define UNROLL_COUNT 8
#endif
#define PASTER(x,y) x ## y
#define EVALUATOR(x,y) PASTER(x,y)
#define VEC_TYPE EVALUATOR(STREAM_TYPE, UNROLL_COUNT)
__kernel
void copy(__global const VEC_TYPE * restrict in,
__global VEC_TYPE * restrict out,
uint array_size) {
uint vector_size = array_size/(UNROLL_COUNT*2);
#pragma ivdep
for(uint i = 0; i < vector_size; i++){
out[i] = in[i];
out[vector_size+i] = in[vector_size+i];
}
}
__kernel
void add(__global const VEC_TYPE * restrict in1,
__global const VEC_TYPE * restrict in2,
__global VEC_TYPE * restrict out,
uint array_size) {
uint vector_size = array_size/UNROLL_COUNT;
for (uint i=0; i<vector_size; i++){
out[i] = in1[i] + in2[i];
}
}
__kernel
void scale(__global const VEC_TYPE * restrict in,
__global VEC_TYPE * restrict out,
STREAM_TYPE scalar,
uint array_size) {
uint vector_size = array_size/(UNROLL_COUNT*2);
#pragma ivdep
for (uint i=0; i<vector_size; i++){
out[i] = scalar * in[i];
out[vector_size+i] = scalar * in[vector_size+i];
}
}
__kernel
void triad(__global const VEC_TYPE * restrict in1,
__global const VEC_TYPE * restrict in2,
__global VEC_TYPE * restrict out,
STREAM_TYPE scalar,
uint array_size) {
uint vector_size = array_size / UNROLL_COUNT;
for (uint i=0; i<vector_size; i++){
out[i] = in1[i] + scalar * in2[i];
}
}