opencl_ruby_ffi 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,7 +36,7 @@ module OpenCL
36
36
  def self.create_sub_buffer( buffer, type, info, options = {} )
37
37
  OpenCL.error_check(OpenCL::INVALID_OPERATION) if buffer.platform.version_number < 1.1
38
38
  flags = OpenCL.get_flags( options )
39
- error = FFI::MemoryPointer.new( :cl_int )
39
+ error = FFI::MemoryPointer::new( :cl_int )
40
40
  buff = OpenCL.clCreateSubBuffer( buffer, flags, type, info, error)
41
41
  OpenCL.error_check(error.read_cl_int)
42
42
  return Buffer::new( buff, false )
@@ -55,7 +55,7 @@ module OpenCL
55
55
  # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
56
56
  def self.create_from_GL_buffer( context, bufobj, options = {} )
57
57
  flags = OpenCL.get_flags( options )
58
- error = FFI::MemoryPointer.new( :cl_int )
58
+ error = FFI::MemoryPointer::new( :cl_int )
59
59
  buff = OpenCL.clCreateFromGLBuffer( context, flags, bufobj, error )
60
60
  OpenCL.error_check(error.read_cl_int)
61
61
  return Buffer::new( buff, false )
@@ -11,6 +11,17 @@ module OpenCL
11
11
  return command_queue
12
12
  end
13
13
 
14
+ # Issues all the commands in a CommandQueue to the Device
15
+ #
16
+ # ==== Attributes
17
+ #
18
+ # * +command_queue+ - the CommandQueue to flush
19
+ def self.flush( command_queue )
20
+ error = OpenCL.clFlush( command_queue )
21
+ OpenCL.error_check( error )
22
+ return command_queue
23
+ end
24
+
14
25
  # Creates a CommandQueue targeting the specified Device
15
26
  #
16
27
  # ==== Attributes
@@ -24,7 +35,7 @@ module OpenCL
24
35
  # * +:properties+ - a single or an Array of :cl_command_queue_properties
25
36
  def self.create_command_queue( context, device, options = {} )
26
37
  properties = OpenCL.get_command_queue_properties( options )
27
- error = FFI::MemoryPointer.new( :cl_int )
38
+ error = FFI::MemoryPointer::new( :cl_int )
28
39
  cmd = OpenCL.clCreateCommandQueue( context, device, properties, error )
29
40
  OpenCL.error_check(error.read_cl_int)
30
41
  return CommandQueue::new(cmd, false)
@@ -51,14 +62,14 @@ module OpenCL
51
62
  num_mem_objects = [mem_objects].flatten.length
52
63
  mem_list = nil
53
64
  if num_mem_objects > 0 then
54
- mem_list = FFI::MemoryPointer.new( OpenCL::Mem, num_mem_objects )
65
+ mem_list = FFI::MemoryPointer::new( OpenCL::Mem, num_mem_objects )
55
66
  [mem_objects].flatten.each_with_index { |e, i|
56
67
  mem_list[i].write_pointer(e)
57
68
  }
58
69
  end
59
70
  flags = OpenCL.get_flags( options )
60
71
  num_events, events = OpenCL.get_event_wait_list( options )
61
- event = FFI::MemoryPointer.new( Event )
72
+ event = FFI::MemoryPointer::new( Event )
62
73
  error = OpenCL.clEnqueueMigrateMemObjects( command_queue, num_mem_objects, mem_list, flags, num_events, events, event )
63
74
  OpenCL.error_check( error )
64
75
  return OpenCL::Event::new( event.read_ptr, false )
@@ -95,10 +106,10 @@ module OpenCL
95
106
  origin, region = OpenCL.get_origin_region( image, options, :origin, :region )
96
107
 
97
108
  num_events, events = OpenCL.get_event_wait_list( options )
98
- image_row_pitch = FFI::MemoryPointer.new( :size_t )
99
- image_slice_pitch = FFI::MemoryPointer.new( :size_t )
100
- event = FFI::MemoryPointer.new( Event )
101
- error = FFI::MemoryPointer.new( :cl_int )
109
+ image_row_pitch = FFI::MemoryPointer::new( :size_t )
110
+ image_slice_pitch = FFI::MemoryPointer::new( :size_t )
111
+ event = FFI::MemoryPointer::new( Event )
112
+ error = FFI::MemoryPointer::new( :cl_int )
102
113
  OpenCL.clEnqueueMapImage( command_queue, image, blocking, map_flags, origin, region, image_row_pitch, image_slice_pitch, num_events, events, event, error )
103
114
  OpenCL.error_check( error.read_cl_int )
104
115
  ev = OpenCL::Event::new( event.read_ptr, false )
@@ -135,8 +146,8 @@ module OpenCL
135
146
  size = buffer.size - offset
136
147
  size = options[:size] - offset if options[:size]
137
148
  num_events, events = OpenCL.get_event_wait_list( options )
