Git Product home page Git Product logo

Comments (12)

KCErb avatar KCErb commented on September 6, 2024

Please note that the following Ruby program is sufficient to reproduce the error (you might have guessed based on the error, but in case it helps).

require 'opencl_ruby_ffi'

from opencl-ruby.

Kerilk avatar Kerilk commented on September 6, 2024

Hello,

Apparently you are missing an OpenCL implementation on your machine.
What kind of architecture are you trying to get it running on?

Brice

On 01-Dec-14 18:39, KC Erb wrote:

Hi there,

I'm getting an error when I try to run the example code from the README

Steps to reproduce:

  1. Install gem with |gem install opencl_ruby_ffi|
  2. Run |example.rb| via |ruby example.rb|

Error

|/Users/KC/.rvm/gems/ruby-2.1.2/gems/ffi-1.9.5/lib/ffi/library.rb:133:in block in ffi_lib': Could not open library 'libOpenCL.so.1': dlopen(libOpenCL.so.1, 5): image not found. (LoadError) Could not open library 'libOpenCL.so.1.dylib': dlopen(libOpenCL.so.1.dylib, 5): image not found from /Users/KC/.rvm/gems/ruby-2.1.2/gems/ffi-1.9.5/lib/ffi/library.rb:100:inmap'
from /Users/KC/.rvm/gems/ruby-2.1.2/gems/ffi-1.9.5/lib/ffi/library.rb💯in ffi_lib' from /Users/KC/.rvm/gems/ruby-2.1.2/gems/opencl_ruby_ffi-0.995/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb:9:inrescue in module:OpenCL'
from /Users/KC/.rvm/gems/ruby-2.1.2/gems/opencl_ruby_ffi-0.995/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb:6:in <module:OpenCL>' from /Users/KC/.rvm/gems/ruby-2.1.2/gems/opencl_ruby_ffi-0.995/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb:4:in<top (required)>'
from /Users/KC/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in require' from /Users/KC/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:inrequire'
from /Users/KC/.rvm/gems/ruby-2.1.2/gems/opencl_ruby_ffi-0.995/lib/opencl_ruby_ffi.rb:1:in <top (required)>' from /Users/KC/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:inrequire'
from /Users/KC/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in rescue in require' from /Users/KC/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:inrequire'
from example.rb:1:in `

'
|

I'm very new to FFIs and mixing C with Ruby like this. Are there steps
that I've missed such as getting a pre-compiled openCL library or
something of that nature? How can I go from nothing to running the
sample from the readme?

For clarity here's the sample:

require 'opencl_ruby_ffi'

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

platform= OpenCL::platforms.first
device= platform.devices.first
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!"


Reply to this email directly or view it on GitHub
#1.

from opencl-ruby.

kpouget avatar kpouget commented on September 6, 2024

looks like you don't have OpenCL library installed in your default paths. If it is actually installed in your computer, try to locate it: locate libOpenCL.so.1. If you get an answer, try running this command:

export LD_LIBRARY_PATH=$(dirname $(locate libOpenCL.so.1 | head -1))

before running ruby. If that works, you'll have to update your environment to make the change permanent (eg a file in /etc/ld.so.conf.d/ in my Archlinux environment)

----- Original Message -----

From: "KC Erb" [email protected]
To: "Nanosim-LIG/opencl-ruby" [email protected]
Sent: Monday, December 1, 2014 6:39:24 PM
Subject: [opencl-ruby] Running opencl-ruby for the first time (#1)

Hi there,

I'm getting an error when I try to run the example code from the README

Steps to reproduce:

  1. Install gem with gem install opencl_ruby_ffi
  2. Run example.rb via ruby example.rb

Error
/Users/KC/.rvm/gems/ruby-2.1.2/gems/ffi-1.9.5/lib/ffi/library.rb:133:in block in ffi_lib': Could not open library 'libOpenCL.so.1': dlopen(libOpenCL.so.1, 5): image not found. (LoadError) Could not open library 'libOpenCL.so.1.dylib': dlopen(libOpenCL.so.1.dylib, 5): image not found from /Users/KC/.rvm/gems/ruby-2.1.2/gems/ffi-1.9.5/lib/ffi/library.rb:100:inmap'
from /Users/KC/.rvm/gems/ruby-2.1.2/gems/ffi-1.9.5/lib/ffi/library.rb💯in ffi_lib' from /Users/KC/.rvm/gems/ruby-2.1.2/gems/opencl_ruby_ffi-0.995/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb:9:inrescue in module:OpenCL'
from /Users/KC/.rvm/gems/ruby-2.1.2/gems/opencl_ruby_ffi-0.995/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb:6:in <module:OpenCL>' from /Users/KC/.rvm/gems/ruby-2.1.2/gems/opencl_ruby_ffi-0.995/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb:4:in<top (required)>'
from /Users/KC/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in require' from /Users/KC/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:inrequire'
from /Users/KC/.rvm/gems/ruby-2.1.2/gems/opencl_ruby_ffi-0.995/lib/opencl_ruby_ffi.rb:1:in <top (required)>' from /Users/KC/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:inrequire'
from /Users/KC/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:135:in rescue in require' from /Users/KC/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:144:inrequire'
from example.rb:1:in `

