void main() { BASS_DEVICEINFO di; int a; printf("Output Devices\n"); for (a=1;BASS_GetDeviceInfo(a,&di);a++) { printf("%d: ",a); DisplayDeviceInfo(&di); } printf("\nInput Devices\n"); for (a=0;BASS_RecordGetDeviceInfo(a,&di);a++) { printf("%d: ",a); DisplayDeviceInfo(&di); } }
/*--------------------------------------------------------- // tmr_ocl_create_contexts - to create OpenCL contexts on a selected platform ---------------------------------------------------------*/ int tmr_ocl_create_contexts( FILE *Interactive_output, /* file or stdout to write messages */ int Platform_id_in, int Monitor ) { cl_int retval; cl_uint numPlatforms; cl_platform_id * platformIds; cl_context context = NULL; cl_uint iplat, jdev, k; // First, query the total number of platforms retval = clGetPlatformIDs(0, (cl_platform_id *) NULL, &numPlatforms); // allocate memory for local platform structures tmv_ocl_struct.number_of_platforms = numPlatforms; tmv_ocl_struct.list_of_platforms = (tmt_ocl_platform_struct *) malloc( sizeof(tmt_ocl_platform_struct) * numPlatforms); // Next, allocate memory for the installed platforms, and qeury // to get the list. platformIds = (cl_platform_id *)malloc(sizeof(cl_platform_id) * numPlatforms); retval = clGetPlatformIDs(numPlatforms, platformIds, NULL); if(Monitor>=TMC_PRINT_INFO){ fprintf(Interactive_output,"\nNumber of OpenCL platforms: \t%d\n", numPlatforms); } // Iterate through the list of platforms displaying associated information for (iplat = 0; iplat < numPlatforms; iplat++) { if(Monitor>TMC_PRINT_INFO){ fprintf(Interactive_output,"\n"); fprintf(Interactive_output,"Platform %d:\n", iplat); } tmv_ocl_struct.list_of_platforms[iplat].id = platformIds[iplat]; //clGetPlatformInfo(platformIds[iplat], CL_PLATFORM_NAME, size_of_name???, // tmv_ocl_struct.list_of_platforms[iplat].name, (size_t *) NULL); if(Monitor>TMC_PRINT_INFO){ // First we display information associated with the platform DisplayPlatformInfo(Interactive_output, platformIds[iplat], CL_PLATFORM_NAME, "CL_PLATFORM_NAME"); DisplayPlatformInfo(Interactive_output, platformIds[iplat], CL_PLATFORM_PROFILE, "CL_PLATFORM_PROFILE"); DisplayPlatformInfo(Interactive_output, platformIds[iplat], CL_PLATFORM_VERSION, "CL_PLATFORM_VERSION"); DisplayPlatformInfo(Interactive_output, platformIds[iplat], CL_PLATFORM_VENDOR, "CL_PLATFORM_VENDOR"); } // Now query the set of devices associated with the platform cl_uint numDevices; retval = clGetDeviceIDs( platformIds[iplat], CL_DEVICE_TYPE_ALL, 0, NULL, &numDevices); tmv_ocl_struct.list_of_platforms[iplat].number_of_devices = numDevices; tmv_ocl_struct.list_of_platforms[iplat].list_of_devices = (tmt_ocl_device_struct *) malloc( sizeof(tmt_ocl_device_struct) * numDevices); cl_device_id * devices = (cl_device_id *) malloc (sizeof(cl_device_id) * numDevices); retval = clGetDeviceIDs( platformIds[iplat], CL_DEVICE_TYPE_ALL, numDevices, devices, NULL); if(Monitor>=TMC_PRINT_INFO){ fprintf(Interactive_output,"\n\tNumber of devices: \t%d\n", numDevices); } // Iterate through each device, displaying associated information for (jdev = 0; jdev < numDevices; jdev++) { if(Monitor>TMC_PRINT_INFO){ fprintf(Interactive_output,"\tDevice %d:\n", jdev); } tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].id = devices[jdev]; clGetDeviceInfo(devices[jdev], CL_DEVICE_TYPE, sizeof(cl_device_type), &tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].type, NULL); if(tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].type == CL_DEVICE_TYPE_CPU){ tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].tmc_type = TMC_OCL_DEVICE_CPU; } if(tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].type == CL_DEVICE_TYPE_GPU){ tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].tmc_type = TMC_OCL_DEVICE_GPU; } if(tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].type == CL_DEVICE_TYPE_ACCELERATOR){ tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].tmc_type = TMC_OCL_DEVICE_ACCELERATOR; } cl_ulong mem_size_ulong = 0; int err_num = clGetDeviceInfo(devices[jdev], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(cl_ulong), &mem_size_ulong, NULL); tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].global_mem_bytes = (double)mem_size_ulong; err_num = clGetDeviceInfo(devices[jdev], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(cl_ulong), &mem_size_ulong, NULL); tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].global_max_alloc= (double)mem_size_ulong; err_num = clGetDeviceInfo(devices[jdev], CL_DEVICE_LOCAL_MEM_SIZE, sizeof(cl_ulong), &mem_size_ulong, NULL); tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].shared_mem_bytes = (double)mem_size_ulong; err_num = clGetDeviceInfo(devices[jdev], CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, sizeof(cl_ulong), &mem_size_ulong, NULL); tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].cache_bytes = (double)mem_size_ulong; err_num = clGetDeviceInfo(devices[jdev], CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, sizeof(cl_ulong), &mem_size_ulong, NULL); tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].constant_mem_bytes = (double)mem_size_ulong; cl_uint cache_line_size = 0; err_num = clGetDeviceInfo(devices[jdev], CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, sizeof(cl_uint), &cache_line_size, NULL); tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].cache_line_bytes = (int) cache_line_size; cl_uint max_num_comp_units = 0; err_num = clGetDeviceInfo(devices[jdev], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), &max_num_comp_units, NULL); tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].max_num_comp_units = (int) max_num_comp_units; size_t max_work_group_size =0; err_num = clGetDeviceInfo(devices[jdev], CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), &max_work_group_size, NULL); tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].max_work_group_size = (int) max_work_group_size; // possible further inquires: //CL_DEVICE_MAX_WORK_GROUP_SIZE, //CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, CL_DEVICE_MAX_WORK_ITEM_SIZES //CL_DEVICE_MAX_CONSTANT_ARGS //CL_DEVICE_MAX_PARAMETER_SIZE //CL_DEVICE_PREFERRED_VECTOR_WIDTH_ - char, int, float, double etc. //CL_DEVICE_MEM_BASE_ADDR_ALIGN, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].command_queue = 0; for(k=0;k<TMC_OCL_MAX_NUM_KERNELS;k++){ tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].program[k]=0; tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].kernel[k]=0; } //clGetDeviceInfo(devices[jdev], CL_DEVICE_NAME, sizeof(device_name?), //&tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].name, NULL); if(Monitor>TMC_PRINT_INFO){ DisplayDeviceInfo(Interactive_output, devices[jdev], CL_DEVICE_NAME, "CL_DEVICE_NAME"); DisplayDeviceInfo(Interactive_output, devices[jdev], CL_DEVICE_VENDOR, "CL_DEVICE_VENDOR"); DisplayDeviceInfo(Interactive_output, devices[jdev], CL_DEVICE_VERSION, "CL_DEVICE_VERSION"); fprintf(Interactive_output,"\t\tdevice global memory size (MB) = %lf\n", tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].global_mem_bytes/1024/1024); fprintf(Interactive_output,"\t\tdevice global max alloc size (MB) = %lf\n", tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].global_max_alloc/1024/1024); fprintf(Interactive_output,"\t\tdevice local memory size (kB) = %lf\n", tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].shared_mem_bytes/1024); fprintf(Interactive_output,"\t\tdevice constant memory size (kB) = %lf\n", tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].constant_mem_bytes/1024); fprintf(Interactive_output,"\t\tdevice cache memory size (kB) = %lf\n", tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].cache_bytes/1024); fprintf(Interactive_output,"\t\tdevice cache line size (B) = %d\n", tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].cache_line_bytes); fprintf(Interactive_output,"\t\tdevice maximal number of comptme units = %d\n", tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].max_num_comp_units); fprintf(Interactive_output,"\t\tdevice maximal number of work units in work group = %d\n", tmv_ocl_struct.list_of_platforms[iplat].list_of_devices[jdev].max_work_group_size); fprintf(Interactive_output,"\n"); } } free(devices); // Next, create OpenCL contexts on platforms cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platformIds[iplat], 0 }; if(Platform_id_in == TMC_OCL_ALL_PLATFORMS || Platform_id_in == iplat){ if(Monitor>TMC_PRINT_INFO){ fprintf(Interactive_output,"\tCreating CPU context (index=0) on platform %d\n", iplat); } tmv_ocl_struct.list_of_platforms[iplat].list_of_contexts[0] = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_CPU, NULL, NULL, &retval); if(Monitor>=TMC_PRINT_INFO && retval != CL_SUCCESS){ fprintf(Interactive_output,"\tCould not create CPU context on platform %d\n", iplat); } if(Monitor>TMC_PRINT_INFO){ fprintf(Interactive_output,"\tCreating GPU context (index=1) on platform %d\n", iplat); } tmv_ocl_struct.list_of_platforms[iplat].list_of_contexts[1] = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_GPU, NULL, NULL, &retval); if(Monitor>=TMC_PRINT_INFO && retval != CL_SUCCESS){ fprintf(Interactive_output,"\tCould not create GPU context on platform %d\n", iplat); } if(Monitor>TMC_PRINT_INFO){ fprintf(Interactive_output,"\tCreating ACCELERATOR context (index=2) on platform %d\n", iplat); } tmv_ocl_struct.list_of_platforms[iplat].list_of_contexts[2] = clCreateContextFromType(contextProperties, CL_DEVICE_TYPE_ACCELERATOR, NULL, NULL, &retval); if(Monitor>=TMC_PRINT_INFO && retval != CL_SUCCESS){ fprintf(Interactive_output,"\tCould not create ACCELERATOR context on platform %d\n", iplat); } } } free(platformIds); return numPlatforms; }