OPENCL compilation Environment configuration (Vs+nvidia)

Source: Internet
Author: User
Tags data structures win32

Nvidia's graphics card first to download the installation Cuda development package, you can refer to the steps here: VS2015 in the build environment Cuda installation configuration

After the installation of Cuda, the configuration of OpenCL has been completed 80%, the rest of the work is to add the OpenCL path to the project.


1. Create a new Win32 Console application, add a property page "Opencl.props" in the project's property manager debug, and then double-click Open


2. Add CUDA's include folder path to the additional include directory in the general-C + +-, my path is "D:\Software\CUDA\Development\include"



3. Add the Lib folder path to the additional library directory, general, linker, and my path is "D:\Software\CUDA\Development\lib\Win32"



4. Add the Lib file to the additional dependencies, input, linker, OpenCL.lib



After the above 4 steps, the OpenCL compilation environment has been configured, you can save the property page "Opencl.props", the next time this property page directly, not to repeat the configuration every time. Here are the test programs:


#include <stdio.h> #include <stdlib.h> #include <iostream> #include <CL/cl.h> int main ()

	{//cl_platform represents an OpenCL execution platform, associated to GPU hardware such as n cards, AMD card cl_platform_id *platforms;
	The cross-platform usigned int and int types defined in OpenCL cl_uint num_platforms;

	Cl_int I, err, platform_index =-1;
	char* Ext_data;
	size_t Ext_size;

	const char icd_ext[] = "CL_KHR_ICD"; It takes two steps to make platform work. 1 You need to allocate memory space for the CL_PLATFORM_ID structure. 2 need to call Clgetplatformids to initialize these data structures.
	In general, step 0: Ask how many platforms//queries on the computer have the OpenCL-enabled device err = Clgetplatformids (5, NULL, &num_platforms);
		if (Err < 0) {perror ("couldn ' t find any platforms.");
	Exit (1);

	} printf ("Number of environments on this machine that support OpenCL:%d\n", num_platforms);

	Allocate space for platforms platforms = (cl_platform_id*) malloc (sizeof (cl_platform_id) * num_platforms);

	Clgetplatformids (num_platforms, platforms, NULL); Get details for GPU platform for (i = 0; i < num_platforms; i++) {//get cache size err = Clgetplatforminfo (Platforms[i], CL_PLATFO Rm_extensions, 0, NULL, &ext_size);
			if (Err < 0) {perror ("couldn ' t read extension data.");
		Exit (1);

		} printf ("Cache Size:%d\n", ext_size);

		Ext_data = (char*) malloc (ext_size);
		Get support for Extended functionality Clgetplatforminfo (Platforms[i], cl_platform_extensions, Ext_size, Ext_data, NULL);

		printf ("Platform%d supported extended features:%s\n", I, ext_data);
		Gets the name of the video card char *name = (char*) malloc (ext_size);
		Clgetplatforminfo (Platforms[i], Cl_platform_name, Ext_size, NAME, NULL);

		printf ("Platform%d is:%s\n", I, name);
		Gets the manufacturer name of the video card char *vendor = (char*) malloc (ext_size);
		Clgetplatforminfo (Platforms[i], Cl_platform_vendor, Ext_size, VENDOR, NULL);

		printf ("The manufacturer of platform%d is:%s\n", I, Vendor);
		Get Platform version char *version = (char*) malloc (ext_size);
		Clgetplatforminfo (Platforms[i], cl_platform_version, Ext_size, VERSION, NULL);

		printf ("Version information for platform%d:%s\n", I, version);
		Query whether the video card is standalone or embedded char *profile = (char*) malloc (ext_size); Clgetplatforminfo (Platforms[i], cl_platform_profile, ext_size, profile, NULL);

		printf ("Platform%d is independent (full profile) or embedded (embeded profile)":%s\n ", I, Profile);
		Whether the query supports ICD extension if (STRSTR (Ext_data, icd_ext)! = NULL) Platform_index = i;
		Std::cout << "Platform id =" << platform_index << Std::endl; /* Display whether ICD extension is supported */if (Platform_index >-1) printf ("Platform%d supports ICD extension:%s\n", PLATFO
		Rm_index, Icd_ext);

		Std::cout << Std::endl;
		Freeing space free (ext_data);
		Free (name);
		Free (vendor);
		Free (version);
	Free (profile);
	} if (Platform_index <=-1) printf ("No platforms support the%s extension.\n", Icd_ext);

	GetChar ();
	Release resources free (platforms);
return 0; }

To perform the output on this machine:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.