次はデバイスの情報を取得してみる。
デバイス情報関連は「clGetDeviceIDs関数」や「clGetDeviceInfo関数」を使う。
【例】
//OpenCLのデバイス情報
cl_uint ciDeviceCount;
cl_device_id *devices = NULL;
//使用可能なデバイスの数を取得
ciErrNum = clGetDeviceIDs (clSelectedPlatformID, CL_DEVICE_TYPE_ALL, 0, NULL, &ciDeviceCount);
std::cout << "there is " <<ciDeviceCount << " devices for OpenCL \n";
//デバイスの詳細な情報を得るためのデータ構造のメモリ確保
devices = new cl_device_id[ciDeviceCount];
if (devices == NULL)
{
std::cout << "Failed to allocate memory for devices\n";
shrEXIT(argc, argv);
}
ciErrNum = clGetDeviceIDs (clSelectedPlatformID, CL_DEVICE_TYPE_ALL, ciDeviceCount, devices, &ciDeviceCount);
if (ciErrNum == CL_SUCCESS)
{
for(unsigned int i = 0; i < ciDeviceCount; ++i )
{
std::cout << "---------------------------------\n";
clGetDeviceInfo(devices[i], CL_DEVICE_NAME, sizeof(cBuffer), &cBuffer, NULL);
std::cout << cBuffer << "\n---------------------------------\n";
oclPrintDevInfo(LOGCONSOLE, devices[i]);//デバイス情報を出力
}
}else
{
std::cerr << "error @ clGetDeviceIDs\n";
shrEXIT(argc, argv);
}
■cl_int clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type, cl_uint num_entries, cl_device_id *devices, cl_uint *num_devices)
現在のプラットフォーム上で利用可能なデバイスのリストを取得する。
【platform】:プラットフォームIDを指定
【device_type】:取得したいデバイスの種類を指定
【num_entries】:デバイスエントリーの数を指定。
【devices】:見つかったデバイスのリストの格納先
【num_devices】:「device_type」にマッチしたデバイスの数の格納先。
この後、「clGetDeviceInfo関数」で色々と情報が取得できる。
詳しくは
オンラインマニュアル参照。