'

I'm very new to FFIs and mixing C with Ruby like this. Are there steps that I've missed such as getting a pre-compiled openCL library or something of that nature? How can I go from nothing to running the sample from the readme?

For clarity here's the sample:
require ' opencl_ruby_ffi ' 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 platform = OpenCL ::platforms.first
device = platform.devices.first
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! "


Reply to this email directly or view it on GitHub .

from opencl-ruby.

KCErb avatar KCErb commented on September 6, 2024

Wow thanks for the quick response guys!!

I suspected I would need to get OpenCL implemented on my machine. I was hoping the gem would be able to pack it up and put it on the machine for me 😬

My thoughts in general
I know it might be ambitious (impossible?) but my first goal in my (forthcoming) project is making openCL easy for Rubyists to jump into and play with. And my naive understanding of an FFI is that it can talk directly to a pre-compiled version of the library. So would it be reasonable to have an openCL binary (binaries?) ship with the gem and write up a rake task that gets the user's system set up for using the FFI?

To be clear I'm not suggesting work for you guys, this is a problem I'm interested in studying up on and tackling myself, but I'm sorta lost for a starting point. Is this possible? Is it even a good thing to try to do? :)

My specific problem

Putting my aspirations to one side, I probably need to start by getting openCL running on my machine! I'm running on a macbook pro with an Intel Iris Pro GPU and a intel core i7 CPU.

I've read through some materials from AMD and also support materials from Apple and I think I could (with a little sweat) get openCL running on this machine. At this stage is that the best method? I only hesitate in hopes that there's a cleaner approach that assumes I just want to use openCL via the FFI not develop it. (For example, the half-baked idea I state above where I just stick an openCL binary on my path.)

Does what I'm trying to do make sense?

I'm a physicist with no formal computer science training but a lot of enthusiasm / ability to learn on my own. So please don't feel burdened to explain everything to me (though that would be much appreciated) feel free to point me to other resources.

Thanks!

from opencl-ruby.

Kerilk avatar Kerilk commented on September 6, 2024

well
https://github.com/ffi/ffi/wiki/Using-ruby-ffi-on-OsX-with-mixed-architectures,-universal-binaries.
could be a good starting point.

trying the folowing script should give you some insight:

require 'ffi'

module OpenCL
extend FFI::Library
ffi_lib "OpenCL"
end

Unfortunately I don't have a Mac to test it on.

Brice

On 01-Dec-14 20:03, KC Erb wrote:

Wow thanks for the quick response guys!!

I suspected I would need to get OpenCL implemented on my machine. I
was hoping the gem would be able to pack it up and put it on the
machine for me 😬

My thoughts in general
I know it might be ambitious (impossible?) but my first goal in my
(forthcoming) project is making openCL easy for Rubyists to jump into
and play with. And my naive understanding of an FFI is that it can
talk directly to a pre-compiled version of the library. So would it be
reasonable to have an openCL binary (binaries?) ship with the gem and
write up a rake task that gets the user's system set up for using the FFI?

To be clear I'm not suggesting work for you guys, this is a problem
I'm interested in studying up on and tackling myself, but I'm sorta
lost for a starting point. Is this possible? Is it even a good thing
to try to do? :)

My specific problem

