# Any OpenCL SDKs for FreeBSD?



## First_Law_of_Unix (Sep 24, 2022)

Hello,

Alright, so I'm learning OpenCL from this book:





						OpenCL in Action: How to Accelerate Graphics and Computations: Scarpino, Matthew: 8601400825129: Amazon.com: Books
					

OpenCL in Action: How to Accelerate Graphics and Computations [Scarpino, Matthew] on Amazon.com. *FREE* shipping on qualifying offers. OpenCL in Action: How to Accelerate Graphics and Computations



					www.amazon.com
				




It seems that I need an OpenCL SDK, couldn't find any for FreeBSD for AMD GPU.

Thanks for any advice.

Edit:
Did some heavy research, hope this might help anyone doing OpenCL work:

Here are some outputs:

`$ clinfo`
https://pastebin.com/sWH0grxc

I installed opencl from ports (I assume this is the header files):
`$ pkg info -lx opencl`
https://pastebin.com/2K5AFjsv

I installed ocl-icd from ports (I assume this is for the latest OpenCL binary driver version):
`$ pkg info -lx ocl-icd`
https://pastebin.com/PekwJb9M

I installed clover from ports (This is the old OpenCL 1.1 version binaries provided by MESA):
`$ pkg info -lx clover`
https://pastebin.com/DBKexapQ

I'm not sure if I should use ocl-icd OpenCL binaries, since it did not mention anything about AMD GPU.
Oddly enough, I did some research and it seems that AMD's GPU GitHub page does provide the OpenCL SDK only for the header files and binaries:
https://github.com/GPUOpen-LibrariesAndSDKs/OCL-SDK/releases

Which I downloaded: lightOCLSDK.zip and extracted it.
These are all the files and subdirectories which contains in the extracted _*lightOCLSDK.zip*_: https://pastebin.com/qQ31UY6n
I do not think this will work on FreeBSD or Linux since the OpenCL.lib contains OpenCL.dll, which is for windows OS.

Here I found the AMD SDK 3.0 archived Linux installer from GitHub discussion: https://github.com/fireice-uk/xmr-stak/issues/1511
There, I was able to download the 187 MB compressed file provided from the user "*KOLANICH*": AMD-APP-SDKInstaller-v3.0.130.136-GA-linux64.tar.bz2

After extracting I only get one file:* AMD-APP-SDK-v3.0.130.136-GA-linux64.sh*

However I can not install it and gives an error (as expected since I am using Unix): https://pastebin.com/NS7xdhA8
I wonder if I can somehow extract the OpenCL library from it and able to manually compile/port it to FreeBSD.


----------



## unitrunker (Sep 24, 2022)

Caution: I have not tried this on FreeBSD:






						FreshPorts -- devel/opencl: Open Computing Language (OpenCL) specifications V3.0 (header files)
					

OpenCL (Open Computing Language) is an open royalty-free standard for general purpose parallel programming across CPUs, GPUs and other processors, giving software developers portable and efficient access to the power of these heterogeneous processing platforms.  These header are covering OpenCL...




					www.freshports.org
				




Worst case is your kernels will run on this emulator:






						FreshPorts -- devel/oclgrind: SPIR interpreter and virtual OpenCL device simulator
					

Oclgrind  SPIR interpreter and virtual OpenCL device simulator  Oclgrind implements a virtual OpenCL device simulator, including an OpenCL runtime with ICD support. The goal is to provide a platform for creating tools to aid OpenCL development. In particular, this project currently implements...




					www.freshports.org
				




I have no idea how the opencl library detects GPUs but now you've go me curious.


----------



## First_Law_of_Unix (Sep 24, 2022)

Thanks but the first link seems to be only the header files, from my understanding is that mesa drivers which provides the amd GPU driver also make the opencl implementation for the GPU as well which they call it “clover”. I installed “clover” from fresh ports:





						FreshPorts -- lang/clover: Mesa OpenCL implementation for AMD GPUs
					

