opencl_ruby_ffi 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
1
2
  module OpenCL
2
3
 
3
4
  # Attaches a callback to memobj the will be called on memobj destruction
@@ -6,7 +7,7 @@ module OpenCL
6
7
  #
7
8
  # * +memobj+ - the Mem to attach the callback to
8
9
  # * +options+ - a hash containing named options
9
- # * +block+ - if provided, a callback invoked when memobj is released. Signature of the callback is { |FFI::Poniter to the deleted Mem, FFI::Pointer to user_data| ... }
10
+ # * +block+ - if provided, a callback invoked when memobj is released. Signature of the callback is { |Poniter to the deleted Mem, Pointer to user_data| ... }
10
11
  #
11
12
  # ==== Options
12
13
  #
@@ -33,7 +34,7 @@ module OpenCL
33
34
 
34
35
  # Returns the Context associated to the Mem
35
36
  def context
36
- ptr = FFI::MemoryPointer::new( Context )
37
+ ptr = MemoryPointer::new( Context )
37
38
  error = OpenCL.clGetMemObjectInfo(self, CONTEXT, Context.size, ptr, nil)
38
39
  error_check(error)
39
40
  return Context::new( ptr.read_pointer )
@@ -46,7 +47,7 @@ module OpenCL
46
47
 
47
48
  # Returns the Buffer this Buffer was created from using create_sub_buffer
48
49
  def associated_memobject
49
- ptr = FFI::MemoryPointer::new( Mem )
50
+ ptr = MemoryPointer::new( Mem )
50
51
  error = OpenCL.clGetMemObjectInfo(self, ASSOCIATED_MEMOBJECT, Mem.size, ptr, nil)
51
52
  error_check(error)
52
53
  return nil if ptr.read_pointer.null?
@@ -100,7 +101,7 @@ module OpenCL
100
101
  # ==== Attributes
101
102
  #
102
103
  # * +options+ - a hash containing named options
103
- # * +block+ - if provided, a callback invoked when memobj is released. Signature of the callback is { |Mem, FFI::Pointer to user_data| ... }
104
+ # * +block+ - if provided, a callback invoked when memobj is released. Signature of the callback is { |Mem, Pointer to user_data| ... }
104
105
  #
105
106
  # ==== Options
106
107
  #
@@ -112,7 +113,7 @@ module OpenCL
112
113
 
113
114
  # Returns the texture_target argument specified in create_from_GL_texture for Mem
114
115
  def gl_texture_target
115
- param_value = FFI::MemoryPointer::new( :cl_GLenum )
116
+ param_value = MemoryPointer::new( :cl_GLenum )
116
117
  error = OpenCL.clGetGLTextureInfo( self, GL_TEXTURE_TARGET, param_value.size, param_value, nil )
117
118
  error_check(error)
118
119
  return param_value.read_cl_GLenum
@@ -121,7 +122,7 @@ module OpenCL
121
122
 
122
123
  # Returns the miplevel argument specified in create_from_GL_texture for Mem
123
124
  def gl_mimap_level
124
- param_value = FFI::MemoryPointer::new( :cl_GLint )
125
+ param_value = MemoryPointer::new( :cl_GLint )
125
126
  error = OpenCL.clGetGLTextureInfo( self, GL_MIPMAP_LEVEL, param_value.size, param_value, nil )
126
127
  error_check(error)
127
128
  return param_value.read_cl_GLint
@@ -130,7 +131,7 @@ module OpenCL
130
131
 
131
132
  # Returns the type of the GL object associated with Mem
132
133
  def gl_object_type
133
- param_value = FFI::MemoryPointer::new( :cl_gl_object_type )
134
+ param_value = MemoryPointer::new( :cl_gl_object_type )
134
135
  error = OpenCL.clGetGLObjectInfo( self, param_value, nil )
135
136
  error_check(error)
136
137
  return GLObjectType::new(param_value.read_cl_gl_object_type)
@@ -139,7 +140,7 @@ module OpenCL
139
140
 
140
141
  # Returns the name of the GL object associated with Mem
141
142
  def gl_object_name
142
- param_value = FFI::MemoryPointer::new( :cl_GLuint )
143
+ param_value = MemoryPointer::new( :cl_GLuint )
143
144
  error = OpenCL.clGetGLObjectInfo( self, nil, param_value )
144
145
  error_check(error)
145
146
  return param_value.read_cl_GLuint
@@ -1,3 +1,4 @@
1
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
1
2
  module OpenCL
2
3
 
3
4
  # Creates a Pipe
@@ -14,7 +15,7 @@ module OpenCL
14
15
  def self.create_pipe( context, pipe_packet_size, pipe_max_packets, options = {} )
