|
|
@ -2,6 +2,8 @@ |
|
|
|
#define CL_HPP_TARGET_OPENCL_VERSION 120 |
|
|
|
|
|
|
|
#include <QCoreApplication> |
|
|
|
#include <QFile> |
|
|
|
#include <QTextStream> |
|
|
|
#include <CL/cl2.hpp> |
|
|
|
#include <QDebug> |
|
|
|
|
|
|
@ -9,84 +11,48 @@ int main(int argc, char* argv[]) |
|
|
|
{ |
|
|
|
QCoreApplication a(argc, argv); |
|
|
|
|
|
|
|
//std::vector<cl::Platform> all_platforms;
|
|
|
|
////std::vector<cl::Device> all_dev;
|
|
|
|
//cl::Platform::get(&all_platforms);
|
|
|
|
////cl::Device::get(&all_dev);
|
|
|
|
std::vector<cl::Platform> all_platforms; |
|
|
|
cl::Platform::get(&all_platforms); |
|
|
|
|
|
|
|
//qDebug() << "Number of platforms found:" << all_platforms.size();
|
|
|
|
qDebug() << "Number of platforms found:" << all_platforms.size(); |
|
|
|
|
|
|
|
//foreach(auto platform, all_platforms)
|
|
|
|
//{
|
|
|
|
//qDebug() << platform.getInfo<CL_PLATFORM_NAME>().data();
|
|
|
|
//}
|
|
|
|
|
|
|
|
//std::vector<cl::Device> all_devices;
|
|
|
|
//all_platforms.front().getDevices(CL_DEVICE_TYPE_GPU, &all_devices);
|
|
|
|
|
|
|
|
//foreach(auto device, all_devices)
|
|
|
|
//{
|
|
|
|
//qDebug() << device.getInfo<CL_DEVICE_NAME>().data();
|
|
|
|
//}
|
|
|
|
|
|
|
|
////cl::Context main_context(all_devices.front());
|
|
|
|
foreach(auto platform, all_platforms) |
|
|
|
{ |
|
|
|
qDebug() << platform.getInfo<CL_PLATFORM_NAME>().data(); |
|
|
|
} |
|
|
|
|
|
|
|
////cl::Program program(main_context)
|
|
|
|
///
|
|
|
|
///
|
|
|
|
///
|
|
|
|
std::vector<cl::Platform> platforms; |
|
|
|
cl::Platform::get(&platforms); |
|
|
|
std::vector<cl::Device> all_devices; |
|
|
|
all_platforms.front().getDevices(CL_DEVICE_TYPE_GPU, &all_devices); |
|
|
|
|
|
|
|
int platform_id = 0; |
|
|
|
int device_id = 0; |
|
|
|
foreach(auto device, all_devices) |
|
|
|
{ |
|
|
|
qDebug() << device.getInfo<CL_DEVICE_NAME>().data(); |
|
|
|
} |
|
|
|
|
|
|
|
qDebug() << "Number of Platforms: " << platforms.size(); |
|
|
|
cl::Context main_context(all_devices.front()); |
|
|
|
|
|
|
|
for(std::vector<cl::Platform>::iterator it = platforms.begin(); it != platforms.end(); ++it) |
|
|
|
QFile cl_file("../OpenCL/test1.cl"); |
|
|
|
if(!cl_file.open(QIODevice::ReadOnly)) |
|
|
|
{ |
|
|
|
cl::Platform platform(*it); |
|
|
|
|
|
|
|
qDebug() << "Platform ID: " << platform_id++; |
|
|
|
qDebug() << "Platform Name: " << platform.getInfo<CL_PLATFORM_NAME>().data(); |
|
|
|
qDebug() << "Platform Vendor: " << platform.getInfo<CL_PLATFORM_VENDOR>().data(); |
|
|
|
qDebug() << cl_file.errorString(); |
|
|
|
} |
|
|
|
auto script = cl_file.readAll(); |
|
|
|
qDebug() << script; |
|
|
|
cl_file.close(); |
|
|
|
|
|
|
|
std::vector<cl::Device> devices; |
|
|
|
platform.getDevices(CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_CPU, &devices); |
|
|
|
cl_int error; |
|
|
|
cl::Program program(main_context, script.toStdString(), CL_TRUE, &error); |
|
|
|
qDebug() << error; |
|
|
|
|
|
|
|
for(std::vector<cl::Device>::iterator it2 = devices.begin(); it2 != devices.end(); ++it2) |
|
|
|
{ |
|
|
|
cl::Device device(*it2); |
|
|
|
cl::Kernel kernel(program, "myVeryFirstFinction", &error); |
|
|
|
qDebug() << error; |
|
|
|
|
|
|
|
qDebug() << "\tDevice " << device_id++ << ": "; |
|
|
|
qDebug() << "\t\tDevice Name: " << device.getInfo<CL_DEVICE_NAME>().data(); |
|
|
|
qDebug() << "\t\tDevice Vendor: " << device.getInfo<CL_DEVICE_VENDOR>().data(); |
|
|
|
qDebug() << "\t\tDevice Version: " << device.getInfo<CL_DEVICE_VERSION>().data(); |
|
|
|
switch(device.getInfo<CL_DEVICE_TYPE>()) |
|
|
|
{ |
|
|
|
case 4: |
|
|
|
qDebug() << "\t\tDevice Type: GPU"; |
|
|
|
break; |
|
|
|
cl::KernelFunctor<> Functor(kernel); |
|
|
|
|
|
|
|
case 2: |
|
|
|
qDebug() << "\t\tDevice Type: CPU"; |
|
|
|
break; |
|
|
|
cl::CommandQueue queue(main_context, all_devices.front()); |
|
|
|
cl::EnqueueArgs enargs(queue, cl::NDRange(5)); |
|
|
|
|
|
|
|
default: |
|
|
|
qDebug() << "\t\tDevice Type: unknown"; |
|
|
|
} |
|
|
|
qDebug() << "\t\tDevice Max Compute Units: " << |
|
|
|
device.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>(); |
|
|
|
qDebug() << "\t\tDevice Global Memory: " << device.getInfo<CL_DEVICE_GLOBAL_MEM_SIZE>(); |
|
|
|
qDebug() << "\t\tDevice Max Clock Frequency: " << |
|
|
|
device.getInfo<CL_DEVICE_MAX_CLOCK_FREQUENCY>(); |
|
|
|
qDebug() << "\t\tDevice Max Memory Allocation: " << |
|
|
|
device.getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>(); |
|
|
|
qDebug() << "\t\tDevice Local Memory: " << device.getInfo<CL_DEVICE_LOCAL_MEM_SIZE>(); |
|
|
|
qDebug() << "\t\tDevice Available: " << device.getInfo<CL_DEVICE_AVAILABLE>(); |
|
|
|
} |
|
|
|
qDebug(); |
|
|
|
} |
|
|
|
Functor(enargs); |
|
|
|
|
|
|
|
return a.exec(); |
|
|
|
} |
|
|
|