How do I use the OpenCL C++/C++ for OpenCL kernel languages? - opencl

I have only tried compiling kernels using pyopencl, but I can only seem to be able to use OpenCl C. Looking at clinfo, I only see support for CLC listed, heres some truncated output from my pc:
Platform Name AMD Accelerated Parallel Processing
Platform Vendor Advanced Micro Devices, Inc.
Platform Version OpenCL 2.1 AMD-APP (3423.0)
Platform Profile FULL_PROFILE
Platform Extensions cl_khr_icd cl_amd_event_callback
Platform Extensions function suffix AMD
Platform Host timer resolution 1ns
Platform Name AMD Accelerated Parallel Processing
Number of devices 1
Device Name gfx1031
Device Vendor Advanced Micro Devices, Inc.
Device Vendor ID 0x1002
Device Version OpenCL 2.0
Driver Version 3423.0 (HSA1.1,LC)
Device OpenCL C Version OpenCL C 2.0
Device Type GPU
Device Board Name (AMD) AMD Radeon RX 6700 XT
Device PCI-e ID (AMD) 0x73df
Device Topology (AMD) PCI-E, 0000:2f:00.0
Device Profile FULL_PROFILE
Device Available Yes
Compiler Available Yes
Linker Available Yes
Max compute units 20
I am using a rocm driver compiled from the AUR, I tried to also install the mesa driver alongside but could not do so (perhaps I need to uninstall the other, but I dread having to recompile it if mesa fails).
My laptop (intel hd graphics) seems to support OpenCL 3.0 but also only lists CLC support. What am I missing, is this not implemented yet? I saw something somewhere about "offline compilation" and maybe using a "clc++" option with clang but can someone elaborate?

C++ for OpenCL can be used in two ways:
Online compilation
If OpenCL device supports cl_ext_cxx_for_opencl, it is possible to compile a program written using the C++ for OpenCL kernel language in runtime. Applications may pass -cl-std=CLC++ to clCompileProgram and clBuildProgram for programs created using clCreateProgramFromSource to request the program be built as C++ for OpenCL.
Offline compilation
If OpenCL device allows to create the program with SPIR-V, then it is possible to compile C++ for OpenCL source into intermediate LLVM IR:
clang -c -cl-std=clc++ -target spir64 -O3 -emit-llvm -o test.ll test.clcpp
Next, LLVM IR can be translated into SPIR-V using llvm-spirv:
llvm-spirv test.ll -o test.spv
Finally, OpenCL program can be created using clCreateProgramWithIL call:
std::ifstream il_file("test.spv", std::ios::binary);
std::vector<char> il_buffer;
std::copy(std::istreambuf_iterator<char>(il_file),
std::istreambuf_iterator<char>(),
std::back_inserter(il_buffer));
cl_program program =
clCreateProgramWithIL(context, il_buffer.data(), il_buffer.size(), &ret);
For PyOpenCL:
with open('test.spv', 'rb') as il_file:
il_buffer = bytes(il_file.read())
prg = cl.Program(ctx, il_buffer)
To check that OpenCL device supports SPIR-V modules, you need to use CL_DEVICE_IL_VERSION query in OpenCL 2.1 or newer and the CL_DEVICE_ILS_WITH_VERSION query in OpenCL 3.0 or newer.
For additional information about offline compilation please see Offline Compilation of OpenCL Kernels into SPIR-V Using Open Source Tooling article.

Related

Why Android x86 or bliss os does not load virtio gpu or amdgpu driver for RX 6500 XT passthrough?

I am new in these waters. After installing aarch64 arch on several arm boards. Decided to try android x86 and then android arm.
However in documentations it says it supports nvidia through nouvaeu driver I have rtx 3060 and NV170 is not supported in nouvaeu I get it. However it should support RX 6500 XT with or without vulkan supports. That I dont get. When I boot with virtual VGA as primary and rx 6500 XT as secondary I see AMD GPU in listed in lspci output however cant make modprobe to load gpu drivers. What am I missing ? Both happens in blissOS'es and Android_X86's latest versions.
Did you make them work, should quadruple check everything ? (vga rom, binary drivers etc)

paraview needs higher OpenGL in Mesa

