-
Notifications
You must be signed in to change notification settings - Fork 8
/
sum_power.cl
69 lines (68 loc) · 1.69 KB
/
sum_power.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
#include "FGPUlib.c"
#include "addsf3.c"
#include "mulsf3.c"
#include "subsf3.c"
__kernel void sum_power_float(__global float *in, __global float *out, unsigned reduce_factor, float mean){
int x = get_global_id(0);
int size0 = get_global_size(0);
unsigned begin = x;
int i = 0;
float sum = 0;
do{
sum += (in[begin]-mean)*(in[begin]-mean);
i++;
begin += size0;
}while(i != reduce_factor);
out[x] = sum;
}
__kernel void sum_float(__global float *in, __global float *out, unsigned int reduce_factor){
int x = get_global_id(0);
int size0 = get_global_size(0);
unsigned int begin = x;
int i = 0;
float sum = 0;
do{
sum += in[begin];
i++;
begin += size0;
}while(i!= reduce_factor);
out[x] = sum;
}
__kernel void sum_power(__global int *in, __global int *out, unsigned reduce_factor, int mean){
int x = get_global_id(0);
int size0 = get_global_size(0);
unsigned begin = x;
int i = 0, sum = 0;
do{
sum += (in[begin]-mean)*(in[begin]-mean);
i++;
begin += size0;
}while(i != reduce_factor);
out[x] = sum;
}
__kernel void sum_power_atomic(__global int *in, __global int *out, unsigned reduce_factor){
int x = get_global_id(0);
int c = 100;
int size0 = get_global_size(0);
unsigned begin = x;
int i = 0, sum = 0;
do{
sum += (in[begin]-c)*(in[begin]-c);
i++;
begin += size0;
}while(i != reduce_factor);
atomic_add(out, sum);
}
__kernel void sum(__global int *in, __global int *out, unsigned int reduce_factor){
int x = get_global_id(0);
int size0 = get_global_size(0);
unsigned int begin = x;
int i = 0;
int sum = 0;
do{
sum += in[begin];
i++;
begin += size0;
}while(i!= reduce_factor);
out[x] = sum;
}