opencl_ruby_ffi 0.95 → 0.96

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,6 +12,8 @@ require "opencl_ruby_ffi/Event.rb"
12
12
  require "opencl_ruby_ffi/Kernel.rb"
13
13
  require "opencl_ruby_ffi/Image.rb"
14
14
  require "opencl_ruby_ffi/Sampler.rb"
15
+ require "opencl_ruby_ffi/Pipe.rb"
16
+ require "opencl_ruby_ffi/SVM.rb"
15
17
 
16
18
  require "narray_ffi"
17
19
 
@@ -15,7 +15,7 @@ module OpenCL
15
15
  def self.create_buffer( context, size, options = {} )
16
16
  flags = OpenCL.get_flags( options )
17
17
  host_ptr = options[:host_ptr]
18
- error = FFI::MemoryPointer.new( :cl_int )
18
+ error = FFI::MemoryPointer::new( :cl_int )
19
19
  buff = OpenCL.clCreateBuffer(context, flags, size, host_ptr, error)
20
20
  OpenCL.error_check(error.read_cl_int)
21
21
  return OpenCL::Buffer::new( buff, false )
@@ -33,10 +33,36 @@ module OpenCL
33
33
  # ==== Options
34
34
  #
35
35
  # * +:properties+ - a single or an Array of :cl_command_queue_properties
36
+ # * +:size+ - the size of the command queue ( if ON_DEVICE is specified in the properties ) 2.0+ only
36
37
  def self.create_command_queue( context, device, options = {} )
37
38
  properties = OpenCL.get_command_queue_properties( options )
39
+ size = options[:size]
38
40
  error = FFI::MemoryPointer::new( :cl_int )
39
- cmd = OpenCL.clCreateCommandQueue( context, device, properties, error )
41
+ if context.platform.version_number < 2.0 then
42
+ cmd = OpenCL.clCreateCommandQueue( context, device, properties, error )
43
+ else
44
+ props = nil
45
+ if properties.to_i != 0 or size then
46
+ props_size = 0
47
+ props_size += 2 if properties.to_i != 0
48
+ props_size += 2 if size
49
+ props_size += 1 if props_size > 0
50
+ props = FFI::MemoryPointer::new( :cl_queue_properties, props_size )
51
+ i=0
52
+ if properties.to_i != 0 then
53
+ props[i].write_cl_queue_properties( OpenCL::Queue::PROPERTIES )
54
+ props[i+1].write_cl_queue_properties( properties.to_i )
55
+ i += 2
56
+ end
57
+ if size then
58
+ props[i].write_cl_queue_properties( OpenCL::Queue::SIZE )
59
+ props[i+1].write_cl_queue_properties( size )
60
+ i += 2
61
+ end
62
+ props[i].write_cl_queue_properties( 0 )
63
+ end
64
+ cmd = OpenCL.clCreateCommandQueueWithProperties( context, device, props, error )
65
+ end
40
66
  OpenCL.error_check(error.read_cl_int)
41
67
  return OpenCL::CommandQueue::new(cmd, false)
42
68
  end
@@ -111,13 +137,13 @@ module OpenCL
111
137
  image_slice_pitch = FFI::MemoryPointer::new( :size_t )
112
138
  event = FFI::MemoryPointer::new( OpenCL::Event )
113
139
  error = FFI::MemoryPointer::new( :cl_int )
114
- OpenCL.clEnqueueMapImage( command_queue, image, blocking, flags, origin, region, image_row_pitch, image_slice_pitch, num_events, events, event, error )
140
+ ptr = OpenCL.clEnqueueMapImage( command_queue, image, blocking, flags, origin, region, image_row_pitch, image_slice_pitch, num_events, events, event, error )
115
141
  OpenCL.error_check( error.read_cl_int )
116
142
  ev = OpenCL::Event::new( event.read_ptr, false )
117
143
  return [ev, ptr, image_row_pitch.read_size_t, image_slice_pitch.read_size_t]
118
144
  end
119
145
 
120
- # Enqueues a command to map an Image into host memory
146
+ # Enqueues a command to map aa Buffer into host memory
121
147
  #
122
148
  # ==== Attributes
