Windows 10 - Visual Studio 2015 - OpenCL - CUDA Toolkit 10.1 - 环境配置

Windows 10 - Visual Studio 2015 - OpenCL - CUDA Toolkit 10.1 - 环境配置

NVIDIA OpenCL SDK Code Samples
https://developer.nvidia.com/opencl

The Khronos Group Inc.
https://www.khronos.org/opencl/

1. yongqiang.cpp

Windows 10 - Visual Studio 2015 - OpenCL - CUDA Toolkit 10.1 - 环境配置

/*
============================================================================
Name        : yongqiang.cpp
Author      : Yongqiang Cheng
Version     : Version 1.0.0
Copyright   : Copyright (c) 2020 Yongqiang Cheng
Description : Hello World in C++, Ansi-style
============================================================================
*/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <time.h>

using namespace std;

int main()
{
	clock_t start = 0, end = 0;
	double cpu_time_used = 0;

	start = clock();
	printf("Start of the program, start = %ld\n", start);
	printf("Start of the program, start = %ld\n\n", start);

	cout << "yongqiang" << endl;

	end = clock();
	printf("\nEnd of the program, end = %ld\n", end);
	printf("End of the program, end = %ld\n", end);

	cpu_time_used = ((double)(end - start)) / CLOCKS_PER_SEC;
	printf("Total time taken by CPU: %f\n", cpu_time_used);

	printf("Exiting of the program...\n");

	return 0;
}

Start of the program, start = 0
Start of the program, start = 0

yongqiang

End of the program, end = 0
End of the program, end = 0
Total time taken by CPU: 0.000000
Exiting of the program...
请按任意键继续. . .

Windows 10 - Visual Studio 2015 - OpenCL - CUDA Toolkit 10.1 - 环境配置

2. Additional Include Directories - 附加包含目录

Properties -> C/C++ -> General -> Additional Include Directories
Windows 10 - Visual Studio 2015 - OpenCL - CUDA Toolkit 10.1 - 环境配置

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include
Windows 10 - Visual Studio 2015 - OpenCL - CUDA Toolkit 10.1 - 环境配置

3. Additional Library Directories - 附加库目录

Properties -> Linker -> General -> Additional Library Directories
Windows 10 - Visual Studio 2015 - OpenCL - CUDA Toolkit 10.1 - 环境配置

Windows 10 - Visual Studio 2015 - OpenCL - CUDA Toolkit 10.1 - 环境配置

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\Win32
Windows 10 - Visual Studio 2015 - OpenCL - CUDA Toolkit 10.1 - 环境配置

4. Additional Dependencies - 附加依赖项

Properties -> Linker -> Input -> Additional Dependencies
Windows 10 - Visual Studio 2015 - OpenCL - CUDA Toolkit 10.1 - 环境配置

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\Win32\OpenCL.lib
Windows 10 - Visual Studio 2015 - OpenCL - CUDA Toolkit 10.1 - 环境配置

5. yongqiang.cpp

/*
============================================================================
Name        : yongqiang.cpp
Author      : Yongqiang Cheng
Version     : Version 1.0.0
Copyright   : Copyright (c) 2020 Yongqiang Cheng
Description : Hello World in C++, Ansi-style
============================================================================
*/

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

#ifdef __APPLE__
#include <OpenCL/opencl.h>
#else
#include <CL/cl.h>
#endif

#define MEM_SIZE (128)
#define MAX_SOURCE_SIZE (0x100000)

int main()
{
	cl_platform_id platform_id = NULL;
	cl_device_id device_id = NULL;
	cl_uint ret_num_devices;
	cl_uint ret_num_platforms;
	cl_int ret;
	cl_uint work_item_dim;
	size_t work_item_sizes[3];
	size_t work_group_size;
	cl_uint ucomput_uint = 0;
	cl_uint uconstant_args = 0;
	cl_ulong uconstant_buffer_size = 0;

	ret = clGetPlatformIDs(1, &platform_id, &ret_num_platforms);
	ret = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_DEFAULT, 1, &device_id, &ret_num_devices);
	printf("devices   : %d\n", ret_num_devices);

	char pform_vendor[40];
	clGetPlatformInfo(platform_id, CL_PLATFORM_VENDOR, sizeof(pform_vendor), &pform_vendor, NULL);
	printf("vendor   : %s\n", &pform_vendor);

	clGetDeviceInfo(device_id, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(cl_uint), (void *)&work_item_dim, NULL);
	clGetDeviceInfo(device_id, CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(work_item_sizes), (void *)work_item_sizes, NULL);
	clGetDeviceInfo(device_id, CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), (void *)&work_group_size, NULL);
	clGetDeviceInfo(device_id, CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), (void *)&ucomput_uint, NULL);
	clGetDeviceInfo(device_id, CL_DEVICE_MAX_CONSTANT_ARGS, sizeof(cl_uint), (void *)&uconstant_args, NULL);
	clGetDeviceInfo(device_id, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, sizeof(cl_ulong), (void *)&uconstant_buffer_size, NULL);

	printf("Max work-item dimensions   : %d\n", work_item_dim);
	printf("Max work-item sizes        : %d %d %d\n", work_item_sizes[0], work_item_sizes[1], work_item_sizes[2]);
	printf("Max work-group sizes       : %d\n", work_group_size);
	printf("Max comput_uint            : %u\n", ucomput_uint);
	printf("Max constant_args          : %u\n", uconstant_args);
	printf("Max constant_buffer_size   : %u\n", uconstant_buffer_size);

	system("pause");
	return 0;
}
devices   : 1
vendor   : NVIDIA Corporation
Max work-item dimensions   : 3
Max work-item sizes        : 1024 1024 64
Max work-group sizes       : 1024
Max comput_uint            : 10
Max constant_args          : 9
Max constant_buffer_size   : 65536
请按任意键继续. . .

Windows 10 - Visual Studio 2015 - OpenCL - CUDA Toolkit 10.1 - 环境配置

References

https://github.com/gcielniak/OpenCL-Tutorials
https://github.com/Dakkers/OpenCL-examples
https://github.com/ibrahimsenan/OpenCl-HelloWorld
https://anteru.net/blog/2012/getting-started-with-opencl-part-1/
https://github.com/tapin13/openCL-helloWorld

上一篇:Ekt 相关知识点


下一篇:Python 分布式缓存之Reids数据类型操作