cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

ernst0
Adept I

Newbie introduction and seeking guidance.

Hello my name is Ernst. I have a passion for binary level data encoding.  I work on my workstation running a AMD 9590 and recently I made the decision to upgrade my NVIDIA GPU to twin Radeon wx 5100s pros'.

I am at the very "introductory level" of learning to write OpenCL code for the 5100s' I have a good grasp of the C language. C is excellent for working on data on the binary level.

I am watching YouTube videos on OpenCl and reading selected web pages. So, friends what, where, who and how are the things I should do to get going learning OpenCl. Are there guides? Groups? How best to use this resource?

No need for me to post in the advanced sections at this time

0 Likes
16 Replies
dipak
Big Boss

Hi Ernst,

Welcome to AMD's DevGurus community.

I've whitelisted you and I'm moving this thread to our OpenCL forum.

Thanks.

0 Likes

Thank You.

OpenCL seems odd to me but I am making the effort.

Perhaps there is a book that is recommended for beginners?

0 Likes
cardboard
Adept I

You have the Reference Cards from Khronos right? they are useful

(24 pages is long for a refcard but its all well segmented, common functions are first & as long as you know what you want you can find it on there, it beats googling any day)

I just finished reading the "AMD OpenCL Programming User Guide"

It has some good examples, you have to download the amd sdk and install it to get the examples, I had to get it from github, I cant find the link atm sorry

If you use it the first few examples i think use some very bloated C++ OpenCL code, but that is just to shorten their examples to fit within the pdf

My version of the PDF dates August 2015 on the cover

You have asked a good question.

I own a few books, but have given up with them, I cannot understand bad grammar, something that "OpenCL programming by example" has, I don't know how you'd manage with it.

I'd recommend you give Anything a read and just look at the AMD examples with the AMD SDK (its pretty easy to get them to use Nvidia devices i think...) the examples are mostly for OpenCL 1.2, so they should work with Nvidia, only a few that actually use 2.0 are written in it. I use windows & Visual Studio, dealing with different IDEs was hell so I gave up, I can just double click project file and they Open up split into 1.2 & 2.0 samples.

0 Likes

cardboard wrote:

You have the Reference Cards from Khronos right? they are useful

(24 pages is long for a refcard but its all well segmented, common functions are first & as long as you know what you want you can find it on there, it beats googling any day)

I just finished reading the "AMD OpenCL Programming User Guide"

It has some good examples, you have to download the amd sdk and install it to get the examples, I had to get it from github, I cant find the link atm sorry

If you use it the first few examples i think use some very bloated C++ OpenCL code, but that is just to shorten their examples to fit within the pdf

My version of the PDF dates August 2015 on the cover

You have asked a good question.

I own a few books, but have given up with them, I cannot understand bad grammar, something that "OpenCL programming by example" has, I don't know how you'd manage with it.

I'd recommend you give Anything a read and just look at the AMD examples with the AMD SDK (its pretty easy to get them to use Nvidia devices i think...) the examples are mostly for OpenCL 1.2, so they should work with Nvidia, only a few that actually use 2.0 are written in it. I use windows & Visual Studio, dealing with different IDEs was hell so I gave up, I can just double click project file and they Open up split into 1.2 & 2.0 samples.

Thanks for your reply! I appreciate it.

Reference cards? Not yet. Cool on telling me about the sdk.. I will get those things accomplished soon. I am experiencing some strange system behaviors here on my workstation that may require a wipe and reinstall. I'm still awaiting advice on that from friends. A wipe and reinstall will be a pain for sure but it's the only thing I can come up with for a fix. Anyway  I am on twin AMD Radeon wx 5100 pros' here . I ended up hating the old nVidea card I had since I am on Fedora Linux and in my experiences nVidea can be difficult with Wayland. I am also an AMD Fan-boy so it was an easy choice for a new GFX card. So, new great professional GFX cards need me to use them fully! So, here I am.

 I am a bit old fashioned because I have never learned C++ I really have not needed to because I specialize in binary level data encoder designs. It's a bit of an obsession I guess. It is not my job just a hobby. In fact I hope these GPUs' ( with 28 compute cores CU ) will speed up transforms. 

 So, if you like, what types of applications do you program your GPU for? Or maybe you do it for work?

0 Likes

Reference Card = a card containing all functions in a language (ish) (its an officially supported cheatsheet!)
https://www.khronos.org/developers/reference-cards/

