#include "NBody.hpp" /////////////////////////////////// NBody::getDeviceInfo Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ // // Returns information about the device on which the simulation // will run. Also some variables will be init here based on the // device information. // /////////////////////////////////// NBody::getDeviceInfo Func \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ int NBody::getDeviceInfo() { cl_int status = CL_SUCCESS; cl_char infoString[1024] = {0}; cl_ulong infoLong; cl_uint infoInt; cl_bool infoBool; size_t infoSize_t; size_t *infoSz_t; //---------------------------------- status= clGetDeviceInfo( devices[0], CL_DEVICE_NAME, sizeof(infoString), infoString, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_NAME failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_NAME : \t\t" << infoString << std::endl; } //---------------------------------- status = clGetDeviceInfo( devices[0], CL_DEVICE_VENDOR, sizeof(infoString), infoString, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_VENDOR failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_VENDOR : \t\t\t" << infoString << std::endl; } //---------------------------------- status = clGetDeviceInfo( devices[0], CL_DRIVER_VERSION, sizeof(infoString), infoString, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DRIVER_VERSION failed." << std::endl; return 1; }else{ std::cout << "CL_DRIVER_VERSION : \t\t\t" << infoString << std::endl; } //---------------------------------- status = clGetDeviceInfo( devices[0], CL_DEVICE_TYPE, sizeof(cl_device_type), (void*)&infoLong, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_TYPE failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_TYPE : \t\t\t"; switch(infoLong){ case CL_DEVICE_TYPE_CPU : std::cout << "CL_DEVICE_TYPE_CPU" << std::endl; break; case CL_DEVICE_TYPE_GPU : std::cout << "CL_DEVICE_TYPE_GPU" << std::endl; break; case CL_DEVICE_TYPE_ACCELERATOR : std::cout << "CL_DEVICE_TYPE_ACCELERATOR" << std::endl; break; case CL_DEVICE_TYPE_ALL : std::cout << "CL_DEVICE_TYPE_ALL" << std::endl; break; case CL_DEVICE_TYPE_DEFAULT : std::cout << "CL_DEVICE_TYPE_DEFAULT" << std::endl; break; } } std::cout << std::endl; //---------------------------------- // The number of parallel compute cores // on the OpenCL device. status = clGetDeviceInfo( devices[0], CL_DEVICE_MAX_COMPUTE_UNITS, sizeof(cl_uint), (void*)&infoInt, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_MAX_COMPUTE_UNITS failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_MAX_COMPUTE_UNITS : \t\t" << (size_t)infoInt << std::endl; } //---------------------------------- status = clGetDeviceInfo( devices[0], CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, sizeof(cl_uint), (void*)&maxDimensions, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS : \t" << (size_t)maxDimensions << std::endl; } maxWorkItemSizes = (size_t*)malloc(maxDimensions * sizeof(size_t)); //---------------------------------- // Maximum number of work-items that can be // specified in each dimension of the work-group // to clEnqueueNDRangeKernel. status = clGetDeviceInfo( devices[0], CL_DEVICE_MAX_WORK_ITEM_SIZES, sizeof(size_t) * maxDimensions, (void*)maxWorkItemSizes, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_MAX_WORK_ITEM_SIZES failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_MAX_WORK_ITEM_SIZES : \t" << (size_t)maxWorkItemSizes << std::endl; } //---------------------------------- // Maximum number of work-items in a work-group // executing a kernel using the data parallel // execution model status = clGetDeviceInfo( devices[0], CL_DEVICE_MAX_WORK_GROUP_SIZE, sizeof(size_t), (void*)&maxWorkGroupSize, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_MAX_WORK_GROUP_SIZE failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_MAX_WORK_GROUP_SIZE : \t" << maxWorkGroupSize << std::endl; } std::cout << std::endl; //---------------------------------- // Is CL_TRUE if images are supported by the // OpenCL device and CL_FALSE otherwise. status = clGetDeviceInfo( devices[0], CL_DEVICE_IMAGE_SUPPORT, sizeof(cl_bool), (void *)&infoBool, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE_SUPPORT failed." << std::endl; return 1; }else{ if (infoBool == true) std::cout << "CL_DEVICE_IMAGE_SUPPORT : \t\t" << "true" << std::endl; else std::cout << "CL_DEVICE_IMAGE_SUPPORT : \t\t" << "false" << std::endl; } //---------------------------------- // Max width of 2D image in pixels. The minimum // value is 8192 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE. status = clGetDeviceInfo( devices[0], CL_DEVICE_IMAGE2D_MAX_WIDTH, sizeof(size_t), (void *)&infoSize_t, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE2D_MAX_WIDTH failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_IMAGE2D_MAX_WIDTH : \t\t" << (size_t)infoSize_t << " pixels" << std::endl; } //---------------------------------- // Max height of 2D image in pixels. The minimum value // is 8192 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE. status = clGetDeviceInfo( devices[0], CL_DEVICE_IMAGE2D_MAX_HEIGHT, sizeof(size_t), (void *)&infoSize_t, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE2D_MAX_HEIGHT failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_IMAGE2D_MAX_HEIGHT : \t\t" << (size_t)infoSize_t << " pixels" << std::endl; } //---------------------------------- // Max width of 3D image in pixels. The minimum value // is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE. status = clGetDeviceInfo( devices[0], CL_DEVICE_IMAGE3D_MAX_WIDTH, sizeof(size_t), (void *)&infoSize_t, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE3D_MAX_WIDTH failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_IMAGE3D_MAX_WIDTH : \t\t" << (size_t)infoSize_t << " pixels" << std::endl; } //---------------------------------- // Max height of 3D image in pixels. The minimum value // is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE. status = clGetDeviceInfo( devices[0], CL_DEVICE_IMAGE3D_MAX_HEIGHT, sizeof(size_t), (void *)&infoSize_t, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE3D_MAX_HEIGHT failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_IMAGE3D_MAX_HEIGHT : \t\t" << (size_t)infoSize_t << " pixels" << std::endl; } //---------------------------------- // Max depth of 3D image in pixels. The minimum value // is 2048 if CL_DEVICE_IMAGE_SUPPORT is CL_TRUE. status = clGetDeviceInfo( devices[0], CL_DEVICE_IMAGE3D_MAX_DEPTH, sizeof(size_t), (void *)&infoSize_t, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_IMAGE3D_MAX_DEPTH failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_IMAGE3D_MAX_DEPTH : \t\t" << (size_t)infoSize_t << " pixels" << std::endl; } std::cout << std::endl; //---------------------------------- status = clGetDeviceInfo( devices[0], CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(cl_uint), (void *)&infoInt, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_MAX_CLOCK_FREQUENCY failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_MAX_CLOCK_FREQUENCY : \t" << infoInt << " MHz" << std::endl; } //---------------------------------- // Size of global device memory in bytes. status = clGetDeviceInfo( devices[0], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(cl_ulong), (void *)&infoLong, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_GLOBAL_MEM_SIZE failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_GLOBAL_MEM_SIZE : \t\t" << infoLong << " bytes" << std::endl; } //---------------------------------- // Size of local memory arena in bytes. // The minimum value is 16 KB. status = clGetDeviceInfo( devices[0], CL_DEVICE_LOCAL_MEM_SIZE, sizeof(cl_ulong), (void *)&totalLocalMemory, NULL); if (status != CL_SUCCESS){ std::cout << "clGetDeviceInfo CL_DEVICE_LOCAL_MEM_SIZE failed." << std::endl; return 1; }else{ std::cout << "CL_DEVICE_LOCAL_MEM_SIZE : \t\t" << totalLocalMemory << " bytes" << std::endl; } return 0; }