ASL  0.1.7
Advanced Simulation Library
asl-hardware.cc
Go to the documentation of this file.
1 /*
2  * Advanced Simulation Library <http://asl.org.il>
3  *
4  * Copyright 2015 Avtech Scientific <http://avtechscientific.com>
5  *
6  *
7  * This file is part of Advanced Simulation Library (ASL).
8  *
9  * ASL is free software: you can redistribute it and/or modify it
10  * under the terms of the GNU Affero General Public License as
11  * published by the Free Software Foundation, version 3 of the License.
12  *
13  * ASL is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with ASL. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 
29 #include "acl/aclHardware.h"
30 #include "aslUtilities.h"
31 
32 using namespace acl;
33 using namespace std;
34 using namespace asl;
35 
36 string typeToString(unsigned int t)
37 {
38  string s;
39  switch (t)
40  {
41  case CL_DEVICE_TYPE_CPU : s="CPU"; break;
42  case CL_DEVICE_TYPE_GPU : s="GPU"; break;
43  case CL_DEVICE_TYPE_ACCELERATOR : s="ACCELERATOR"; break;
44  case CL_DEVICE_TYPE_DEFAULT : s="DEFAULT"; break;
45 // case CL_DEVICE_TYPE_CUSTOM : s="CUSTOM"; break; //in opencl 1.1 is undefined
46  default: s="type is unknown";
47  }
48  return s;
49 }
50 
51 void printHardwareInfo(const CommandQueue & queue)
52 {
53 
54  cout << "\t\ttype: " << typeToString(getDeviceType(queue)) << endl;
55  cout << "\t\tnumber of compute units: " << getNComputeUnits(queue) << endl;
56  cout << "\t\talignment: " << getAlignment(queue) << endl;
57  cout << "\t\tlocal memory type: "
58  << (getLocalMemoryType(queue) == CL_LOCAL ? "CL_LOCAL" : "CL_GLOBAL") << endl;
59  cout << "\t\tlocal memory size: " << getLocalMemorySize(queue) << endl;
60  cout << "\t\tmax item size: " << getMaxItemSize(queue) << endl;
61  cout << "\t\tvector width float: " << getVectorWidth(queue, TYPE_FLOAT) << endl;
62  cout << "\t\tvector width double: " << getVectorWidth(queue, TYPE_DOUBLE) << endl;
63  cout << "\t\textension CL_KHR_FP64: "
64  << extensionAvailable(queue, CL_KHR_FP64) << endl;
65  cout << "\t\textension CL_KHR_INT64_EXTENDED_ATOMICS: "
67  cout << "\t\tsupported OpenCL version: " << getDeviceVersion(queue) << endl;
68  cout << "\t\tOpenCL driver version: "<< getDriverVersion(queue) << endl;
69 }
70 
71 
72 int main()
73 {
74 
75  // Have a look at the available platforms and their devices
76  vector<cl::Platform> platforms;
77  vector<cl::Device> devices;
78  cl_context_properties cps[3];
79  cl::Context context;
80  CommandQueue queue;
81 
82  cl_int status = 0;
83  status = cl::Platform::get(&platforms);
84  errorMessage(status, "Platform::get()");
85 
86  if (platforms.size() > 0)
87  {
88  for (unsigned int i = 0; i < platforms.size(); ++i)
89  {
90  status = platforms[i].getDevices(CL_DEVICE_TYPE_ALL, &devices);
91  errorMessage(status, "Platform::getDevices()");
92  cout << "Platform: " << platforms[i].getInfo<CL_PLATFORM_VENDOR>()
93  << "\nNumber of devices: " << devices.size() << endl;
94 
95  cps[0] = CL_CONTEXT_PLATFORM;
96  cps[1] = (cl_context_properties)(platforms[i])();
97  cps[2] = 0;
98 
99  for (unsigned int j = 0; j < devices.size(); ++j)
100  {
101  // Create an OpenCL context for the current device
102  context = cl::Context(vector<cl::Device>(1, devices[j]), cps, NULL, NULL, &status);
103  errorMessage(status, "Context::Context()");
104 
105  // Create an OpenCL command queue for current context and device
106  queue = CommandQueue(new cl::CommandQueue(context, devices[j], 0, &status));
107  errorMessage(status, "CommandQueue::CommandQueue()");
108 
109  cout << "\t" << devices[j].getInfo<CL_DEVICE_NAME>() << endl;
110  printHardwareInfo(queue);
111  cout << endl;
112  }
113  cout << endl;
114  }
115  }
116 
117  return 0;
118 }
cl_uint getVectorWidth(const CommandQueue &queue, const TypeID typeID)
cl_uint getNComputeUnits(const CommandQueue &queue)
Advanced Simulation Library.
Definition: aslDataInc.h:30
Advanced Computational Language.
Definition: acl.h:40
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
std::shared_ptr< cl::CommandQueue > CommandQueue
Definition: acl.h:51
cl_ulong getLocalMemorySize(const CommandQueue &queue)
string typeToString(unsigned int t)
Definition: asl-hardware.cc:36
unsigned int getAlignment(const CommandQueue &queue)
cl_device_type getDeviceType(const CommandQueue &queue)
CommandQueue interface for cl_command_queue.
Definition: cl.hpp:5354
bool extensionAvailable(const CommandQueue &queue, const Extension extension)
static cl_int get(VECTOR_CLASS< Platform > *platforms)
Gets a list of available platforms.
Definition: cl.hpp:2211
int main()
Definition: asl-hardware.cc:72
cl_device_local_mem_type getLocalMemoryType(const CommandQueue &queue)
void printHardwareInfo(const CommandQueue &queue)
Definition: asl-hardware.cc:51
std::string getDeviceVersion(const CommandQueue &queue)
useful common utilities
Class interface for cl_context.
Definition: cl.hpp:2341
size_t getMaxItemSize(const CommandQueue &queue)
std::string getDriverVersion(const CommandQueue &queue)