// the new OpenCL 2.2 one is 24 pg long, but be aware a lot of it is to interface with other languages you won't use, like DirectX, they put this stuff at the end so its harder to find
I use a pdf editor to annotate both the reference card & programming guide as I go through (I use Xodo, as it is available on all platforms as an app + as a web app). Generally I just use slashes to slash text that I don't read and highlight important information in a range of colors according to a method I use, it helps me keep track of where I am after spending a week or more away from OpenCL.
I haven't used Linux really at all so I can't help you with too much, but all the official amd/openCL pdf (that are free) have a ton of installation guides, so it should be easy.

I am a student, I am trying to get a "job" in GPU programming though I have found it frustrating as there is no course available to me for programing in low-level languages, not even C++. I am doing a programming course atm, but it is primarily web languages. It is speeding up my progress though (as I dislike the IDE side of programming and it forces me to use them). I know I can learn C & C++ online, but I really need a social environment so its hard...

Thanks Cardboard.

 LOL on your comment " t helps me keep track of where I am after spending a week or more away from OpenCL." I know the feeling as I sometime go back and have issues understanding what the experimental code I wrote was supposed to do exactly.

I am now setting up OpenCL on this Fedora distro.

 It has been a struggle but it seems Gnome is the potential trouble maker for my system issues. Linus Torvalds is pointing out that Linux desktop(s) are falling behind because of uncoordinated  efforts between the different desktops. I have not exactly solved the issues that caused me to opt for a reinstall which turned into 6 reinstalls' and days of struggle and needing help. So it's a different set of behaviors now then I had. The system freeze-ups are reduced to temporary for the most part.

 Cardboard, I see I have the Installed Packages opencl-filesystem.noarch, opencl-headers.noarch, opencl-utils.x86_64 and opencl-utils-devel.x86 so any includes and I assume some "tools" are available to me.

 Okay so now to get my feet wet  I still have vague ideas of what the OpenCL paradigm is and that is okay at the moment. 

P.S. Wow that 2.2 card is packed with functions. ha! Intimidating.

Also thanks for your help.

0 Likes

cardboard wrote:

Reference Card = a card containing all functions in a language (ish) (its an officially supported cheatsheet!)
https://www.khronos.org/developers/reference-cards/

// the new OpenCL 2.2 one is 24 pg long, but be aware a lot of it is to interface with other languages you won't use, like DirectX, they put this stuff at the end so its harder to find
I use a pdf editor to annotate both the reference card & programming guide as I go through (I use Xodo, as it is available on all platforms as an app + as a web app). Generally I just use slashes to slash text that I don't read and highlight important information in a range of colors according to a method I use, it helps me keep track of where I am after spending a week or more away from OpenCL.
I haven't used Linux really at all so I can't help you with too much, but all the official amd/openCL pdf (that are free) have a ton of installation guides, so it should be easy.

I am a student, I am trying to get a "job" in GPU programming though I have found it frustrating as there is no course available to me for programing in low-level languages, not even C++. I am doing a programming course atm, but it is primarily web languages. It is speeding up my progress though (as I dislike the IDE side of programming and it forces me to use them). I know I can learn C & C++ online, but I really need a social environment so its hard...

You sound like a young person getting started! That is good. I just turned 58 and I know my mind is not as quick to new ideas as it used to be.

 I wouldn't presume to give advice however I took my one and only programming class the first year C was to replace Pascal at my community college. That was 1992. 

 What I know about learning C is that we all "jump in" and gain skill through the pain of experience.  I have defaulted to learning what I have to now

 Well I like binary. I discovered an encoding back in 2010 I named dynamic unary. It can be considered a dynamic data type. I can make a case for it to be called dynamic integer.  I mention this in case it interests you. You should be able to "ask the guy" if you have questions. After all it sounds like you are learning with a fresh young mind

 I offer my, not so well written and so far only attempt at writing a, paper on dynamic unary https://arxiv.org/pdf/1405.2846 

 I have been trying to compress data on the binary level for a long time. It's my obsession basically. From the pain of learning I have several clever encoders I should write about in an ebook I think.

 I understand when you wrote "I know I can learn C & C++ online, but I really need a social environment so its hard..." I have been there too.

 Well I am unsure as to why my gcc compiler cannot find the opencl link library so I will ask that separately. There are times I am smart and times I am dumb. This library link issue is a dumb one I can't figure out.

I welcome chatting with you more.

This one looks good. Learn C - Free Interactive C Tutorial 

Pointers to pointers can be a real mind-F and I think I have it right so I can be of some help. Advanced things like pointers to functions are things I have not needed so far. So yeah the very basics I can help you with.

I know that "gcc" ( a compiler ) is available for Windows so it's free. Installing GCC- GNU Project - Free Software Foundation (FSF) Gcc does a lot of different languages I understand including C++, Fortran and more. None of which I use so far.

0 Likes
ernst0
Adept I

Well, like Cardboard I like a bit of the old social environment. So if it's okay I'll be chatting in this thread.

