>Better starts Now!

1、废话不说,直接看CUDA API

低级API: cuda_runtime_api.h,c类型接口,不需要nvcc编译
高级API: cuda_runtime.h, C++接口类型,基于低级API接口之上。
CUDA API

2、废话不说,直接上代码

#include <stdio.h>
#include <cuda_runtime.h>

int main()
{
	int count = 0;
	cudaError_t ret;
	ret = cudaGetDeviceCount(&count);
	printf("cudaGetDeviceCount ret(%d)\n", ret);
	printf("cuda num:%d\n", count);

	cudaDeviceProp prop = {0};
	cudaGetDeviceProperties(&prop, 0);
	printf("prop.major = (%d)\n", prop.major);
	printf("prop.name = (%s)\n", prop.name);
	printf("prop.totalGlobalMem = (%u)\n", prop.totalGlobalMem);
	printf("prop.sharedMemPerBlock = (%u)\n", prop.sharedMemPerBlock);
	printf("prop.regsPerBlock = (%d)\n", prop.regsPerBlock);
	printf("prop.warpSize = (%d)\n", prop.warpSize);
	printf("prop.memPitch = (%u)\n", prop.memPitch);
	printf("prop.maxThreadsPerBlock = (%d)\n", prop.maxThreadsPerBlock);
	printf("prop.totalConstMem = (%u)\n", prop.totalConstMem);
	printf("prop.clockRate = (%d)\n", prop.clockRate);
	printf("prop.textureAlignment = (%u)\n", prop.textureAlignment);
	printf("prop.maxThreadsDim = (%d)\n", prop.maxThreadsDim[0]);
	printf("prop.maxThreadsDim = (%d)\n", prop.maxThreadsDim[1]);
	printf("prop.maxThreadsDim = (%d)\n", prop.maxThreadsDim[2]);
	printf("prop.maxGridSize = (%d)\n", prop.maxGridSize[0]);
	printf("prop.maxGridSize = (%d)\n", prop.maxGridSize[1]);
	printf("prop.maxGridSize = (%d)\n", prop.maxGridSize[2]);

	printf("Hello CUDA!\n");
	getchar();
	return 0;
}

3、废话不说,直接看输出

在这里插入图片描述

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