15
16
  error_check(INVALID_OPERATION) if self.context.platform.version_number < 2.0
16
17
  flags = get_flags( options )
17
- error = FFI::MemoryPointer::new( :cl_int )
18
+ error = MemoryPointer::new( :cl_int )
18
19
  pipe_ptr = clCreatePipe( context, flags, pipe_packet_size, pipe_max_packets, nil, error)
19
20
  error_check(error.read_cl_int)
20
21
  return Pipe::new(pipe_ptr, false)
@@ -1,3 +1,4 @@
1
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
1
2
  module OpenCL
2
3
 
3
4
  # Unloads a Platform compiler
@@ -19,22 +20,22 @@ module OpenCL
19
20
  return nil
20
21
  end
21
22
 
22
- # Returns an FFI::Function corresponding to an extension function
23
+ # Returns a Function corresponding to an extension function
23
24
  #
24
25
  # ==== Attributes
25
26
  #
26
27
  # * +name+ - a String representing the name of the function
27
28
  # * +return_type+ - the type of data returned by the function
28
29
  # * +param_types+ - an Array of types, corresponding to the parameters type
29
- # * +options+ - if given, a hash of named options that will be given to FFI::Function::new. See FFI doc for details.
30
+ # * +options+ - if given, a hash of named options that will be given to Function::new. See FFI doc for details.
30
31
  def self.get_extension_function( name, return_type, param_types, options = {} )
31
- name_p = FFI::MemoryPointer.from_string(name)
32
+ name_p = MemoryPointer.from_string(name)
32
33
  ptr = clGetExtensionFunctionAddress( name_p )
33
34
  return nil if ptr.null?
34
- return FFI::Function::new(return_type, param_types, ptr, options)
35
+ return Function::new(return_type, param_types, ptr, options)
35
36
  end
36
37
 
37
- # Returns an FFI::Function corresponding to an extension function for the Platform
38
+ # Returns a Function corresponding to an extension function for the Platform
38
39
  #
39
40
  # ==== Attributes
40
41
  #
@@ -42,22 +43,22 @@ module OpenCL
42
43
  # * +name+ - a String representing the name of the function
43
44
  # * +return_type+ - the type of data returned by the function
44
45
  # * +param_types+ - an Array of types, corresponding to the parameters type
45
- # * +options+ - if given, a hash of named options that will be given to FFI::Function::new. See FFI doc for details.
46
+ # * +options+ - if given, a hash of named options that will be given to Function::new. See FFI doc for details.
46
47
  def self.get_extension_function_for_platform( platform, name, return_type, param_types, options = {} )
47
48
  error_check(INVALID_OPERATION) if platform.version_number < 1.2
48
- name_p = FFI::MemoryPointer.from_string(name)
49
+ name_p = MemoryPointer.from_string(name)
49
50
  ptr = clGetExtensionFunctionAddressForPlatform( platform, name_p )
50
51
  return nil if ptr.null?
51
- return FFI::Function::new(return_type, param_types, ptr, options)
52
+ return Function::new(return_type, param_types, ptr, options)
52
53
  end
53
54
 
54
55
  # Returns an Array of Platform containing the available OpenCL platforms
55
56
  def self.get_platforms
56
- ptr1 = FFI::MemoryPointer::new(:cl_uint , 1)
57
+ ptr1 = MemoryPointer::new(:cl_uint , 1)
57
58
 
58
59
  error = clGetPlatformIDs(0, nil, ptr1)
59
60
  error_check(error)
60
- ptr2 = FFI::MemoryPointer::new(:pointer, ptr1.read_uint)
61
+ ptr2 = MemoryPointer::new(:pointer, ptr1.read_uint)
61
62
  error = clGetPlatformIDs(ptr1.read_uint(), ptr2, nil)
62
63
  error_check(error)
