ubuntuopencllinux-device-driverubuntu-18.04amd-processor

How can I install opencl on Ubuntu for AMD Ryzen Mobile CPU


I have a notebook with an AMD Ryzen 5 2500U (with integrated Radeon Vega 8 mobile GPU) processor and use Ubuntu 18.04.2. I would like to run some OpenCL calculations with C++ on the CPU and GPU. My problem is that I'm not sure how OpenCL can recognize the CPU.

I have installed AMDGPU-PRO from the AMD website and the AMD APP SDK 3.0. After I run clinfo I get the following output:

Number of platforms                               2
Platform Name                                   Clover
  Platform Vendor                                 Mesa
  Platform Version                                OpenCL 1.1 Mesa 18.2.8
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_icd
  Platform Extensions function suffix             MESA
Platform Name                                   AMD Accelerated 
Parallel Processing
  Platform Vendor                                 Advanced Micro Devices, Inc.
  Platform Version                                OpenCL 2.1 AMD-APP (2671.3)
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_icd cl_amd_event_callback cl_amd_offline_devices 
  Platform Host timer resolution                  1ns
  Platform Extensions function suffix             AMD
  Platform Name                                   Clover
Number of devices                                 1
  Device Name                                     AMD RAVEN (DRM 3.26.0, 4.18.0-16-generic, LLVM 7.0.0)
  Device Vendor                                   AMD
  Device Vendor ID                                0x1002
  Device Version                                  OpenCL 1.1 Mesa 18.2.8
  Driver Version                                  18.2.8
  Device OpenCL C Version                         OpenCL C 1.1 
  Device Type                                     GPU
  Device Profile                                  FULL_PROFILE
  Device Available                                Yes
  Compiler Available                              Yes
  Max compute units                               8
  Max clock frequency                             1100MHz
  Max work item dimensions                        3
  Max work item sizes                             256x256x256
  Max work group size                             256
  Preferred work group size multiple              64
  Preferred / native vector sizes                 
    char                                                16 / 16      
    short                                                8 / 8       
    int                                                  4 / 4       
    long                                                 2 / 2       
    half                                                 8 / 8        (cl_khr_fp16)
    float                                                4 / 4       
    double                                               2 / 2        (cl_khr_fp64)
  Half-precision Floating-point support           (cl_khr_fp16)

...


  Platform Name                                   AMD Accelerated Parallel Processing
Number of devices                                 1
  Device Name                                     gfx902
  Device Vendor                                   Advanced Micro Devices, Inc.
  Device Vendor ID                                0x1002
  Device Version                                  OpenCL 1.2 AMD-APP (2671.3)
  Driver Version                                  2671.3 (PAL,HSAIL)
  Device OpenCL C Version                         OpenCL C 1.2 
  Device Type                                     GPU
  Device Board Name (AMD)                         Unknown AMD GPU
  Device Topology (AMD)                           PCI-E, 05:00.0
  Device Profile                                  FULL_PROFILE

 .......

NULL platform behavior
  clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  No platform
  clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...)   No platform
  clCreateContext(NULL, ...) [default]            No platform
  clCreateContext(NULL, ...) [other]              Success [MESA]
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT)  Success (1)
 
    Platform Name                                 Clover
 
    Device Name                                   AMD RAVEN (DRM 3.26.0, 4.18.0-16-generic, LLVM 7.0.0)
 
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  No devices found in platform
 
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  Success (1)
 
    Platform Name                                 Clover
 
    Device Name                                   AMD RAVEN (DRM 3.26.0, 4.18.0-16-generic, LLVM 7.0.0)
 
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ACCELERATOR)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CUSTOM)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_ALL)  Success (1)
    Platform Name                                 Clover
    Device Name                                   AMD RAVEN (DRM 3.26.0, 4.18.0-16-generic, LLVM 7.0.0)

The first platform Clover with Device AMD RAVEN (DRM 3.26.0, 4.18.0-16-generic, LLVM 7.0.0) has the Device type GPU and the second platform with Device gfx902 also seems to be the GPU of my system.

So my question is: What do I have to install so that OpenCL also recognizes the CPU of my system?

Thanks for helping!


Solution

  • Using the CPU with OpenCL requires a CPU-capable OpenCL implementation, naturally. In particular POCL should be available. AMD seems to have abandoned their CPU OpenCL implementation, and Intel claims theirs is only for their brand of processors.

    By the way, mixing OpenCL implementations for the same device (such as Clover and APP) may give surprising results should something try to autodistribute work to all devices. It should be fine if you can specify which devices to use.