asl-hardware.cc
Go to the documentation of this file.
/*
* Advanced Simulation Library <http://asl.org.il>
*
* Copyright 2015 Avtech Scientific <http://avtechscientific.com>
*
*
* This file is part of Advanced Simulation Library (ASL).
*
* ASL is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, version 3 of the License.
*
* ASL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with ASL. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "acl/aclHardware.h"
#include "aslUtilities.h"
using namespace acl;
using namespace std;
using namespace asl;
string typeToString(unsigned int t)
{
string s;
switch (t)
{
case CL_DEVICE_TYPE_CPU : s="CPU"; break;
case CL_DEVICE_TYPE_GPU : s="GPU"; break;
case CL_DEVICE_TYPE_ACCELERATOR : s="ACCELERATOR"; break;
case CL_DEVICE_TYPE_DEFAULT : s="DEFAULT"; break;
// case CL_DEVICE_TYPE_CUSTOM : s="CUSTOM"; break; //in opencl 1.1 is undefined
default: s="type is unknown";
}
return s;
}
void printHardwareInfo(const CommandQueue & queue)
{
cout << "\t\ttype: " << typeToString(getDeviceType(queue)) << endl;
cout << "\t\tnumber of compute units: " << getNComputeUnits(queue) << endl;
cout << "\t\talignment: " << getAlignment(queue) << endl;
cout << "\t\tlocal memory type: "
<< (getLocalMemoryType(queue) == CL_LOCAL ? "CL_LOCAL" : "CL_GLOBAL") << endl;
cout << "\t\tlocal memory size: " << getLocalMemorySize(queue) << endl;
cout << "\t\tmax item size: " << getMaxItemSize(queue) << endl;
cout << "\t\tvector width float: " << getVectorWidth(queue, TYPE_FLOAT) << endl;
cout << "\t\tvector width double: " << getVectorWidth(queue, TYPE_DOUBLE) << endl;
cout << "\t\textension CL_KHR_FP64: "
<< extensionAvailable(queue, CL_KHR_FP64) << endl;
cout << "\t\textension CL_KHR_INT64_EXTENDED_ATOMICS: "
<< extensionAvailable(queue, CL_KHR_INT64_EXTENDED_ATOMICS) << endl;
cout << "\t\tsupported OpenCL version: " << getDeviceVersion(queue) << endl;
cout << "\t\tOpenCL driver version: "<< getDriverVersion(queue) << endl;
}
int main()
{
// Have a look at the available platforms and their devices
vector<cl::Platform> platforms;
vector<cl::Device> devices;
cl_context_properties cps[3];
cl::Context context;
CommandQueue queue;
cl_int status = 0;
status = cl::Platform::get(&platforms);
errorMessage(status, "Platform::get()");
if (platforms.size() > 0)
{
for (unsigned int i = 0; i < platforms.size(); ++i)
{
status = platforms[i].getDevices(CL_DEVICE_TYPE_ALL, &devices);
errorMessage(status, "Platform::getDevices()");
cout << "Platform: " << platforms[i].getInfo<CL_PLATFORM_VENDOR>()
<< "\nNumber of devices: " << devices.size() << endl;
cps[0] = CL_CONTEXT_PLATFORM;
cps[1] = (cl_context_properties)(platforms[i])();
cps[2] = 0;
for (unsigned int j = 0; j < devices.size(); ++j)
{
// Create an OpenCL context for the current device
context = cl::Context(vector<cl::Device>(1, devices[j]), cps, NULL, NULL, &status);
errorMessage(status, "Context::Context()");
// Create an OpenCL command queue for current context and device
queue = CommandQueue(new cl::CommandQueue(context, devices[j], 0, &status));
errorMessage(status, "CommandQueue::CommandQueue()");
cout << "\t" << devices[j].getInfo<CL_DEVICE_NAME>() << endl;
printHardwareInfo(queue);
cout << endl;
}
cout << endl;
}
}
return 0;
}
printHardwareInfo
void printHardwareInfo(const CommandQueue &queue)
Definition: asl-hardware.cc:51
typeToString
string typeToString(unsigned int t)
Definition: asl-hardware.cc:36
main
int main()
Definition: asl-hardware.cc:72
cl::CommandQueue
CommandQueue interface for cl_command_queue.
Definition: cl.hpp:5355
cl::Context
Class interface for cl_context.
Definition: cl.hpp:2343
cl::Platform::get
static cl_int get(VECTOR_CLASS< Platform > *platforms)
Gets a list of available platforms.
Definition: cl.hpp:2211
asl::errorMessage
void errorMessage(cl_int status, const char *errorMessage)
Prints errorMessage and exits depending on the status.
acl::getMaxItemSize
size_t getMaxItemSize(const CommandQueue &queue)
acl::getVectorWidth
cl_uint getVectorWidth(const CommandQueue &queue, const TypeID typeID)
acl::getDeviceType
cl_device_type getDeviceType(const CommandQueue &queue)
acl::extensionAvailable
bool extensionAvailable(const CommandQueue &queue, const Extension extension)
acl::getNComputeUnits
cl_uint getNComputeUnits(const CommandQueue &queue)
acl::getAlignment
unsigned int getAlignment(const CommandQueue &queue)
acl::getLocalMemorySize
cl_ulong getLocalMemorySize(const CommandQueue &queue)
acl::getLocalMemoryType
cl_device_local_mem_type getLocalMemoryType(const CommandQueue &queue)
acl
Advanced Computational Language.
Definition: acl.h:41
acl::CommandQueue
std::shared_ptr< cl::CommandQueue > CommandQueue
Definition: acl.h:51
acl::getDriverVersion
std::string getDriverVersion(const CommandQueue &queue)
acl::CL_KHR_FP64
@ CL_KHR_FP64
Definition: aclTypes.h:31
acl::CL_KHR_INT64_EXTENDED_ATOMICS
@ CL_KHR_INT64_EXTENDED_ATOMICS
Definition: aclTypes.h:33
acl::TYPE_DOUBLE
@ TYPE_DOUBLE
Definition: aclTypes.h:43
acl::TYPE_FLOAT
@ TYPE_FLOAT
Definition: aclTypes.h:42
acl::getDeviceVersion
std::string getDeviceVersion(const CommandQueue &queue)
asl
Advanced Simulation Library.
Definition: aslDataInc.h:31