OpenCL installation

Hello, i want to install opencl in my notebook. I have i have a core i-3 processor and nvidia GT 640M. How can i install it? Also, how can i compile opencl projects on MS Visual studio?

Thank you in advance

I will tell you how to set up your notebook in order to build OpenCL projects for the NVIDIA platform.

First of all, you have to instal the GPU driver. Select GeForce GT 640M and the corresponding OS.

Next, you have to install CUDA. Select the corresponding OS for notebooks.

That’s all you need.

For compiling OpenCL programs in VS:

Setting up the Project

First thing to do is set up an empty VS project by choosing
‘New Project->Visual C+±>Win32 Console Application’
Enter a name for the project and choose OK
In the application creation wizard choose ‘Next’
Under ‘Additional options’ check the ‘Empty project’ box and click ‘Finish’

Including OpenCL in the Project

The first step in including OpenCL is to create a C++ file, this enables the configuration options we will need.
Right click on the ‘Source Files’ folder in the solution explorer and select ‘Add-> New Item’
Select C++ File and give the file a name
Click the ‘Add’ button in the bottom right hand corner of the dialog box
Now we are ready to point the project to the include directories for OpenCL
Right click on the project name in the solution explorer and select ‘Properties’
Navigate to ‘Configuration Properties-> C/C++ -> General’
In the ‘Additional Include Directories’ field add the following information

$(CUDA_PATH)\include

Linking OpenCL

Now we are going to tell the project where to find the actual library file which contains OpenCL. This is where the actual implementation of OpenCL is contained.

Without closing the dialog box used above:
Choose ‘Linker-> General’
In the ‘Additional Dependencies’ field enter the following

$(CUDA_PATH)\lib\Win32 (for Win32 platform projects)

$(CUDA_PATH)\lib\x64 (for x64 platform projects)

Still in the ‘Linker’ submenu, select ‘Input’
In the ‘Additional Dependencies’ field click on the arrow that appears at the end of the field and choose Edit…
In the dialog that appears enter “OpenCL.lib” (without the quotes obviously)

Click OK in the dialog box
Click OK in the Properties dialog to bring you back to the main IDE

Now you are ready to code your OpenCL project. :wink:

Paste this code in your .cpp file to check that everything is correct:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#ifdef MAC
#include <OpenCL/cl.h>
#else
#include <CL/cl.h>
#endif
 