63
64
  return ptr2.get_array_of_pointer(0,ptr1.read_uint()).collect { |platform_ptr|
@@ -111,10 +112,10 @@ module OpenCL
111
112
 
112
113
  # Returns an Array of string corresponding to the Platform extensions
113
114
  def extensions
114
- extensions_size = FFI::MemoryPointer::new( :size_t )
115
+ extensions_size = MemoryPointer::new( :size_t )
115
116
  error = OpenCL.clGetPlatformInfo( self, EXTENSIONS, 0, nil, extensions_size)
116
117
  error_check(error)
117
- ext = FFI::MemoryPointer::new( extensions_size.read_size_t )
118
+ ext = MemoryPointer::new( extensions_size.read_size_t )
118
119
  error = OpenCL.clGetPlatformInfo( self, EXTENSIONS, extensions_size.read_size_t, ext, nil)
119
120
  error_check(error)
120
121
  ext_string = ext.read_string
@@ -124,10 +125,10 @@ module OpenCL
124
125
  # Returns an Array of Device corresponding to the available devices on the Platform
125
126
  # The type of the desired devices can be specified
126
127
  def devices(type = Device::Type::ALL)
127
- ptr1 = FFI::MemoryPointer::new(:cl_uint , 1)
128
+ ptr1 = MemoryPointer::new(:cl_uint , 1)
128
129
  error = OpenCL.clGetDeviceIDs(self, type, 0, nil, ptr1)
129
130
  error_check(error)
130
- ptr2 = FFI::MemoryPointer::new(:pointer, ptr1.read_uint)
131
+ ptr2 = MemoryPointer::new(:pointer, ptr1.read_uint)
131
132
  error = OpenCL.clGetDeviceIDs(self, type, ptr1.read_uint(), ptr2, nil)
132
133
  error_check(error)
133
134
  return ptr2.get_array_of_pointer(0, ptr1.read_uint()).collect { |device_ptr|
@@ -147,16 +148,16 @@ module OpenCL
147
148
  return OpenCL.unload_platform_compiler(self)
148
149
  end
149
150
 
150
- # Returns an FFI::Function corresponding to an extension function for a Platform
151
+ # Returns a Function corresponding to an extension function for a Platform
151
152
  #
152
153
  # ==== Attributes
153
154
  #
154
155
  # * +name+ - a String representing the name of the function
155
156
  # * +return_type+ - the type of data returned by the function
156
157
  # * +param_types+ - an Array of types, corresponding to the parameters type
157
- # * +options+ - if given, a hash of named options that will be given to FFI::Function::new. See FFI doc for details.
158
+ # * +options+ - if given, a hash of named options that will be given to Function::new. See FFI doc for details.
158
159
  def get_extension_function( name, return_type, param_types, options = {} )
159
- return OpenCL.get_extension_function( self, name, return_type, param_types, options )
160
+ return OpenCL.get_extension_function_for_platform( self, name, return_type, param_types, options )
160
161
  end
161
162
 
162
163
  # Creates a Context gathering devices of a certain type and belonging to this Platform
@@ -165,12 +166,12 @@ module OpenCL
165
166
  #
166
167
  # * +type+ - type of device to be used
167
168
  # * +options+ - if given, a hash of named options
168
- # * +block+ - if provided, a callback invoked when error arise in the context. Signature of the callback is { |FFI::Pointer to null terminated c string, FFI::Pointer to binary data, :size_t number of bytes of binary data, FFI::Pointer to user_data| ... }
169
+ # * +block+ - if provided, a callback invoked when error arise in the context. Signature of the callback is { |Pointer to null terminated c string, Pointer to binary data, :size_t number of bytes of binary data, Pointer to user_data| ... }
169
170
  #
170
171
  # ==== Options
171
172
  #
172
173
  # * +:properties+ - a list of :cl_context_properties, the Platform will be prepended
173
- # * +:user_data+ - an FFI::Pointer or an object that can be converted into one using to_ptr. The pointer is passed to the callback.
174
+ # * +:user_data+ - an Pointer or an object that can be converted into one using to_ptr. The pointer is passed to the callback.
174
175
  def create_context_from_type(type, options = {}, &block)
175
176
  props = [ Context::PLATFORM, self ]
176
177
  if options[:properties] then
@@ -1,3 +1,4 @@
1
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
1
2
  module OpenCL
2
3
 
3
4
  # Builds (compile and link) a Program created from sources or binary
@@ -6,7 +7,7 @@ module OpenCL
6
7
  #
7
8
  # * +program+ - the program to build
8
9
  # * +options+ - a hash containing named options
9
- # * +block+ - if provided, a callback invoked when the Program is built. Signature of the callback is { |Program, FFI::Pointer to user_data| ... }
10
+ # * +block+ - if provided, a callback invoked when the Program is built. Signature of the callback is { |Program, Pointer to user_data| ... }
10
11
  #
11
12
  # ==== Options
12
13
  #
@@ -18,7 +19,7 @@ module OpenCL
18
19
  num_devices, devices_p = get_device_list( options )
19
20
  opt = ""
20
21
  opt = options[:options] if options[:options]
21
- options_p = FFI::MemoryPointer.from_string(opt)
22
+ options_p = MemoryPointer.from_string(opt)
22
23
  error = clBuildProgram(program, num_devices, devices_p, options_p, block, options[:user_data] )
23
24
  error_check(error)
24
25
  return program
@@ -31,7 +32,7 @@ module OpenCL
31
32
  # * +context+ - Context the created Program will be associated with
32
33
  # * +input_programs+ - a single or an Array of Program
33
34
  # * +options+ - a Hash containing named options
34
- # * +block+ - if provided, a callback invoked when the Program is built. Signature of the callback is { |Program, FFI::Pointer to user_data| ... }
35
+ # * +block+ - if provided, a callback invoked when the Program is built. Signature of the callback is { |Program, Pointer to user_data| ... }
35
36
  #
36
37
  # ==== Options
37
38
  #
@@ -43,12 +44,12 @@ module OpenCL
43
44
  num_devices, devices_p = get_device_list( options )
44
45
  opt = ""
45
46
  opt = options[:options] if options[:options]
46
- options_p = FFI::MemoryPointer.from_string(opt)
47
+ options_p = MemoryPointer.from_string(opt)
47
48
  programs = [input_programs].flatten
48
49
  num_programs = programs.length
49
- programs_p = FFI::MemoryPointer::new( Program, num_programs )
50
+ programs_p = MemoryPointer::new( Program, num_programs )
50
51
  programs_p.write_array_of_pointer(programs)
51
- error = FFI::MemoryPointer::new( :cl_int )
52
+ error = MemoryPointer::new( :cl_int )
52
53
  prog = clLinkProgram( context, num_devices, devices_p, options_p, num_programs, programs_p, block, options[:user_data], error)
53
54
  error_check(error.read_cl_int)
54
55
  return Program::new( prog, false )
@@ -60,7 +61,7 @@ module OpenCL
60
61
  #
61
62
  # * +program+ - the program to build
62
63
  # * +options+ - a Hash containing named options
63
- # * +block+ - if provided, a callback invoked when the Program is compiled. Signature of the callback is { |Program, FFI::Pointer to user_data| ... }
64
+ # * +block+ - if provided, a callback invoked when the Program is compiled. Signature of the callback is { |Program, Pointer to user_data| ... }
64
65
  #
65
66
  # ==== Options
66
67
  #
@@ -73,19 +74,19 @@ module OpenCL
73
74
  num_devices, devices_p = get_device_list( options )
74
75
  opt = ""
75
76
  opt = options[:options] if options[:options]
76
- options_p = FFI::MemoryPointer.from_string(opt)
77
+ options_p = MemoryPointer.from_string(opt)
77
78
  headers = options[:input_headers]
78
79
  headers_p = nil
79
80
  header_include_names = nil
80
81
  num_headers = 0
81
82
  num_headers = headers.length if headers
82
83
  if num_headers then
83
- headers_p = FFI::MemoryPointer::new( Program, num_headers )
84
- header_include_names = FFI::MemoryPointer::new( :pointer, num_headers )
84
+ headers_p = MemoryPointer::new( Program, num_headers )
85
+ header_include_names = MemoryPointer::new( :pointer, num_headers )
85
86
  indx = 0
86
87
  headers.each { |key, value|
87
88
  headers_p[indx].write_pointer(value)
88
- header_include_names[indx] = FFI::MemoryPointer.from_string(key)
89
+ header_include_names[indx] = MemoryPointer.from_string(key)
89
90
  indx = indx + 1
90
91
  }
91
92
  end
@@ -104,13 +105,13 @@ module OpenCL
104
105
  def self.create_program_with_built_in_kernels(context, device_list, kernel_names)
105
106
  devices = [device_list].flatten
106
107
  num_devices = devices.length
107
- devices_p = FFI::MemoryPointer::new( Device, num_devices )
108
+ devices_p = MemoryPointer::new( Device, num_devices )
108
109
  num_devices.times { |indx|
109
110
  devices_p[indx].write_pointer(devices[indx])
110
111
  }
111
112
  names = [kernel_names].flatten.join(",")
112
- names_p = FFI::MemoryPointer.from_string(names)
113
- error = FFI::MemoryPointer::new( :cl_int )
113
+ names_p = MemoryPointer.from_string(names)
114
+ error = MemoryPointer::new( :cl_int )
114
115
  prog = clCreateProgramWithBuiltInKernels( context, num_devices, devices_p, names_p, error )
115
116
  error_check(error.read_cl_int)
116
117
  return Program::new(prog, false)
@@ -128,18 +129,18 @@ module OpenCL
128
129
  num_devices = bins.length
129
130
  devices = [device_list].flatten
130
131
  error_check(INVALID_VALUE) if devices.length != bins.length
131
- devices_p = FFI::MemoryPointer::new( Device, num_devices )
132
- lengths = FFI::MemoryPointer::new( :size_t, num_devices )
133
- binaries_p = FFI::MemoryPointer::new( :pointer, num_devices )
132
+ devices_p = MemoryPointer::new( Device, num_devices )
133
+ lengths = MemoryPointer::new( :size_t, num_devices )
134
+ binaries_p = MemoryPointer::new( :pointer, num_devices )
134
135
  num_devices.times { |indx|
135
136
  devices_p[indx].write_pointer(devices[indx])
136
137
  lengths[indx].write_size_t(binaries[indx].bytesize)
137
- p = FFI::MemoryPointer::new(binaries[indx].bytesize)
138
+ p = MemoryPointer::new(binaries[indx].bytesize)
138
139
  p.write_bytes(binaries[indx])
139
140
  binaries_p[indx].write_pointer(p)
140
141
  }
141
- binary_status = FFI::MemoryPointer::new( :cl_int, num_devices )
142
- error = FFI::MemoryPointer::new( :cl_int )
142
+ binary_status = MemoryPointer::new( :cl_int, num_devices )
143
+ error = MemoryPointer::new( :cl_int )
143
144
  prog = clCreateProgramWithBinary(context, num_devices, devices_p, lengths, binaries_p, binary_status, error)
144
145
  error_check(error.read_cl_int)
145
146
  d_s = []
@@ -163,24 +164,24 @@ module OpenCL
163
164
  strs = [strings].flatten
164
165
  end
165
166
  n_strs = strs.size
166
- strs_lengths = FFI::MemoryPointer::new( :size_t, n_strs )
167
- c_strs = FFI::MemoryPointer::new( :pointer, n_strs )
167
+ strs_lengths = MemoryPointer::new( :size_t, n_strs )
168
+ c_strs = MemoryPointer::new( :pointer, n_strs )
168
169
 
169
170
  c_strs_p = []
170
171
  strs.each { |str|
171
172
  if str then
172
- c_strs_p.push (FFI::MemoryPointer.from_string(str))
173
+ c_strs_p.push (MemoryPointer.from_string(str))
173
174
  end
174
175
  }
175
176
  error_check(INVALID_VALUE) if c_strs_p.size == 0
176
177
 
177
- c_strs = FFI::MemoryPointer::new( :pointer, c_strs_p.size )
178
- c_strs_length = FFI::MemoryPointer::new( :size_t, c_strs_p.size )
178
+ c_strs = MemoryPointer::new( :pointer, c_strs_p.size )
179
+ c_strs_length = MemoryPointer::new( :size_t, c_strs_p.size )
179
180
  c_strs_p.each_with_index { |p, i|
180
181
  c_strs[i].write_pointer(p)
181
182
  c_strs_length[i].write_size_t(p.size)
182
183
  }
183
- error = FFI::MemoryPointer::new( :cl_int )
184
+ error = MemoryPointer::new( :cl_int )
184
185
  program_ptr = clCreateProgramWithSource(context, c_strs_p.size, c_strs, c_strs_length, error)
185
186
  error_check(error.read_cl_int)
186
187
  return Program::new( program_ptr, false )
@@ -195,8 +196,8 @@ module OpenCL
195
196
  def self.create_program_with_il(context, il)
196
197
  error_check(INVALID_OPERATION) if context.platform.version_number < 2.1
197
198
  length = il.bytesize
198
- il_p = FFI::MemoryPointer::new( length )
199
- error = FFI::MemoryPointer::new( :cl_int )
199
+ il_p = MemoryPointer::new( length )
200
+ error = MemoryPointer::new( :cl_int )
200
201
  il_p.write_bytes(il)
201
202
  program_ptr = clCreateProgramWithIL(context, il_p, length, error)
202
203
  error_check(error.read_cl_int)
@@ -249,10 +250,10 @@ module OpenCL
249
250
  if context.platform.version_number < 1.2 then
250
251
  return kernels.collect(&:name)
251
252
  else
252
- kernel_names_size = FFI::MemoryPointer::new( :size_t )
253
+ kernel_names_size = MemoryPointer::new( :size_t )
253
254
  error = OpenCL.clGetProgramInfo( self, KERNEL_NAMES, 0, nil, kernel_names_size)
254
255
  error_check(error)
255
- k_names = FFI::MemoryPointer::new( kernel_names_size.read_size_t )
256
+ k_names = MemoryPointer::new( kernel_names_size.read_size_t )
256
257
  error = OpenCL.clGetProgramInfo( self, KERNEL_NAMES, kernel_names_size.read_size_t, k_names, nil)
257
258
  error_check(error)
258
259
  k_names_string = k_names.read_string
@@ -267,7 +268,7 @@ module OpenCL
267
268
  def build_global_variable_total_size(devs = nil)
268
269
  devs = self.devices if not devs
269
270
  devs = [devs].flatten
270
- ptr = FFI::MemoryPointer::new( :size_t )
271
+ ptr = MemoryPointer::new( :size_t )
271
272
  return devs.collect { |dev|
272
273
  error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_GLOBAL_VARIABLE_TOTAL_SIZE, ptr.size, ptr, nil)
273
274
  error_check(error)
@@ -279,7 +280,7 @@ module OpenCL
279
280
  def build_status(devs = nil)
280
281
  devs = self.devices if not devs
281
282
  devs = [devs].flatten
282
- ptr = FFI::MemoryPointer::new( :cl_build_status )
283
+ ptr = MemoryPointer::new( :cl_build_status )
283
284
  return devs.collect { |dev|
284
285
  error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_STATUS, ptr.size, ptr, nil)
285
286
  error_check(error)
@@ -291,7 +292,7 @@ module OpenCL
291
292
  def binary_type(devs = nil)
292
293
  devs = self.devices if not devs
293
294
  devs = [devs].flatten
294
- ptr = FFI::MemoryPointer::new( :cl_program_binary_type )
295
+ ptr = MemoryPointer::new( :cl_program_binary_type )
295
296
  return devs.collect { |dev|
296
297
  error = OpenCL.clGetProgramBuildInfo(self, dev, BINARY_TYPE, ptr.size, ptr, nil)
297
298
  error_check(error)
@@ -304,10 +305,10 @@ module OpenCL
304
305
  devs = self.devices if not devs
305
306
  devs = [devs].flatten
306
307
  return devs.collect { |dev|
307
- ptr1 = FFI::MemoryPointer::new( :size_t, 1)
308
+ ptr1 = MemoryPointer::new( :size_t, 1)
308
309
  error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_OPTIONS, 0, nil, ptr1)
309
310
  error_check(error)
310
- ptr2 = FFI::MemoryPointer::new( ptr1.read_size_t )
311
+ ptr2 = MemoryPointer::new( ptr1.read_size_t )
311
312
  error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_OPTIONS, ptr1.read_size_t, ptr2, nil)
312
313
  error_check(error)
313
314
  [dev, ptr2.read_string]
@@ -319,10 +320,10 @@ module OpenCL
319
320
  devs = self.devices if not devs
320
321
  devs = [devs].flatten
321
322
  return devs.collect { |dev|
322
- ptr1 = FFI::MemoryPointer::new( :size_t, 1)
323
+ ptr1 = MemoryPointer::new( :size_t, 1)
323
324
  error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_LOG, 0, nil, ptr1)
324
325
  error_check(error)
325
- ptr2 = FFI::MemoryPointer::new( ptr1.read_size_t )
326
+ ptr2 = MemoryPointer::new( ptr1.read_size_t )
326
327
  error = OpenCL.clGetProgramBuildInfo(self, dev, BUILD_LOG, ptr1.read_size_t, ptr2, nil)
327
328
  error_check(error)
328
329
  [dev, ptr2.read_string]
@@ -332,12 +333,12 @@ module OpenCL
332
333
  # Returns the binaries associated to the Program for each Device. Returns an Array of tuple [ Device, String ]
333
334
  def binaries
334
335
  sizes = self.binary_sizes
335
- bin_array = FFI::MemoryPointer::new( :pointer, sizes.length )
336
+ bin_array = MemoryPointer::new( :pointer, sizes.length )
336
337
  sizes.length
337
338
  total_size = 0
338
339
  sizes.each_with_index { |s, i|
339
340
  total_size += s
340
- bin_array[i].write_pointer(FFI::MemoryPointer::new(s))
341
+ bin_array[i].write_pointer(MemoryPointer::new(s))
341
342
  }
342
343
  error = OpenCL.clGetProgramInfo(self, BINARIES, total_size, bin_array, nil)
343
344
  error_check(error)
@@ -351,12 +352,12 @@ module OpenCL
351
352
 
352
353
  # Return the intermediate level representation of the program if any, nil otherwise
353
354
  def il
354
- il_size = FFI::MemoryPointer::new( :size_t )
355
+ il_size = MemoryPointer::new( :size_t )
355
356
  error = OpenCL.clGetProgramInfo(self, IL, 0, nil, il_size)
356
357
  error_check(error)
357
358
  return nil if il_size == 0
358
359
  length = il_size.read_size_t
359
- il_p = FFI::MemoryPointer::new( length )
360
+ il_p = MemoryPointer::new( length )
360
361
  error = OpenCL.clGetProgramInfo(self, IL, length, il_p, nil)
361
362
  error_check(error)
362
363
  return il_p.read_bytes(length)
@@ -367,7 +368,7 @@ module OpenCL
367
368
  # ==== Attributes
368
369
  #
369
370
  # * +options+ - a hash containing named options
370
- # * +block+ - if provided, a callback invoked when the Program is built. Signature of the callback is { |Program, FFI::Pointer to user_data| ... }
371
+ # * +block+ - if provided, a callback invoked when the Program is built. Signature of the callback is { |Program, Pointer to user_data| ... }
371
372
  #
372
373
  # ==== Options
373
374
  # * +:device_list+ - an Array of Device to build the program for
@@ -382,7 +383,7 @@ module OpenCL
382
383
  # ==== Attributes
383
384
  #
384
385
  # * +options+ - a Hash containing named options
385
- # * +block+ - if provided, a callback invoked when the Program is compiled. Signature of the callback is { |Program, FFI::Pointer to user_data| ... }
386
+ # * +block+ - if provided, a callback invoked when the Program is compiled. Signature of the callback is { |Program, Pointer to user_data| ... }
386
387
  #
387
388
  # ==== Options
388
389
  #
@@ -396,7 +397,7 @@ module OpenCL
396
397
 
397
398
  # Returns the Context the Program is associated to
398
399
  def context
399
- ptr = FFI::MemoryPointer::new( Context )
400
+ ptr = MemoryPointer::new( Context )
400
401
  error = OpenCL.clGetProgramInfo(self, CONTEXT, Context.size, ptr, nil)
401
402
  error_check(error)
402
403
  return Context::new( ptr.read_pointer )
@@ -416,7 +417,7 @@ module OpenCL
416
417
  # Returns the Array of Device the Program is associated with
417
418
  def devices
418
419
  n = self.num_devices
419
- ptr2 = FFI::MemoryPointer::new( Device, n )
420
+ ptr2 = MemoryPointer::new( Device, n )
420
421
  error = OpenCL.clGetProgramInfo(self, DEVICES, Device.size*n, ptr2, nil)
421
422
  error_check(error)
422
423
  return ptr2.get_array_of_pointer(0, n).collect { |device_ptr|
@@ -1,7 +1,8 @@
1
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
1
2
  module OpenCL
2
3
 
3
4
  # maps the SVM pointer type
4
- class SVMPointer < FFI::Pointer
5
+ class SVMPointer < Pointer
5
6
 
6
7
  # create a new SVMPointer from its address and the context it pertains to
7
8
  def initialize( address, context, size, base = nil )
@@ -79,7 +80,7 @@ module OpenCL
79
80
  # * +command_queue+ - CommandQueue used to execute the write command
80
81
  # * +svm_pointer+ - a single or an Array of SVMPointer (or Pointer)
81
82
  # * +options+ - a hash containing named options
82
- # * +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| ... }
83
+ # * +block+ - if provided, a callback invoked to free the pointers. Signature of the callback is { |CommandQueue, num_pointers, Pointer to an array of num_pointers Pointers, Pointer to user_data| ... }
83
84
  #
84
85
  # ==== Options
85
86
  #
@@ -93,12 +94,12 @@ module OpenCL
93
94
  error_check(INVALID_OPERATION) if command_queue.context.platform.version_number < 2.0
94
95
  pointers = [svm_pointers].flatten
95
96
  num_pointers = pointers.length
96
- ptr = FFI::MemoryPointer::new( :pointer, num_pointers)
97
+ ptr = MemoryPointer::new( :pointer, num_pointers)
97
98
  pointers.each_with_index { |p, indx|
98
99
  ptr[indx].write_pointer(p)
99
100
  }
100
101
  num_events, events = get_event_wait_list( options )
101
- event = FFI::MemoryPointer::new( Event )
102
+ event = MemoryPointer::new( Event )
102
103
  error = clEnqueueSVMFree(command_queue, num_pointers, ptr, block, options[:user_data], num_events, events, event)
103
104
  error_check(error)
104
105
  return Event::new(event.read_pointer, false)
@@ -128,7 +129,7 @@ module OpenCL
128
129
  blocking = FALSE
129
130
  blocking = TRUE if options[:blocking] or options[:blocking_copy]
130
131
  num_events, events = get_event_wait_list( options )
131
- event = FFI::MemoryPointer::new( Event )
132
+ event = MemoryPointer::new( Event )
132
133
  error = clEnqueueSVMMemcpy(command_queue, blocking, dst_ptr, src_ptr, size, num_events, events, event)
133
134
  error_check(error)
134
135
  return Event::new(event.read_pointer, false)
@@ -156,7 +157,7 @@ module OpenCL
156
157
  num_events, events = get_event_wait_list( options )
157
158
  pattern_size = pattern.size
158
159
  pattern_size = options[:pattern_size] if options[:pattern_size]
159
- event = FFI::MemoryPointer::new( Event )
160
+ event = MemoryPointer::new( Event )
160
161
  error = clEnqueueSVMMemFill(command_queue, svm_ptr, pattern, pattern_size, size, num_events, events, event)
161
162
  error_check(error)
162
163
  return Event::new(event.read_pointer, false)
@@ -187,7 +188,7 @@ module OpenCL
187
188
  blocking = TRUE if options[:blocking] or options[:blocking_map]
188
189
  flags = get_flags( {:flags => map_flags} )
189
190
  num_events, events = get_event_wait_list( options )
190
- event = FFI::MemoryPointer::new( Event )
191
+ event = MemoryPointer::new( Event )
191
192
  error = clEnqueueSVMMap( command_queue, blocking, flags, svm_ptr, size, num_events, events, event )
192
193
  error_check( error.read_cl_int )
193
194
  return Event::new( event.read_ptr, false )
@@ -211,7 +212,7 @@ module OpenCL
211
212
  def self.enqueue_svm_unmap( command_queue, svm_ptr, options = {} )
212
213
  error_check(INVALID_OPERATION) if command_queue.context.platform.version_number < 2.0
213
214
  num_events, events = get_event_wait_list( options )
214
- event = FFI::MemoryPointer::new( Event )
215
+ event = MemoryPointer::new( Event )
215
216
  error = clEnqueueSVMUnmap( command_queue, svm_ptr, num_events, events, event )
216
217
  error_check( error )
217
218
  return Event::new( event.read_ptr, false )
@@ -241,15 +242,15 @@ module OpenCL
241
242
  flags = get_flags( options )
242
243
  sizes = [0]*num_svm_pointers
243
244
  sizes = options[:sizes] if options[:sizes]
244
- svn_ptrs_p = FFI::MemoryPointer::new( :pointer, num_svm_pointers)
245
+ svn_ptrs_p = MemoryPointer::new( :pointer, num_svm_pointers)
245
246
  svn_ptrs.each_with_index { |e, i|
246
247
  svn_ptrs_p[i].write_pointer(e)
247
248
  }
248
- sizes_p = FFI::MemoryPointer::new( :size_t, num_svm_pointers)
249
+ sizes_p = MemoryPointer::new( :size_t, num_svm_pointers)
249
250
  num_svm_pointers.times { |i|
250
251
  sizes_p[i].write_size_t(sizes[i])
251
252
  }
252
- event = FFI::MemoryPointer::new( Event )
253
+ event = MemoryPointer::new( Event )
253
254
  error = clEnqueueSVMMigrateMem( command_queue, num_svm_pointers, svn_ptrs_p, sizes_p, flags, num_events, events, event )
254
255
  error_check( error )
255
256
  return Event::new( event.read_ptr, false )
@@ -1,3 +1,4 @@
1
+ using OpenCLRefinements if RUBY_VERSION.scan(/\d+/).collect(&:to_i).first >= 2
1
2
  module OpenCL
2
3
 
3
4
  # Creates a Sampler
@@ -21,7 +22,7 @@ module OpenCL
21
22
  addressing_mode = options[:addressing_mode] if options[:addressing_mode]
22
23
  filter_mode = FilterMode::NEAREST
23
24
  filter_mode = options[:filter_mode] if options[:filter_mode]
24
- error = FFI::MemoryPointer::new( :cl_int )
25
+ error = MemoryPointer::new( :cl_int )
25
26
  if context.platform.version_number < 2.0 then
26
27
  sampler_ptr = clCreateSampler( context, normalized_coords, addressing_mode, filter_mode, error )
27
28
  else
@@ -29,7 +30,7 @@ module OpenCL
29
30
  prop_size += 2 if options[:mip_filter_mode]
30
31
  prop_size += 2 if options[:lod_min]
31
32
  prop_size += 2 if options[:lod_max]
32
- properties = FFI::MemoryPointer::new( :cl_sampler_info )
33
+ properties = MemoryPointer::new( :cl_sampler_info )
33
34
  properties[0].write_cl_sampler_info( Sampler::NORMALIZED_COORDS )
34
35
  properties[1].write_cl_bool( normalized_coords )
35
36
  properties[2].write_cl_sampler_info( Sampler::ADDRESSING_MODE )
@@ -73,7 +74,7 @@ module OpenCL
73
74
 
74
75
  # Returns the context associated with the Sampler
75
76
  def context
76
- ptr = FFI::MemoryPointer::new( Context )
77
+ ptr = MemoryPointer::new( Context )
77
78
  error = OpenCL.clGetSamplerInfo(self, CONTEXT, Context.size, ptr, nil)
78
79
  error_check(error)
79
80
  return Context::new( ptr.read_pointer )