This package contains Mesa's libOpenCL implementation "Clover". It is built upon GALLIUM and currently only supports Radeon GPUs.




					www.freshports.org
				



but have no idea how to make all of this work as an “OpenCL SDK”.

“clinfo” detects the amd GPU as OpenCL 1.1 provided by mesa clover.

I also found out that the group who makes the OpenCL standard also provides an “OpenCL SDK” of their own:








						GitHub - KhronosGroup/OpenCL-SDK: OpenCL SDK
					

OpenCL SDK. Contribute to KhronosGroup/OpenCL-SDK development by creating an account on GitHub.




					github.com
				




But I get an error after “cmake ..” stating:


```
Unix Makefiles

  does not support platform specification, but platform

    x64

  was specified.
```


----------



## unitrunker (Sep 24, 2022)

I'd ignore the Kronos stuff SDK. Instead, just #include your opencl header files and link against this:






						FreshPorts -- devel/ocl-icd: OpenCL Installable Client Driver
					

OpenCL implementations are provided as ICD (Installable Client Driver). An OpenCL program can use several ICD thanks to the use of an ICD Loader as provided by this project. This free ICD Loader can load any (free or non free) ICD.




					www.freshports.org


----------



## First_Law_of_Unix (Sep 24, 2022)

Thanks, alright I’ll do that. I guess the “ocl-icd” port you linked should provide OpenCL version 2.0 driver for the amd GPU I have, since the GPU is advertised to support up to version 2.0

Hope everything works throughout the book, I bet the sample codes uses OpenCL 1.1, since the book was published on November 13, 2011. (However I’m also reading OpenCL books published since 2015).


----------



## astyle (Oct 5, 2022)

First_Law_of_Unix said:


> However I can not install it and gives an error (as expected since I am using Unix): https://pastebin.com/NS7xdhA8
> I wonder if I can somehow extract the OpenCL library from it and able to manually compile/port it to FreeBSD.


For starters, check your pastebin... I'm seeing this right now:






First_Law_of_Unix said:


> `$ clinfo`
> https://pastebin.com/sWH0grxc


This looks like it dumps core at the end. I spent some time trying to solve that,  saw some info that I'd need an x570 chipset (I had a B350 at the time).


----------



## First_Law_of_Unix (Oct 6, 2022)

Seems like the pastebin was false reported and taken down... wired.

I was able to successfully install the Khrono's OpenCL SDK:








						GitHub - KhronosGroup/OpenCL-SDK: OpenCL SDK
					

OpenCL SDK. Contribute to KhronosGroup/OpenCL-SDK development by creating an account on GitHub.




					github.com
				




I originally made a report issue about it and one of the devs helped solved the issue:








						How to build for FreeBSD 13.1? · Issue #55 · KhronosGroup/OpenCL-SDK
					

I get this error: Unix Makefiles does not support platform specification, but platform x64 was specified.




					github.com
				




Seems like the devs will patch it on the next release so that it can easily be installed on FreeBSD.

But I read that a SDK is not needed, just the OpenCL headers and the AMD OpenCL binaries (via Clover) is all thats needed, which "unitrunker" was preferring me to do.

Any how, not sure whats so special about "Khrono's OpenCL SDK" now that it is fully installed on FreeBSD, we should make a port for it, since after all Khronos is the maintainer and the group who creates/updates the OpenCL standard.


----------



## unitrunker (Oct 29, 2022)

For anyone else stumbling across this thread ...

I've not found GPU support for Haswell so I must fall back to using the oclgrind emulator.

I already had clang.

Installed clinfo, ocl-icd, and oclgrind. If clinfo shows no platforms, run it with oclgrind prefix to use the emulator:


> oclgrind clinfo


Compile your "hello world" opencl sample code:


> c++ main.cpp -I/usr/local/include -L/usr/local/lib -lOpenCL -o main


... and run with the oclgrind prefix:


> oclgrind ./main


----------

