kenba / opencl-sys-rs

OpenCL C FFI bindings for the Rust programming language.
Apache License 2.0
3 stars 0 forks source link

Dlopen option #2

Open MatejMagat305 opened 1 year ago

MatejMagat305 commented 1 year ago

Hi, I know that it look like sily isue, but sometime is not able know direct path to opencl, (mainly in android are 12 path to library), I sugest add to option with dlopen similar https://github.com/krrishnarraj/libopencl-stub and https://github.com/vlang/vsl/tree/master/vcl

kenba commented 1 year ago

I'm sorry but I don't understand precisely what your issue is?
If it is for the path to the OpenCL ICD lib file, the code is in the opencl-sys-rs repo.

Please submit a pull request with your proposed solution following the CONTRIBUTING guidelines.

MatejMagat305 commented 1 year ago

so, maybe I m silly programer, this is more question than sugestion (but of course, if tell me i will try make PR to contribute), so my question is: is this library suitable to have option dlopen ? I mean that if I do not give flag it compile normaly, but if I give flag (for example "dlopencl") it would be using internary dlopen with multiple path (for platform) and call first which can open

why: in normal linux and windows is small variable of path, but in android we have many ...

kenba commented 1 year ago

You are not a silly programmer, I simply didn't understand what you wanted.

I think that what you want is to add a new OpenCL SDK path to search for the ICD.
The code currently resides in: https://github.com/kenba/opencl-sys-rs/blob/main/build.rs.
There is a list of known SDKs and their environment variables - you just ned to add yours to it, or use OPENCL_ROOT if you can.

MatejMagat305 commented 1 year ago

well, if I understand code, program at build will find opencl ".dll" and it will be embeded into binary ..., that way work in linux, mac and windows ...,

but in android it does not work for example if I build binary for android_xyz_samsung it would not work on android_abc_lenovo, because it has diferent path and name to "opencl.so"..., of course sometime in other OS it can be similar problem, but here is linking ...

I would need to build not "static" (concreate) path, but I would need build "dynamic" (at begin in runtime search in list of paths and make dlopen of available), I was parcipiate in similar situation in Vlang and can I in summer sugest PR?

of course this way has small performance penalty, but it would make library more flexible ...

kenba commented 1 year ago

Not quite. The program searches for OpenCL.so on linux., it only searches for OpenCL.dll on Windows.
Since android is a effectively a port of linux, it should "dlopen" OpenCL.so as long as you ensure that OpenCL.so is on the dynamic library search path, i.e. one of the environment variables in build.rs must define the location of OpenCL.so . Is your issue specific to your android device, see: https://stackoverflow.com/questions/48453097/opencl-dlopen-issue?