Open CL programming with G++ in Windows - c++

I am trying to write Open CL programs in C++ using G++ compiler in Windows 10 but I am not able to find any SDK for my work.
Nvidia CUDA requires Visual Studio compilers to work and AMD AMP SDK seems to be discontinued saying that the libraries are included in the driver itself.
My PC has both AMD and Nvidia GPUs so any of the implementation should be fine with OpenCL. Can anyone suggest how can I carry on and also kindly clarify on how to use the libraries present in OpenCL driver in my C++ program as mentioned by AMD if possible?
Edit :
I found out that OpenCL libraries are already present in Windows as,
C:\Windows\System32\OpenCL.dll
We only need headers to compile our program using g++. It can be done as shown below.
Install OpenCL headers from below,
https://packages.msys2.org/package/mingw-w64-x86_64-opencl-headers
Once headers are present in include directory of MinGW64, I wrote my program normally and compiled the program using the below g++ command.
g++ main.cpp C:\Windows\System32\OpenCL.dll -o main.exe
And that's it. It worked !!!
http://arkanis.de/weblog/2014-11-25-minimal-opencl-development-on-windows was of great help to understand the OpenCL library implementation in Windows.

You don't need to install anything besides Visual Studio Community with the C++ compiler, and GPU drivers (these already contain the OpenCL runtimes).
For OpenCL development, you only need the OpenCL header files and the lib file. To setup Visual Studio, see here. This works for any OpenCL device, including Nvidia/AMD/Intel GPUs and even Intel CPUs if the CPU runtime is installed.
Alternatively, you can use my lightweight OpenCL-Wrapper. This comes with all Visual Studio settings already in the project file. OpenCL learning and developing with the wrapper is so much simpler than with the cumbersome OpenCL bindings directly.

Related

Is Intel OpenCL SDK available for Windows 11?

I want to run some C++ on my Laptop GPU with Windows 11. I saw in the Internet that I need the Intel OpenCL SDK. I tried to download it, but I got a warning that it's only recommended for Windows 10. I still continued with the installation, but i can't find all the C++ header files. Is that because I use Windows 11 or is there another reason for this?
I thought that the Download would contain all the OpenCL header files and so on.
You don't need the Intel OpenCL SDK for OpenCL development. All you need is the graphics driver, which probably is already present, and the OpenCL header files. For how to set it up in a Visual Studio Community project, see here; this works for Intel/AMD GPUs too, and on both Windows 10 and 11.

Use Shared Object (.so) in a C++ project develop in Windows with Visual Studio for Linux using WSL

