OpenCL:查询移动GPU的最大时钟频率始终返回较小的值

时间:2018-03-29 01:28:22

标签: c opencl gpu-programming mali

为了了解Mali T760 GPU的最大时钟频率,我使用了下面的代码片段:

// Get device max clock frequency
cl_uint max_clock_freq;
err_num = clGetDeviceInfo(cl_devices[device_idx], CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(max_clock_freq), &max_clock_freq, NULL);
check_cl_error(err_num, "clGetDeviceInfo: Getting device max clock frequency");
printf("CL_DEVICE_MAX_CLOCK_FREQUENCY: %d MHz\n", max_clock_freq);

此处提供完整源代码:https://github.com/sivagnanamn/opencl-device-info

查询结果显示CL_DEVICE_MAX_CLOCK_FREQUENCY: 99 MHz,而规格中报告的时钟频率为600MHz(src:https://www.notebookcheck.net/ARM-Mali-T760-MP4.148383.0.html

为什么规格&中报告的实际时钟频率之间存在差异?来自OpenCL查询的时钟频率?

编辑1:

这是用于查询支持OpenCl的GPU设备的最大时钟频率的最小代码版本。

#include <stdio.h>
#include <stdlib.h>

#ifdef __APPLE__
  #include <OpenCL/opencl.h>
#else
  #include <CL/cl.h>
#endif

void check_cl_error(cl_int err_num, char* msg) {
  if(err_num != CL_SUCCESS) {
    printf("[Error] OpenCL error code: %d in %s \n", err_num, msg);
    exit(EXIT_FAILURE);
  }
}

int main(void) {

  cl_int err_num;
  char str_buffer[1024];
  cl_uint num_platforms_available;

  // Get the number of OpenCL capable platforms available
  err_num = clGetPlatformIDs(0, NULL, &num_platforms_available);

  // Exit if no OpenCL capable platform found
  if(num_platforms_available == 0){
    printf("No OpenCL capable platforms found ! \n");
    return EXIT_FAILURE;
  }

  // Create a list for storing the platform id's
  cl_platform_id cl_platforms[num_platforms_available];

  err_num = clGetPlatformIDs(num_platforms_available, cl_platforms, NULL);
  check_cl_error(err_num, "clGetPlatformIDs: Getting available platform id's");

  // Get attributes of each platform available
  for(int platform_idx = 0; platform_idx < num_platforms_available; platform_idx++) {

    // Get the number of OpenCL supported device available in this platform
    cl_uint num_devices_available;
    err_num = clGetDeviceIDs(cl_platforms[platform_idx], CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices_available);
    check_cl_error(err_num, "clGetDeviceIDs: Get number of OpenCL supported devices available");

    cl_device_id cl_devices[num_devices_available];
    err_num = clGetDeviceIDs(cl_platforms[platform_idx], CL_DEVICE_TYPE_ALL, num_devices_available, cl_devices, NULL);
    check_cl_error(err_num, "clGetDeviceIDs: Getting available OpenCL capable device id's");

    // Get attributes of each device
    for(int device_idx = 0; device_idx < num_devices_available; device_idx++) {

      // Get device max clock frequency
      cl_uint max_clock_freq;
      err_num = clGetDeviceInfo(cl_devices[device_idx], CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(max_clock_freq), &max_clock_freq, NULL);
      check_cl_error(err_num, "clGetDeviceInfo: Getting device max clock frequency");
      printf("[Platform %d] [Device %d] CL_DEVICE_MAX_CLOCK_FREQUENCY: %d MHz\n", platform_idx, device_idx, max_clock_freq);
    }
  }

  return 0;
}

在使用Mali T760 GPU在华硕TinkerBoard上执行后获得的输出是

[Platform 0] [Device 0] CL_DEVICE_MAX_CLOCK_FREQUENCY: 99 MHz

根据OpenCL文档,没有缩放因子。查询应返回以MHz为单位的频率(https://www.khronos.org/registry/OpenCL/sdk/1.2/docs/man/xhtml/clGetDeviceInfo.html

摘自OpenCL文档: CL_DEVICE_MAX_CLOCK_FREQUENCY - cl_uint - 设备的最大配置时钟频率,单位为MHz。

然而,在PC上运行相同的代码(在NVIDIA和英特尔GPU上测试)会根据规格返回预期的时钟频率。

2 个答案:

答案 0 :(得分:2)

CPU / GPU时钟速度通常会受到电源/热量管理的限制。您的GPU可能处于低功耗模式。但是,如果以编程方式更改电源模式,请注意不要超出电路板配置的规格。有时这些开发板没有足够的散热片来达到最大时钟频率。

答案 1 :(得分:1)

我也遇到了同样的问题。该设备是带有Adreno640 GPU的Snapdragon 855,其最大频率为585MHz。我首先达到了最大时钟频率。然后使用代码获取最大时钟速率。 但是结果是1 MHz!

cl_uint clockFreq = targetDevice.getInfo<CL_DEVICE_MAX_CLOCK_FREQUENCY>();
std::cout << "Max freq: " << clockFreq << " MHz" << std::endl;