123
149
  #
@@ -151,7 +177,7 @@ module OpenCL
151
177
  num_events, events = OpenCL.get_event_wait_list( options )
152
178
  event = FFI::MemoryPointer::new( OpenCL::Event )
153
179
  error = FFI::MemoryPointer::new( :cl_int )
154
- ptr = OpenCL.clEnqueueMapBuffer( command_queue, buffer, blocking, flags, offset, size, num_events, events, error )
180
+ ptr = OpenCL.clEnqueueMapBuffer( command_queue, buffer, blocking, flags, offset, size, num_events, events, event, error )
155
181
  OpenCL.error_check( error.read_cl_int )
156
182
  ev = OpenCL::Event::new( event.read_ptr, false )
157
183
  return [ev, ptr]
@@ -1030,6 +1056,11 @@ module OpenCL
1030
1056
  # Returns the reference count of the CommandQueue
1031
1057
  eval OpenCL.get_info("CommandQueue", :cl_uint, "REFERENCE_COUNT")
1032
1058
 
1059
+ ##
1060
+ # :method: size
1061
+ # Returns the currently specified size for the command queue (2.0 and for device queue only)
1062
+ eval OpenCL.get_info("CommandQueue", :cl_uint, "SIZE")
1063
+
1033
1064
  ##
1034
1065
  # :method: properties
1035
1066
  # Returns the :cl_command_queue_properties used to create the CommandQueue
@@ -1477,7 +1508,7 @@ module OpenCL
1477
1508
  return OpenCL.enqueue_release_GL_object( self, mem_objects, options )
1478
1509
  end
1479
1510
 
1480
- # Enqueues a command to map an Image into host memory using the CommandQueue
1511
+ # Enqueues a command to map a Buffer into host memory using the CommandQueue
1481
1512
  #
1482
1513
  # ==== Attributes
1483
1514
  #
@@ -1597,6 +1628,108 @@ module OpenCL
1597
1628
  return OpenCL.flush( self )
1598
1629
  end
1599
1630
 
