OpenCL Ruby Bindings

Hello,

Just a short message to bring to your attention the release of opencl_ruby_ffi, OpenCL bindings for ruby based on FFI. They can be installed as a gem (gem install opencl_ruby_ffi). There is full coverage for 1.2 plus a lot of syntactic sugar mainly inspired from the ruby-opencl and pyopencl.
Homepage for the project can be found here: https://forge.imag.fr/projects/opencl-ruby/
It is an alpha release, and even though for my personal projects it works just fine, I am sure there are a lot of bugs/improvements remaining so feel free to contribute bug reports or comments (here or on the project page)
It is fully documented at the module/class/method level.

Best regards,

Brice

Hello,

Just a short message to state that the package has been been updated for OpenCL 2.0, should someone with access to a 2.0 implementation be willing to try.
Here is a link to the rubydoc:
http://opencl-ruby.forge.imag.fr/
And the gem page:
http://rubygems.org/gems/opencl_ruby_ffi

Brice

[QUOTE=Kerilk;30499]Hello,

Just a short message to state that the package has been been updated for OpenCL 2.0, should someone with access to a 2.0 implementation be willing to try.

Brice[/QUOTE]

Hi Brice,

Do you have any working examples that I can use with this documentation? I’m eager to get started with it, no other Ruby implementation has worked for me so far.

Thanks,
Derek

Hi Derek,

Sorry to respond so late I had subscribed to this post but apparently something went wrong.
Here is a small sample of code showing how to create, execute a kernel, get data back and check for correctness.


require 'opencl_ruby_ffi'
platform = OpenCL::platforms.first
device = platform.devices.first

source = <<EOF
__kernel void addition(  float2 alpha, __global const float *x, __global float *y) {
\
  size_t ig = get_global_id(0);
\
  y[ig] = (alpha.s0 + alpha.s1 + x[ig])*0.3333333333333333333f;
\
}
EOF

context = OpenCL::create_context(device)
queue = context.create_command_queue(device, :properties => OpenCL::CommandQueue::PROFILING_ENABLE)
prog = context.create_program_with_source( source )
prog.build
a_in = NArray.sfloat(65536).random(1.0)
a_out = NArray.sfloat(65536)
f = OpenCL::Float2::new(3.0,2.0)
b_in = context.create_buffer(a_in.size * a_in.element_size, :flags => OpenCL::Mem::COPY_HOST_PTR, :host_ptr => a_in)
b_out = context.create_buffer(a_out.size * a_out.element_size)
event = prog.addition(queue, [65536], f, b_in, b_out, :local_work_size => [128])
# #Or if you want to be more OpenCL like:
# k = prog.create_kernel("addition")
# k.set_arg(0, f)
# k.set_arg(1, b_in)
# k.set_arg(2, b_out)
# event = queue.enqueue_NDrange_kernel(k, [65536],:local_work_size => [128])
queue.enqueue_read_buffer(b_out, a_out, :event_wait_list => [event])
queue.finish
diff = (a_in - a_out*3.0)
65536.times { |i|
  raise "Computation error #{i} : #{diff[i]+f.s0+f.s1}" if (diff[i]+f.s0+f.s1).abs > 0.00001
}
puts "Success!"

Here is also attached a small script that use quite a bit of the features of opencl_ruby_ffi, it is used for non regression testing while developing the library.

Best regards,

Brice