Browse Source

Successfully running kernel first time

master
Hatef 2 years ago
parent
commit
daeeeb8676
  1. 98
      main.cpp
  2. 5
      test1.cl

98
main.cpp

@ -2,6 +2,8 @@
#define CL_HPP_TARGET_OPENCL_VERSION 120 #define CL_HPP_TARGET_OPENCL_VERSION 120
#include <QCoreApplication> #include <QCoreApplication>
#include <QFile>
#include <QTextStream>
#include <CL/cl2.hpp> #include <CL/cl2.hpp>
#include <QDebug> #include <QDebug>
@ -9,84 +11,48 @@ int main(int argc, char* argv[])
{ {
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
//std::vector<cl::Platform> all_platforms; std::vector<cl::Platform> all_platforms;
////std::vector<cl::Device> all_dev; cl::Platform::get(&all_platforms);
//cl::Platform::get(&all_platforms);
////cl::Device::get(&all_dev);
//qDebug() << "Number of platforms found:" << all_platforms.size(); qDebug() << "Number of platforms found:" << all_platforms.size();
//foreach(auto platform, all_platforms) foreach(auto platform, all_platforms)
//{ {
//qDebug() << platform.getInfo<CL_PLATFORM_NAME>().data(); 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());
////cl::Program program(main_context) std::vector<cl::Device> all_devices;
/// all_platforms.front().getDevices(CL_DEVICE_TYPE_GPU, &all_devices);
///
///
std::vector<cl::Platform> platforms;
cl::Platform::get(&platforms);
int platform_id = 0; foreach(auto device, all_devices)
int device_id = 0; {
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() << cl_file.errorString();
}
qDebug() << "Platform ID: " << platform_id++; auto script = cl_file.readAll();
qDebug() << "Platform Name: " << platform.getInfo<CL_PLATFORM_NAME>().data(); qDebug() << script;
qDebug() << "Platform Vendor: " << platform.getInfo<CL_PLATFORM_VENDOR>().data(); cl_file.close();
std::vector<cl::Device> devices; cl_int error;
platform.getDevices(CL_DEVICE_TYPE_GPU | CL_DEVICE_TYPE_CPU, &devices); 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::Kernel kernel(program, "myVeryFirstFinction", &error);
{ qDebug() << error;
cl::Device device(*it2);
qDebug() << "\tDevice " << device_id++ << ": "; cl::KernelFunctor<> Functor(kernel);
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;
case 2: cl::CommandQueue queue(main_context, all_devices.front());
qDebug() << "\t\tDevice Type: CPU"; cl::EnqueueArgs enargs(queue, cl::NDRange(5));
break;
default: Functor(enargs);
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();
}
return a.exec(); return a.exec();
} }

5
test1.cl

@ -0,0 +1,5 @@
void __kernel myVeryFirstFinction()
{
if(get_global_id(0))
printf("Success!");
}
Loading…
Cancel
Save