GPGPU using Opencl

cayoenrique

Member
Messages
475
GPGPU - General-purpose computing on graphics processing units

Here we are going to try to introduce you guys in the computing using our GPU. Most people in the forum do know Colibri's RBT that uses Nvidia GPU. That program use CUDA programing.

Now here in the other hand we are going to try to introduce you in OpenCL. OpenCL has the advantage that can be execute in many devices including AMD GPU and even on CPU . Beware that CPU can be use for learning but most of the time is not practical. And Brute-force should never be done on Laptops as brute-force generate lost of heat. But for learning purposed is ok to run a kernel for short periods of time in a PC.

Here is the 1rst of our tutorial. I am doing it on PDF to have a copy at home. So that in the future is easily to re-post. Also we do not clog the thread. This part if to verify that we have our drivers installed.

01_Inspcecting_PC.pdf.zip (287.77 KB)
Code:
https://workupload.com/file/vBWfkfyJvCb

Password is as always www.sat-universe.com
 

cayoenrique

Member
Messages
475
@Me2019H and also to @all

I know I said that for Linux you should do
Code:
sudo lspci -nn -k | grep -i -e "vga"

But if VGA is not part of name it will not show. Now lets see what happen if we include a change a little
Code:
# > sudo lspci -nn -k | grep -i -A3 -e "vga\|NVIDIA\|amd"
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b)
Subsystem: Dell Haswell-ULT Integrated Graphics Controller
Kernel driver in use: i915
Kernel modules: i915
--
08:00.0 3D controller: NVIDIA Corporation GF117M [GeForce 610M/710M/810M/820M / GT 620M/625M/630M/720M] (rev a1)
Subsystem: Dell GeForce 820M
Kernel driver in use: nouveau
Kernel modules: nouveau
# >

This means that @Me2019H do have a 2 GPU that he can used to do GPGPU. But in particular he has Nvidia GPU with 96 cores
Code:
https://www.techpowerup.com/gpu-specs/dell-geforce-820m-2-gb.b5431

Now the other GPU Dell Haswell-ULT may be interestig too but he faild to provide me with his CPU information to guess how many core he got.
So he could do
Code:
sudo lscpu

Or he can go to Windows and run the two app I show in the tutorials.
 

Me2019H

Registered
Messages
101
Hello

root@live:~# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
Address sizes: 39 bits physical, 48 bits virtual
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 2
Core(s) per socket: 2
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 69
Model name: Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
Stepping: 1
CPU MHz: 2193.443
CPU max MHz: 2700.0000
CPU min MHz: 800.0000
BogoMIPS: 3392.28
Virtualization: VT-x
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 3072K
NUMA node0 CPU(s): 0-3
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
root@live:~# uname
Linux
root@live:~# uname -a
Linux live 4.19.0-10-amd64 #1 SMP Debian 4.19.132-1 (2020-07-24) x86_64 GNU/Linux
root@live:~#

root@live:~# sudo lspci -nn -k | grep -i -e "vga"
00:02.0 VGA compatible controller [0300]: Intel Corporation Haswell-ULT Integrated Graphics Controller [8086:0a16] (rev 0b)
root@live:~# sudo lspci -nn -k | grep -i -A3 -e "vga\|NVIDIA\|amd"
00:02.0 VGA compatible controller [0300]: Intel Corporation Haswell-ULT Integrated Graphics Controller [8086:0a16] (rev 0b)
Subsystem: Dell Haswell-ULT Integrated Graphics Controller [1028:0652]
Kernel driver in use: i915
Kernel modules: i915
--
08:00.0 3D controller [0302]: NVIDIA Corporation GF117M [GeForce 610M/710M/810M/820M / GT 620M/625M/630M/720M] [10de:1140] (rev a1)
Subsystem: Dell GeForce 820M [1028:0652]
Kernel driver in use: nouveau
Kernel modules: nouveau
root@live:~# sudo apt install clinfo
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
ocl-icd-libopencl1
Suggested packages:
opencl-icd
The following NEW packages will be installed:
clinfo ocl-icd-libopencl1
0 upgraded, 2 newly installed, 0 to remove and 177 not upgraded.
Need to get 78.5 kB of archives.
After this operation, 255 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ftp.us.debian.org/debian buster/main amd64 ocl-icd-libopencl1 amd64 2.2.12-2 [37.5 kB]
Get:2 http://ftp.us.debian.org/debian buster/main amd64 clinfo amd64 2.2.18.04.06-1 [41.0 kB]
Fetched 78.5 kB in 1s (60.8 kB/s)
Selecting previously unselected package ocl-icd-libopencl1:amd64.
(Reading database ... 34078 files and directories currently installed.)
Preparing to unpack .../ocl-icd-libopencl1_2.2.12-2_amd64.deb ...
Unpacking ocl-icd-libopencl1:amd64 (2.2.12-2) ...
Selecting previously unselected package clinfo.
Preparing to unpack .../clinfo_2.2.18.04.06-1_amd64.deb ...
Unpacking clinfo (2.2.18.04.06-1) ...
Setting up ocl-icd-libopencl1:amd64 (2.2.12-2) ...
Setting up clinfo (2.2.18.04.06-1) ...
Processing triggers for libc-bin (2.28-10) ...
root@live:~# clinfo
Number of platforms 0
root@live:~#