138
- event = FFI::MemoryPointer.new( Event )
139
- error = FFI::MemoryPointer.new( :cl_int )
149
+ event = FFI::MemoryPointer::new( Event )
150
+ error = FFI::MemoryPointer::new( :cl_int )
140
151
  ptr = OpenCL.clEnqueueMapBuffer( command_queue, buffer, blocking, map_flags, offset, size, num_events, events, error )
141
152
  OpenCL.error_check( error.read_cl_int )
142
153
  ev = OpenCL::Event::new( event.read_ptr, false )
@@ -161,7 +172,7 @@ module OpenCL
161
172
  # the Event associated with the command
162
173
  def self.enqueue_unmap_mem_object( command_queue, mem_obj, mapped_ptr, options = {} )
163
174
  num_events, events = OpenCL.get_event_wait_list( options )
164
- event = FFI::MemoryPointer.new( Event )
175
+ event = FFI::MemoryPointer::new( Event )
165
176
  error = OpenCL.clEnqueueUnmapMemObject( command_queue, mem_obj, mapped_ptr, num_events, events, event )
166
177
  OpenCL.error_check( error )
167
178
  return OpenCL::Event::new( event.read_ptr, false )
@@ -197,7 +208,7 @@ module OpenCL
197
208
  blocking = OpenCL::FALSE
198
209
  blocking = OpenCL::TRUE if options[:blocking] or options[:blocking_read]
199
210
 
200
- buffer_origin = FFI::MemoryPointer.new( :size_t, 3 )
211
+ buffer_origin = FFI::MemoryPointer::new( :size_t, 3 )
201
212
  (0..2).each { |i| buffer_origin[i].write_size_t(0) }
202
213
  bo = options[:src_origin] ? options[:src_origin] : options[:buffer_origin]
203
214
  if bo then
@@ -206,7 +217,7 @@ module OpenCL
206
217
  }
207
218
  end
208
219
 
209
- host_origin = FFI::MemoryPointer.new( :size_t, 3 )
220
+ host_origin = FFI::MemoryPointer::new( :size_t, 3 )
210
221
  (0..2).each { |i| host_origin[i].write_size_t(0) }
211
222
  ho = options[:dst_origin] ? options[:dst_origin] : options[:host_origin]
212
223
  if ho then
@@ -215,7 +226,7 @@ module OpenCL
215
226
  }
216
227
  end
217
228
 
218
- r = FFI::MemoryPointer.new( :size_t, 3 )
229
+ r = FFI::MemoryPointer::new( :size_t, 3 )
219
230
  (0..2).each { |i| r[i].write_size_t(0) }
220
231
  region[0..3].each_with_index { |e, i|
221
232
  r[i].write_size_t(e)
@@ -238,7 +249,7 @@ module OpenCL
238
249
  host_slice_pitch = 0
239
250
  end
240
251
  num_events, events = OpenCL.get_event_wait_list( options )
241
- event = FFI::MemoryPointer.new( Event )
252
+ event = FFI::MemoryPointer::new( Event )
242
253
  error = OpenCL.clEnqueueReadBufferRect(command_queue, buffer, blocking, buffer_origin, host_origin, r, buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, ptr, num_events, events, event)
243
254
  OpenCL.error_check(error)
244
255
  return OpenCL::Event::new(event.read_pointer, false)
@@ -274,7 +285,7 @@ module OpenCL
274
285
  blocking = OpenCL::FALSE
275
286
  blocking = OpenCL::TRUE if options[:blocking] or options[:blocking_write]
276
287
 
277
- buffer_origin = FFI::MemoryPointer.new( :size_t, 3 )
288
+ buffer_origin = FFI::MemoryPointer::new( :size_t, 3 )
278
289
  (0..2).each { |i| buffer_origin[i].write_size_t(0) }
279
290
  bo = options[:dst_origin] ? options[:dst_origin] : options[:buffer_origin]
280
291
  if bo then
@@ -283,7 +294,7 @@ module OpenCL
283
294
  }
284
295
  end
285
296
 
286
- host_origin = FFI::MemoryPointer.new( :size_t, 3 )
297
+ host_origin = FFI::MemoryPointer::new( :size_t, 3 )
287
298
  (0..2).each { |i| host_origin[i].write_size_t(0) }
288
299
  ho = options[:src_origin] ? options[:src_origin] : options[:host_origin]
289
300
  if ho then
@@ -292,7 +303,7 @@ module OpenCL
292
303
  }
293
304
  end
294
305
 
295
- r = FFI::MemoryPointer.new( :size_t, 3 )
306
+ r = FFI::MemoryPointer::new( :size_t, 3 )
296
307
  (0..2).each { |i| r[i].write_size_t(0) }
