Windows+vs2013+cuda8.0测试

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/evilparadise/article/details/79594827
#include< stdio.h>
#include "cuda_runtime.h" 
#include <stdlib.h>
#include "device_launch_parameters.h" 

bool InitCUDA()

{

	int count;

	cudaGetDeviceCount(&count);

	if (count == 0)

	{

		fprintf(stderr, "There is no device.\n");

		return false;

	}

	int i;

	for (i = 0; i < count; i++)

	{

		cudaDeviceProp prop;

		if (cudaGetDeviceProperties(&prop, i) == cudaSuccess)

		{

			if (prop.major >= 1)

			{

				break;

			}

		}

	}

	if (i == count)

	{

		fprintf(stderr, "There is no device supporting CUDA 1.x.\n");

		return false;

	}

	cudaSetDevice(i);

	return true;

}



int main()

{

	if (!InitCUDA())

	{

		return 0;

	}

	printf("HelloWorld, CUDA has been initialized.\n");
	system("pause");

	return 0;

}

展开阅读全文

没有更多推荐了,返回首页