After i installed the OpenCL the Number of platforms is 0?
 

cayoenrique

Member
Messages
475
Code:
https://www.techpowerup.com/cpu-specs/core-i5-4210u.c2028

The GPU inside the CPU is a Intel HD 4400

Code:
https://www.techpowerup.com/gpu-specs/hd-graphics-4400.c2470

I can really find out the real # of cores. That page before seems to suggest there are a maximum of 160 cores!
I guess it should be less as why adding an Nvidia GPU with 96 cores!
 

cayoenrique

Member
Messages
475
I did test today installation without msys2 nor mesa. The results where positive. But involve some manual download and extraction of the OpenCL packages that originates from MSYS2-mesa.
I hope to have for tomorrow a tutorial on how to install and do 1rst Opencl test.

Soo ,see you tomorrow. Is late and I got to sleep.
 

cayoenrique

Member
Messages
475
Ok here is the Tutorial to install mingw,opencl,codeblocks

Tutorial_Opencl_installation_ver_0.01.zip (1.21 MB)
Code:
https://workupload.com/file/9d5cTUDnMxv

Next I will post a project to build clinfo and a sample of opencl. Need a few hours to rest. See you guys latert
 

cayoenrique

Member
Messages
475
@Me2019H and to anyone else that want to use Linux.
Regards installation of Codeblocks, follow the Tutorial 04_Installing_Codeblocks._ver_0.01pdf
1rst you should not have any throuble as Debian had clean it for you.

Open a Terminal.
Code:
# > sudo apt update
# > sudo apt install Codeblocks

I know I for got to mention what settings in the compiler. Well Is much simpler that in Windows. You ONLY need to do page 10 and page 12

Code:
Now lets go over all other settings
[Menu]> Setting> Compiler> Compiler settings> Other compiler options
-fopenmp
-std=gnu11

[Menu]> Setting> Compiler> Linker Settings > Other linker options
-lgomp
-lOpenCL

Also, as I am doing this thread focus in Windows users, I have not personally tested this instructions. I have only tested Windows. No enough time for all. If you have any any trouble just ask. I will quickly test and find any solution for you guys.
 

cayoenrique

Member
Messages
475
And here are tho sample.
They are from github. 1 simleb.clinfo-master , is a clinfo I have to mod it to make it work as I wanted. So that it can list all devices and their capabilities.

In general you right click over clinfo.cbp and select open with codeblocks.
make sure what you are building, I suggest you select Release
Then you go to [Menu]>Build>Build
you close Codeblock, Open a terminal and cd into bin\Release

Then to see how it works you can do:
clinfo -l #this give you a short list with devices available
clinfo 0:0 # this give you de info of Platform 0 device 0
clinfo -a # will provide all info available from all devices.

Now what you just did is not REAL Opencl, you are only querying the GPU for information.

The second program is called add_numbers. Againgyou look for the *.cbp in this case add_numbers.cbp Right click and open with codeblocks.
You build with [Menu]>Build>Build
Then you go into [Menu]>Build>Run

You will see almost nothing. As it will almost instantaneous do some adding calculations. Do an internal check of the results and tell you that program pass check.
Now here you can see that you have a file called: add_numbers.cl This is in fact the kernel that is sent to the GPU for computations.

Up to here we go I need to rest.

here the file sfor download

opencl_samples.zip (35.36 KB)
Code:
https://workupload.com/file/uz4QmNcuLN3
 

Me2019H

Registered
Messages
101
Hello,

It did't work