1631
+ # Enqueues a command to copy from or to an SVMPointer using the CommandQueue
1632
+ #
1633
+ # ==== Attributes
1634
+ #
1635
+ # * +dst_ptr+ - the Pointer (or convertible to Pointer using to_ptr) or SVMPointer to be written to
1636
+ # * +src_ptr+ - the Pointer (or convertible to Pointer using to_ptr) or SVMPointer to be read from
1637
+ # * +size+ - the size of data to copy
1638
+ # * +options+ - a hash containing named options
1639
+ #
1640
+ # ==== Options
1641
+ #
1642
+ # * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
1643
+ # * +:blocking_copy+ - if provided indicates if the command blocks until the copy finishes
1644
+ # * +:blocking+ - if provided indicates if the command blocks until the copy finishes
1645
+ #
1646
+ # ==== Returns
1647
+ #
1648
+ # the Event associated with the command
1649
+ def enqueue_svm_memcpy( dst_ptr, src_ptr, size, options = {})
1650
+ return OpenCL.enqueue_svm_memcpy(self, dst_ptr, src_ptr, size, options)
1651
+ end
1652
+
1653
+ # Enqueues a command that frees SVMPointers (or Pointers using a callback) using the CommandQueue
1654
+ #
1655
+ # ==== Attributes
1656
+ #
1657
+ # * +svm_pointer+ - a single or an Array of SVMPointer (or Pointer)
1658
+ # * +options+ - a hash containing named options
1659
+ # * +block+ - if provided, a callback invoked to free the pointers. Signature of the callback is { |CommandQueue, num_pointers, FFI::Pointer to an array of num_pointers Pointers, FFI::Pointer to user_data| ... }
1660
+ #
1661
+ # ==== Options
1662
+ #
1663
+ # * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
1664
+ # * +:user_data+ - if provided, a Pointer (or convertible to using to_ptr) that will be passed to the callback
1665
+ #
1666
+ # ==== Returns
1667
+ #
1668
+ # the Event associated with the command
1669
+ def enqueue_svm_free(svm_pointers, options = {}, &block)
1670
+ return OpenCL.enqueue_svm_free(self, svm_pointers, options, &block)
1671
+ end
1672
+
1673
+ # Enqueues a command to fill a an SVM memory area using the CommandQueue
1674
+ #
1675
+ # ==== Attributes
1676
+ #
1677
+ # * +svm_ptr+ - the SVMPointer to the area to fill
1678
+ # * +pattern+ - the Pointer (or convertible to Pointer using to_ptr) to the memory area where the pattern is stored
1679
+ # * +size+ - the size of the area to fill
1680
+ #
1681
+ # ==== Options
1682
+ #
1683
+ # * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
1684
+ # * +:pattern_size+ - if provided indicates the size of the pattern, else the maximum pattern data is used
1685
+ #
1686
+ # ==== Returns
1687
+ #
1688
+ # the Event associated with the command
1689
+ def enqueue_svm_fill(command_queue, svm_ptr, pattern, size, options = {})
1690
+ return OpenCL.enqueue_svm_fill(self, svm_ptr, pattern, size, options)
1691
+ end
1692
+
1693
+ # Enqueues a command to map an Image into host memory using the CommandQueue
1694
+ #
1695
+ # ==== Attributes
1696
+ #
1697
+ # * +svm_ptr+ - the SVMPointer to the area to map
1698
+ # * +size+ - the size of the region to map
1699
+ # * +map_flags+ - a single or an Array of :cl_map_flags flags
1700
+ # * +options+ - a hash containing named options
1701
+ #
1702
+ # ==== Options
1703
+ #
1704
+ # * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
1705
+ # * +:blocking_map+ - if provided indicates if the command blocks until the region is mapped
1706
+ # * +:blocking+ - if provided indicates if the command blocks until the region is mapped
1707
+ #
1708
+ # ==== Returns
1709
+ #
1710
+ # the Event associated with the command
1711
+ def enqueue_svm_map( svm_ptr, size, map_flags, options = {} )
1712
+ return OpenCL.enqueue_svm_map( self, svm_ptr, size, map_flags, options )
1713
+ end
1714
+
1715
+ # Enqueues a command to unmap a previously mapped SVM memory area using the CommandQueue
1716
+ #
1717
+ # ==== Attributes
1718
+ #
1719
+ # * +svm_ptr+ - the SVMPointer of the area to be unmapped
1720
+ # * +options+ - a hash containing named options
1721
+ #
1722
+ # ==== Options
1723
+ #
1724
+ # * +:event_wait_list+ - if provided, a list of Event to wait upon before executing the command
1725
+ #
1726
+ # ==== Returns
1727
+ #
1728
+ # the Event associated with the command
1729
+ def enqueue_svm_unmap( svm_ptr, options = {} )
1730
+ return OpenCL.enqueue_svm_unmap( self, svm_ptr, options )
1731
+ end
1732
+
1600
1733
  end
1601
1734
 
1602
1735
  end
@@ -129,6 +129,7 @@ module OpenCL
129
129
  # ==== Options
130
130
  #
131
131
  # * +:properties+ - a single or an Array of :cl_command_queue_properties
132
+ # * +:size+ - the size of the command queue ( if ON_DEVICE is specified in the properties ) 2.0+ only
132
133
  def create_command_queue( device, options = {} )
133
134
  return OpenCL.create_command_queue( self, device, options )
134
135
  end
@@ -350,14 +351,32 @@ module OpenCL
350
351
 
351
352
  # Creates a Sampler in the Context
352
353
  #
354
+ # ==== Options
355
+ #
356
+ # * +:normalized_coords+ - a :cl_bool specifying if the image coordinates are normalized
357
+ # * +:addressing_mode+ - a :cl_addressing_mode specifying how out-of-range image coordinates are handled when reading from an image
358
+ # * +:filter_mode+ - a :cl_filter_mode specifying the type of filter that must be applied when reading an image
359
+ # * +:mip_filter_mode+ - the filtering mode to use if using mimaps (default CL_FILTER_NONE, requires cl_khr_mipmap_image)
360
+ # * +:lod_min+ - floating point value representing the minimal LOD (default 0.0f, requires cl_khr_mipmap_image)
361
+ # * +:lod_max+ - floating point value representing the maximal LOD (default MAXFLOAT, requires cl_khr_mipmap_image)
362
+ def create_sampler( options = {} )
363
+ return OpenCL.create_sampler( self, options )
364
+ end
365
+
366
+ # Creates a Pipe in the Context
367
+ #
353
368
  # ==== Attributes
