-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpi.cl
More file actions
29 lines (23 loc) · 1.08 KB
/
pi.cl
File metadata and controls
29 lines (23 loc) · 1.08 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
__kernel void add_point(__global bool *inside, __global unsigned int *prng_state, __global unsigned int *wg_size) {
unsigned int state = prng_state[(get_group_id(0) % *wg_size) * get_local_size(0) + get_local_id(0)];
// XOR-Shift state array element
state ^= state << 13;
state ^= state >> 17;
state ^= state << 5;
// Use state element for x coordinate, dividing by max int size
// to get range 0-1
float x = state / (float)0xFFFFFFFF;
// XOR-Shift state array element
state ^= state << 13;
state ^= state >> 17;
state ^= state << 5;
// Use state element for y coordinate, dividing by max int size
// to get range 0-1
float y = state / (float)0xFFFFFFFF;
// Write new state element back to array
prng_state[(get_group_id(0) % *wg_size) * get_local_size(0) + get_local_id(0)] = state;
// See if point is inside circle, if it is, increment counter array
if (sqrt((x*x) + (y*y)) < 1.0) {
inside[(get_group_id(0) % *wg_size) * get_local_size(0) + get_local_id(0)] = true;
}
}