For a task I have I must develop C++ code for Linux but from Windows. I'm using Visual Studio 2019 with WSL 2 and the tests I've run worked well, it compile .out/.so/.a and giving me the ability to debug the code as if it was a regular project.
The problem is when I need to link external .so to my project. In regular Windows-VS-c++ development I define the input linker to the directory of the .lib. But in Linux their no .lib (or is their? I'm not familiar with Linux-C++).
In short how do I consume Shared Object (.so) files from another project using Visual Studio 2019 compiling for Linux using WSL 2 ?
Ask your boss permission to install Linux on your work computer
(e.g. some genuine Linux distribution such as Debian or Ubuntu in some separate disk partition). This is -in terms of effort and your time- the cheapest route to follow.
Read of course Advanced Linux Programming, syscalls(2), How to write shared libraries, dlopen(3), proc(5), elf(5), ld.so(8), the Program Library HowTo, the C++ dlopen minihowto, the documentation of GCC, the documentation of GNU make, the documentation of GNU binutils, the documentation of GDB.
Of course, read more about programming in C++. C++ is a difficult language (on both Linux and Windows). Refer to this website. Read later the C++11 standard n3337.
If you code a single C++ translation unit foo.cc (you could use GNU emacs to edit it), compile it first into a shared object foo.so using a command g++ -Wall -Wextra -g -fPIC -shared foo.cc -o foo.so (all warnings, DWARF debug information, position independent code).
If your C++ shared library is built from several C++ translation units, learn how to use a build automation tool such as GNU make or ninja. And use it in a terminal emulator on the command line. Be aware of ASLR. Use strace(1), ltrace(1), gdb(1) to understand the dynamic behavior of your or others software.
In some cases, generating parts of your C++ code (e.g. with ANTLR or SWIG) is worthwhile. Notice that Qt is doing so.
Consider using some cross-platform C++ frameworks such as Qt or POCO.
For some projects, writing your GCC plugin could be useful. See this draft report.
In short how do I consume Shared Object (.so) files from another project using Visual Studio 2019 compiling for Linux using WSL 2 ?
Don't use Visual Studio (I never used it myself, but according to rumors it is unfit for cross-compilation from Windows to Linux). Perhaps use Visual Studio Code (to which I prefer GNU emacs, but you might try gedit, geany, vim, kate etc...)
On Linux, all IDE for C++ programming would run a GCC or Clang compiler (and you'll need to understand what compilation command they are running for you). You could also be interested by the Clang static analyzer or by Frama-C++
Take inspiration from existing open source C++ projects on Linux
Look on github or gitlab - e.g. libonion, Qt, FLTK, fish, icecream) ... Read also Linux From Scratch.
above all, approach Linux programming with a fresh and open mindset.
Read about the Unix philosophy, it is relevant on Linux. And very different from Microsoft design ideas related to Windows.
I never used Windows (and I am coding since 1974), but my biased opinion is that WSL is targeted for Linux gurus who (sadly for them) have to use Windows. I believe WSL is not targeting Linux newbies.

How do I use other c++ compilers with CUDA on Windows?

I'm trying to build a simple application with CUDA and I've been trying for hours on end and I just can't make it work on windows. nvcc absolutely refuses to compile without Visual Studio's compiler which doesn't support things I need. I tried building using nvcc with clang but It just asks me to use Visual Studio's compiler. I've also tried using clang directly since it now supports CUDA but I receive this error:
clang++.exe: error: Unsupported CUDA gpu architecture: compute_52
This makes no sense to me because I have the CUDA toolkit version 7.5 and my graphics card is a GTX 970 (two of them). I have googled this extensively and everywhere I come across the error the person always has is their CUDA toolkit is < 7.5. I'm on the brink of tears right now trying to get something as simple as VLA to work on this CUDA application and I just can't achieve it...
The CUDA windows toolchain requires the Visual Studio C++ compiler. You cannot use anything else on that platform. If the VS compiler doesn't support the language features you need within CUDA host code, you have no choice but to change platforms, or your expectations.
You can still potentially compile non-CUDA host code using another compiler and then link that code using NVCC and the VS toolchain.
Try to use clang-cl, --cubin=clang-cl.exe
It may be worth to work on a Linux VM or WSL2 within windows. As per the CUDA docs.
To compile new CUDA applications, a CUDA Toolkit for Linux x86 is
needed. CUDA Toolkit support for WSL is still in preview stage as
developer tools such as profilers are not available yet. However, CUDA
application development is fully supported in the WSL2 environment, as
a result, users should be able to compile new CUDA Linux applications
with the latest CUDA Toolkit for x86 Linux.
https://docs.nvidia.com/cuda/wsl-user-guide/index.html#:~:text=However%2C%20CUDA%20application%20development%20is,becomes%20available%20within%20WSL%202.

Remove errors in clgpustress C++ GPU stress code

I opened the C++ code from clgpustress in Visual Studio 2010 but it shows many errors, as seen in the following image:
How to add the libraries? Or is there another C++ gpu stress code?
I am author of the clgpustress.
clgpustress requires the popt library which provides the command line
parsing.
Unfortunatelly, popt is not too much portable and it is compilable under
Unix/Linux systems. I created on the github special version of a popt library
here: https://github.com/matszpk/popt-msvc.
This version was created to be compilable under MSVC and Windows.
Download that version and try to compile and link with clgpustress.
CLgpustress is an OpenCL application, so it requires the OpenCL runtimes and development libraries which can be found in AMDAPP package.

Compile A MSVC++2010 Project So It Can Run On Ubuntu

I have a MSVC++ 2010 project. All the libraries it's using are cross platform (SDL, OpenGL and FLTK).
Obviously, all I have to do right now is press the debug button and it will compile a nice old .exe for me which can now run on Windows, as long as the DLL files are with it.
I had thought before that if you use cross platform libraries, then the generated .exe would run fine on Ubuntu too. I recently found out that this is not possible, and that the program must be compiled in a special way to run on a certain platform.
Is it possible to compile my project in this magical way with MSVC++ 2010 so that it can run on a Ubuntu computer? If so, then could you please answer my question with some clear steps as to what I should do to compile it this way, keeping in mind I'm new to how all this cross platform stuff works?
EDIT:
If I cannot compile a MSVC++ 2010 project for Ubuntu, is there an IDE I could use that could compile the project for both Windows and Ubuntu?
Thanks.
I suggest you use QT. http://qt.digia.com/
It's probably the best cross platform IDE that can let you compile for Windows, Mac and Linux(ubuntu) systems.
Nope, not possible. While the binary code corresponding to the program can be portable, that's not enough. Executable formats on various file systems are different and not compatible. The executable format is essentially a packaging of the binary data and wrapping it with a header that the target file system understands. In order to produce executables for Ubuntu, the linker must support it. MSVC++ doesn't support Linux formats.