Skip to content

Instantly share code, notes, and snippets.

@ShawonAshraf
Created February 26, 2021 19:07
Show Gist options
  • Save ShawonAshraf/6a0326c4bbe5e434c0c43effca21fc72 to your computer and use it in GitHub Desktop.
Save ShawonAshraf/6a0326c4bbe5e434c0c43effca21fc72 to your computer and use it in GitHub Desktop.
AMD Navi (Radeon RX 5500, 5600, 5700) OpenCL with ROCm for Fedora (and REHL, CentOS, ...)

AMD Navi OpenCL with ROCm

Mesa doesn't provide OpenCL 1.2 support for Navi

AMD provide closed-source AMDGPU-PRO OpenCL 2.0 (PAL for Vega and Navi and Legacy for older product)

Alternatively you can use open-sourced AMD Radeon Open Compute platforM with OpenCL 2.0 support (Hardware Support)

It doesn't breaks Mesa/LLVM dependencies or UEFI Secure Boot

Add ROCm repository and install

REHL / CentOS / Fedora

Create a new repository file with vi or nano sudo vi /etc/yum.repos.d/rocm.repo and past

[ROCm]
name=ROCm
#set https instead http
baseurl=https://repo.radeon.com/rocm/yum/rpm
enabled=1
#AMD dosen't sign RPM packages
gpgcheck=0

Install packages

REHL / CentOS / Fedora

Standard sudo dnf install rocm-opencl hsakmt-roc or devel sudo dnf install rocm-opencl-devel hsakmt-roct-devel

Official ROCm wiki

From my Fedora 31 with RX 5700 xt

0b:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 10 [Radeon RX 5600 OEM/5600 XT / 5700/5700 XT] [1002:731f] (rev c1)
	Subsystem: Sapphire Technology Limited Device [1da2:e408]
	Kernel driver in use: amdgpu
	Kernel modules: amdgpu
$ dnf repository-packages ROCm list installed
Paquets installés
comgr.x86_64                1.6.0.124_rocm_rel_3.3_19_7ac2e34-1            @ROCm
hsa-rocr-dev.x86_64         1.1.30300.0_rocm_rel_3.3_19_23fc088b-1         @ROCm
hsakmt-roct.x86_64          1.0.9_330_gd84bc09-1                           @ROCm
rocm-opencl.x86_64          2.0.0-rocm_rel_3.3_19_363509c8d                @ROCm
$ clinfo 
Number of platforms                               1
  Platform Name                                   AMD Accelerated Parallel Processing
  Platform Vendor                                 Advanced Micro Devices, Inc.
  Platform Version                                OpenCL 2.1 AMD-APP (3098.0)
  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                                   AMD Accelerated Parallel Processing