I am now attempting to compile and run a program I found on the Web Getting started with OpenCL and GPU Computing – Erik Smistad 

Just a cut and paste

I feel dumb once again so I will work through this:

gcc -o First_OpenCL_Program First_OpenCL_Program.c -lopencl
First_OpenCL_Program.c: In function ‘main’:
First_OpenCL_Program.c:50:5: warning: ‘clCreateCommandQueue’ is deprecated [-Wdeprecated-declarations]
cl_command_queue command_queue = clCreateCommandQueue(context, device_id, 0, &ret);
^~~~~~~~~~~~~~~~
In file included from /usr/include/CL/opencl.h:47,
from First_OpenCL_Program.c:5:
/usr/include/CL/cl.h:1443:1: note: declared here
clCreateCommandQueue(cl_context /* context */,
^~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: cannot find -lopencl
collect2: error: ld returned 1 exit status

I am no where near knowing why

"First_OpenCL_Program.c:50:5: warning: ‘clCreateCommandQueue’ is deprecated [-Wdeprecated-declarations]"
cl_command_queue command_queue = clCreateCommandQueue(context, device_id, 0, &ret);

That is something I would gladly accept some hand-holding on.

The really dumb thing is gcc ( my compiler ) is not finding the library for the linker of -lopencl

That is a Linux issue so I welcome help on that.

------

Still working on learning however I thought to add a command I found " clinfo " I had to install it but it give some interesting information.

Device Name AMD Radeon (TM) Pro WX 5100 Graphics (POLARIS10, DRM 3.27.0, 5.0.5-200.fc29.x86_64, LLVM 7.0.1)
Device Vendor AMD
Device Vendor ID 0x1002
Device Version OpenCL 1.1 Mesa 18.3.5
Driver Version 18.3.5
Device OpenCL C Version OpenCL C 1.1
Device Type GPU
Device Available Yes
Device Profile FULL_PROFILE
Max compute units 28
Max clock frequency 1086MHz
Max work item dimensions 3
Max work item sizes 256x256x256
Max work group size 256
Compiler Available Yes
Preferred work group size multiple 64
Preferred / native vector sizes
char 16 / 16
short 8 / 8
int 4 / 4
long 2 / 2
half 8 / 8 (cl_khr_fp16)
float 4 / 4
double 2 / 2 (cl_khr_fp64)
Half-precision Floating-point support (cl_khr_fp16)
Denormals No
Infinity and NANs Yes
Round to nearest Yes
Round to zero No
Round to infinity No
IEEE754-2008 fused multiply-add No
Support is emulated in software No
Single-precision Floating-point support (core)
Denormals No
Infinity and NANs Yes
Round to nearest Yes
Round to zero No
Round to infinity No
IEEE754-2008 fused multiply-add No
Support is emulated in software No
Correctly-rounded divide and sqrt operations No
Double-precision Floating-point support (cl_khr_fp64)
Denormals Yes
Infinity and NANs Yes
Round to nearest Yes
Round to zero Yes
Round to infinity Yes
IEEE754-2008 fused multiply-add Yes
Support is emulated in software No
Address bits 64, Little-Endian
Global memory size 8589934592 (8GiB)
Error Correction support No
Max memory allocation 6871947673 (6.4GiB)
Unified memory for Host and Device No
Minimum alignment for any data type 128 bytes
Alignment of base address 32768 bits (4096 bytes)
Global Memory cache type None
Image support No
Local memory type Local
Local memory size 32768 (32KiB)
Max constant buffer size 2147483647 (2GiB)
Max number of constant args 16
Max size of kernel argument 1024
Queue properties
Out-of-order execution No
Profiling Yes
Profiling timer resolution 0ns
Execution capabilities
Run OpenCL kernels Yes
Run native kernels No
Device Extensions cl_khr_byte_addressable_store cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp64 cl_khr_fp16

Platform Name Portable Computing Language
Number of devices 1
Device Name pthread-AMD FX(tm)-9590 Eight-Core Processor
Device Vendor AuthenticAMD
Device Vendor ID 0x6c636f70
Device Version OpenCL 1.2 pocl HSTR: pthread-x86_64-unknown-linux-gnu-bdver2
Driver Version 1.2
Device OpenCL C Version OpenCL C 1.2 pocl
Device Type CPU
Device Available Yes
Device Profile FULL_PROFILE
Max compute units 8
Max clock frequency 4700MHz
Device Partition (core)
Max number of sub-devices 8
Supported partition types equally, by counts
Max work item dimensions 3
Max work item sizes 4096x4096x4096
Max work group size 4096
Compiler Available Yes
Linker Available Yes
Preferred work group size multiple 8

0 Likes

these problems are quite common, clCreateCommandQueue was deprecated in OpenCL2.0, it was the BIGGEST change to the language, also there's only like 2 changes, so...
you just need to specify that you are using OpenCL1.2 or lower I think (haven't run into this)
also finding the actual OpenCL linker is super hard, I had to use a special driver remover for my graphics card on windows, then reinstalling the drivers worked fine
you've checked this right, its just the 1st result on google... https://github.com/nginnever/zogminer/issues/54


btw I'm running into problems personally because I have multiple GPUs and a lot of the "samples" don't work because of it, also large portions of the C++ in the samples are not compiling, with no errors... 

Well! I manage to hit on two out of three!   I'm good.

Usually I would get the linker library in a "devel" package but I don't see anything.

It could be part of gcc itself. I'm still looking.

That link appears to be for RHEL not Fedora. I'll see if that makes a difference if I can.

I'm asking around. I'm surprised I haven't found anything but that is possibly because I have not searched for the correct things yet.

0 Likes

I don't expect a reply.

This getting OpenCl programming to work on Fedora 29 is very confusing.

I am going to give it a rest for a few days then try to separate the learning from the installation confusions.

0 Likes

yeah, like I said I kinda gave up trying to do anything fancy, so I would only use Ubuntu if I tried it on Linux, its always possible but its definitely annoying in the beginning, I don't know if you are running into the same problem I was, but I had to use a GPU driver wiping utility (uninstalling normally wasn't enough), I then reinstalled my GPU drivers and almost magically the OpenCL linker would now recognize both my cards. If you have 2 GPUs in your system taking it down to 1 may help, my conflict was due to the fact Nvidia doesn't use the OpenCL linker properly. I cannot remember in what order I installed my drivers but it just needed a reinstallation (I didn't need to reinstall Windows 10 though, I just left it I think). 

