47 std::cout <<
"\t\t\t#" << n <<
" Device: (id: " << device() <<
")\n";
49 const auto name = device.getInfo<CL_DEVICE_NAME>();
50 std::cout <<
"\t\t\t\tName: " << name <<
"\n";
52 const auto compute_unit = device.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>();
53 std::cout <<
"\t\t\t\tMax Compute Unit: " << compute_unit <<
"\n";
55 const auto max_work_item_size = device.getInfo<CL_DEVICE_MAX_WORK_ITEM_SIZES>();
56 std::cout <<
"\t\t\t\tMax Work Item Size: [";
57 for (
auto size : max_work_item_size)
58 std::cout <<
size <<
",";
61 const auto max_work_group_size = device.getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>();
62 std::cout <<
"\t\t\t\tMax Work Grpup Size: " << max_work_group_size <<
"\n";
64 const auto max_clock_frequency = device.getInfo<CL_DEVICE_MAX_CLOCK_FREQUENCY>();
65 std::cout <<
"\t\t\t\tMax Clock Frequency: " << max_clock_frequency <<
"\n";
70 if (device_type == CL_DEVICE_TYPE_DEFAULT)
71 std::cout <<
"\t #" << n <<
" context when CL_DEVICE_TYPE_DEFAULT";
72 else if (device_type == CL_DEVICE_TYPE_GPU)
73 std::cout <<
"\t #" << n <<
" context when CL_DEVICE_TYPE_GPU";
74 else if (device_type == CL_DEVICE_TYPE_CPU)
75 std::cout <<
"\t #" << n <<
" context when CL_DEVICE_TYPE_CPU";
76 else if (device_type == CL_DEVICE_TYPE_ACCELERATOR)
77 std::cout <<
"\t #" << n <<
" context when CL_DEVICE_TYPE_ACCELERATOR";
78 else if (device_type == CL_DEVICE_TYPE_CUSTOM)
79 std::cout <<
"\t #" << n <<
" context when CL_DEVICE_TYPE_CUSTOM";
80 else if (device_type == CL_DEVICE_TYPE_ALL)
81 std::cout <<
"\t #" << n <<
" context when CL_DEVICE_TYPE_ALL";
87 cl_context_properties properties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties)plat(), 0};
91 context = cl::Context(device_type, properties, NULL, NULL, &default_error);
93 catch (cl::Error &err)
95 std::cout <<
"\t\t No Context Found\n";
99 std::cout <<
" (id: " << context() <<
")\n";
101 const auto device_num = context.getInfo<CL_CONTEXT_NUM_DEVICES>();
102 std::cout <<
"\t\t\tDevice num: " << device_num <<
"\n";
106 auto devices = context.getInfo<CL_CONTEXT_DEVICES>();
109 for (
auto device : devices)
115 std::cout <<
"#" << n <<
". Platform: (id: " << plat() <<
")\n";
117 cl::Context default_context;
128int main(
const int argc,
char **argv)
132 std::cout <<
"\nOpenCL Platform, Context, Device Info are as follows:\n\n";
134 std::vector<cl::Platform> platforms;
135 cl::Platform::get(&platforms);
138 for (
auto &
p : platforms)
144 std::cout <<
"\n\nShowing default platfom, context, and device:\n"
145 <<
"(Note: this may throw an error depending on system or compiler)\n";
147 auto platform = cl::Platform::getDefault();
148 std::cout <<
"* default platform (id: " << platform() <<
")\n";
149 auto context = cl::Context::getDefault();
150 std::cout <<
"* default context (id: " << context() <<
")\n";
151 auto device = cl::Device::getDefault();
155 catch (cl::Error &err)
157 std::cerr <<
"cl::Error was thrown: Please refer to the info below:\n"
158 <<
"\terror code: " << err.err() <<
", meaning: " << err.what() << std::endl;
160 catch (std::system_error &err)
162 std::cerr <<
"std::system_error was thrown: Please refer to the info below:\n"
163 <<
"\terror code: " << err.code() <<
", meaning: " << err.what() << std::endl;