354
369
  #
355
- # * +normalized_coords+ - a :cl_bool specifying if the image coordinates are normalized
356
- # * +addressing_mode+ - a :cl_addressing_mode specifying how out-of-range image coordinates are handled when reading from an image
357
- # * +filter_mode+ - a :cl_filter_mode specifying the type of filter that must be applied when reading an image
358
- def create_sampler( normalized_coords, addressing_mode, filter_mode )
359
- return OpenCL.create_sampler( self, normalized_coords, addressing_mode, filter_mode )
370
+ # * +pipe_packet_size+ - size of a packet in the Pipe
371
+ # * +pipe_max_packets+ - size of the Pipe in packet
372
+ #
373
+ # ==== Options
374
+ #
375
+ # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
376
+ def create_pipe( pipe_packet_size, pipe_max_packets, opts = {} )
377
+ return OpenCL.create_pipe( self, pipe_packet_size, pipe_max_packets, opts )
360
378
  end
379
+
361
380
  end
362
381
 
363
382
  end
@@ -68,11 +68,11 @@ module OpenCL
68
68
  eval OpenCL.get_info("Device", :cl_ulong, prop)
69
69
  }
70
70
 
71
- %w( IMAGE_PITCH_ALIGNMENT IMAGE_BASE_ADDRESS_ALIGNMENT REFERENCE_COUNT PARTITION_MAX_SUB_DEVICES VENDOR_ID PREFERRED_VECTOR_WIDTH_HALF PREFERRED_VECTOR_WIDTH_CHAR PREFERRED_VECTOR_WIDTH_SHORT PREFERRED_VECTOR_WIDTH_INT PREFERRED_VECTOR_WIDTH_LONG PREFERRED_VECTOR_WIDTH_FLOAT PREFERRED_VECTOR_WIDTH_DOUBLE NATIVE_VECTOR_WIDTH_CHAR NATIVE_VECTOR_WIDTH_SHORT NATIVE_VECTOR_WIDTH_INT NATIVE_VECTOR_WIDTH_LONG NATIVE_VECTOR_WIDTH_FLOAT NATIVE_VECTOR_WIDTH_DOUBLE NATIVE_VECTOR_WIDTH_HALF MIN_DATA_TYPE_ALIGN_SIZE MEM_BASE_ADDR_ALIGN MAX_WRITE_IMAGE_ARGS MAX_WORK_ITEM_DIMENSIONS MAX_SAMPLERS MAX_READ_IMAGE_ARGS MAX_CONSTANT_ARGS MAX_COMPUTE_UNITS MAX_CLOCK_FREQUENCY ADDRESS_BITS GLOBAL_MEM_CACHELINE_SIZE ).each { |prop|
71
+ %w( IMAGE_PITCH_ALIGNMENT IMAGE_BASE_ADDRESS_ALIGNMENT REFERENCE_COUNT PARTITION_MAX_SUB_DEVICES VENDOR_ID PREFERRED_VECTOR_WIDTH_HALF PREFERRED_VECTOR_WIDTH_CHAR PREFERRED_VECTOR_WIDTH_SHORT PREFERRED_VECTOR_WIDTH_INT PREFERRED_VECTOR_WIDTH_LONG PREFERRED_VECTOR_WIDTH_FLOAT PREFERRED_VECTOR_WIDTH_DOUBLE NATIVE_VECTOR_WIDTH_CHAR NATIVE_VECTOR_WIDTH_SHORT NATIVE_VECTOR_WIDTH_INT NATIVE_VECTOR_WIDTH_LONG NATIVE_VECTOR_WIDTH_FLOAT NATIVE_VECTOR_WIDTH_DOUBLE NATIVE_VECTOR_WIDTH_HALF MIN_DATA_TYPE_ALIGN_SIZE MEM_BASE_ADDR_ALIGN MAX_WRITE_IMAGE_ARGS MAX_READ_WRITE_IMAGE_ARGS MAX_WORK_ITEM_DIMENSIONS MAX_SAMPLERS MAX_READ_IMAGE_ARGS MAX_CONSTANT_ARGS MAX_COMPUTE_UNITS MAX_CLOCK_FREQUENCY ADDRESS_BITS GLOBAL_MEM_CACHELINE_SIZE QUEUE_ON_DEVICE_PREFERRED_SIZE QUEUE_ON_DEVICE_MAX_SIZE MAX_ON_DEVICE_QUEUES MAX_ON_DEVICE_EVENTS MAX_PIPE_ARGS PIPE_MAX_ACTIVE_RESERVATIONS PIPE_MAX_PACKET_SIZE PREFERRED_PLATFORM_ATOMIC_ALIGNMENT PREFERRED_GLOBAL_ATOMIC_ALIGNMENT PREFERRED_LOCAL_ATOMIC_ALIGNMENT).each { |prop|
72
72
  eval OpenCL.get_info("Device", :cl_uint, prop)
73
73
  }
74
74
 
75
- %w( PRINTF_BUFFER_SIZE IMAGE_MAX_BUFFER_SIZE IMAGE_MAX_ARRAY_SIZE PROFILING_TIMER_RESOLUTION MAX_WORK_GROUP_SIZE MAX_PARAMETER_SIZE IMAGE2D_MAX_WIDTH IMAGE2D_MAX_HEIGHT IMAGE3D_MAX_WIDTH IMAGE3D_MAX_HEIGHT IMAGE3D_MAX_DEPTH ).each { |prop|
75
+ %w( PRINTF_BUFFER_SIZE IMAGE_MAX_BUFFER_SIZE IMAGE_MAX_ARRAY_SIZE PROFILING_TIMER_RESOLUTION MAX_WORK_GROUP_SIZE MAX_PARAMETER_SIZE IMAGE2D_MAX_WIDTH IMAGE2D_MAX_HEIGHT IMAGE3D_MAX_WIDTH IMAGE3D_MAX_HEIGHT IMAGE3D_MAX_DEPTH MAX_GLOBAL_VARIABLE_SIZE GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE).each { |prop|
76
76
  eval OpenCL.get_info("Device", :size_t, prop)
77
77
  }
78
78
 
@@ -104,6 +104,16 @@ module OpenCL
104
104
  # Returns a CommandQueue::Properties representing the properties supported by a CommandQueue targetting the Device
105
105
  eval OpenCL.get_info("Device", :cl_command_queue_properties, "QUEUE_PROPERTIES")
106
106
 
107
+ ##
108
+ # :method: queue_on_device_properties()
109
+ # Returns a CommandQueue::Properties representing the properties supported by a CommandQueue on the Device
110
+ eval OpenCL.get_info("Device", :cl_command_queue_properties, "QUEUE_ON_DEVICE_PROPERTIES")
111
+
112
+ ##
113
+ # :method: queue_on_host_properties()
114
+ # Returns a CommandQueue::Properties representing the properties supported by a CommandQueue targetting the Device
115
+ eval OpenCL.get_info("Device", :cl_command_queue_properties, "QUEUE_ON_HOST_PROPERTIES")
116
+
107
117
  ##
108
118
  # :method: type()
109
119
  # Returns a Device::Type representing the type of the Device
@@ -124,6 +134,11 @@ module OpenCL
124
134
  # Returns the list of partition types supported by the Device
125
135
  eval OpenCL.get_info_array("Device", :cl_device_partition_property, "PARTITION_PROPERTIES")
126
136
 
137
+ ##
138
+ # :method: svm_capabilities()
139
+ # Returns an SVMCapabilities representing the the SVM capabilities corresponding to the device
140
+ eval OpenCL.get_info_array("Device", :cl_device_svm_capabilities, "SVM_CAPABILITIES")
141
+
127
142
  # Return an Array of partition properties names representing the partition type supported by the device
128
143
  def partition_properties_names
129
144
  prop_names = []
@@ -6,11 +6,11 @@ module OpenCL
6
6
  #
7
7
  # * +context+ - Context the created Image will be associated to
8
8
  # * +format+ - an ImageFormat
9
- # * +options+ - an ImageDesc
9
+ # * +desc+ - an ImageDesc
10
10
  #
11
11
  # ==== Options
12
12
  #
13
- # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
13
+ # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
14
14
  # * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
15
15
  def self.create_image( context, format, desc, options = {} )
16
16
  flags = OpenCL.get_flags( options )
@@ -31,9 +31,9 @@ module OpenCL
31
31
  #
32
32
  # ==== Options
33
33
  #
34
- # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
34
+ # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
35
35
  # * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
36
- def self.create_image_1D( context, format, width, options )
36
+ def self.create_image_1D( context, format, width, options = {} )
37
37
  if context.platform.version_number > 1.1 then
38
38
  desc = OpenCL::ImageDesc::new(OpenCL::Mem::IMAGE1D, width, 0, 0, 0, 0, 0, 0, 0, nil)
39
39
  return OpenCL.create_image( context, format, desc, options )
@@ -52,7 +52,7 @@ module OpenCL
52
52
  #
53
53
  # ==== Options
54
54
  #
55
- # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
55
+ # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
56
56
  # * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
57
57
  # * +:row_pitch+ - if provided the row_pitch of data in host_ptr
58
58
  def self.create_image_2D( context, format, width, height, options = {} )
@@ -80,7 +80,7 @@ module OpenCL
80
80
  #
81
81
  # ==== Options
82
82
  #
83
- # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Buffer
83
+ # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Image
84
84
  # * +:host_ptr+ - if provided, the Pointer (or convertible to Pointer using to_ptr) to the memory area to use
85
85
  # * +:row_pitch+ - if provided the row_pitch of data in host_ptr
86
86
  # * +:slice_pitch+ - if provided the slice_pitch of data in host_ptr
@@ -16,9 +16,9 @@ module OpenCL
16
16
 
17
17
  # Returns the Kernel corresponding the the specified name in the given Program
18
18
  def self.create_kernel(program, name)
19
- pointer_err = FFI::MemoryPointer::new( :cl_int )
20
- kernel_ptr = OpenCL.clCreateKernel(program, name, pointer_err)
21
- OpenCL.error_check(pointer_err.read_cl_int)
19
+ error = FFI::MemoryPointer::new( :cl_int )
20
+ kernel_ptr = OpenCL.clCreateKernel(program, name, error)
21
+ OpenCL.error_check(error.read_cl_int)
22
22
  return OpenCL::Kernel::new( kernel_ptr, false )
23
23
  end
24
24
 
@@ -104,7 +104,11 @@ module OpenCL
104
104
 
105
105
  # Sets this Arg to value. The size of value can be specified.
106
106
  def set(value, size = nil)
107
- OpenCL.set_kernel_arg(@kernel, @index, value, size)
107
+ if value.class == OpenCL::SVMPointer and @kernel.context.platform.version_number >= 2.0 then
108
+ OpenCL.set_kernel_arg_svm_pointer( @kernel, @index, value )
109
+ else
110
+ OpenCL.set_kernel_arg(@kernel, @index, value, size)
111
+ end
108
112
  end
109
113
 
110
114
  end
@@ -119,6 +123,29 @@ module OpenCL
119
123
  return a
120
124
  end
121
125
 
126
+ # Specifies the list of SVM pointers the kernel will be using
127
+ def set_svm_ptrs( ptrs )
128
+ OpenCL.error_check(OpenCL::INVALID_OPERATION) if self.context.platform.version_number < 2.0
129
+ pointers = [ptrs].flatten
130
+ pt = FFI::MemoryPointer::new( :pointer, pointers.length )
131
+ pointers.each_with_index { |p, i|
132
+ pt[i].write_pointer(p)
133
+ }
134
+ error = OpenCL.clSetKernelExecInfo( self, OpenCL::Kernel::EXEC_INFO_SVM_PTRS, pt.size, pt)
135
+ OpenCL.error_check(error)
136
+ return self
137
+ end
138
+
139
+ # Specifies the granularity of the SVM system.
140
+ def set_svm_fine_grain_system( flag )
141
+ OpenCL.error_check(OpenCL::INVALID_OPERATION) if self.context.platform.version_number < 2.0
142
+ pt = FFI::MemoryPointer::new( :cl_bool )
143
+ pt.write_cl_bool( flag )
144
+ error = OpenCL.clSetKernelExecInfo( self, OpenCL::Kernel::EXEC_INFO_SVM_FINE_GRAIN_SYSTEL, pt.size, pt)
145
+ OpenCL.error_check(error)
146
+ return self
147
+ end
148
+
122
149
  ##
123
150
  # :method: function_name()
124
151
  # returns a String correspondig to the Kernel function name
@@ -164,6 +191,11 @@ module OpenCL
164
191
  OpenCL.set_kernel_arg(self, index, value, size)
165
192
  end
166
193
 
194
+ # Set the index th argument of the Kernel to an svm pointer value.
195
+ def set_arg_svm_pointer(index, svm_pointer)
196
+ OpenCL.set_kernel_arg_svm_pointer(self, index, svm_pointer)
197
+ end
198
+
167
199
  # Enqueues the Kernel in the given queue, specifying the global_work_size. Arguments for the kernel are specified afterwards. Last, a hash containing options for enqueuNDrange kernel can be specified
168
200
  def enqueue_with_args(command_queue, global_work_size, *args)
169
201
  n = self.num_args
@@ -175,7 +207,11 @@ module OpenCL
175
207
  options = {}
176
208
  end
177
209
  n.times { |i|
178
- self.set_arg(i, args[i])
210
+ if args[i].class == OpenCL::SVMPointer and self.context.platform.version_number >= 2.0 then
211
+ self.set_arg_svm_pointer(i, args[i])
212
+ else
213
+ self.set_arg(i, args[i])
214
+ end
179
215
  }
180
216
  command_queue.enqueue_NDrange_kernel(self, global_work_size, options)
181
217
  end
@@ -65,6 +65,11 @@ module OpenCL
65
65
  eval OpenCL.get_info("Mem", :cl_uint, prop)
66
66
  }
67
67
 
68
+ ##
69
+ # :method: uses_svn_pointer()
70
+ # Returns true if Mem uses an SVM pointer
71
+ eval OpenCL.get_info("Mem", :cl_bool, "USES_SVM_POINTER")
72
+
68
73
  ##
69
74
  # :method: type()
70
75
  # Returns an OpenCL::Mem::Type corresponding to the Mem
@@ -0,0 +1,38 @@
1
+ module OpenCL
2
+
3
+ # Creates a Pipe
4
+ #
5
+ # ==== Attributes
6
+ #
7
+ # * +context+ - Context the created Pipe will be associated to
8
+ # * +pipe_packet_size+ - size of a packet in the Pipe
9
+ # * +pipe_max_packets+ - size of the Pipe in packet
10
+ #
11
+ # ==== Options
12
+ #
13
+ # * +:flags+ - a single or an Array of :cl_mem_flags specifying the flags to be used when creating the Pipe
14
+ def self.create_pipe( context, pipe_packet_size, pipe_max_packets, options = {} )
15
+ OpenCL.error_check(OpenCL::INVALID_OPERATION) if self.context.platform.version_number < 2.0
16
+ flags = OpenCL.get_flags( options )
17
+ error = FFI::MemoryPointer::new( :cl_int )
18
+ pipe_ptr = OpenCL::clCreatePipe( context, flags, pipe_packet_size, pipe_max_packets, nil, error)
19
+ OpenCL.error_check(error.read_cl_int)
20
+ return OpenCL::Pipe::new(pipe_ptr, false)
21
+ end
22
+
23
+ class Pipe
24
+
25
+ ##
26
+ # :method: packet_size
27
+ # Returns the packet_size of the Pipe
28
+
29
+ ##
30
+ # :method: max_packets
31
+ # Returns the max_packets of the Pipe
32
+ %w( PACKET_SIZE MAX_PACKETS ).each { |prop|
33
+ eval OpenCL.get_info("Pipe", :cl_uint, prop)
34
+ }
35
+
36
+ end
37
+
38
+ end