0 Likes

cardboard wrote:

yeah, like I said I kinda gave up trying to do anything fancy, so I would only use Ubuntu if I tried it on Linux, its always possible but its definitely annoying in the beginning, I don't know if you are running into the same problem I was, but I had to use a GPU driver wiping utility (uninstalling normally wasn't enough), I then reinstalled my GPU drivers and almost magically the OpenCL linker would now recognize both my cards. If you have 2 GPUs in your system taking it down to 1 may help, my conflict was due to the fact Nvidia doesn't use the OpenCL linker properly. I cannot remember in what order I installed my drivers but it just needed a re-installation (I didn't need to reinstall Windows 10 though, I just left it I think). 

I cannot makes sense of what I am reading as to what to do and how to do it.

I don't have a clear understanding of OpenCL and there is the issue of depreciation?

On my ToDo list is to upgrade basic system storage capacity so that will be a storage wipe and system re-install. I plan to resume "figuring this out" after that.

It might be a simple "path" issue as I see some OpenCL libraries here. I'm simply spoiled as installing packages usually takes care of everything but if Fedora is the unwanted Linux in AMD's eyes then perhaps packages alone wouldn't necessarily work directly?  I don't know. It is simply another layer of learning to get through.

 On the two GPUs' I thought I saw code that allowed us to discover what is there and code to select the GPU to work on. I was simply getting an overview while I was trying to get a basic understanding of how to Program on a GPU.

 This using the GPU sounds like it can speed up some rather time consuming transforms I designed. I don't work with them because of the amount of time they take and I should explore them more.

 One thing is certain I would be taxing the GPU at 100% for hours on end. Good thing I have two like you. Your concern is also mine.

0 Likes

just btw deprecation isn't much of an issue, it only applies to a few things, they massively change functionality, so this is why OpenCL1.2 moved straight to OpenCL2.0.
Just specify the version in your program at the start and you will have no problems, or just use the latest version (that way you don't have to specify (though OpenCL2.0 doesn't work on Nvidia...) )
https://www.khronos.org/registry/OpenCL/sdk/2.1/docs/man/xhtml/deprecated.html

I think basically the most important things that have been deprecated are
clEnqueueTask & atomics
// they have just changed formats
clEnqueueTask is basically enqueuing of ANYTHING (kernels most importantly, plus other stuff)

Cool if it is that easy. I think I will try to find the reason I can't link -lopencl tomorrow. If I am successful then that problem will be solved but Monday I strip the system down erase drives reconstruct and re-install.

I've got some glitches here I can't figure out as well as adding a larger drive.

Thanks for your help.

0 Likes

I have a suggestion. Please try "-lOpenCL" instead of "-lopencl". For example, with amdgpu-pro driver:

 g++ <source.cpp> -L/opt/amdgpu-pro/lib/x86_64-linux-gnu/ -lOpenCL

Thanks.

0 Likes