0
votes

I am learning OpenCL from the beginning and get confused by platform = host + device idea. In my work PC there are 2 platforms detected: Platform 0 has only the CPU, Platform 1 has only the NVIDIA GPU. Detected platforms

This PC actually has also an Intel GPU but I assume that it doesn't support OpenCL so it does not show here. My question goes: In an OpenCL application there are host and device. Normally the host and device come from one platform according to my understanding from book . Then in my PC I need to use either the CPU or the NVIDIA GPU as both host and device for the OpenCL application. Is this true?

I tried to search by myself, some answers indeed help me to understand more in this topic like this one: What is a host in opencl?. But about using one hardware for both host and device is not being answered or confirmed by my searching.

1

1 Answers

5
votes

I think you're mixing up some terminology here.

  • The host is the regular program executing on the CPU itself.
  • The platforms are provided by OpenCL drivers, representing a set of devices and features.
  • The devices are underlying hardware that may be used for OpenCL, provided by a platform.

A platform may provide multiple different devices: For example, if you have the Nvidia OpenCL driver installed, it provides an OpenCL device for every supported GPU. Meanwhile, the Intel driver provides the Intel CPU as an OpenCL device.

Generally, your program flow will look something like this:

  1. Find OpenCL platforms using clGetPlatformIds
  2. Find OpenCL devices using clGetDeviceIds for whichever platform(s) you want to use.
  3. Create the OpenCL context, program, command queue, and kernel using clCreateContext, clCreateProgram, etc.
  4. Copy necessary data to buffers or kernel parameters.
  5. Execute the kernel on one or more devices using clEnqueueNDRangeKernel.
  6. Copy data back from buffers