Im trying to use paraview 5.3.0 in CentOS.
I compiled it with Qt5. When I start paraview it tells me:
GL version 2.1 with the gpu_shader4 extension is not supported by your graphics driver but
is required for the new OpenGL rendering backend. Please update your OpenGL driver. If you
are using Mesa please make sure you have version 10.6.5 or later and make sure your driver
in Mesa supports OpenGL 3.2.
Here is the OnBoard graphics card:
lspci |grep VGA
03:00.0 VGA compatible controller: Matrox Electronics Systems Ltd. Device 0536 (rev 04)
And the glxinfo:
glxinfo | grep OpenGL
OpenGL vendor string: VMware, Inc.
OpenGL renderer string: Gallium 0.4 on llvmpipe (LLVM 3.9, 256 bits)
OpenGL version string: 2.1 Mesa 17.0.1
OpenGL shading language version string: 1.30
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 2.0 Mesa 17.0.1
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 1.0.16
OpenGL ES profile extensions:
I dont understand what "... make sure your driver in Mesa ..." means.
kind regards
When using llvmpipe/gallium with mesa, a software renderer, the OpenGL capabilities can be incorrectly detected. The simplest way to fix that is to force it :
MESA_GL_VERSION_OVERRIDE=3.3 ./bin/paraview
The llvmpipe is the software rendering driver.
I don't know if you are running CentOS on a VM or not (even if glxinfo says "OpenGL vendor string: VMware, Inc." that doesn't necessary imply you are running on VMware).
If you are not running CentOS as a VM guest, consider installing the appropriate mesa drivers for your video card.

Compiling OpenCL 1.2 codes on nvidia gpus

I am going to compile a chunk of codes which needs OpenCL 1.2. As I understood, nVIDIA has released OpenCL 1.2 driver. I have installed the latest CUDA Toolkit which is version 7.0. But when I compiled then code, I got errors like:
Error 9 error LNK2001: unresolved external symbol clReleaseDevice C:\Users\???\Downloads\FireRaysSDK-1.0\FireRaysSDK-1.0\App\CLW64.lib(CLWParallelPrimitives.obj) App
Error 7 error LNK2001: unresolved external symbol clRetainDevice C:\Users\???\Downloads\FireRaysSDK-1.0\FireRaysSDK-1.0\App\CLW64.lib(CLWContext.obj) App
After that I download the header files from khronos website for OpenCL 1.2. Now, it compiles but I am getting unresolved external link to these functions as their implementation is not in OpenCL.lib.
Is there any OpenCL.lib that I can use to compile OpenCL 1.2 codes? Is there any way to get their implementation from DLL files? Because as I know nvidia has added the opencl 1.2 support to its driver.
You are correct that NVIDIA now provide OpenCL 1.2 support in their latest drivers, but the CUDA 7.0 SDK was released sometime before these drivers were shipped, and so may not contain OpenCL 1.2 headers or libraries. I've just checked the CUDA 7.5 Release Candidate and it appears to ship with the OpenCL 1.2 library that you need.
You can link against any OpenCL 1.2 library, and it should work with NVIDA's drivers. You should just be able to install an SDK from AMD or Intel, or just download and build the OpenCL 1.2 Installable Client Driver (ICD) Loader directly from Khronos.

CL_DEVICE_NOT_AVAILABLE using Intel Core 2 Duo E8500 CPU

