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
|
package com.mbien.opencl;
import static com.mbien.opencl.CLException.*;
/**
*
* @author Michael Bien
*/
public class CLCommandQueue {
public final long ID;
private final CLContext context;
private final CL cl;
CLCommandQueue(CLContext context, CLDevice device, long properties) {
this.context = context;
this.cl = context.cl;
int[] status = new int[1];
this.ID = cl.clCreateCommandQueue(context.ID, device.ID, properties, status, 0);
if(status[0] != CL.CL_SUCCESS)
throw new CLException(status[0], "can not create command queue on "+device);
}
public CLCommandQueue putWriteBuffer(CLBuffer writeBuffer, boolean blockingWrite) {
int ret = cl.clEnqueueWriteBuffer(
ID, writeBuffer.ID, blockingWrite ? CL.CL_TRUE : CL.CL_FALSE,
0, writeBuffer.buffer.capacity(), writeBuffer.buffer,
0, null, 0,
null, 0 );
if(ret != CL.CL_SUCCESS)
throw new CLException(ret, "can not enqueue WriteBuffer: " + writeBuffer);
return this;
}
public CLCommandQueue putReadBuffer(CLBuffer readBuffer, boolean blockingRead) {
int ret = cl.clEnqueueReadBuffer(
ID, readBuffer.ID, blockingRead ? CL.CL_TRUE : CL.CL_FALSE,
0, readBuffer.buffer.capacity(), readBuffer.buffer,
0, null, 0,
null, 0 );
if(ret != CL.CL_SUCCESS)
throw new CLException(ret, "can not enqueue ReadBuffer: " + readBuffer);
return this;
}
public CLCommandQueue putNDRangeKernel(CLKernel kernel, int workDimension, long[] globalWorkOffset, long[] globalWorkSize, long[] localWorkSize) {
int ret = cl.clEnqueueNDRangeKernel(
ID, kernel.ID, 1,
null, 0,
globalWorkSize, 0,
localWorkSize, 0,
0,
null, 0,
null, 0 );
if(ret != CL.CL_SUCCESS)
throw new CLException(ret, "can not enqueue NDRangeKernel: " + kernel);
return this;
}
public void release() {
int ret = cl.clReleaseCommandQueue(ID);
checkForError(ret, "can not release command queue");
}
}
|