blob: f076324a385784c0cc8ee28c4dd5b0b5bdc6b0aa (
plain)
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
78
79
80
81
82
83
84
85
|
/*
* Created on Tuesday, May 03 2011
*/
package com.jogamp.opencl.util.concurrent;
import com.jogamp.opencl.CLContext;
import com.jogamp.opencl.CLDevice;
import com.jogamp.opencl.CLPlatform;
import com.jogamp.opencl.util.concurrent.CLQueueContextFactory.CLSimpleContextFactory;
import org.junit.Rule;
import org.junit.rules.MethodRule;
import org.junit.rules.Timeout;
import com.jogamp.opencl.util.CLMultiContext;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.*;
import static java.lang.System.*;
/**
*
* @author Michael Bien
*/
public class CLMultiContextTest {
// @Rule
// public MethodRule methodTimeout= new Timeout(10000);
@Test
public void createMultiContextTest() {
CLMultiContext mc = CLMultiContext.create(CLPlatform.listCLPlatforms());
try{
List<CLContext> contexts = mc.getContexts();
List<CLDevice> devices = mc.getDevices();
assertFalse(contexts.isEmpty());
assertFalse(devices.isEmpty());
for (CLContext context : contexts) {
out.println(context);
}
for (CLDevice device : devices) {
out.println(device);
}
}finally{
mc.release();
}
}
private final static String programSource =
" // OpenCL Kernel Function for element by element vector addition \n"
+ "kernel void vectorAdd(global const int* a, global const int* b, global int* c, int iNumElements) { \n"
+ " // get index in global data array \n"
+ " int iGID = get_global_id(0); \n"
+ " // bound check (equivalent to the limit on a 'for' loop for standard/serial C code \n"
+ " if (iGID >= iNumElements) { \n"
+ " return; \n"
+ " } \n"
+ " // add the vector elements \n"
+ " c[iGID] = a[iGID] + b[iGID]; \n"
+ "} \n";
@Test
public void commandQueuePoolTest() {
CLMultiContext mc = CLMultiContext.create(CLPlatform.listCLPlatforms());
try {
CLSimpleContextFactory factory = CLQueueContextFactory.createSimple(programSource);
CLCommandQueuePool pool = CLCommandQueuePool.create(factory, mc);
assertTrue(pool.getSize() > 0);
pool.release();
}finally{
mc.release();
}
}
}
|