Frequency of GPU


#1

I try GPGPU on Hikey 960. I run on AOSP in https://snapshots.linaro.org/96boards//hikey960/linaro/aosp-master/latest/.
In this image, clinfo say a little bit strange thing:

hikey960:/data/local/tmp # ./clinfo
./clinfo
Number of platforms                               1
  Platform Name                                   ARM Platform
  Platform Vendor                                 ARM
  Platform Version                                OpenCL 2.0 v1.r9p0-01rel0.ce7494c0731c96b36fc618ba44190051
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             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_byte_addressable_store cl_khr_3d_image_writes cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp16 cl_khr_icd cl_khr_egl_image cl_khr_image2d_from_buffer cl_khr_depth_images cl_khr_il_program cl_arm_core_id cl_arm_printf cl_arm_thread_limit_hint cl_arm_non_uniform_work_group_size cl_arm_import_memory cl_arm_shared_virtual_memory
  Platform Extensions function suffix             ARM

  Platform Name                                   ARM Platform
Number of devices                                 1
  Device Name                                     Mali-G71
  Device Vendor                                   ARM
  Device Vendor ID                                0x60a00002
  Device Version                                  OpenCL 2.0 v1.r9p0-01rel0.ce7494c0731c96b36fc618ba44190051
  Driver Version                                  2.0
  Device OpenCL C Version                         OpenCL C 2.0 v1.r9p0-01rel0.ce7494c0731c96b36fc618ba44190051
  Device Type                                     GPU
  Device Profile                                  FULL_PROFILE
  Device Available                                Yes
  Compiler Available                              Yes
  Linker Available                                Yes
  Max compute units                               8
  Max clock frequency                             5MHz
  Device Partition                                (core)
    Max number of sub-devices                     0
    Supported partition types                     None
    Supported affinity domains                    (n/a)
  Max work item dimensions                        3
  Max work item sizes                             256x256x256
  Max work group size                             384
  Preferred work group size multiple              4
  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                                               0 / 0        (n/a)
  Half-precision Floating-point support           (cl_khr_fp16)
    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
  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  No
  Double-precision Floating-point support         (n/a)
  Address bits                                    64, Little-Endian
  Global memory size                              3092430848 (2.88GiB)
  Error Correction support                        No
  Max memory allocation                           773107712 (737.3MiB)
  Unified memory for Host and Device              Yes
  Shared Virtual Memory (SVM) capabilities        (core)
    Coarse-grained buffer sharing                 Yes
    Fine-grained buffer sharing                   No
    Fine-grained system sharing                   No
    Atomics                                       No
  Shared Virtual Memory (SVM) capabilities (ARM)  
    Coarse-grained buffer sharing                 Yes
    Fine-grained buffer sharing                   No
    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                    65536 (64KiB)
  Preferred total size of global vars             0
  Global Memory cache type                        Read/Write
  Global Memory cache size                        524288 (512KiB)
  Global Memory cache line size                   64 bytes
  Image support                                   Yes
    Max number of samplers per kernel             16
    Max size for 1D images from buffer            65536 pixels
    Max 1D or 2D image array size                 2048 images
    Base address alignment for 2D image buffers   32 bytes
    Pitch alignment for 2D image buffers          64 pixels
    Max 2D image size                             32768x32768 pixels
    Max 3D image size                             32768x32768x32768 pixels
    Max number of read image args                 128
    Max number of write image args                64
    Max number of read/write image args           64
  Max number of pipe args                         16
  Max active pipe reservations                    1
  Max pipe packet size                            1024
  Local memory type                               Global
  Local memory size                               32768 (32KiB)
  Max number of constant args                     8
  Max constant buffer size                        65536 (64KiB)
  Max size of kernel argument                     1024
  Queue properties (on host)                      
    Out-of-order execution                        Yes
    Profiling                                     Yes
  Queue properties (on device)                    
    Out-of-order execution                        Yes
    Profiling                                     Yes
    Preferred size                                2097152 (2MiB)
    Max size                                      16777216 (16MiB)
  Max queues on device                            1
  Max events on device                            1024
  Prefer user sync for interop                    No
  Profiling timer resolution                      1000ns
  Execution capabilities                          
    Run OpenCL kernels                            Yes
    Run native kernels                            No
    IL version                                    <printDeviceInfo:160: get CL_DEVICE_IL_VERSION size : error -30>
  printf() buffer size                            1048576 (1024KiB)
  Built-in kernels                                (n/a)
  Device Extensions                               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_byte_addressable_store cl_khr_3d_image_writes cl_khr_int64_base_atomics cl_khr_int64_extended_atomics cl_khr_fp16 cl_khr_icd cl_khr_egl_image cl_khr_image2d_from_buffer cl_khr_depth_images cl_khr_il_program cl_arm_core_id cl_arm_printf cl_arm_thread_limit_hint cl_arm_non_uniform_work_group_size cl_arm_import_memory cl_arm_shared_virtual_memory

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

