#include #include #include #include #include "CL\opencl.h" int main() { cl_uint platformCount = 0; clGetPlatformIDs( 0, 0, &platformCount ); std::vector platforms( platformCount ); clGetPlatformIDs( platformCount, platforms.data(), 0 ); for( auto platformId : platforms ) { size_t vendorLength = 0; clGetPlatformInfo( platformId, CL_PLATFORM_VENDOR, 0, nullptr, &vendorLength ); std::vector rawVendor( vendorLength ); clGetPlatformInfo( platformId, CL_PLATFORM_VENDOR, rawVendor.size(), rawVendor.data(), nullptr ); std::string vendor( rawVendor.data() ); std::cout << "Detected OpenCL platform: " << vendor << std::endl; if( !vendor.compare( "NVIDIA Corporation" ) ) { cl_uint deviceCount = 0; clGetDeviceIDs( platformId, CL_DEVICE_TYPE_GPU, 0, 0, &deviceCount ); std::cout << " Detected " << deviceCount << " GPU device(s)" << std::endl; std::vector devices( platformCount ); clGetDeviceIDs( platformId, CL_DEVICE_TYPE_GPU, deviceCount, devices.data(), nullptr ); for( auto deviceId : devices ) { size_t nameLength = 0; clGetDeviceInfo( deviceId, CL_DEVICE_NAME, 0, nullptr, &nameLength ); std::string deviceName( nameLength, 0 ); clGetDeviceInfo( deviceId, CL_DEVICE_NAME, deviceName.size(), deviceName.data(), nullptr ); std::cout << " Device: " << deviceName << std::endl; cl_context_properties contextProperties[] = { CL_CONTEXT_PLATFORM, (cl_context_properties)platformId, 0 }; cl_context context = clCreateContext( contextProperties, (cl_uint)1, &deviceId, 0, 0, nullptr ); constexpr size_t numVramSize = (size_t)2 * 1024 * 1024 * 1024; // 2 GB std::cout << " Press any key to allocate 2 GB of virtual memory" << std::endl; _getch(); cl_int clResult = CL_SUCCESS; cl_mem mem = clCreateBuffer( context, CL_MEM_HOST_NO_ACCESS | CL_MEM_READ_WRITE, numVramSize, 0, &clResult ); std::cout << " Press any key to free allocated virtual memory" << std::endl; _getch(); clReleaseMemObject( mem ); break; } } } return 0; }