root@live:~/Crypto/opencl_samples/add_numbers# ls
add_numbers.c add_numbers.cbp add_numbers.cl main.c Makefile README.md
root@live:~/Crypto/opencl_samples/add_numbers# make
make: Warning: File 'add_numbers.c' has modification time 4458 s in the future
gcc -std=c99 -Wall -DUNIX -g -DDEBUG -m64 -o add_numbers add_numbers.c -lOpenCL
add_numbers.c:18:10: fatal error: CL/cl.h: No such file or directory
#include <CL/cl.h>
^~~~~~~~~
compilation terminated.
make: *** [Makefile:55: add_numbers] Error 1
root@live:~/Crypto/opencl_samples/add_numbers# clinfo
Number of platforms 0
root@live:~/Crypto/opencl_samples/add_numbers#
the same error in th second example (clinfo)

please explain the code to us
 

cayoenrique

Member
Messages
475
@Me2019H
I will try to help you via PM. Why? so that we do not clog this thread with Linux stuff. I want for people to join and have fun. But most of them when the see Linux stuff the turn around and move away.
Now if for any reasons there are more interested in Linux then we can see what we can do.

I did post those without any explanation because @C0der was interested.

Yes I will go slow on it. Soon I will explain.
 

cayoenrique

Member
Messages
475
Now back with my SU friends that Love W10.

I do not know if you had notice. But preparing this project takes a lot of time from me. It will be nice if any one of you Windows users has try to install Mingw64-Codeblocks-OpenCL_IDC. And finally try the samples. So if you are litsening PLEASE report here in this tread.

Now I have some E-books in PDF for reading. But I feel that if I post people will get scare. So I will going to try explain in simple terms. By doing so I could say someting a litle wrong. But is an attenpt to simplify the stuff. In any case I am no expert and for sure I can always be wrong.

Now using your GPU requires a MAIN.C program. This will start querying the GPU adapter for info. Once the MAIN.C program see that there is a PLATFORM(AMD/NVIDIA/INTEL) and that PLATFORM has at least 1 DEVICE (GPU) then it knows that it can proceed. So you may have notice that there is a MAIN.C program that is functioning like a Manager. Now for the GPU to do stuff it requires a Separate Program build in a specific way for it to work. It can be CUDA or OpenCL. We say that this second program contains a OpenCL KERNEL. To lets other know where the kernel is located the file will end *.cl, you may have notice in the past that C programs are save like *.c or for headers *.h.

So if you look at any project I may sent you
*.c hold C programing
*.h Hold C header stuff
*.cl Hold Opencl stuff
*.cbp Is the Codeblocks project File. When you click this it will bring all files needed for the project to run
makefile if provided allow you to compile the project without the need for Codeblocks, just GNU gcc compiler

To provide both access to Linux or Windows Y may add at the end of the file _win or _Linux. You the copy or rename that file without _* so that you can do it on your own OS.

Now for OpenCL the main.c manager! has to do many step that are going to look weird to you or any other person that has experience in C.
Quickly they are going to say that it is confusing. Listen, most of the 100th lines of code do not change at all it is the same skeleton over and over.
What we need to change is the Special Initialization and Handling of the Variables. We call this variables Buffers. You will say WHY?
It is because some variables need to reserve memory inside the Computer, others reserve memory inside GPU, other in both.
Some may be move from PC to GPU memory only, because they are for initial values. Others may move from GPU to CPU, this are for output results.

Then there are command lines that send the Input variables from PC to GPU, there are lines that send the Kernel(program) from PC to GPU,
there are lines that request to receive the result buffers form GPU to back to PC.
At the end there are lines that free all reserve memory so that the PC again can used them. This is the reason for all that overhead of lines.

Instead of been afraid of all those hundreds ( they are not hundreds but quite a few) you should always ignore them for the most part,
and only think or take care of the buffers and the kernels it self.

Up to here with the general explanation. So please if you are following give us a Like and Subscribe.... Ups this is not youtube. But PLEASE post a comment so that I know that I am been follow.
 

dvlajkovic

Member
Messages
498
I have followed your Tutorial_Opencl_installation_ver_0.01.zip and did everything per your instructions there.
Then I downloaded https://github.com/hnw/clinfo

Tried to build and got this error:
Code:
gcc.exe -LC:\Apps\MSys2\mingw64\lib -LC:\Apps\CodeBlocks\lib -o bin\Debug\clinfo.exe obj\Debug\main.o  -lgomp -lOpenCL 
C:/Apps/MSys2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lOpenCL
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 0 warning(s) (0 minute(s), 0 second(s))