Number of devices                                 1
  Device Name                                     gfx1010
  Device Vendor                                   Advanced Micro Devices, Inc.
  Device Vendor ID                                0x1002
  Device Version                                  OpenCL 2.0 
  Driver Version                                  3098.0 (HSA1.1,LC)
  Device OpenCL C Version                         OpenCL C 2.0 
  Device Type                                     GPU
  Device Board Name (AMD)                         Navi 10 [Radeon RX 5600 OEM/5600 XT / 5700/5700 XT]
  Device Topology (AMD)                           PCI-E, 0b:00.0
  Device Profile                                  FULL_PROFILE
  Device Available                                Yes
  Compiler Available                              Yes
  Linker Available                                Yes
  Max compute units                               20
  SIMD per compute unit (AMD)                     2
  SIMD width (AMD)                                32
  SIMD instruction width (AMD)                    1
  Max clock frequency                             100MHz
  Graphics IP (AMD)                               10.10
  Device Partition                                (core)
    Max number of sub-devices                     20
    Supported partition types                     None
    Supported affinity domains                    (n/a)
  Max work item dimensions                        3
  Max work item sizes                             1024x1024x1024
  Max work group size                             256
  Preferred work group size (AMD)                 256
  Max work group size (AMD)                       1024
  Preferred work group size multiple              32
  Wavefront width (AMD)                           32
  Preferred / native vector sizes                 
    char                                                 4 / 4       
    short                                                2 / 2       
    int                                                  1 / 1       
    long                                                 1 / 1       
    half                                                 1 / 1        (cl_khr_fp16)
    float                                                1 / 1       
    double                                               1 / 1        (cl_khr_fp64)
  Half-precision Floating-point support           (cl_khr_fp16)
    Denormals                                     No
    Infinity and NANs                             No
    Round to nearest                              No
    Round to zero                                 No
    Round to infinity                             No
    IEEE754-2008 fused multiply-add               No
    Support is emulated in software               No
  Single-precision Floating-point support         (core)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 Yes
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               Yes
    Support is emulated in software               No
    Correctly-rounded divide and sqrt operations  Yes
  Double-precision Floating-point support         (cl_khr_fp64)
    Denormals                                     Yes
    Infinity and NANs                             Yes
    Round to nearest                              Yes
    Round to zero                                 Yes
    Round to infinity                             Yes
    IEEE754-2008 fused multiply-add               Yes
    Support is emulated in software               No
  Address bits                                    64, Little-Endian
  Global memory size                              8573157376 (7.984GiB)
  Global free memory (AMD)                        8372224 (7.984GiB)
  Global memory channels (AMD)                    8
  Global memory banks per channel (AMD)           4
  Global memory bank width (AMD)                  256 bytes
  Error Correction support                        No
  Max memory allocation                           7287183769 (6.787GiB)
  Unified memory for Host and Device              No
  Shared Virtual Memory (SVM) capabilities        (core)
    Coarse-grained buffer sharing                 Yes
    Fine-grained buffer sharing                   Yes
    Fine-grained system sharing                   No
    Atomics                                       No
  Minimum alignment for any data type             128 bytes
  Alignment of base address                       1024 bits (128 bytes)
  Preferred alignment for atomics                 
    SVM                                           0 bytes
    Global                                        0 bytes
    Local                                         0 bytes
  Max size for global variable                    7287183769 (6.787GiB)
  Preferred total size of global vars             8573157376 (7.984GiB)
  Global Memory cache type                        Read/Write
  Global Memory cache size                        16384 (16KiB)
  Global Memory cache line size                   64 bytes
  Image support                                   No
    Base address alignment for 2D image buffers   0 bytes
    Pitch alignment for 2D image buffers          0 pixels
  Max number of pipe args                         16
  Max active pipe reservations                    16
  Max pipe packet size                            2992216473 (2.787GiB)
  Local memory type                               Local
  Local memory size                               65536 (64KiB)
  Local memory syze per CU (AMD)                  65536 (64KiB)
  Local memory banks (AMD)                        32
  Max number of constant args                     8
  Max constant buffer size                        7287183769 (6.787GiB)
  Preferred constant buffer size (AMD)            16384 (16KiB)
  Max size of kernel argument                     1024
  Queue properties (on host)                      
    Out-of-order execution                        No
    Profiling                                     Yes
  Queue properties (on device)                    
    Out-of-order execution                        Yes
    Profiling                                     Yes
    Preferred size                                262144 (256KiB)
    Max size                                      8388608 (8MiB)
  Max queues on device                            1
  Max events on device                            1024
  Prefer user sync for interop                    Yes
  Number of P2P devices (AMD)                     0
  P2P devices (AMD)                               <printDeviceInfo:147: get number of CL_DEVICE_P2P_DEVICES_AMD : error -30>
  Profiling timer resolution                      1ns
  Profiling timer offset since Epoch (AMD)        0ns (Thu Jan  1 01:00:00 1970)
  Execution capabilities                          
    Run OpenCL kernels                            Yes
    Run native kernels                            No
    Thread trace supported (AMD)                  No
    Number of async queues (AMD)                  8
    Max real-time compute queues (AMD)            8
    Max real-time compute units (AMD)             20
  printf() buffer size                            4194304 (4MiB)
  Built-in kernels                                (n/a)
  Device Extensions                               cl_khr_fp64 cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_3d_image_writes cl_khr_byte_addressable_store cl_khr_fp16 cl_khr_gl_sharing cl_amd_device_attribute_query cl_amd_media_ops cl_amd_media_ops2 cl_khr_image2d_from_buffer cl_khr_subgroups cl_khr_depth_images cl_amd_copy_buffer_p2p cl_amd_assembly_program 

NULL platform behavior
  clGetPlatformInfo(NULL, CL_PLATFORM_NAME, ...)  AMD Accelerated Parallel Processing
  clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, ...)   Success [AMD]
  clCreateContext(NULL, ...) [default]            Success [AMD]
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_DEFAULT)  Success (1)
    Platform Name                                 AMD Accelerated Parallel Processing
    Device Name                                   gfx1010
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_CPU)  No devices found in platform
  clCreateContextFromType(NULL, CL_DEVICE_TYPE_GPU)  Success (1)
    Platform Name                                 AMD Accelerated Parallel Processing
    Device Name                                   gfx1010
  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                                 AMD Accelerated Parallel Processing
    Device Name                                   gfx1010

ICD loader properties
  ICD loader Name                                 OpenCL ICD Loader
  ICD loader Vendor                               OCL Icd free software
  ICD loader Version                              2.2.12
  ICD loader Profile                              OpenCL 2.2
$ clpeak 

Platform: AMD Accelerated Parallel Processing
  Device: gfx1010
    Driver version  : 3098.0 (HSA1.1,LC) (Linux x64)
    Compute units   : 20
    Clock frequency : 100 MHz

    Global memory bandwidth (GBPS)
      float   : 380.76
      float2  : 395.42
      float4  : 378.60
      float8  : 349.30
      float16 : 328.73

    Single-precision compute (GFLOPS)
      float   : 9969.46
      float2  : 10078.73
      float4  : 10105.71
      float8  : 9931.42
      float16 : 9733.45

    half-precision compute (GFLOPS)
      half   : 4773.16
      half2  : 19634.51
      half4  : 19819.50
      half8  : 19292.39
      half16 : 18667.01

    Double-precision compute (GFLOPS)
      double   : 639.87
      double2  : 639.40
      double4  : 638.14
      double8  : 635.64
      double16 : 630.66

    Integer compute (GIOPS)
      int   : 2035.75
      int2  : 2035.54
      int4  : 2034.42
      int8  : 2032.29
      int16 : 2031.85

    Transfer bandwidth (GBPS)
      enqueueWriteBuffer         : 25.34
      enqueueReadBuffer          : 19.51
      enqueueMapBuffer(for read) : 142217.45
        memcpy from mapped ptr   : 18.96
      enqueueUnmap(after write)  : 228455.72
        memcpy to mapped ptr     : 19.58

    Kernel launch latency : 11.94 us
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment