Basic concept: Hosts and devices

Time for some basic concepts of OpenCL. As I notice a growing number of visitors to this page, I notices 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 is there is one host and 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&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 a “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 and 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 but delicate, as I noticed is that sometimes the names on different OSes differ. Hopefully this gets fixed, but don’t assume.

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

It is possible to make your own driver; this can be one made from scratch, a wrapper around an existing driver (i.e. 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 implementing 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 the name (CL_DEVICE_NAME) can be trusted. 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 with each 1 device. Wrong. You get 3 hosts with all one device: Nvidia with its GPU, Intel with its CPU and AMD with Intel’s CPU. This means you cannot really count how many devices by dumb counting. Also the number of supported devices Since some optimising is done by the driver you 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 its 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 education-page for more and come back later for more in this series.

Related Posts