Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task00 Роман Гостило HSE #29

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 54 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void reportError(cl_int err, const std::string &filename, int line) {

#define OCL_SAFE_CALL(expr) reportError(expr, __FILE__, __LINE__)


int main() {
// Пытаемся слинковаться с символами OpenCL API в runtime (через библиотеку libs/clew)
if (!ocl_init())
Expand Down Expand Up @@ -68,25 +67,77 @@ int main() {
// TODO 1.2
// Аналогично тому, как был запрошен список идентификаторов всех платформ - так и с названием платформы, теперь, когда известна длина названия - его можно запросить:
std::vector<unsigned char> platformName(platformNameSize, 0);
// clGetPlatformInfo(...);
OCL_SAFE_CALL(clGetPlatformInfo(platform, CL_PLATFORM_NAME, platformNameSize, platformName.data(), NULL));
std::cout << " Platform name: " << platformName.data() << std::endl;

// TODO 1.3
// Запросите и напечатайте так же в консоль вендора данной платформы
size_t platformVendorSize = 0;
OCL_SAFE_CALL(clGetPlatformInfo(platform, CL_PLATFORM_VENDOR, 0, nullptr, &platformVendorSize));
std::vector<unsigned char> platformVendor(platformVendorSize, 0);
OCL_SAFE_CALL(clGetPlatformInfo(platform, CL_PLATFORM_VENDOR, platformVendorSize, platformVendor.data(), NULL));
std::cout << " Platform vendor: " << platformVendor.data() << std::endl;

// TODO 2.1
// Запросите число доступных устройств данной платформы (аналогично тому, как это было сделано для запроса числа доступных платформ - см. секцию "OpenCL Runtime" -> "Query Devices")
cl_uint devicesCount = 0;
OCL_SAFE_CALL(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, 0, NULL, &devicesCount));

std::vector<cl_device_id> platform_devices_id(devicesCount, nullptr);
OCL_SAFE_CALL(clGetDeviceIDs(platform, CL_DEVICE_TYPE_ALL, devicesCount, platform_devices_id.data(), NULL));
std::cout << " Devices count: " << devicesCount << std::endl;

for (int deviceIndex = 0; deviceIndex < devicesCount; ++deviceIndex) {

// TODO 2.2
// Запросите и напечатайте в консоль:
// - Название устройства
// - Тип устройства (видеокарта/процессор/что-то странное)
// - Размер памяти устройства в мегабайтах
// - Еще пару или более свойств устройства, которые вам покажутся наиболее интересными

cl_device_id cur_id = platform_devices_id[deviceIndex];

std::cout << " Device ID: " << cur_id << std::endl;

size_t device_name_size = 0;
OCL_SAFE_CALL(clGetDeviceInfo(cur_id, CL_DEVICE_NAME, 0, nullptr, &device_name_size));
std::vector<unsigned char> device_name(device_name_size, 0);
OCL_SAFE_CALL(clGetDeviceInfo(cur_id, CL_DEVICE_NAME, device_name_size, device_name.data(), nullptr));
std::cout << " Device name: " << device_name.data() << std::endl;

cl_device_type device_type;
OCL_SAFE_CALL(clGetDeviceInfo(cur_id, CL_DEVICE_TYPE, 8, &device_type, NULL));

std::string device_type_name = "";
switch (device_type)
{
case CL_DEVICE_TYPE_GPU:
device_type_name = "GPU";
break;
case CL_DEVICE_TYPE_CPU:
device_type_name = "CPU";
break;
case CL_DEVICE_TYPE_ACCELERATOR:
device_type_name = "ACCELERATOR";
break;
}
std::cout << " Device type: " << device_type_name << std::endl;

cl_ulong global_mem_size_in_bytes;
OCL_SAFE_CALL(clGetDeviceInfo(cur_id, CL_DEVICE_GLOBAL_MEM_SIZE, 8, &global_mem_size_in_bytes, NULL));
std::cout << " Device global memory size: " << global_mem_size_in_bytes / 1000000 << std::endl;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

На будущее лучше пользоваться двоичным мегабайтом вместо десятичного, для консистентности


cl_uint compute_units_max;
OCL_SAFE_CALL(clGetDeviceInfo(cur_id, CL_DEVICE_MAX_COMPUTE_UNITS, 4, &compute_units_max, NULL));
std::cout << " Device max compute units: " << compute_units_max << std::endl;

size_t max_work_group_size;
OCL_SAFE_CALL(clGetDeviceInfo(cur_id, CL_DEVICE_MAX_WORK_GROUP_SIZE, 8, &max_work_group_size, NULL));

std::cout << " Device max work group size: " << max_work_group_size << std::endl;
}
}

return 0;
}
}
Loading