ASL  0.1.6
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 }
69 
70 
71 int main()
72 {
73 
74  // Have a look at the available platforms and their devices
75  vector<cl::Platform> platforms;
76  vector<cl::Device> devices;
77  cl_context_properties cps[3];
78  cl::Context context;
79  CommandQueue queue;
80 
81  cl_int status = 0;
82  status = cl::Platform::get(&platforms);
83  errorMessage(status, "Platform::get()");
84 
85  if (platforms.size() > 0)
86  {
87  for (unsigned int i = 0; i < platforms.size(); ++i)
88  {
89  status = platforms[i].getDevices(CL_DEVICE_TYPE_ALL, &devices);
90  errorMessage(status, "Platform::getDevices()");
91  cout << "Platform: " << platforms[i].getInfo<CL_PLATFORM_VENDOR>()
92  << "\nNumber of devices: " << devices.size() << endl;
93 
94  cps[0] = CL_CONTEXT_PLATFORM;
95  cps[1] = (cl_context_properties)(platforms[i])();
96  cps[2] = 0;
97 
98  for (unsigned int j = 0; j < devices.size(); ++j)
99  {
100  // Create an OpenCL context for the current device
101  context = cl::Context(vector<cl::Device>(1, devices[j]), cps, NULL, NULL, &status);
102  errorMessage(status, "Context::Context()");
103 
104  // Create an OpenCL command queue for current context and device
105  queue = CommandQueue(new cl::CommandQueue(context, devices[j], 0, &status));
106  errorMessage(status, "CommandQueue::CommandQueue()");
107 
108  cout << "\t" << devices[j].getInfo<CL_DEVICE_NAME>() << endl;
109  printHardwareInfo(queue);
110  cout << endl;
111  }
112  cout << endl;
113  }
114  }
115 
116  return 0;
117 }
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
STL namespace.
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:71
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)
Class interface for cl_context.
Definition: cl.hpp:2341
size_t getMaxItemSize(const CommandQueue &queue)