Basic concept: Hosts and devices

Time for some basic concepts of OpenCL. As I notice a growing number of visitors to this page, I noticed I have actually not written much about coding and basics.

One of the first steps of an OpenCL program is selecting hosts and devices. If you program for a tablet, which has one chip and a screen, you don’t think of several devices. And if you log in on a server, your context there is one host. That’s the one you logged into. If you have read my article about how to install all drivers on Ubuntu, you have gotten several clues. I added some tips and tricks, but not too many. If you know more stuff about this subject yourself, please share with others in the comments.

Hosts

The best translation for an “OpenCL-host” (also named “OpenCL-platform”) is “OpenCL-driver”. On OSX these are already installed, on Windows and Linux you need to install them by downloading them from the internet first. Currently “hosts” are provided by Nvidia, AMD, Intel and IBM – ARM will come probably this year. Furthermore there are projects like Nokia’s CLEP and IBM’s common runtime (which creates one host which are all others combined).

When you request to get a list of all hosts, the OpenCL-library checks which drivers are installed. It returns you the names of all drivers that have found one or more devices. You can select by name (CL_PLATFORM_NAME). This selecting on names is a very common method, used in most SDK-examples. It is delicate, as I noticed that sometimes the names on different OSes differ. Hopefully this gets fixed, but don’t assume.

For Nvidia CUDA or Intel ISPC you skip this step, as there is only one driver and thus one host available. Now you know why you cannot skip this step for OpenCL.

It is possible to make your own driver. This can be one made from scratch, a wrapper around an existing driver (e.g. when you want to do some automated optimising), or if you’re good even an interface to the CUDA-driver by translating the OpenCL-code to CUDA. All you need to do is implement the OpenCL header-file(s).

Using AMD’s clinfo on my PC gave me this (I left out the extensions, because that is another subject):

Number of platforms: 3
  Platform Profile:		 FULL_PROFILE
  Platform Version:		 OpenCL 1.1 LINUX
  Platform Name:		 Intel(R) OpenCL
  Platform Vendor:		 Intel(R) Corporation

  Platform Profile:		 FULL_PROFILE
  Platform Version:		 OpenCL 1.0 CUDA 4.0.1
  Platform Name:		 NVIDIA CUDA
  Platform Vendor:		 NVIDIA Corporation

  Platform Profile:		 FULL_PROFILE
  Platform Version:		 OpenCL 1.1 AMD-APP-SDK-v2.4 (595.10)
  Platform Name:		 AMD Accelerated Parallel Processing
  Platform Vendor:		 Advanced Micro Devices, Inc.

So in this case there are 3 hosts available.

Devices

Each host can have one or more OpenCL devices. A device can be a CPU, a GPU and/or an Accelerator (think the processor in the PS3 or an FPGA). Like with selecting the host, don’t be too sure you can trust the name (CL_DEVICE_NAME). You also might encounter an unknown device – better is to check a few characteristics for selecting a kernel or fill a kernel-template optimally.

An example: If you have all drivers installed, and one Nvidia plus a recent Intel CPU in your PC, you might expect to find 2 hosts, each with one device. Wrong. You get 3 hosts with one device each: Nvidia with its GPU, Intel with its CPU and AMD with Intel’s CPU. This means you cannot really count how many devices there are by simply counting them. Since the driver does some optimisation, you may get different results with the same device.

Be creative with finding the best devices and hosts. Sometimes you might want to have the reverse tree: a list of devices and their hosts. Or why not put a mini-benchmark in the installation-program?

More

I hope you learnt to look at OpenCL differently. Check out the for developers page for more basic concepts of OpenCL and come back later for more in this series.

Scroll to Top