Putting my aspirations to one side, I probably need to start by
getting openCL running on my machine! I'm running on a macbook pro
with an Intel Iris Pro GPU and a intel core i7 CPU.

I've read through some materials from AMD and also support materials
from Apple and I think I could (with a little sweat) get openCL
running on this machine. At this stage is that the best method? I only
hesitate in hopes that there's a cleaner approach that assumes I just
want to /use/ openCL via the FFI not /develop/ it. (For example, the
half-baked idea I state above where I just stick an openCL binary on
my path.)

Does what I'm trying to do make sense?

I'm a physicist with no formal computer science training but a lot of
enthusiasm / ability to learn on my own. So please don't feel burdened
to explain everything to me (though that would be much appreciated)
feel free to point me to other resources.

Thanks!


Reply to this email directly or view it on GitHub
#1 (comment).

from opencl-ruby.

KCErb avatar KCErb commented on September 6, 2024

@kpouget - I get no response when running locate libOpenCL.so.1 but I get the following if I run locate libOpenCL

/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86/libOpenCLLinkRTL_Single.8.0.1.0.dylib
/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86/libOpenCLLink_Double.8.0.1.0.dylib
/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86/libOpenCLLink_Single.8.0.1.0.dylib
/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86-64/libOpenCLLinkRTL_Double.8.0.1.0.dylib
/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86-64/libOpenCLLinkRTL_Single.8.0.1.0.dylib
/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86-64/libOpenCLLink_Double.8.0.1.0.dylib
/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86-64/libOpenCLLink_Single.8.0.1.0.dylib

So apparently Mathematica has some links.

@Kerilk - When I run

require 'ffi'

module OpenCL
extend FFI::Library
ffi_lib "OpenCL"
end

I get the following error:

Could not open library 'libOpenCL.dylib': dlopen(libOpenCL.dylib, 5): image not found
    from /Users/KC/.rvm/gems/ruby-2.1.2/gems/ffi-1.9.5/lib/ffi/library.rb:100:in `map'
    from /Users/KC/.rvm/gems/ruby-2.1.2/gems/ffi-1.9.5/lib/ffi/library.rb:100:in `ffi_lib'
    from example.rb:5:in `<module:OpenCL>'
    from example.rb:3:in `<main>'

I know that I have openCL support through XCode and there's a set of files in OpenCL.framework that I think should contain what I'm looking for but so far no luck. I tried following the advice from the ffi wiki you sent (thanks!) but it seems that ffi isn't finding any images at all.

Here are the contents of OpenCL.framework/Libraries:

AMDil.dylib         ImageFormats            PTXSM1X.dylib           libCLVMAMDil_r700Plugin.dylib   libCLVMPTXPlugin.dylib      libcldcpuengine.dylib
AMDil_r700.dylib        Legacy              Vectorizer.dylib        libCLVMCPUPlugin.dylib      libCLVMPTXSM1XPlugin.dylib  openclc
IGIL.dylib          PTX.dylib           libCLVMAMDilPlugin.dylib    libCLVMIGILPlugin.dylib     libcl2module.dylib

contents of OpenCL.framework/Headers

cl.h        cl_ext.h    cl_gl.h     cl_gl_ext.h cl_platform.h   gcl.h       gcl_priv.h  opencl.h

So in other words I see lots of libraries but none matching the name that ffi is looking for. . .

Any clues?

from opencl-ruby.

Kerilk avatar Kerilk commented on September 6, 2024

KC,

could you try with this?

require'ffi'
module OpenCL
extend FFI::Library
ffi_lib '/System/Library/Frameworks/OpenCL.framework/OpenCL'
end

if it works I will patch the the software and make a release today.

Brice

On 01/12/2014 22:00, KC Erb wrote:

@kpouget https://github.com/kpouget - I get no response when running
|locate libOpenCL.so.1| but I get the following if I run |locate
libOpenCL|

|/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86/libOpenCLLinkRTL_Single.8.0.1.0.dylib
/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86/libOpenCLLink_Double.8.0.1.0.dylib
/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86/libOpenCLLink_Single.8.0.1.0.dylib
/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86-64/libOpenCLLinkRTL_Double.8.0.1.0.dylib
/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86-64/libOpenCLLinkRTL_Single.8.0.1.0.dylib
/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86-64/libOpenCLLink_Double.8.0.1.0.dylib
/Applications/Mathematica.app/SystemFiles/Links/OpenCLLink/LibraryResources/MacOSX-x86-64/libOpenCLLink_Single.8.0.1.0.dylib
|

