CUDA学习(二)

本文是CUDA学习系列的第二篇,重点介绍了cuda_runtime.h库和cudaDeviceProp结构体。通过cudaGetDeviceCount获取GPU设备数量,并解析cudaDeviceProp中如全局内存、多处理器数量、共享内存等关键参数。
摘要由CSDN通过智能技术生成

首先来看一个sample

 

test_cuda.cpp

// test_cuda_consle_2.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"


#include "stdio.h"
#include "cuda_runtime.h"
#include "device_launch_parameters.h"


int main()
{

	int deviceCount = 0;
	
	cudaGetDeviceCount(&deviceCount);//runtime API中的函数以cuda为前缀,driver API中的函数则以cu为前缀
	if (deviceCount == 0)
	{
		printf("There is no device suppporting CUDA\n");
	}
	int dev = 0;
	for (; dev < deviceCount; dev++)
	{
		cudaDeviceProp deviceProp;
		cudaGetDeviceProperties(&deviceProp,dev);
		if (dev == 0)
		{
			if (deviceProp.major == 9999 && deviceProp.minor == 9999)//deviceProp.(major,minor)分别是设备计算能力的主版本号和次版本号
				printf("There is no device supporting CUDA.\n");
			else if (deviceCount == 1)
				printf("There is 1 device supporting CUDA.\n");
			else
				printf("there are %d devices supporting CUDA.\n",deviceCount);
		}
		printf("\n Device %d:\"%s\"\n",dev,deviceProp.name);
		printf("Major revision number: %d\n",deviceProp.major);
		printf("Minor revision number: %d\n",deviceProp.minor);
		printf("Total amount of global memory: %u bytes\n",deviceProp.totalGlobalMem);

#if CUDART_VERSION>=2000
		printf("Number of multiprocessors:%d\n",deviceProp.multiProcessorCount);
		printf("Number of cores:%d\n",8*deviceProp.multiProcessorCount);
#endif
		printf("Total amount of constant memory:%u bytes\n",deviceProp.totalConstMem);
		printf("Total amount of shared memory per block: %u bytes\n",deviceProp.sharedMemPerBlock);
		printf("Total number of registers available per block:%d\n",deviceProp.regsPerBlock);
		printf("Warp size:%d\n",deviceProp.warpSize);
		printf("Maximum number of threads per block: %d\n",deviceProp.maxThreadsPerBlock);
		printf("Maximum sizes of each dimension of a block:%d x %d x %d \n",
			dev
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值