This say, the maximum frequency is 5MHz. Is it correct?
I think, clinfo just say information from opencl api.


#2

I think this is probably a reporting error in the Mali opencl library. AFAIK Kirin 960 has Mali-G71 MP8 @ 1037 MHz.


#3

I am not sure this is just a bug of OpenCL runtime, a bug of kernel, or mali-g71 really work in this frequency.


#4

In this environment, actuall mali is too slow:

hikey960:/data/local/tmp # ./cl_sgemm 400 400 400
./cl_sgemm 400 400 400

./cl_sgemm

1573 milli sec 

sgemm of 400x400 spend 1.6s. Too slow.
cl_sgemm is example program of ARM computation library.

CPU version of sgemm is much fast (in linux environment):

$ python3
>>> import numpy as np
>>> N = 400; ma = np.random.randn(N, N); mb = np.random.randn(N, N); start = time.time(); a = np.dot(ma, mb); end = time.time(); print (end - start)
0.022644519805908203

This say, it spent 0.02 second to calculate sgemm of 400x400.


#5

MALI GPU operating frequencies are defined in the device-tree, going from 178MHz to 1037Mhz. You would have serious graphic problem if the clock was so slow.

Actually, I had a look at the Kernel driver (midgard), and it seems that the GPU max frequency property is statically set to 5000Khz and does not match the real MALI frequency.
cf https://android.googlesource.com/kernel/hikey-linaro/+/android-hikey-linaro-4.14/drivers/gpu/arm_gpu/platform/hisilicon/mali_kbase_config_platform.h#26.

Explication seems the following: https://android.googlesource.com/kernel/hikey-linaro/+/android-hikey-linaro-4.14/drivers/gpu/arm_gpu/mali_base_kernel.h#1256

* The properties returned extend the Midgard Configuration Discovery
* registers. For example, GPU clock speed is not specified in the Midgard
* Architecture, but is <b>necessary for OpenCL's clGetDeviceInfo() function</b>.

How do you calculate time of execution?


#6

Afaik, CL clock speeds are not representative of the gpu clock speed. On my 835 powered smartphone It shows as 1MHz on multiple apps like OpenCL-Z
UPDATE: looks like this moght be specific to AOSP, however openCL should perform as expected.


#7

Just modify the sample program cl_sgemm.cpp as follows:

--- a/examples/cl_sgemm.cpp
+++ b/examples/cl_sgemm.cpp
@@ -32,6 +32,7 @@
 #include "utils/Utils.h"
 
 #include <cstdlib>
+#include <chrono>
 
 using namespace arm_compute;
 using namespace utils;
@@ -163,7 +164,12 @@ public:
         }
 
         // Dummy run for CLTuner
+        auto start = std::chrono::system_clock::now();
         sgemm.run();
+        auto end = std::chrono::system_clock::now();
+        auto dur = end - start;
+        auto msec = std::chrono::duration_cast<std::chrono::milliseconds>(dur).count();
+        std::cout << msec << " milli sec \n";
     }
     void do_run() override
     {