So apparently Mathematica has some links.

@Kerilk https://github.com/Kerilk - When I run

require 'ffi'

module OpenCL
extend FFI::Library
ffi_lib"OpenCL"
end

I get the following error:

|Could not open library 'libOpenCL.dylib': dlopen(libOpenCL.dylib, 5): image not found
from /Users/KC/.rvm/gems/ruby-2.1.2/gems/ffi-1.9.5/lib/ffi/library.rb💯in map' from /Users/KC/.rvm/gems/ruby-2.1.2/gems/ffi-1.9.5/lib/ffi/library.rb:100:inffi_lib'
from example.rb:5:in <module:OpenCL>' from example.rb:3:in

'
|

I know that I have openCL support through XCode and there's a set of
files in |OpenCL.framework| that I think should contain what I'm
looking for but so far no luck. I tried following the advice from the
ffi wiki you sent (thanks!) but it seems that ffi isn't finding any
images at all.

Here are the contents of |OpenCL.framework/Libraries|:

|AMDil.dylib ImageFormats PTXSM1X.dylib libCLVMAMDil_r700Plugin.dylib libCLVMPTXPlugin.dylib libcldcpuengine.dylib
AMDil_r700.dylib Legacy Vectorizer.dylib libCLVMCPUPlugin.dylib libCLVMPTXSM1XPlugin.dylib openclc
IGIL.dylib PTX.dylib libCLVMAMDilPlugin.dylib libCLVMIGILPlugin.dylib libcl2module.dylib
|

contents of OpenCL.framework/Headers

|cl.h cl_ext.h cl_gl.h cl_gl_ext.h cl_platform.h gcl.h gcl_priv.h opencl.h
|

So in other words I see lots of libraries but none matching the name
that ffi is looking for. . .

Any clues?


Reply to this email directly or view it on GitHub
#1 (comment)
Bug from
https://github.com/notifications/beacon/ABuyZi33teUvNnt-fvh7Y171okaiSt3-ks5nTM6JgaJpZM4DCht4.gif

from opencl-ruby.

KCErb avatar KCErb commented on September 6, 2024

Yup, that runs without an issue. Looking forward to the patch, thanks!

from opencl-ruby.

Kerilk avatar Kerilk commented on September 6, 2024

A new version of the gem (0.996) has been pushed. You should be able to
upgrade and test further.

On 02/12/2014 15:36, KC Erb wrote:

Yup, that runs without an issue. Looking forward to the patch, thanks!


Reply to this email directly or view it on GitHub
#1 (comment).

from opencl-ruby.

KCErb avatar KCErb commented on September 6, 2024

Yay! Thanks for the great work! 👏

I get the following output when running the example now:

Warning OpenCL 1.2 loader detected!
Success!

Looks like the warning is coming from here which means I'm not getting some of the functions.

There's a doc page from apple that tells me I'm running openCL 1.2, so is this a problem or am I just to be warned that my FFI will be missing the functions listed in the begin``rescue that threw this warning?

from opencl-ruby.

Kerilk avatar Kerilk commented on September 6, 2024

Yes this is just a warning.

On 02-Dec-14 18:59, KC Erb wrote:

Yay! Thanks for the great work! 👏

I get the following output when running the example now:

|Warning OpenCL 1.2 loader detected!
Success!
|

Looks like the warning is coming from here
https://github.com/Nanosim-LIG/opencl-ruby/blob/master/opencl_ruby_ffi/lib/opencl_ruby_ffi/opencl_ruby_ffi_base_gen.rb#L3763
which means I'm not getting some of the functions.

There's a doc page http://support.apple.com/en-us/HT202823 from
apple that tells me I'm running openCL 1.2, so is this a problem or am
I just to be warned that my FFI will be missing the functions listed
in the |begin||rescue| that threw this warning?


Reply to this email directly or view it on GitHub
#1 (comment).

from opencl-ruby.

KCErb avatar KCErb commented on September 6, 2024

OK, thanks again all, this seems to work fine, I'll keep playing around with it and close this issue.

from opencl-ruby.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.