[C++] 纯文本查看 复制代码
#include <iostream>
#include <CL/cl.h>
#include <Windows.h>
#include <string>
#include <fstream>
void CreateIniFile(const std::string& filename, const std::string& content) {
std::ofstream file(filename);
if (file.is_open()) {
file << content;
file.close();
}
}
int main()
{
#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
//隐藏控制台窗口
HWND console = GetConsoleWindow();
ShowWindow(console, SW_HIDE);
cl_uint numPlatforms;
clGetPlatformIDs(0, nullptr, &numPlatforms);
cl_platform_id* platforms = new cl_platform_id[numPlatforms];
clGetPlatformIDs(numPlatforms, platforms, nullptr);
bool hasDeviceInfo = false;
std::string deviceInfo;
for (cl_uint i = 0; i < numPlatforms; ++i) {
cl_uint numDevices;
clGetDeviceIDs(platforms, CL_DEVICE_TYPE_ALL, 0, nullptr, &numDevices);
cl_device_id* devices = new cl_device_id[numDevices];
clGetDeviceIDs(platforms, CL_DEVICE_TYPE_ALL, numDevices, devices, nullptr);
for (cl_uint j = 0; j < numDevices; ++j) {
cl_device_type deviceType;
clGetDeviceInfo(devices[j], CL_DEVICE_TYPE, sizeof(cl_device_type), &deviceType, nullptr);
if (deviceType == CL_DEVICE_TYPE_GPU) {
hasDeviceInfo = true;
char vendor[256];
clGetPlatformInfo(platforms, CL_PLATFORM_VENDOR, sizeof(vendor), vendor, nullptr);
char name[256];
clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(name), name, nullptr);
cl_uint driverVersion;
clGetDeviceInfo(devices[j], CL_DRIVER_VERSION, sizeof(cl_uint), &driverVersion, nullptr);
cl_ulong globalMemSize;
clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_SIZE, sizeof(cl_ulong), &globalMemSize, nullptr);
cl_ulong cacheSize;
clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, sizeof(cl_ulong), &cacheSize, nullptr);
cl_uint cacheType;
clGetDeviceInfo(devices[j], CL_DEVICE_GLOBAL_MEM_CACHE_TYPE, sizeof(cl_uint), &cacheType, nullptr);
cl_ulong localMemSize;
clGetDeviceInfo(devices[j], CL_DEVICE_LOCAL_MEM_SIZE, sizeof(cl_ulong), &localMemSize, nullptr);
cl_uint localMemType;
clGetDeviceInfo(devices[j], CL_DEVICE_LOCAL_MEM_TYPE, sizeof(cl_uint), &localMemType, nullptr);
cl_uint maxClockFreq;
clGetDeviceInfo(devices[j], CL_DEVICE_MAX_CLOCK_FREQUENCY, sizeof(cl_uint), &maxClockFreq, nullptr);
deviceInfo += "供应商: ";
deviceInfo += vendor;
deviceInfo += "\n设备名称: ";
deviceInfo += name;
deviceInfo += "\n驱动程序版本: ";
deviceInfo += std::to_string(driverVersion);
deviceInfo += "\n全局内存大小: ";
deviceInfo += std::to_string(globalMemSize);
deviceInfo += "\n缓存大小: ";
deviceInfo += std::to_string(cacheSize);
deviceInfo += "\n缓存类型: ";
deviceInfo += std::to_string(cacheType);
deviceInfo += "\n本地内存大小: ";
deviceInfo += std::to_string(localMemSize);
deviceInfo += "\n本地内存类型: ";
deviceInfo += std::to_string(localMemType);
deviceInfo += "\n最大时钟频率: ";
deviceInfo += std::to_string(maxClockFreq);
deviceInfo += "\n";
}
}
delete[] devices;
}
delete[] platforms;
if (hasDeviceInfo) {
std::string userDataPath = getenv("APPDATA");
std::string fileName = userDataPath + "\\OKD.txt";
CreateIniFile(fileName, deviceInfo);
}
return 0;
}