Then I went to the other link you have shared https://github.com/Oblomov/clinfo
and downloaded precompiled 64-bit clinfo.exe from there.
It runs just fine, giving me this output > link

As I said, I'm no programmer and would appreciate info what should I do to build and run https://github.com/hnw/clinfo without errors?
 

cayoenrique

Member
Messages
475
See from what you post this is the error
Code:
cannot find -lOpenCL

from 03_Installation_Opencl_IDC.pdf
that means it can not find C:\Apps\OpenCL_IDC\lib\libOpenCL.dll.a

Remember you should see as 03_Installation_Opencl_IDC.pdf
Code:
C:\Apps\OpenCL_IDC
C:\Apps\OpenCL_IDC\bin
C:\Apps\OpenCL_IDC\bin\cllayerinfo.exe
C:\Apps\OpenCL_IDC\bin\OpenCL.dll
C:\Apps\OpenCL_IDC\include
C:\Apps\OpenCL_IDC\include\CL
C:\Apps\OpenCL_IDC\include\CL\cl.h
C:\Apps\OpenCL_IDC\include\CL\cl_d3d10.h
C:\Apps\OpenCL_IDC\include\CL\cl_d3d11.h
C:\Apps\OpenCL_IDC\include\CL\cl_dx9_media_sharing.h
C:\Apps\OpenCL_IDC\include\CL\cl_dx9_media_sharing_intel.h
C:\Apps\OpenCL_IDC\include\CL\cl_egl.h
C:\Apps\OpenCL_IDC\include\CL\cl_ext.h
C:\Apps\OpenCL_IDC\include\CL\cl_ext_intel.h
C:\Apps\OpenCL_IDC\include\CL\cl_gl.h
C:\Apps\OpenCL_IDC\include\CL\cl_gl_ext.h
C:\Apps\OpenCL_IDC\include\CL\cl_half.h
C:\Apps\OpenCL_IDC\include\CL\cl_icd.h
C:\Apps\OpenCL_IDC\include\CL\cl_layer.h
C:\Apps\OpenCL_IDC\include\CL\cl_platform.h
C:\Apps\OpenCL_IDC\include\CL\cl_va_api_media_sharing_intel.h
C:\Apps\OpenCL_IDC\include\CL\cl_version.h
C:\Apps\OpenCL_IDC\include\CL\opencl.h
C:\Apps\OpenCL_IDC\lib
C:\Apps\OpenCL_IDC\lib\libOpenCL.dll.a
C:\Apps\OpenCL_IDC\lib\pkgconfig
C:\Apps\OpenCL_IDC\lib\pkgconfig\OpenCL.pc


Now 1rst check that the System variable is available.
Get a terminal [WIN KEY] + R then CMD [ENTER]
Code:
echo %OpenCL_IDC%
It should respond C:\Apps\OpenCL_IDC

I just saw the problem. page3 of 02_Instalin_GNU_Compiler.pdf wrongly say

OpenCL_IDC = C:\Apps\CodeBlocks This is BAD-WRONG

It should say
OpenCL_IDC = C:\Apps\OpenCL_IDC

[Windows Key]+R
Then type or C&P
env [ENTER]
You should see “environment variables for your account”
Click on it
User up/down arrow keys to select OpenCL_IDC in User
Then Hit [Edit] and change the value to correct info C:\Apps\OpenCL_IDC

Then save and exit..

Close Codeblocks and restart, try to compile again and execute. It should work this time.
 

dvlajkovic

Member
Messages
498
Thank you, Enrique.
At first, let me present the way I did it on Win 10 regarding page 3 of 02_Instalin_GNU_Compiler.pdf.

Press Win key, type env on keyboard and click on the top listed app in menu named "Edit the system environment variables".
This app will open up. Click on the button "Environment Variables" at the bottom (see button marked with red arrow on pic below).

D8zFwEU.png


Select Variable PATH in botom window named System variables (marked 1. on the pic below).
Click Edit... button at the bottom (marked 2. on the pic below).

GzxGYNK.png


Click New... button on the top right side of that window.
Copy/paste the lines below, one at a time, to the empty line that will show up at he bottom of variable list:
C:\Apps\home\bin
C:\Apps\Msys2\mingw64\bin
C:\Apps\OpenCL_IDC\bin


Once you've done that, it should look like this:
ZG4YT3Q.png


