Révision 110
Epidevomath/vector4.py (revision 110) | ||
---|---|---|
1 |
import numpy as np |
|
2 |
import pyopencl as cl |
|
3 |
import pyopencl.array as cl_array |
|
4 |
from numpy.random import randint as nprnd |
|
5 |
|
|
6 |
deviceID = 0 |
|
7 |
platformID = 0 |
|
8 |
workGroup=(1,1) |
|
9 |
|
|
10 |
N = 10 |
|
11 |
MyData = np.zeros(N, dtype=cl_array.vec.float4) |
|
12 |
|
|
13 |
dev = cl.get_platforms()[platformID].get_devices()[deviceID] |
|
14 |
|
|
15 |
ctx = cl.Context([dev]) |
|
16 |
queue = cl.CommandQueue(ctx) |
|
17 |
mf = cl.mem_flags |
|
18 |
clData = cl.Buffer(ctx, mf.READ_WRITE, MyData.nbytes) |
|
19 |
|
|
20 |
|
|
21 |
prg = cl.Program(ctx, """ |
|
22 |
#define znew ((z=36969*(z&65535)+(z>>16))<<16) |
|
23 |
#define wnew ((w=18000*(w&65535)+(w>>16))&65535) |
|
24 |
#define MWC (znew+wnew) |
|
25 |
#define SHR3 (jsr=(jsr=(jsr=jsr^(jsr<<17))^(jsr>>13))^(jsr<<5)) |
|
26 |
#define CONG (jcong=69069*jcong+1234567) |
|
27 |
#define KISS ((MWC^CONG)+SHR3) |
|
28 |
|
|
29 |
#define MWCfp MWC * 2.328306435454494e-10f |
|
30 |
#define KISSfp KISS * 2.328306435454494e-10f |
|
31 |
#define SHR3fp SHR3 * 2.328306435454494e-10f |
|
32 |
#define CONGfp CONG * 2.328306435454494e-10f |
|
33 |
|
|
34 |
__kernel void SplutterSpace(__global float4* clData, |
|
35 |
uint seed_z,uint seed_w) |
|
36 |
{ |
|
37 |
int gid = get_global_id(0); |
|
38 |
uint z=seed_z+(uint)gid; |
|
39 |
uint w=seed_w-(uint)gid; |
|
40 |
|
|
41 |
clData[gid].xyzw = (float4) (MWCfp,MWCfp,MWCfp,0.); |
|
42 |
} |
|
43 |
|
|
44 |
|
|
45 |
""").build() |
|
46 |
|
|
47 |
#prg.Pack_Cmplx(queue, (N,1), workGroup, Data_In, np.int32(N)) |
|
48 |
|
|
49 |
prg.SplutterSpace(queue, (N,1), None, clData, |
|
50 |
numpy.uint32(nprnd(2**32)),numpy.uint32(nprnd(2**32))) |
|
51 |
cl.enqueue_copy(queue, MyData, clData) |
|
52 |
|
|
53 |
|
|
54 |
print MyData |
Epidevomath/vector.py (revision 110) | ||
---|---|---|
1 |
import numpy as np |
|
2 |
import pyopencl as cl |
|
3 |
import pyopencl.array as cl_array |
|
4 |
from numpy.random import randint as nprnd |
|
5 |
|
|
6 |
deviceID = 0 |
|
7 |
platformID = 0 |
|
8 |
workGroup=(1,1) |
|
9 |
|
|
10 |
N = 10 |
|
11 |
MyData = np.zeros(N, dtype=cl_array.vec.float4) |
|
12 |
|
|
13 |
dev = cl.get_platforms()[platformID].get_devices()[deviceID] |
|
14 |
|
|
15 |
ctx = cl.Context([dev]) |
|
16 |
queue = cl.CommandQueue(ctx) |
|
17 |
mf = cl.mem_flags |
|
18 |
clData = cl.Buffer(ctx, mf.READ_WRITE, MyData.nbytes) |
|
19 |
|
|
20 |
|
|
21 |
prg = cl.Program(ctx, """ |
|
22 |
#define znew ((z=36969*(z&65535)+(z>>16))<<16) |
|
23 |
#define wnew ((w=18000*(w&65535)+(w>>16))&65535) |
|
24 |
#define MWC (znew+wnew) |
|
25 |
#define SHR3 (jsr=(jsr=(jsr=jsr^(jsr<<17))^(jsr>>13))^(jsr<<5)) |
|
26 |
#define CONG (jcong=69069*jcong+1234567) |
|
27 |
#define KISS ((MWC^CONG)+SHR3) |
|
28 |
|
|
29 |
#define MWCfp MWC * 2.328306435454494e-10f |
|
30 |
#define KISSfp KISS * 2.328306435454494e-10f |
|
31 |
#define SHR3fp SHR3 * 2.328306435454494e-10f |
|
32 |
#define CONGfp CONG * 2.328306435454494e-10f |
|
33 |
|
|
34 |
__kernel void SplutterSpace(__global float4* clData, |
|
35 |
uint seed_z,uint seed_w) |
|
36 |
{ |
|
37 |
int gid = get_global_id(0); |
|
38 |
uint z=seed_z+(uint)gid; |
|
39 |
uint w=seed_w-(uint)gid; |
|
40 |
|
|
41 |
clData[gid].xyzw = (float4) (MWCfp,MWCfp,MWCfp,0.); |
|
42 |
} |
|
43 |
|
|
44 |
|
|
45 |
""").build() |
|
46 |
|
|
47 |
#prg.Pack_Cmplx(queue, (N,1), workGroup, Data_In, np.int32(N)) |
|
48 |
|
|
49 |
prg.SplutterSpace(queue, (N,1), None, clData, |
|
50 |
numpy.uint32(nprnd(2**32)),numpy.uint32(nprnd(2**32))) |
|
51 |
cl.enqueue_copy(queue, MyData, clData) |
|
52 |
|
|
53 |
|
|
54 |
print MyData |
Epidevomath/float.py (revision 110) | ||
---|---|---|
1 |
import numpy as np |
|
2 |
import pyopencl as cl |
|
3 |
import pyopencl.array as cl_array |
|
4 |
|
|
5 |
|
|
6 |
deviceID = 0 |
|
7 |
platformID = 0 |
|
8 |
workGroup=(1,1) |
|
9 |
|
|
10 |
N = 10 |
|
11 |
testData = np.zeros(N, dtype=cl_array.vec.float4) |
|
12 |
|
|
13 |
dev = cl.get_platforms()[platformID].get_devices()[deviceID] |
|
14 |
|
|
15 |
ctx = cl.Context([dev]) |
|
16 |
queue = cl.CommandQueue(ctx) |
|
17 |
mf = cl.mem_flags |
|
18 |
Data_In = cl.Buffer(ctx, mf.READ_WRITE, testData.nbytes) |
|
19 |
|
|
20 |
|
|
21 |
prg = cl.Program(ctx, """ |
|
22 |
|
|
23 |
__kernel void Pack_Cmplx( __global float4* Data_In, int N) |
|
24 |
{ |
|
25 |
int gid = get_global_id(0); |
|
26 |
|
|
27 |
Data_In[gid] = 1; |
|
28 |
} |
|
29 |
""").build() |
|
30 |
|
|
31 |
prg.Pack_Cmplx(queue, (N,1), workGroup, Data_In, np.int32(N)) |
|
32 |
cl.enqueue_copy(queue, testData, Data_In) |
|
33 |
|
|
34 |
|
|
35 |
print testData |
Formats disponibles : Unified diff