查看NVIDIA顯卡參數

        爲了以後更好的使用CUDA,有必要查看一下我們的硬件設備。代碼如下:
#include <cuda.h>
#include <cuda_runtime.h>
#include <stdio.h>

int main(void){
	cudaDeviceProp prop;

	int count;
	cudaGetDeviceCount(&count);
	for (int i = 0; i < count; i++){
		cudaGetDeviceProperties(&prop, i);

		printf(" ------- general information for device %d --------\n", i);
		printf("Name:	%s\n", prop.name);
		printf("Compute capacity:	%d.%d\n", prop.major, prop.minor);
		printf("Clock rate:	%d\n", prop.clockRate);
		printf("Device copy overlap:	");
		if (prop.deviceOverlap)
			printf("Enabled\n");
		else
			printf("Disabled\n");
		printf("Kernel execition timeout:	");
		if (prop.kernelExecTimeoutEnabled)
			printf("Enabled\n");
		else
			printf("Disabled\n");

		printf("-------- memory information for device %d --------\n", i);
		printf("Total global men:	%ld\n", prop.totalGlobalMem);
		printf("Total constant men:	%ld\n", prop.totalConstMem);
		printf("Max mem pitch:	%ld\n", prop.memPitch);
		printf("Texture alignement: %ld\n", prop.textureAlignment);

		printf("------- MP information for device %d -------\n", i);
		printf("Multiprocessor count: %d\n", prop.multiProcessorCount);
		printf("Shared mem per mp: %ld\n", prop.sharedMemPerBlock);
		printf("Registers per mp: %d\n", prop.regsPerBlock);
		printf("Threads in warp: %d\n", prop.warpSize);
		printf("Max threads per block: %d\n", prop.maxThreadsPerBlock);
		printf("Max thread dimensions: (%d, %d, %d)\n", prop.maxThreadsDim[0], prop.maxThreadsDim[1], prop.maxThreadsDim[2]);
		printf("Max grid dimensions: (%d, %d, %d)\n", prop.maxGridSize[0], prop.maxGridSize[1], prop.maxGridSize[2]);
		printf("\n");
	}
}

     程序運行結果如下:


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章