Click on OK button.

Now we need to create 4 additional System variables.
Click on New... button at the bottom (marked 1. on the pic below)
Copy/paste the lines below, one at a time, to the empty lines in New System Variable pop-out window (marked 2. and 3. on the pic below)
Click OK button (marked 4. on the pic below)
Repeat this procedure for the other 3 Variables MSYS2, MINGW64 and OpenCL_IDC using their respective names and values as listed here below:

Variable nameVariable value
HOMEC:\Apps\home
MINGW64C:\Apps\MSys2\mingw64
MSYS2C:\Apps\MSys2
OpenCL_IDCC:\Apps\OpenCL_IDC

ap5W73U.png

Once you've done that, it should look like this (marked 1, 2, 3, 4 on the pic below):
SXrFQY9.png

Make sure you have all 4 inserted as on screenshot above!
Click OK button.

Now lets open a new terminal to test.
[Windows Key]+R Then type or C&P
CMD [ENTER]
C:\> set
C:\> echo %PATH%
C:\> gcc -v
You should see response.
 
Last edited:

dvlajkovic

Member
Messages
498
This time it has compiled clinfo.exe without any errors.
When I run clinfo.exe it just shows Hello world! :rolleyes:
 

cayoenrique

Member
Messages
475
I had a busy day today. But I did had time to play a litle.
@dvlajkovic
1rst , we can not expect to be able to compile what ever we find in github. Most of the time we need to do some twicks ( adjustment ).
The hnw-clinfo expect to be compile in a certain way. That will produce a config.h. And a few other things. See @Me2019H also have some issues with a different sample.

So I decided to minimize a little the problem.

1rst mingw decided not to provide make. Instead they called it mingw32-make.exe
So to make it standard, we need to overcome the problem by making a copy of C:\Apps\MSys2\mingw64\bin\ mingw32-make.exe.

So Open a terminal and do
Code:
cp C:\Apps\MSys2\mingw64\bin\mingw32-make.exe C:\Apps\MSys2\mingw64\bin\make.exe
Now you will be able to do just make

Second, I create a makefile, that most work if not for all but at least for most projects. The reason is that we usually will have just 1 *.c file. my makefile will look for that single c file nad compile it. It will not work if there is more than 1 *.c file.
I created the makefile so that it can build in windows or linux. Even under wine or just cross-compiling with Linux mingw. The make file is in both the samples you two guy ask me to help.

Here are the two samples

opencl_samples2.zip (13.12 KB)
Code:
https://workupload.com/file/GPLUW5KhkwV

So this will not just say hello ;)

Listen this are not the best samples. I will try to create / clean a template to discus how it work.
 

dvlajkovic

Member
Messages
498
Gracias, Enrique.
I knew it needed properly adjusted makefile, but haven't had a clue how to do it myself, so I just wanted to help everyone to know that the compiler in general has been set up once they see Hello world! :)

With your latest additions (make.exe , makefile , clinfo.cbp , clinfo.layout , config.h) the Code Blocks successfully compiled clinfo.exe

dSoeagF.png


It runs just fine.

Then I have compiled clinfo.exe with CYGWIN as well. It also runs good on win 10.

Now let me say an observation here.
According to just two people that showed any reactions here (@Me2019H and me) I can only conclude that everyone else is just awaiting to download compiled executable file(s) to run 'em on their windows / linux pc.
Unfortunately, that is our reality.
I hope that the others will actively join us here with their own remarks, suggestions and fresh ideas.
 

moonbase

VIP
Donating Member
Messages
550
...According to just two people that showed any reactions here (@Me2019H and me) I can only conclude that everyone else is just awaiting to download compiled executable file(s) to run 'em on their windows / linux pc.


Yes, I think you are correct, most members on Sat Universe do not want to get involved with the programming, they only want the final *.exe file to install on their PC.

It was the same when Colibri released the Rainbow Tool and the chain files.
A small number of members contributed to making the chain files for many months, even years.
All the other people were just leeches and maggots who were feeding off the chain files without creating any chains to help the project.
 

cayoenrique

Member
Messages
475
GPGPU is not for every programmer. Every company does it different, No single tool. But we are showing that Opencl can be setup in away similar to all. In this way we all can share a little of what we learn.
Once we get going. Many will say, I knew that. I used to do that this way. And a few more will join. I am going to stop. To start working on the skeleton. I need to add a few comments so that you all know what it does each part.
 
Last edited:
Top