如何获取 cuda 设备中的核心数? [英] How can I get number of Cores in cuda device?

查看:13
本文介绍了如何获取 cuda 设备中的核心数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个计算我的 cuda 设备核心数的函数.我知道每个微处理器都有特定的内核,而我的 cuda 设备有 2 个微处理器.

I am looking for a function that count number of core of my cuda device. I know each microprocessor have specific cores, and my cuda device has 2 microprocessors.

我进行了很多搜索以找到一个计算每个微处理器内核数的属性函数,但我找不到.我使用下面的代码,但我仍然需要核心数?

I searched a lot to find a property function that count number of cores per microprocessor but I couldn't. I use the code below but I still need number of cores?

  • cuda 7.0
  • 程序语言 C
  • 视觉工作室 2013

代码:

void printDevProp(cudaDeviceProp devProp)
{   printf("%s
", devProp.name);
printf("Major revision number:         %d
", devProp.major);
printf("Minor revision number:         %d
", devProp.minor);
printf("Total global memory:           %u", devProp.totalGlobalMem);
printf(" bytes
");
printf("Number of multiprocessors:     %d
", devProp.multiProcessorCount);
printf("Total amount of shared memory per block: %u
",devProp.sharedMemPerBlock);
printf("Total registers per block:     %d
", devProp.regsPerBlock);
printf("Warp size:                     %d
", devProp.warpSize);
printf("Maximum memory pitch:          %u
", devProp.memPitch);
printf("Total amount of constant memory:         %u
",   devProp.totalConstMem);
return;
}

推荐答案

每个多处理器的内核是唯一的缺失";一块数据.该数据未直接在 cudaDeviceProp 结构中提供,但可以根据 已发布数据更多已发布的数据来自 devProp.majordevProp.minor 条目,它们共同构成了 CUDA 计算能力设备.

The cores per multiprocessor is the only "missing" piece of data. That data is not provided directly in the cudaDeviceProp structure, but it can be inferred based on published data and more published data from the devProp.major and devProp.minor entries, which together make up the CUDA compute capability of the device.

这样的事情应该可以工作:

Something like this should work:

#include "cuda_runtime_api.h"
// you must first call the cudaGetDeviceProperties() function, then pass 
// the devProp structure returned to this function:
int getSPcores(cudaDeviceProp devProp)
{  
    int cores = 0;
    int mp = devProp.multiProcessorCount;
    switch (devProp.major){
     case 2: // Fermi
      if (devProp.minor == 1) cores = mp * 48;
      else cores = mp * 32;
      break;
     case 3: // Kepler
      cores = mp * 192;
      break;
     case 5: // Maxwell
      cores = mp * 128;
      break;
     case 6: // Pascal
      if ((devProp.minor == 1) || (devProp.minor == 2)) cores = mp * 128;
      else if (devProp.minor == 0) cores = mp * 64;
      else printf("Unknown device type
");
      break;
     case 7: // Volta and Turing
      if ((devProp.minor == 0) || (devProp.minor == 5)) cores = mp * 64;
      else printf("Unknown device type
");
      break;
     case 8: // Ampere
      if (devProp.minor == 0) cores = mp * 64;
      else if (devProp.minor == 6) cores = mp * 128;
      else printf("Unknown device type
");
      break;
     default:
      printf("Unknown device type
"); 
      break;
      }
    return cores;
}

(在浏览器中编码)

核心"是一个营销术语.在我看来,最常见的含义是将其与 SM 中的 SP 单位等同起来.这就是我在这里展示的意思.我也省略了 cc 1.x 设备,因为 CUDA 7.0 和 CUDA 7.5 不再支持这些设备类型

"cores" is a bit of a marketing term. The most common connotation in my opinion is to equate it with SP units in the SM. That is the meaning I have demonstrated here. I've also omitted cc 1.x devices from this, as those device types are no longer supported in CUDA 7.0 and CUDA 7.5

pythonic 版本是 这里

A pythonic version is here

这篇关于如何获取 cuda 设备中的核心数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