297
308
  region[0..3].each_with_index { |e, i|
298
309
  r[i].write_size_t(e)
@@ -315,7 +326,7 @@ module OpenCL
315
326
  host_slice_pitch = 0
316
327
  end
317
328
  num_events, events = OpenCL.get_event_wait_list( options )
318
- event = FFI::MemoryPointer.new( Event )
329
+ event = FFI::MemoryPointer::new( Event )
319
330
  error = OpenCL.clEnqueueWriteBufferRect(command_queue, buffer, blocking, buffer_origin, host_origin, r, buffer_row_pitch, buffer_slice_pitch, host_row_pitch, host_slice_pitch, ptr, num_events, events, event)
320
331
  OpenCL.error_check(error)
321
332
  return OpenCL::Event::new(event.read_pointer, false)
@@ -347,7 +358,7 @@ module OpenCL
347
358
  def self.enqueue_copy_buffer_rect(command_queue, src_buffer, dst_buffer, region, options = {})
348
359
  OpenCL.error_check(OpenCL::INVALID_OPERATION) if command_queue.context.platform.version_number < 1.1
349
360
 
350
- src_origin = FFI::MemoryPointer.new( :size_t, 3 )
361
+ src_origin = FFI::MemoryPointer::new( :size_t, 3 )
351
362
  (0..2).each { |i| src_origin[i].write_size_t(0) }
352
363
  if options[:src_origin] then
353
364
  options[:src_origin].each_with_index { |e, i|
@@ -355,7 +366,7 @@ module OpenCL
355
366
  }
356
367
  end
357
368
 
358
- dst_origin = FFI::MemoryPointer.new( :size_t, 3 )
369
+ dst_origin = FFI::MemoryPointer::new( :size_t, 3 )
359
370
  (0..2).each { |i| dst_origin[i].write_size_t(0) }
360
371
  if options[:dst_origin] then
361
372
  options[:dst_origin].each_with_index { |e, i|
@@ -363,7 +374,7 @@ module OpenCL
363
374
  }
364
375
  end
365
376
 
366
- r = FFI::MemoryPointer.new( :size_t, 3 )
377
+ r = FFI::MemoryPointer::new( :size_t, 3 )
367
378
  (0..2).each { |i| r[i].write_size_t(0) }
368
379
  region[0..3].each_with_index { |e, i|
369
380
  r[i].write_size_t(e)
@@ -386,7 +397,7 @@ module OpenCL
386
397
  dst_slice_pitch = 0
387
398
  end
388
399
  num_events, events = OpenCL.get_event_wait_list( options )
389
- event = FFI::MemoryPointer.new( Event )
400
+ event = FFI::MemoryPointer::new( Event )
390
401
  error = OpenCL.clEnqueueCopyBufferRect(command_queue, src_buffer, dst_buffer, src_origin, dst_origin, r, src_row_pitch, src_slice_pitch, dst_row_pitch, dst_slice_pitch, num_events, events, event)
391
402
  OpenCL.error_check(error)
392
403
  return OpenCL::Event::new(event.read_pointer, false)
@@ -419,7 +430,7 @@ module OpenCL
419
430
  size = [ src_buffer.size - src_offset, dst_buffer.size - dst_offset ].min
420
431
  size = options[:size] if options[:size]
421
432
  num_events, events = OpenCL.get_event_wait_list( options )
422
- event = FFI::MemoryPointer.new( Event )
433
+ event = FFI::MemoryPointer::new( Event )
423
434
  error = OpenCL.clEnqueueCopyBuffer(command_queue, src_buffer, dst_buffer, src_offset, dst_offset, size, num_events, events, event)
424
435
  OpenCL.error_check(error)
425
436
  return OpenCL::Event::new(event.read_pointer, false)
@@ -454,7 +465,7 @@ module OpenCL
454
465
  size = buffer.size - offset
455
466
  size = options[:size] if options[:size]
456
467
  num_events, events = OpenCL.get_event_wait_list( options )
457
- event = FFI::MemoryPointer.new( Event )
468
+ event = FFI::MemoryPointer::new( Event )
458
469
  error = OpenCL.clEnqueueWriteBuffer(command_queue, buffer, blocking, offset, size, ptr, num_events, events, event)
459
470
  OpenCL.error_check(error)
460
471
  return OpenCL::Event::new(event.read_pointer, false)
@@ -488,7 +499,7 @@ module OpenCL
488
499
  size = buffer.size - offset
489
500
  size = options[:size] if options[:size]
490
501
  num_events, events = OpenCL.get_event_wait_list( options )
491
- event = FFI::MemoryPointer.new( Event )
502
+ event = FFI::MemoryPointer::new( Event )
492
503
  error = OpenCL.clEnqueueReadBuffer(command_queue, buffer, blocking, offset, size, ptr, num_events, events, event)
493
504
  OpenCL.error_check(error)
494
505
  return OpenCL::Event::new(event.read_pointer, false)
@@ -513,13 +524,13 @@ module OpenCL
513
524
  num_objs = [mem_objects].flatten.length
514
525
  objs = nil
515
526
  if num_objs > 0 then
516
- objs = FFI::MemoryPointer.new( Mem, num_objs )
527
+ objs = FFI::MemoryPointer::new( Mem, num_objs )
517
528
  [mem_objects].flatten.each_with_index { |o, i|
518
529
  objs[i].write_pointer(e)
519
530
  }
520
531
  end
521
532
  num_events, events = OpenCL.get_event_wait_list( options )
522
- event = FFI::MemoryPointer.new( Event )
533
+ event = FFI::MemoryPointer::new( Event )
523
534
  error = OpenCL.clEnqueueAcquireGLObject( command_queue, num_objs, objs, num_events, events, event )
524
535
  OpenCL.error_check(error)
525
536
  return OpenCL::Event::new(event.read_pointer, false)
@@ -544,13 +555,13 @@ module OpenCL
544
555
  num_objs = [mem_objects].flatten.length
545
556
  objs = nil
546
557
  if num_objs > 0 then
547
- objs = FFI::MemoryPointer.new( Mem, num_objs )
558
+ objs = FFI::MemoryPointer::new( Mem, num_objs )
548
559
  [mem_objects].flatten.each_with_index { |o, i|
549
560
  objs[i].write_pointer(e)
550
561
  }
551
562
  end
552
563
  num_events, events = OpenCL.get_event_wait_list( options )
553
- event = FFI::MemoryPointer.new( Event )
564
+ event = FFI::MemoryPointer::new( Event )
554
565
  error = OpenCL.clEnqueueReleaseGLObject( command_queue, num_objs, objs, num_events, events, event )
555
566
  OpenCL.error_check(error)
556
567
  return OpenCL::Event::new(event.read_pointer, false)
@@ -584,7 +595,7 @@ module OpenCL
584
595
  size = (buffer.size - offset) % pattern_size
585
596
  size = options[:size] if options[:size]
586
597
  num_events, events = OpenCL.get_event_wait_list( options )
587
- event = FFI::MemoryPointer.new( Event )
598
+ event = FFI::MemoryPointer::new( Event )
588
599
  error = OpenCL.clEnqueueFillBuffer( command_queue, buffer, pattern, pattern_size, offset, size, num_events, events, event )
589
600
  OpenCL.error_check(error)
590
601
  return OpenCL::Event::new(event.read_pointer, false)
@@ -612,7 +623,7 @@ module OpenCL
612
623
  OpenCL.error_check(OpenCL::INVALID_OPERATION) if command_queue.context.platform.version_number < 1.1
613
624
  origin, region = OpenCL.get_origin_region( image, options, :origin, :region )
614
625
  num_events, events = OpenCL.get_event_wait_list( options )
615
- event = FFI::MemoryPointer.new( Event )
626
+ event = FFI::MemoryPointer::new( Event )
616
627
  error = OpenCL.clEnqueueFillImage( command_queue, image, fill_color, origin, region, num_events, events, event )
617
628
  OpenCL.error_check(error)
618
629
  return OpenCL::Event::new(event.read_pointer, false)
@@ -642,7 +653,7 @@ module OpenCL
642
653
  dst_offset = 0
643
654
  dst_offset = options[:dst_offset] if options[:dst_offset]
644
655
  num_events, events = OpenCL.get_event_wait_list( options )
645
- event = FFI::MemoryPointer.new( Event )
656
+ event = FFI::MemoryPointer::new( Event )
646
657
  error = OpenCL.clEnqueueCopyImageToBuffer( command_queue, src_image, dst_buffer, src_origin, region, dst_offset, num_events, events, event )
647
658
  OpenCL.error_check(error)
648
659
  return OpenCL::Event::new(event.read_pointer, false)
@@ -672,7 +683,7 @@ module OpenCL
672
683
  src_offset = 0
673
684
  src_offset = options[:src_offset] if options[:src_offset]
674
685
  num_events, events = OpenCL.get_event_wait_list( options )
675
- event = FFI::MemoryPointer.new( Event )
686
+ event = FFI::MemoryPointer::new( Event )
676
687
  error = OpenCL.clEnqueueCopyBufferToImage( command_queue, src_buffer, dst_image, src_offset, dst_origin, region, num_events, events, event )
677
688
  OpenCL.error_check(error)
678
689
  return OpenCL::Event::new(event.read_pointer, false)
@@ -711,7 +722,7 @@ module OpenCL
711
722
  input_slice_pitch = 0
712
723
  input_slice_pitch = options[:input_slice_pitch] if options[:input_slice_pitch]
713
724
  num_events, events = OpenCL.get_event_wait_list( options )
714
- event = FFI::MemoryPointer.new( Event )
725
+ event = FFI::MemoryPointer::new( Event )
715
726
  error = OpenCL.clEnqueueWriteImage( command_queue, image, blocking, origin, region, input_row_pitch, input_slice_pitch, ptr, num_events, events, event )
716
727
  OpenCL.error_check(error)
717
728
  return OpenCL::Event::new(event.read_pointer, false)
@@ -739,12 +750,12 @@ module OpenCL
739
750
  def self.enqueue_copy_image( command_queue, src_image, dst_image, options = {} )
740
751
  src_origin, src_region = OpenCL.get_origin_region( src_image, options, :src_origin, :region )
741
752
  dst_origin, dst_region = OpenCL.get_origin_region( dst_image, options, :dst_origin, :region )
742
- region = FFI::MemoryPointer.new( :size_t, 3 )
753
+ region = FFI::MemoryPointer::new( :size_t, 3 )
743
754
  (0..2).each { |i|
744
755
  region[i].write_size_t( [src_region[i].read_size_t, dst_region[i].read_size_t].min )
745
756
  }
746
757
  num_events, events = OpenCL.get_event_wait_list( options )
747
- event = FFI::MemoryPointer.new( Event )
758
+ event = FFI::MemoryPointer::new( Event )
748
759
  error = OpenCL.clEnqueueCopyImage( command_queue, src_image, dst_image, src_origin, dst_origin, region, num_events, events, event )
749
760
  OpenCL.error_check(error)
750
761
  return OpenCL::Event::new(event.read_pointer, false)
@@ -782,14 +793,13 @@ module OpenCL
782
793
  slice_pitch = 0
783
794
  slice_pitch = options[:slice_pitch] if options[:slice_pitch]
784
795
  num_events, events = OpenCL.get_event_wait_list( options )
785
- event = FFI::MemoryPointer.new( Event )
796
+ event = FFI::MemoryPointer::new( Event )
786
797
  error = OpenCL.clEnqueueReadImage( command_queue, image, blocking, origin, region, row_pitch, slice_pitch, ptr, num_events, events, event )
787
798
  OpenCL.error_check(error)
788
799
  return OpenCL::Event::new(event.read_pointer, false)
789
800
  end
790
801
 
791
802
  # Enqueues a native kernel
792
- # not yet fully implemented
793
803
  #
794
804
  # ==== Attributes
795
805
  #
@@ -799,26 +809,46 @@ module OpenCL
799
809
  #
800
810
  # ==== Options
801
811
  #
812
+ # * +:args+ - if provided, a list of arguments to pass to the kernel. Arguments should have a size method and be convertible to Pointer with to_ptr
813
+ # * +:mem_list+ - if provided, a hash containing Buffer objects and their index inside the argument list.
802
814
  # * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
803
815
  #
804
816
  # ==== Returns
805
817
  #
806
818
  # the Event associated with the command
807
819
  def self.enqueue_native_kernel( command_queue, options = {}, &func )
808
- # num_mem_objects = 0
809
- # mem_list = nil
810
- # if options[:mem_list] then
811
- # num_mem_objects = options[:mem_list].length
812
- # if num_mem_objects > 0 then
813
- # mem_list = FFI::MemoryPointer.new( OpenCL::Mem, num_mem_objects )
814
- # options[:mem_list].each_with_index { |e, i|
815
- # mem_list[i].write_pointer(e)
816
- # }
817
- # end
818
- # end
820
+ arguments = options[:args]
821
+ arg_offset = []
822
+ args = nil
823
+ args_size = 0
824
+ if arguments then
825
+ [arguments].flatten.each { |e|
826
+ arg_offset.push(arg_size)
827
+ args_size += e.size
828
+ }
829
+ args = FFI::MemoryPointer::new(args_size)
830
+ [arguments].flatten.each_with_index { |e, i|
831
+ args.put_bytes(arg_offset[i], e.to_ptr.read_bytes(e.size))
832
+ }
833
+ end
834
+ num_mem_objects = 0
835
+ mem_list = nil
836
+ if options[:mem_list] then
837
+ num_mem_objects = options[:mem_list].length
838
+ if num_mem_objects > 0 then
839
+ mem_list = FFI::MemoryPointer::new( OpenCL::Mem, num_mem_objects )
840
+ mem_loc = FFI::MemoryPointer::new( Pointer, num_mem_objects )
841
+ i = 0
842
+ options[:mem_list].each { |key, value|
843
+ mem_list[i].write_pointer(key)
844
+ mem_loc[i].write_pointer(args+arg_offset[value])
845
+ i = i + 1
846
+ }
847
+ end
848
+ end
819
849
  num_events, events = OpenCL.get_event_wait_list( options )
820
- event = FFI::MemoryPointer.new( Event )
821
- error = OpenCL.clEnqueueNativeKernel( command_queue, func, nil, 0, 0, nil, nil, num_events, events, event )
850
+ event = FFI::MemoryPointer::new( Event )
851
+ error = OpenCL.clEnqueueNativeKernel( command_queue, func, args, args_size, num_mem_objects, mem_list, mem_loc, num_events, events, event )
822
852
  OpenCL.error_check(error)
823
853
  return OpenCL::Event::new(event.read_pointer, false)
824
854
  end
@@ -840,7 +870,7 @@ module OpenCL
840
870
  # the Event associated with the command
841
871
  def self.enqueue_task( command_queue, kernel, options = {} )
842
872
  num_events, events = OpenCL.get_event_wait_list( options )
843
- event = FFI::MemoryPointer.new( Event )
873
+ event = FFI::MemoryPointer::new( Event )
844
874
  error = OpenCL.clEnqueueTask( command_queue, kernel, num_events, events, event )
845
875
  OpenCL.error_check(error)
846
876
  return OpenCL::Event::new(event.read_pointer, false)
@@ -865,26 +895,26 @@ module OpenCL
865
895
  #
866
896
  # the Event associated with the command
867
897
  def self.enqueue_NDrange_kernel( command_queue, kernel, global_work_size, options={} )
868
- gws = FFI::MemoryPointer.new( :size_t, global_work_size.length )
898
+ gws = FFI::MemoryPointer::new( :size_t, global_work_size.length )
869
899
  global_work_size.each_with_index { |g, i|
870
900
  gws[i].write_size_t(g)
871
901
  }
872
902
  lws = nil
873
903
  if options[:local_work_size] then
874
- lws = FFI::MemoryPointer.new( :size_t, global_work_size.length )
904
+ lws = FFI::MemoryPointer::new( :size_t, global_work_size.length )
875
905
  global_work_size.each_index { |i|
876
906
  lws[i].write_size_t(options[:local_work_size][i])
877
907
  }
878
908
  end
879
909
  gwo = nil
880
910
  if options[:global_work_offset] then
881
- gwo = FFI::MemoryPointer.new( :size_t, global_work_size.length )
911
+ gwo = FFI::MemoryPointer::new( :size_t, global_work_size.length )
882
912
  global_work_size.each_index { |i|
883
913
  gwo[i].write_size_t(options[:global_work_offset][i])
884
914
  }
885
915
  end
886
916
  num_events, events = OpenCL.get_event_wait_list( options )
887
- event = FFI::MemoryPointer.new( Event )
917
+ event = FFI::MemoryPointer::new( Event )
888
918
  error = OpenCL.clEnqueueNDRangeKernel(command_queue, kernel, global_work_size.length, gwo, gws, lws, num_events, events, event)
889
919
  OpenCL.error_check(error)
890
920
  return OpenCL::Event::new(event.read_pointer, false)
@@ -918,7 +948,7 @@ module OpenCL
918
948
  if command_queue.context.platform.version_number < 1.2 then
919
949
  num_events = [events].flatten.length
920
950
  if num_events > 0 then
921
- evts = FFI::MemoryPointer.new( Event, num_events )
951
+ evts = FFI::MemoryPointer::new( Event, num_events )
922
952
  [events].flatten.each_with_index { |e, i|
923
953
  evts[i].write_pointer(e)
924
954
  }
@@ -932,12 +962,12 @@ module OpenCL
932
962
  num_events = [events].flatten.length
933
963
  evts = nil
934
964
  if num_events > 0 then
935
- evts = FFI::MemoryPointer.new( Event, num_events )
965
+ evts = FFI::MemoryPointer::new( Event, num_events )
936
966
  [events].flatten.each_with_index { |e, i|
937
967
  evts[i].write_pointer(e)
938
968
  }
939
969
  end
940
- event = FFI::MemoryPointer.new( Event )
970
+ event = FFI::MemoryPointer::new( Event )
941
971
  error = OpenCL.clEnqueueBarrierWithWaitList( command_queue, num_events, evts, event )
942
972
  OpenCL.error_check(error)
943
973
  return OpenCL::Event::new(event.read_pointer, false)
@@ -955,14 +985,14 @@ module OpenCL
955
985
  #
956
986
  # an Event
957
987
  def self.enqueue_marker( command_queue, events = [] )
958
- event = FFI::MemoryPointer.new( Event )
988
+ event = FFI::MemoryPointer::new( Event )
959
989
  if command_queue.context.platform.version_number < 1.2 then
960
990
  error = OpenCL.clEnqueueMarker( command_queue, event )
961
991
  else
962
992
  num_events = [events].flatten.length
963
993
  evts = nil
964
994
  if num_events > 0 then
965
- evts = FFI::MemoryPointer.new( Event, num_events )
995
+ evts = FFI::MemoryPointer::new( Event, num_events )
966
996
  [events].flatten.each_with_index { |e, i|
967
997
  evts[i].write_pointer(e)
968
998
  }
@@ -978,7 +1008,7 @@ module OpenCL
978
1008
 
979
1009
  # Returns the Context associated to the CommandQueue
980
1010
  def context
981
- ptr = FFI::MemoryPointer.new( Context )
1011
+ ptr = FFI::MemoryPointer::new( Context )
982
1012
  error = OpenCL.clGetCommandQueueInfo(self, CommandQueue::CONTEXT, Context.size, ptr, nil)
983
1013
  OpenCL.error_check(error)
984
1014
  return OpenCL::Context::new( ptr.read_pointer )
@@ -986,7 +1016,7 @@ module OpenCL
986
1016
 
987
1017
  # Returns the Device associated to the CommandQueue
988
1018
  def device
989
- ptr = FFI::MemoryPointer.new( Device )
1019
+ ptr = FFI::MemoryPointer::new( Device )
990
1020
  error = OpenCL.clGetCommandQueueInfo(self, CommandQueue::DEVICE, Device.size, ptr, nil)
991
1021
  OpenCL.error_check(error)
992
1022
  return OpenCL::Device::new( ptr.read_pointer )
@@ -1534,11 +1564,36 @@ module OpenCL
1534
1564
  return OpenCL.enqueue_migrate_mem_objects( self, mem_objects, options )
1535
1565
  end
1536
1566
 
1567
+ # Enqueues a native kernel in the CommandQueue
1568
+ #
1569
+ # ==== Attributes
1570
+ #
1571
+ # * +options+ - a hash containing named options
1572
+ # * +func+ - a Proc object to execute
1573
+ #
1574
+ # ==== Options
1575
+ #
1576
+ # * +:args+ - if provided, a list of arguments to pass to the kernel. Arguments should have a size method and be convertible to Pointer with to_ptr
1577
+ # * +:mem_list+ - if provided, a hash containing Buffer objects and their index inside the argument list.
1578
+ # * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
1579
+ #
1580
+ # ==== Returns
1581
+ #
1582
+ # the Event associated with the command
1583
+ def enqueue_native_kernel( options = {}, &func )
1584
+ return OpenCL.enqueue_native_kernel( self, options, &func )
1585
+ end
1586
+
1537
1587
  # Blocks until all the commands in the CommandQueue have completed
1538
1588
  def finish
1539
1589
  return OpenCL.finish(self)
1540
1590
  end
1541
1591
 
1592
+ # Issues all the commands in a CommandQueue to the Device
1593
+ def flush
1594
+ return OpenCL.flush( self )
1595
+ end
1596
+
1542
1597
  end
1543
1598
 
1544
1599
  end
@@ -14,13 +14,13 @@ module OpenCL
14
14
  # * +:user_data+ - an FFI::Pointer or an object that can be converted into one using to_ptr. The pointer is passed to the callback.
15
15
  def self.create_context(devices, options = {}, &block)
16
16
  @@callbacks.push( block ) if block
17
- pointer = FFI::MemoryPointer.new( Device, devices.size)
17
+ pointer = FFI::MemoryPointer::new( Device, devices.size)
18
18
  devices.size.times { |indx|
19
19
  pointer.put_pointer(indx, devices[indx])
20
20
  }
21
21
  properties = OpenCL.get_context_properties( options )
22
22
  user_data = options[:user_data]
23
- error = FFI::MemoryPointer.new( :cl_int )
23
+ error = FFI::MemoryPointer::new( :cl_int )
24
24
  ptr = OpenCL.clCreateContext(properties, devices.size, pointer, block, user_data, error)
25
25
  OpenCL.error_check(error.read_cl_int)
26
26
  return OpenCL::Context::new(ptr, false)
@@ -42,7 +42,7 @@ module OpenCL
42
42
  @@callbacks.push( block ) if block
43
43
  properties = OpenCL.get_context_properties( options )
44
44
  user_data = options[:user_data]
45
- error = FFI::MemoryPointer.new( :cl_int )
45
+ error = FFI::MemoryPointer::new( :cl_int )
46
46
  ptr = OpenCL.clCreateContextFromType(properties, type, block, user_data, error)
47
47
  OpenCL.error_check(error.read_cl_int)
48
48
  return OpenCL::Context::new(ptr, false)
@@ -71,12 +71,12 @@ module OpenCL
71
71
  # Returns the number of devices associated to the Context
72
72
  def num_devices
73
73
  d_n = 0
74
- ptr = FFI::MemoryPointer.new( :size_t )
74
+ ptr = FFI::MemoryPointer::new( :size_t )
75
75
  error = OpenCL.clGetContextInfo(self, Context::DEVICES, 0, nil, ptr)
76
76
  OpenCL.error_check(error)
77
77
  d_n = ptr.read_size_t / Platform.size
78
78
  # else
79
- # ptr = FFI::MemoryPointer.new( :cl_uint )
79
+ # ptr = FFI::MemoryPointer::new( :cl_uint )
80
80
  # error = OpenCL.clGetContextInfo(self, Context::NUM_DEVICES, ptr.size, ptr, nil)
81
81
  # OpenCL.error_check(error)
82
82
  # d_n = ptr.read_cl_uint
@@ -87,11 +87,11 @@ module OpenCL
87
87
  # Returns an Array of Device associated to the Context
88
88
  def devices
89
89
  n = self.num_devices
90
- ptr2 = FFI::MemoryPointer.new( Device, n )
90
+ ptr2 = FFI::MemoryPointer::new( Device, n )
91
91
  error = OpenCL.clGetContextInfo(self, Context::DEVICES, Device.size*n, ptr2, nil)
92
92
  OpenCL.error_check(error)
93
93
  return ptr2.get_array_of_pointer(0, n).collect { |device_ptr|
94
- OpenCL::Device.new(device_ptr)
94
+ OpenCL::Device::new(device_ptr)
95
95
  }
96
96
  end
97
97
 
@@ -106,11 +106,11 @@ module OpenCL
106
106
  # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
107
107
  def supported_image_formats( image_type, options = {} )
108
108
  flags = OpenCL.get_flags( options )
109
- num_image_formats = FFI::MemoryPointer.new( :cl_uint )
109
+ num_image_formats = FFI::MemoryPointer::new( :cl_uint )
110
110
  error = OpenCL.clGetSupportedImageFormats( self, flags, image_type, 0, nil, num_image_formats )
111
111
  OpenCL.error_check(error)
112
112
  num_entries = num_image_formats.read_cl_uint
113
- image_formats = FFI::MemoryPointer.new( ImageFormat, num_entries )
113
+ image_formats = FFI::MemoryPointer::new( ImageFormat, num_entries )
114
114
  error = OpenCL.clGetSupportedImageFormats( self, flags, image_type, num_entries, image_formats, nil )
115
115
  OpenCL.error_check(error)
116
116
  return num_entries.times.collect { |i|
@@ -301,6 +301,43 @@ module OpenCL
301
301
  return OpenCL.create_user_event(self)
302
302
  end
303
303
 
304
+ # Links a set of compiled programs for all device in the Context, or a subset of devices
305
+ #
306
+ # ==== Attributes
307
+ #
308
+ # * +input_programs+ - a single or an Array of Program
309
+ # * +options+ - a Hash containing named options
310
+ # * +block+ - if provided, a callback invoked when the Program is built. Signature of the callback is { |Program, FFI::Pointer to user_data| ... }
311
+ #
312
+ # ==== Options
313
+ #
314
+ # * +:device_list+ - an Array of Device to build the program for
315
+ # * +:options+ - a String containing the options to use for the build
316
+ # * +:user_data+ - a Pointer (or convertible to Pointer using to_ptr) to the memory area to pass to the callback
317
+ def link_program( input_programs, options = {}, &block)
318
+ return OpenCL.link_program(self, input_programs, options, &block)
319
+ end
320
+
321
+ # Creates a Program from binary
322
+ #
323
+ # ==== Attributes
324
+ #
325
+ # * +device_list+ - an Array of Device to create the program for. Can throw an OpenCL::Invalid value if the number of supplied devices is different from the number of supplied binaries.
326
+ # * +binaries+ - Array of binaries
327
+ def create_program_with_binary( device_list, binaries)
328
+ return OpenCL.create_program_with_binary(self, device_list, binaries)
329
+ end
330
+
331
+ # Creates a Program from a list of built in kernel names
332
+ #
333
+ # ==== Attributes
334
+ #
335
+ # * +device_list+ - an Array of Device to create the program for
336
+ # * +kernel_names+ - a single or an Array of String representing the kernel names
337
+ def self.create_program_with_built_in_kernels( device_list, kernel_names )
338
+ return OpenCL.create_program_with_built_in_kernels(self, device_list, kernel_names )
339
+ end
340
+
304
341
  # Creates a Program from sources in the Context
305
342
  #
306
343
  # ==== Attributes
@@ -25,7 +25,7 @@ module OpenCL
25
25
  error = OpenCL.clCreateSubDevice( in_device, props, device_number, devices_ptr, nil )
26
26
  OpenCL.error_check(error)
27
27
  devices_ptr.get_array_of_pointer(0, device_number).collect { |device_ptr|
28
- OpenCL::Device.new(device_ptr, false)
28
+ OpenCL::Device::new(device_ptr, false)
29
29
  }
30
30
  end
31
31
 
@@ -116,19 +116,19 @@ module OpenCL
116
116
 
117
117
  # Returns the platform the Device belongs to
118
118
  def platform
119
- ptr = FFI::MemoryPointer.new( OpenCL::Platform )
119
+ ptr = FFI::MemoryPointer::new( OpenCL::Platform )
120
120
  error = OpenCL.clGetDeviceInfo(self, Device::PLATFORM, OpenCL::Platform.size, ptr, nil)
121
121
  OpenCL.error_check(error)
122
- return OpenCL::Platform.new(ptr.read_pointer)
122
+ return OpenCL::Platform::new(ptr.read_pointer)
123
123
  end
124
124
 
125
125
  # Returns the parent Device if it exists
126
126
  def parent_device
127
- ptr = FFI::MemoryPointer.new( OpenCL::Device )
127
+ ptr = FFI::MemoryPointer::new( OpenCL::Device )
128
128
  error = OpenCL.clGetDeviceInfo(self, Device::PARENT_DEVICE, OpenCL::Device.size, ptr, nil)
129
129
  OpenCL.error_check(error)
130
130
  return nil if ptr.null?
131
- return OpenCL::Device.new(ptr.read_pointer)
131
+ return OpenCL::Device::new(ptr.read_pointer)
132
132
  end
133
133
 
134
134
  # Partitions the Device in serveral sub-devices