void main()
{
    cl_platform_id *plataformas;
    cl_device_id *dispositivos;
    cl_uint num_plataformas, num_dispositivos, dir_w, c_units, work_items, frec, i, j;
	cl_ulong mem;
    cl_int err;
    char *pform_nombre, *disp_nombre, *disp_vendedor, *version, *d_version, *perfil;
    size_t psize_nombre, dsize_nombre, dsize_vendedor, size_perfil, size_version, sized_version,
		   group_size, p_time, max_height, max_width;
	cl_bool image = CL_FALSE, disponible = CL_FALSE;
 
    err = clGetPlatformIDs( 0 , NULL , &num_plataformas );
    if( err < 0 )
    {
		perror( "Couldn't find any platforms" );
		printf( "


" );
		system("pause");
		exit(1);
    }
    printf( "Numero de plataformas instaladas: %d
" , num_plataformas );
    printf( "
" );
    plataformas = ( cl_platform_id* ) malloc( sizeof( cl_platform_id ) * num_plataformas );
    clGetPlatformIDs( num_plataformas , plataformas , NULL );
 
    for( i = 0 ; i < num_plataformas ; i++ )
    {
  		err = clGetPlatformInfo( plataformas[i] , CL_PLATFORM_NAME , 0 , NULL , &psize_nombre );
		if( err < 0  )
		{
			perror( "Couldn't read platform's name" );
			exit(1);
		}
		pform_nombre = ( char* ) malloc( psize_nombre );
		clGetPlatformInfo( plataformas[i] , CL_PLATFORM_NAME , psize_nombre , pform_nombre , NULL );
		printf( "*PLATAFORMA: %s*
" , pform_nombre );
 
		err = clGetDeviceIDs( plataformas[i], CL_DEVICE_TYPE_ALL , 0 , NULL , &num_dispositivos );
		if( err < 0 )
		{
			perror( "Couldn't access any devices" );
			printf( "


" );
			system("pause");
			exit(1);   
		}
		printf( "Dispositivos: %d

" , num_dispositivos );
		dispositivos = ( cl_device_id* ) malloc( sizeof( cl_device_id ) * num_dispositivos );
		clGetDeviceIDs( plataformas[i] , CL_DEVICE_TYPE_ALL , num_dispositivos , dispositivos , NULL );
 
		for( j = 0 ; j < num_dispositivos ; j++ )
		{
			err = clGetDeviceInfo( dispositivos[j] , CL_DEVICE_NAME , 0 , NULL , &dsize_nombre );			
			if( err < 0 )
			{
				perror( "Couldn't read device's name" );
				exit(1);
			}
			disp_nombre = ( char* ) malloc( dsize_nombre );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_NAME , dsize_nombre , disp_nombre , NULL );
 
			err = clGetDeviceInfo( dispositivos[j] , CL_DEVICE_VENDOR , 0 , NULL , &dsize_vendedor );			
			if( err < 0 )
			{
				perror( "Couldn't read device's vendor" );
				exit(1);
			}
			disp_vendedor = ( char* ) malloc( dsize_vendedor );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_VENDOR , dsize_vendedor , disp_vendedor , NULL );

			err = clGetDeviceInfo( dispositivos[j] , CL_DEVICE_VERSION , 0 , NULL , &size_version );			
			if( err < 0 )
			{
				perror( "Couldn't read device's version" );
				exit(1);
			}
			version = ( char* ) malloc( size_version );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_VERSION , size_version , version , NULL );

			err = clGetDeviceInfo( dispositivos[j] , CL_DRIVER_VERSION , 0 , NULL , &sized_version );			
			if( err < 0 )
			{
				perror( "Couldn't read driver's version" );
				exit(1);
			}
			d_version = ( char* ) malloc( sized_version );
			clGetDeviceInfo( dispositivos[j] , CL_DRIVER_VERSION , sized_version , d_version , NULL );

			err = clGetDeviceInfo( dispositivos[j] , CL_DEVICE_PROFILE , 0 , NULL , &size_perfil );			
			if( err < 0 )
			{
				perror( "Couldn't read device's profile" );
				exit(1);
			}
			perfil = ( char* ) malloc( sized_version );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_PROFILE , size_perfil , perfil , NULL );
 
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_GLOBAL_MEM_SIZE , 8 , &mem , NULL );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_ADDRESS_BITS , 4 , &dir_w , NULL );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_MAX_COMPUTE_UNITS , 4 , &c_units , NULL );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS , sizeof(cl_uint) , &work_items , NULL );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_MAX_WORK_GROUP_SIZE , sizeof(size_t) , &group_size , NULL );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_MAX_CLOCK_FREQUENCY , sizeof(cl_uint) , &frec , NULL );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_IMAGE_SUPPORT , sizeof(cl_bool) , &image , NULL );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_IMAGE2D_MAX_WIDTH , sizeof(size_t) , &max_width , NULL );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_IMAGE2D_MAX_HEIGHT , sizeof(size_t) , &max_height , NULL );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_AVAILABLE , sizeof(cl_bool) , &disponible , NULL );
			clGetDeviceInfo( dispositivos[j] , CL_DEVICE_PROFILING_TIMER_RESOLUTION , sizeof(size_t) , &p_time , NULL );
 
			printf( "  *DISPOSITIVO %d*
" , j+1 );
			printf( "  NOMBRE: %s
", disp_nombre );
			printf( "  FABRICANTE: %s
", disp_vendedor );
			printf( "  VERSION DE OPENCL: %s
" , version );
			printf( "  VERSION DEL CONTROLADOR: %s
" , d_version );
			printf( "  PERFIL: %s
" , perfil );
			printf( "  BITS: %u
" , dir_w );
			printf( "  UNIDADES DE COMPUTO: %u
" , c_units );
			printf( "  FRECUENCIA MAXIMA: %u MHz
" , frec );
			printf( "  MEMORIA: %u Mb
" , mem/(1024*1024) );
			printf( "  WORK-ITEMS MAXIMOS POR WORK-GROUP: %u
" , group_size );
			printf( "  DIMENSION MAXIMA DE LOS WORK-ITEMS: %u
" , work_items );
			printf( "  RESOLUCION DEL TIMER: %u ns
" , p_time );
			if( image )
				printf( "  SOPORTE PARA IMAGENES: SI" );
			else
				printf( "  SOPORTE PARA IMAGENES: NO" );
			printf( "
" );
			printf( "  IMAGEN 2D MAXIMO ANCHO: %u
" , max_width );
			printf( "  IMAGEN 2D MAXIMO ALTO: %u
" , max_height );
			if( disponible )
				printf( "  DISPONIBLE: SI" );
			else
				printf( "  DISPONIBLE: NO" );
			printf( "

" );
			free( disp_nombre );
			free( disp_vendedor );
			free( version );
			free( d_version );
		}
		free( dispositivos );
 	}
	free( plataformas );
	printf( "
" );
	system( "pause" );
}

You have to see something like this:

[ATTACH=CONFIG]65[/ATTACH]

Instead of GeForce GTX 750, it has to say GeForce GT 640M (I made this code in spanish, sorry ;))

If you want to know how to install the OpenCL API for AMD and Intel platforms, I can help you too.

Regards.