YaccConstructor / Brahma.FSharp

F# quotation to OpenCL translator and respective runtime to utilize GPGPUs in F# applications.
http://yaccconstructor.github.io/Brahma.FSharp
Eclipse Public License 1.0
74 stars 17 forks source link

Provide a way to specify exact path to OpenCL dll #124

Closed m0rphed closed 2 years ago

m0rphed commented 2 years ago

Description There are a huge number of different Linux distributions, custom Linux builds, and so on, so the location of libOpenCL.so.1.0.0 may vary.

I think it will be convenient for a library user to be able to specify exact OpenCL DLL path through environment variable (e.g. BrahmaOCLdllPath="usr/lib/libOpenCL.so.1.0.0") or explicitly by passing a path-string in code.

This could help a lot when using Brahma in uncommon setup (not sure if there is such thing as common setup in Linux)

Related to Related issue

Alternatives considered


Provide pre-configuration documentation for others Linux systems e.g.

Here is my take on making Brahma.FSharp work with proper libOpenCL.so.1.0.0


The instructions bellow were tested on EndevourOS, which is a popular Arch-based linux distribution - so all further steps are most likely the same for others arch-based distros.

Installing opencl dependencies on arch

Installing vendor OpenCL implementation and OpenCL ICD Loader

sudo pacman -Syu nvidia nvidia-utils
sudo pacman -S ocl-icd opencl-headers opencl-nvidia intel-compute-runtime # I have both intel graphics and nvidia gpu

[OPTIONAL] Installing clinfo - which is a simple cli-tool that enumerates all possible (known) properties of the OpenCL platform and devices available on the system.

sudo pacman -S clinfo  

Installing OpenCL ICD loaders

sudo pacman -S lib32-ocl-icd lib32-opencl-nvidia # nvidia loader required for NVIDIA CUDA

Configuring OpenCL ICD loader (libOpenCl.so) To ensure the ICD loader from the ocl-icd package is used we should create a file in /etc/ld.so.conf.d which adds /usr/lib to the dynamic program loader's search directories

$ sudo touch /etc/ld.so.conf.d/00-usrlib.conf
$ sudo echo "/usr/lib" > /etc/ld.so.conf.d/00-usrlib.conf
$ cat /etc/ld.so.conf.d/00-usrlib.conf # now let's check
/usr/lib

for more details ICD read ArchWiki

Now, after rebooting the machine - check if DLLs paths are similar to:

$ locate libOpenCL.so.1.0.0
/usr/lib/libOpenCL.so.1.0.0
/usr/lib32/libOpenCL.so.1.0.0

Linking DLLs (+ aliasing std. Debian MultiArch DLL path)

Creating symbolic link:

sudo mkdir -p /usr/lib/x86_64-linux-gnu
sudo ln -s /usr/lib/usr/lib/libOpenCL.so.1.0.0 /usr/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0

After all is done - double-check sym-links, should be something like this:

$ ls -la /usr/lib/ | grep opencl # vendors implementations
drwxr-xr-x   2 root root      4096 окт 19 16:38 intel-opencl
lrwxrwxrwx   1 root root        21 сен 20 22:47 libnvidia-opencl.so -> libnvidia-opencl.so.1
lrwxrwxrwx   1 root root        26 сен 20 22:47 libnvidia-opencl.so.1 -> libnvidia-opencl.so.470.74
-rwxr-xr-x   1 root root  19461936 сен 20 22:47 libnvidia-opencl.so.470.74
lrwxrwxrwx   1 root root        21 мая 29 18:03 libopencl-clang.so -> libopencl-clang.so.12
-rwxr-xr-x   1 root root    982232 мая 29 18:03 libopencl-clang.so.12
$ ls -la /usr/lib/ | grep libOpenCL # DLLs (OpenCL ICD) which is used by Brahma 
lrwxrwxrwx   1 root root        18 авг 19 14:32 libOpenCL.so -> libOpenCL.so.1.0.0
lrwxrwxrwx   1 root root        18 авг 19 14:32 libOpenCL.so.1 -> libOpenCL.so.1.0.0
-rwxr-xr-x   1 root root    183664 авг 19 14:32 libOpenCL.so.1.0.0
$ ls -la /usr/lib/x86_64-linux-gnu/ # created symbolic link to OpenCl ICD DLL
total 140
drwxr-xr-x   2 root root   4096 окт 20 14:10 .
drwxr-xr-x 183 root root 135168 окт 20 14:27 ..
lrwxrwxrwx   1 root root     27 окт 20 14:10 libOpenCL.so.1.0.0 -> /usr/lib/libOpenCL.so.1.0.0