Interfacing NMatrix with OpenCL

16 views
Skip to first unread message

Prasun Anand

unread,
Mar 25, 2017, 7:58:45 AM3/25/17
to SciRuby Development
Hi,

I would like to share my ideas about how I would like to interface NMatrix with OpenCL
(through ArrayFire). 

**I would like to hear your feedback regarding how this can be done in the best possible way.**

I will start with MRI. Copying data from GPU RAM to CPU RAM will be done using res.host<double>().
Daru wraps to NMatrix and gsl using wrappers[0] which is the ideal inspiration for wrapping NMatrix with OpenCL.

In the nmatrix/lib/opencl directory there would be all the NMatrix wrappers that call the 
ArrayFire-rb equivalents. The frontend decides to call BLAS and LAPACK(CPU) routines or ArrayFire methods.

For example, if I need to configure NMatrix#det to use ArrayFire I just need to add the following code 
in lib/nmatrix/nmatrix-opencl.rb

class NMatrix
  def det
    af = Af_Array.new(@shape,@s)
    af.det
  end
end
The final outcome should be that any program that uses NMatrix can switch to GPU by adding:

require 'nmatrix/nmatrix-opencl'

to your program.

Next, add changes to NMatrix tests.

Regards,
Prasun

Sameer Deshmukh

unread,
Mar 26, 2017, 5:44:19 AM3/26/17
to SciRuby Development
Hi Prasun,

Here's an idea that I thought of.

Is it possible to make ArrrayFire as a module like `Enumerable` so that any class that does an `include ArrayFireable` will get certain methods from ArrayFire that run on the GPU? This way, it can be extended to classes other than NMatrix too (if you can make it generic enough).

Prasun Anand

unread,
Mar 26, 2017, 4:35:47 PM3/26/17
to sciru...@googlegroups.com
Hi Sameer,

On Sunday 26 March 2017 03:14 PM, Sameer Deshmukh wrote:
> Hi Prasun,
>
> Here's an idea that I thought of.
>
> Is it possible to make ArrrayFire as a module like `Enumerable` so that
> any class that does an `include ArrayFireable` will get certain methods
> from ArrayFire that run on the GPU? This way, it can be extended to
> classes other than NMatrix too (if you can make it generic enough).
>

Yeah, its a very nice idea. I remember John suggested it last year that
he would have made NMatrix like Enumerable if rewritten to make it more
Ruby-friendly.

I have been studying about Enumerable implementation in Ruby[0]. I feel
certain features can be made like Enumerable like searching, sorting
because the ArrayFire api will allow us to do that.

However other features need to take care of casting, passing data from
GPU RAM to CPU RAM. And I may need to writing the kernels. I feel this
will be next to impossible for the summers[1] :( . And it will be too
slow. For JRuby, I even don't want to imagine writing the JNI.

What do you think?

Regards,
Prasun

[0].
https://github.com/ruby/ruby/blob/7c7444bcd3f40d0594aa24875f66519b6c53fccf/enumerator.c
[1].
https://github.com/prasunanand/resume/wiki/GSoC-2017-proposal#comparing-opencl-and-arrayfire
Reply all
Reply to author
Forward
0 new messages