Both Nvidia CUDA and ATI Stream OpenCL implementation support the Khronos ICD extension, so when you call clGetPlatformIDs you'll get two different platforms, and therefore you can query for CPU/GPU devices on these platforms and of course the ATI platform will return the CPU device and Nvidia platform will return the GPU device.
Then you can create CommandQueues on these devices and start your kernel. Of course this means that it's not trivial to share the task between GPU and CPU, but at least having a button in your app that switches from CPU to GPU would be quite easy to do.
If you want to code on your CPU/GPU the AMD guide is probably a good place to start. To get the OpenCL drivers working on a computer with an AMD APU/GPU you simply need to install the fglrx driver from the software center. To test that its working and to write code you may also want the AMD APP SDK.
I used version 3.0 of the SDK from the AMD site.
The install guide is here.
Once you have it you can follow their programming guide.
Here is one of the early examples modified to simply print out the number of compute units on your machines GPU:
//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
// Modified by Aedazan for learning purposes.
// Uploaded as fair use teaching material 17 U.S. Code § 107.
// A minimalist OpenCL program.
#include <CL/cl.h>
#include <stdio.h>
#define NWITEMS 512
// A simple memset kernel
//const char *source = "__kernel void memset( __global uint *dst ) \n" "{ \n" " dst[get_global_id(0)] = get_global_id(0); \n" "} \n";
const char *source = "__kernel void memset( __global uint *dst ) " "{ " " dst[get_global_id(0)] = get_global_id(0)*get_global_id(0);"
""
"\n" "} \n";
int main(int argc, char ** argv)
{
// 1. Get a platform.
cl_platform_id platform;
clGetPlatformIDs( 1, &platform, NULL );
// 2. Find a gpu device.
cl_device_id device;
cl_uint compute_units;
clGetDeviceIDs( platform, CL_DEVICE_TYPE_GPU,1,&device,NULL);
clGetDeviceInfo( device, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &compute_units, NULL);
printf("Compute units: %d\n", compute_units);
// 3. Create a context and command queue on that device.
cl_context context = clCreateContext( NULL, 1, &device, NULL, NULL, NULL);
cl_command_queue queue = clCreateCommandQueue( context, device, 0, NULL );
// 4. Perform runtime source compilation, and obtain kernel entry point.
cl_program program = clCreateProgramWithSource( context, 1, &source, NULL, NULL );
clBuildProgram( program, 1, &device, NULL, NULL, NULL );
cl_kernel kernel = clCreateKernel( program, "memset", NULL );
// 5. Create a data buffer.
cl_mem buffer = clCreateBuffer( context, CL_MEM_WRITE_ONLY, NWITEMS * sizeof(cl_uint), NULL, NULL );
// 6. Launch the kernel. Let OpenCL pick the local work size.
size_t global_work_size = NWITEMS;
clSetKernelArg(kernel, 0, sizeof(buffer), (void*) &buffer);
clEnqueueNDRangeKernel( queue,
kernel,
1,
NULL,
&global_work_size,
NULL, 0, NULL, NULL);
clFinish( queue );
// 7. Look at the results via synchronous buffer map.
cl_uint *ptr;
ptr = (cl_uint *) clEnqueueMapBuffer( queue, buffer, CL_TRUE, CL_MAP_READ, 0, NWITEMS * sizeof(cl_uint), 0, NULL, NULL, NULL );
int i;
for(i=0; i < NWITEMS; i++)
//printf("%d %d\n", i, ptr[i]);
return 0;
}
You can compile it with the following line. It assumes you installed the SDK as root into the default locations.
gcc -o computec.bin -I /opt/AMDAPPSDK-3.0/include/ -L /opt/AMDAPPSDK-3.0/lib/x86_64/ test.c -lOpenCL
Best Answer
install packets
Generic ubuntu packages for OpenCL
Basic installation
sudo apt install ocl-icd-libopencl1 sudo apt install opencl-headers sudo apt install clinfo
Package that allows to compile OpenCL code (1.2 I think)
Needed to link and compile
sudo apt install ocl-icd-opencl-dev
For Intel GT core
Package that enables runnig openCL on Intel GT, IvyBridge and up
sudo apt install beignet
For SandyBridge Intel CPU and possible others
Download this file OpenCL™ Runtime 16.1.1 for Intel® Core™ and Intel® Xeon® Processors for Ubuntu* (64-bit) On https://software.intel.com/en-us/articles/opencl-drivers#latest_linux_SDK_release
Install packages for turning rpm to deb
sudo apt-get install -y rpm alien libnuma1
Untar downloaded file
tar -xvf opencl_runtime_16.1.1_x64_ubuntu_6.4.0.25.tgz cd opencl_runtime_16.1.1_x64_ubuntu_6.4.0.25/rpm/
Turn rpm files to debfakeroot alien --to-deb opencl-1.2-base-6.4.0.25-1.x86_64.rpm fakeroot alien --to-deb opencl-1.2-intel-cpu-6.4.0.25-1.x86_64.rpm
Install .deb packagessudo dpkg -i opencl-1.2-base_6.4.0.25-2_amd64.deb sudo dpkg -i opencl-1.2-intel-cpu_6.4.0.25-2_amd64.deb
Touch local config filesudo touch /etc/ld.so.conf.d/intelOpenCL.conf
Open the filesudo vim /etc/ld.so.conf.d/intelOpenCL.conf
and add the lineCreate a vendors dir and add intel.icd
sudo mkdir -p /etc/OpenCL/vendors sudo ln /opt/intel/opencl-1.2-6.4.0.25/etc/intel64.icd /etc/OpenCL/vendors/intel64.icd sudo ldconfig
test if this worked
Command to list your devices
clinfo
Dowload this file
Run this code to make sure everything works
tar xzvf tools-master.tar.gz cd tools-master make ./print-devices ./cl-demo 1000 10
This should print out GOOD in the endFor Nvidia
install nvidia drivers (I used 370), this should include all the runtime dirvers
Usefull linkes I have used to put this together
https://wiki.tiker.net/OpenCLHowTo http://korniychuk.org.ua/instruction/how-to-use-opencl-on-ubuntu-16-04/ https://laanwj.github.io/2016/05/06/opencl-ubuntu1604.html https://software.intel.com/en-us/articles/opencl-drivers#latest_linux_SDK_release https://software.intel.com/en-us/forums/opencl/topic/285869 https://streamcomputing.eu/blog/2011-06-24/install-opencl-on-debianubuntu-orderly/ https://software.intel.com/en-us/forums/opencl/topic/390630 https://stackoverflow.com/questions/16977216/opencl-compile-on-linux