5151 * Contexts are used by the OpenCL runtime for managing objects such as command-queues, memory, program and kernel objects and for executing kernels on one or more devices specified in the context.
5252 * @author Olivier Chafik
5353 */
54- public class CLContext extends CLAbstractEntity < cl_context > {
54+ public class CLContext extends CLAbstractEntity {
5555
5656#macro (docCreateBufferCopy $bufferType $details )
5757 /**
@@ -131,9 +131,9 @@ else if ("false".equals(prop) || "0".equals(env))
131131 #declareInfosGetter ("infos" , "CL.clGetContextInfo" )
132132
133133 CLPlatform platform ;
134- protected Pointer <cl_device_id > deviceIds ;
134+ protected Pointer <SizeT > deviceIds ;
135135
136- CLContext (CLPlatform platform , Pointer <cl_device_id > deviceIds , cl_context context ) {
136+ CLContext (CLPlatform platform , Pointer <SizeT > deviceIds , long context ) {
137137 super (context );
138138 this .platform = platform ;
139139 this .deviceIds = deviceIds ;
@@ -143,11 +143,6 @@ else if ("false".equals(prop) || "0".equals(env))
143143 }
144144 }
145145
146- @ Override
147- protected cl_context createEntityPointer (long peer ) {
148- return new cl_context (peer );
149- }
150-
151146 /**
152147 * Creates a user event object. <br/>
153148 * User events allow applications to enqueue commands that wait on a user event to finish before the command is executed by the device.
@@ -171,7 +166,7 @@ public CLEvent createUserEvent() {
171166 * @return new OpenCL queue
172167 */
173168 public CLQueue createDefaultQueue (QueueProperties ... queueProperties ) {
174- return new CLDevice (platform , deviceIds .get ( 0 )).createQueue (this , queueProperties );
169+ return new CLDevice (platform , deviceIds .getSizeT ( )).createQueue (this , queueProperties );
175170 }
176171
177172 /**
@@ -180,7 +175,7 @@ public CLQueue createDefaultQueue(QueueProperties... queueProperties) {
180175 * @return new out-of-order OpenCL queue
181176 */
182177 public CLQueue createDefaultOutOfOrderQueue () {
183- return new CLDevice (platform , deviceIds .get ( 0 )).createOutOfOrderQueue (this );
178+ return new CLDevice (platform , deviceIds .getSizeT ( )).createOutOfOrderQueue (this );
184179 }
185180
186181
@@ -211,23 +206,23 @@ public CLQueue createDefaultOutOfOrderQueueIfPossible() {
211206 * @return new profiling-enabled OpenCL queue
212207 */
213208 public CLQueue createDefaultProfilingQueue () {
214- return new CLDevice (platform , deviceIds .get ( 0 )).createProfilingQueue (this );
209+ return new CLDevice (platform , deviceIds .getSizeT ( )).createProfilingQueue (this );
215210 }
216211
217212 @ SuppressWarnings ("deprecation" )
218213 public CLImageFormat [] getSupportedImageFormats (CLBuffer .Flags flags , CLBuffer .ObjectType imageType ) {
219214 Pointer <Integer > pCount = allocateInt ();
220215 int memFlags = (int ) flags .value ();
221216 int imTyp = (int ) imageType .value ();
222- CL .clGetSupportedImageFormats (getEntity (), memFlags , imTyp , 0 , null , pCount );
217+ CL .clGetSupportedImageFormats (getEntityPeer (), memFlags , imTyp , 0 , 0 , getPeer ( pCount ) );
223218 //cl_image_format ft = new cl_image_format();
224219 //int sz = ft.size();
225220 int n = pCount .getInt ();
226221 if (n == 0 ) {
227222 n = 30 ; // There HAS to be at least one format. the spec even says even more, but in fact on Mac OS X / CPU there's only one...
228223 }
229224 Pointer <cl_image_format > formats = allocateArray (cl_image_format .class , n );
230- CL .clGetSupportedImageFormats (getEntity (), memFlags , imTyp , n , formats , ( Pointer < Integer >) null );
225+ CL .clGetSupportedImageFormats (getEntityPeer (), memFlags , imTyp , n , getPeer ( formats ), 0 );
231226 List <CLImageFormat > ret = new ArrayList <CLImageFormat >(n );
232227 for (cl_image_format ft : formats ) {
233228 if (ft .image_channel_data_type () == 0 && ft .image_channel_order () == 0 )
@@ -241,12 +236,12 @@ public CLImageFormat[] getSupportedImageFormats(CLBuffer.Flags flags, CLBuffer.O
241236 @ SuppressWarnings ("deprecation" )
242237 public CLSampler createSampler (boolean normalized_coords , AddressingMode addressing_mode , FilterMode filter_mode ) {
243238 #declareReusablePtrsAndPErr ()
244- cl_sampler sampler = CL .clCreateSampler (
245- getEntity (),
239+ long sampler = CL .clCreateSampler (
240+ getEntityPeer (),
246241 normalized_coords ? CL_TRUE : CL_FALSE ,
247242 (int ) addressing_mode .value (),
248243 (int ) filter_mode .value (),
249- pErr
244+ getPeer ( pErr )
250245 );
251246 #checkPErr ()
252247 return new CLSampler (sampler );
@@ -262,13 +257,13 @@ public int getDeviceCount() {
262257 */
263258 public synchronized CLDevice [] getDevices () {
264259 if (deviceIds == null ) {
265- deviceIds = infos .getMemory (getEntityPeer (), CL_CONTEXT_DEVICES ).as (cl_device_id .class );
260+ deviceIds = infos .getMemory (getEntityPeer (), CL_CONTEXT_DEVICES ).as (SizeT .class );
266261 }
267262 int n = (int )deviceIds .getValidElements ();
268263
269264 CLDevice [] devices = new CLDevice [n ];
270265 for (int i = n ; i -- != 0 ;) {
271- devices [i ] = new CLDevice (platform , deviceIds .get ( i ));
266+ devices [i ] = new CLDevice (platform , deviceIds .getSizeTAtOffset ( i * Pointer . SIZE ));
272267 }
273268 return devices ;
274269 }
@@ -320,19 +315,29 @@ public CLDevice guessCurrentGLDevice() {
320315 Pointer <SizeT > pCount = allocateSizeT ();
321316 Pointer <Pointer <?>> mem = allocatePointer ();
322317 if (Platform .isMacOSX ())
323- error (CL .clGetGLContextInfoAPPLE (getEntity (), OpenGLContextUtils .CGLGetCurrentContext (),
324- CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR ,
325- Pointer .SIZE , mem , pCount ));
318+ error (CL .clGetGLContextInfoAPPLE (
319+ getEntityPeer (),
320+ getPeer (OpenGLContextUtils .CGLGetCurrentContext ()),
321+ CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR ,
322+ Pointer .SIZE ,
323+ getPeer (mem ),
324+ getPeer (pCount )));
326325 else
327- error (CL .clGetGLContextInfoKHR ((Pointer )propsRef , CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR , Pointer .SIZE , mem , pCount ));
326+ error (CL .clGetGLContextInfoKHR (
327+ getPeer (propsRef ),
328+ CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR ,
329+ Pointer .SIZE ,
330+ getPeer (mem ),
331+ getPeer (pCount )
332+ ));
328333
329334 if (pCount .getSizeT () != Pointer .SIZE )
330335 throw new RuntimeException ("Not a device : len = " + pCount .get ().intValue ());
331336
332337 Pointer p = mem .getPointer ();
333338 if (p .equals (Pointer .NULL ))
334339 return null ;
335- return new CLDevice (null , new cl_device_id (p ));
340+ return new CLDevice (null , getPeer (p ));
336341 }
337342
338343 private static <T extends CLMem > T markAsGL (T mem ) {
0 commit comments