谢邀。不懂android,也不懂OpenCL。但是我尝试了解了一下你的问题。
既然你用了第三方库,那就得查源码了。翻开ocl 库的源码搜android关键字,很容易定位到下面代码。
#https://github.com/cogciprocate/ocl/blob/master/ocl-interop/build.rs}elseiftarget.contains("android"){//androidletmutfile=File::create(&dest.join("egl_bindings.rs")).unwrap();Registry::new(Api::Egl,(1,4),Profile::Core,Fallbacks::All,[]).write_bindings(gl_generator::StaticGenerator,&mutfile).unwrap();println!("warning=Android support is untested! Use at your own risk, and please report any problems!");
build.rs这个文件里,看得出来它会在编译前先根据你的target判断出android,然后生成一个egl_bindings.rs文件,再往里写入一些内容。
这个过程依赖 gl_generator 库。再翻一下gl_generator库的源码,发现该库主要是用来动态生成一些OpenCL FFI的Rust绑定代码。比如android的话,就生成egl绑定 https://github.com/brendanzab/gl-rs/blob/master/gl_generator/generators/static_gen.rs
里面有人谈到ocl调用OpenCL驱动的机制:Here's how it works... OpenCL uses what's called an ICD loader which just stands for installable client driver loader. All that does is act as a front end and loads every driver listed in /etc/OpenCL/vendors (on Linux). It's what lets you choose between different platforms at runtime.
When you install any OpenCL drivers for any vendor, they will automatically install an ICD and it will be hooked up correctly. This is how you should leave things by default. Importantly, when using the ICD you have to link dynamically (which is what ocl does).
A side note if you're curious: a library or binary also has the option of linking directly to a driver statically. If you wanted to do that you or I would have to configure cl-sys properly before compiling for it to work though.
也就是说,在linux上面,ocl会去固定的一个目录去找 libOpenCL.so 。 但是他也说了,你也可以自己配置cl-sys来直接静态链接驱动。
由此,可以得出一个推论:这个libOpenCL.so动态库, 在特定的OS上面,位置是固定的。这个应该和语言无关。也就是说,不管是Rust语言还是其他语言,都应该去那个固定目录寻找so文件。这是在Linux上面。那么安卓肯定也一样(暂时不知道so文件默认放哪)。
也许,你碰到这个问题,也许只是安卓上面的OpenCL驱动没有弄好? 所以我专门搜了是不是有android开发者经常找不到opencl这个动态库。于是找到下面两个issues:
也许你可以照这俩issues寻找下答案。
也许你需要做个软链把so文件链到安卓的OpenCL驱动默认目录?(评论区有人对安卓软链的内容有相关补充)
希望对你有帮助。