I get the error CL_DEVICE_NOT_AVAILABLE when running this sample code. However, unlike in that question, my CPU, the Intel Core 2 Duo E8500 CPU, appears to be supported. I've made sure to link against the Intel version of the OpenCL libraries, since I also have the Nvidia libraries installed. Why is this error occurring?
The Intel OpenCL SDK 2013 required SSE 4.2. From what I can tell (here) the Intel Core 2 Duo E8500 CPU only has SSE 4.1
"CL_DEVICE_NOT_AVAILABLE" is the error you get when you try to create an OpenCL device on an unsupported CPU.
The good news for you is that the Intel OpenCL SDK 2012 works on SSE 4.1; you should uninstall the 2013 SDK and use the 2012 SDK instead (or get a newer CPU).
"CL_DEVICE_NOT_AVAILABLE" has nothing to do with the SDK. It's due to the OpenCL device driver which is part of the video card device driver.
It's common to confuse the SDK and the OpenCL device driver. You develop the host code with the SDK but the kernel is compiled and run through the device driver. I often develop with the Intel SDK but I run my kernels on the CPU using the Intel video driver or the AMD Radeon drivers and on the GPU using the Nvidia video drivers (GTX590). I have all three video drivers installed in Windows. You don't have to have an AMD video card to instal the Radeon drivers.
So in your case you can use the AMD drivers to run your kernel on the CPU. They are much less restrictive than Intel's.
On windows I get faster results running my Kernel on my Sandy Bridge CPU using the Intel OpenCL drivers than AMD. However, on Linux the AMD driver runs my kernel faster on my Intel CPU than the Intel driver does.
I encountered this error while creating a tutorial on how to install hashcat on Ubuntu 18.04; I've included the instructions below for Installing OpenCL™ Runtimes for Intel® Processors - Option A (Recommended)- feel free to review my full gist on GitHub. Hope that helps!
Installing OpenCL™ Runtimes for Intel® Processors
Installing OpenCL™ Runtimes for Intel® Processors - Option A (Recommended)
Check your CPU system processor architecture by running sudo lscpu to identify the class of CPU e.g. "Intel (R) Core (TM) i7-7700 CPU # 3.60Ghz"- alternatively, you can go to Settings > Details which will also reveal the CPU-family (e.g. Intel (R) HD Graphics 630 (Kaby Lake GT2)).
Go to the Intel Developer Zone and scroll down to the corresponding download link for your system; assuming you're running Ubuntu 18.04 and have a Intel Core-class CPU, scroll down to "Linux* OS Ubuntu* 16.04.x (deb)" and click on the Github link for 18.46.11837 Runtimes to access the runtime-packages to download.
There should be instructions within the aforementioned Github repo- or you can proceed with the following in the next steps.
cd ~/Desktop
mkdir neo
cd neo
sudo wget https://github.com/intel/compute-runtime/releases/download/18.46.11837/intel-gmmlib_18.4.0.348_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/18.46.11837/intel-igc-core_18.44.1060_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/18.46.11837/intel-igc-opencl_18.44.1060_amd64.deb
wget https://github.com/intel/compute-runtime/releases/download/18.46.11837/intel-opencl_18.46.11837_amd64.deb
Install the packages by running sudo dpkg -i *.deb.
Restart the system by running sudo reboot.
Installing OpenCL™ Runtimes for Intel® Processors - Option B
Go to Intel OpenCL Runtimes website and scroll down to the bottom of the page to Download Intel CPU Runtime for OpenCL Applications 18.1 for LINUX OS (64-bit only).
After downloading the OpenCL Runtimes for Intel Processors, cd ~/Downloads
Run sudo tar -xzf l_opencl_p_18.1.0.013.tgz to unpack the tgz file- please note, the OpenCL file version may update since the time as of this gist (ie as of this gist, the version is 18.1.0.013.)
cd l_opencl_p_18.1.0.013
Run sudo ./install.sh
A welcome screen is prompted- hold-down the "Enter" key until able to input select "2" for "I do NOT consent to the collection of my Information"
Hit "1"
Hit "1"
Hit "Enter" and then restart the computer.
If any additional Intel OpenCL errors are encountered after testing hashcat, go to section 'Installing OpenCL™ Runtimes for Intel® Processors - B'- if not, proceed with section "Testing Hashcat"

OpenCL: working with doubles error

The error states:
error: can't enable all OpenCL extensions or unrecognized OpenCL extension
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
System configuration:
Windows 7 on 64 bit
Notebook with ATI Mobility Radeon HD 5400 series
Visual Studio 2010
Drivers installed:
AMD-APP-SDK-v2.8-Windows-64
amd_catalyst_13.5_mobility_beta3
How can i solve this problem because i need to use double type in the kernel?
The directive is declared in the first kernel line.
Your GPU doesn't support double precision. This is why the OpenCL runtime is reporting it cannot enable the cl_khr_fp64 extension. If you really need double precision, try using the CPU as an OpenCL device instead and run your kernel on that.

Resources