/perf/kseta

To get this branch, use:
bzr branch http://darksoft.org/webbzr/perf/kseta

« back to all changes in this revision

Viewing changes to tutorials/4_pi/pi.cl

  • Committer: Suren A. Chilingaryan
  • Date: 2013-10-08 23:53:50 UTC
  • Revision ID: csa@dside.dyndns.org-20131008235350-hsu8oukzkh05gtcm
Add tutorials

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "random123/threefry.h"
 
2
 
 
3
#define rnd_init(a) \
 
4
    threefry4x32_key_t k = {{a, 0xdecafbad, 0xfacebead, 0x12345678}}; \
 
5
    threefry4x32_ctr_t c = {{0, 0xf00dcafe, 0xdeadbeef, 0xbeeff00d}};
 
6
 
 
7
#define rnd(a, b) \
 
8
    { \
 
9
        union { \
 
10
            threefry4x32_ctr_t c; \
 
11
            int4 i; \
 
12
        } u; \
 
13
        c.v[0]++; \
 
14
        u.c = threefry4x32(c, k); \
 
15
        float4 res = convert_float4(u.i) / ((unsigned int)0x7FFFFFFF); \
 
16
        a.x = res.x; a.y = res.y; b.x = res.z; b.y = res.w; \
 
17
    }
 
18
 
 
19
__kernel void pi(__global unsigned long *res, unsigned long n, __global unsigned long *gmem, __local unsigned long *lmem) {
 
20
    unsigned long hits = 0, i;
 
21
    
 
22
    rnd_init(get_global_id(0))
 
23
 
 
24
    for(i = 0; i < n; i+=2) {
 
25
        float2 a, b;
 
26
        rnd(a, b);
 
27
 
 
28
 
 
29
    }
 
30
 
 
31
 
 
32
    *res = hits;
 
33
}