Is there a good openCL wrapper for Ruby?


I am aware of:

Which hasn't been updated since 01/11


Which hasn't been updated since 03/10.

Are these projects dead? Or have they simply not changed because their functioning, and OpenCL/Ruby haven't changed since then. Is anybody using these projects? Any luck?

If not, can you recommend another opencl gem for Ruby? Or how is this sort of call done usually? Just call raw C from Ruby?

You can try opencl_ruby_ffi, it's actively developed (by a colleague of mine) and working well with OpenCL version 1.2. OpenCL 2.0 should also be available soon.

sudo gem install opencl_ruby_ffi

In Khronos forum you can find a quick example that shows how it works:

require 'opencl_ruby_ffi'

# select the first platform/device available
# improve it if you have multiple GPU on your machine
platform = OpenCL::platforms.first
device = platform.devices.first

# prepare the source of GPU kernel
# this is not Ruby but OpenCL C
source = <<EOF
__kernel void addition(  float2 alpha, __global const float *x, __global float *y) {\n\
  size_t ig = get_global_id(0);\n\
  y[ig] = (alpha.s0 + alpha.s1 + x[ig])*0.3333333333333333333f;\n\

# configure OpenCL environment, refer to OCL API if necessary
context = OpenCL::create_context(device)
queue = context.create_command_queue(device, :properties => OpenCL::CommandQueue::PROFILING_ENABLE)

# create and compile the OpenCL C source code
prog = context.create_program_with_source(source)

# allocate CPU (=RAM) buffers and 
# fill the input one with random values
a_in = NArray.sfloat(65536).random(1.0)
a_out = NArray.sfloat(65536)

# allocate GPU buffers matching the CPU ones
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)

# create a constant pair of float
f = OpenCL::Float2::new(3.0,2.0)

# trigger the execution of kernel 'addition' on 128 cores
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])

# tell OCL to transfer the content GPU buffer b_out 
# to the CPU memory (a_out), but only after `event` (= kernel execution)
# has completed
queue.enqueue_read_buffer(b_out, a_out, :event_wait_list => [event])

# wait for everything in the command queue to finish
# now a_out contains the result of the addition performed on the GPU

# add some cleanup here ...

# verify that the computation went well
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!"

lsegal/barracuda: Barracuda is a Ruby wrapper library for the , Barracuda aims to abstract both CUDA and OpenCL, however for now only OpenCL on OSX 10.6 is supported. Patches to extend this support would be joyously  Yet another OpenCL wrapper for Ruby. A Ruby binding for OpenCL 1.2. Created : 2015-10-25; Last modified : 2016-01-03; Features. Based on Fiddle (One of the Ruby standard libraries that wraps libffi)

You may want to package whatever C functionality you would like as a gem. This is pretty straightforward and this way you can wrap all your c logic in a specific namespace that you can reuse in other projects.

Barracuda: An OpenCL Library for Ruby (, Barracuda: An OpenCL Library for Ruby and as far as I've seen, there are no CUDA or OpenCL wrapper libraries out there for Ruby. There's a great demo of why this is cool at MacResearch (skip to the end of the video). As OpenCL is an open standard, these projects are an important part of the evolution of OpenCL. You won’t find solutions that provide a new programming paradigm or work with pragmas, generating optimised OpenCL. This list is in the making.

If you want to do high speed calculations with GPU, Cumo / NArray is a good choice. Cumo has the same interface as NArray. Although it is cuda rather than opencl.

OpenCL Wrappers, The advantages of Qt in the OpenCL programmer's hands. Boost.Compute. for OpenCL 1.1. Used in OpenTK, which has good integration with OpenGL, OpenGL|ES and OpenAL. Ruby-OpenCL: Ruby bindings for OpenCL. Not active. Barracuda. Written by Loren Segal in 2009. SYNOPSIS. Barracuda is a Ruby wrapper library for the OpenCL architecture. OpenCL is a framework for multi-processor computing, most notably allowing a programmer to run parallel programs on a GPU, taking advantage of the many cores available.

Using OpenCL: Programming Massively Parallel Computers, Or have they simply not changed because their functioning, and OpenCL/Ruby haven't changed since then. Is anybody using these projects? PyOpenCL - PyOpenCL is a complete, object-oriented language binding of OpenCL to Python. It has full documentation available and is licensed under the liberal MIT license OpenCL binding for Ruby - opencl_ruby_ffi is a complete OpenCL binding of OpenCL to Ruby. It is entirely written in Ruby using FFI

Introducing TensorStream, a pure ruby/OpenCL implementation of , PyOpenCL - OpenCL binding for the Python programming language [12]. • Ruby-​OpenCL - binding for Ruby [13]. This file is actually a wrapper. There are  Yes, glutSwapBuffers() worked when I used it with my C++ app. However, this time, I'm using Ruby with Ray, so I'm hoping I don't have to resort to GLUT (then, I would need to bring in GLEW as well). I have looked through Ray's documentation, but I couldn't find the wrapper that let me swap the buffers - maybe I haven't looked hard enough.

OpenCL Overview, Introducing TensorStream, a pure ruby/OpenCL implementation of TensorFlow Nice! Love to see Ruby getting some love in the AI space. Because let's face it, Every time I've tried to use one of the many ncurses wrappers, there's like one  OpenGL.Net is a complete wrapper library supporting OpenGL 4.6, OpenGL ES 3.2, EGL, WGL and GLX APIs. Exposes all enumerations and commands managed by the Khronos registry. The Open Toolkit is an advanced, low-level C# library that wraps OpenGL, OpenCL and OpenAL; Silk.NET is a collection of bindings for OpenGL, OpenAL, and Vulkan among many

  • This looks even more stale, but yet another option:
  • So I'm gathering the short answer is "no"...
  • Nothing more here, but the link may be useful anyway
  • post back when you make your own ... :)
  • There is also a ruby ffi opencl gem which was automatically generated via swig.
  • Is it possible to elaborate a bit more about what is happening here? Where can I read out the actual values that were added, etc.?
  • I've commented the source code, the result of the addition is retrieved from the GPU memory with operation queue.enqueue_read_buffer. There are plenty of (C) OpenCL tutorial available on the web, it should be fairly easy to translate to Ruby once you get the gist of the API.
  • Gonna go ahead and give you the bounty. Don't want points to go to waste do I....
  • Yes!! - I will never forget you Abraham P.