ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
opencl_info.cc File Reference
#include "arm_compute/core/CL/OpenCL.h"
#include <iostream>
#include <vector>

Go to the source code of this file.

Functions

void printDeviceInfo (int n, cl::Device &device)
 
void printContext (int n, cl::Platform &plat, int device_type)
 
void printPlatform (int n, cl::Platform &plat)
 
int main (const int argc, char **argv)
 

Function Documentation

◆ main()

int main ( const int  argc,
char **  argv 
)

Definition at line 128 of file opencl_info.cc.

129{
130 try
131 {
132 std::cout << "\nOpenCL Platform, Context, Device Info are as follows:\n\n";
133 {
134 std::vector<cl::Platform> platforms;
135 cl::Platform::get(&platforms);
136
137 int n = 0;
138 for (auto &p : platforms)
139 {
140 printPlatform(++n, p);
141 }
142 }
143
144 std::cout << "\n\nShowing default platfom, context, and device:\n"
145 << "(Note: this may throw an error depending on system or compiler)\n";
146 {
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();
152 printDeviceInfo(0, device);
153 }
154 }
155 catch (cl::Error &err)
156 {
157 std::cerr << "cl::Error was thrown: Please refer to the info below:\n"
158 << "\terror code: " << err.err() << ", meaning: " << err.what() << std::endl;
159 }
160 catch (std::system_error &err)
161 {
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;
164 }
165
166 return 0;
167}
void printPlatform(int n, cl::Platform &plat)
void printDeviceInfo(int n, cl::Device &device)
Configuration p

References p, printDeviceInfo(), and printPlatform().

◆ printContext()

void printContext ( int  n,
cl::Platform &  plat,
int  device_type 
)

Definition at line 68 of file opencl_info.cc.

69{
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";
82
83 cl::Context context;
84
85 try
86 {
87 cl_context_properties properties[3] = {CL_CONTEXT_PLATFORM, (cl_context_properties)plat(), 0};
88
89 cl_int default_error;
90
91 context = cl::Context(device_type, properties, NULL, NULL, &default_error);
92 }
93 catch (cl::Error &err) // thrown when there is no Context for this platform
94 {
95 std::cout << "\t\t No Context Found\n";
96 return;
97 }
98
99 std::cout << " (id: " << context() << ")\n";
100
101 const auto device_num = context.getInfo<CL_CONTEXT_NUM_DEVICES>();
102 std::cout << "\t\t\tDevice num: " << device_num << "\n";
103 if (device_num == 0)
104 return;
105
106 auto devices = context.getInfo<CL_CONTEXT_DEVICES>();
107
108 int d = 0;
109 for (auto device : devices)
110 printDeviceInfo(++d, device);
111}

References printDeviceInfo().

Referenced by printPlatform().

◆ printDeviceInfo()

void printDeviceInfo ( int  n,
cl::Device &  device 
)

Definition at line 45 of file opencl_info.cc.

46{
47 std::cout << "\t\t\t#" << n << " Device: (id: " << device() << ")\n";
48
49 const auto name = device.getInfo<CL_DEVICE_NAME>();
50 std::cout << "\t\t\t\tName: " << name << "\n";
51
52 const auto compute_unit = device.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>();
53 std::cout << "\t\t\t\tMax Compute Unit: " << compute_unit << "\n";
54
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 << ",";
59 std::cout << "]\n";
60
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";
63
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";
66}
int32_t size[5]
Definition Slice.cpp:35

References size.

Referenced by main(), and printContext().

◆ printPlatform()

void printPlatform ( int  n,
cl::Platform &  plat 
)

Definition at line 113 of file opencl_info.cc.

114{
115 std::cout << "#" << n << ". Platform: (id: " << plat() << ")\n";
116
117 cl::Context default_context;
118
119 int x = 0;
120 printContext(++x, plat, CL_DEVICE_TYPE_DEFAULT);
121 printContext(++x, plat, CL_DEVICE_TYPE_GPU);
122 printContext(++x, plat, CL_DEVICE_TYPE_CPU);
123 printContext(++x, plat, CL_DEVICE_TYPE_ACCELERATOR);
124 printContext(++x, plat, CL_DEVICE_TYPE_CUSTOM);
125 printContext(++x, plat, CL_DEVICE_TYPE_ALL);
126}
void printContext(int n, cl::Platform &plat, int device_type)

References printContext().

Referenced by main().