Browse Source

Making readFile Function and minor qDebug() changes

master
Hatef 2 years ago
parent
commit
94209c9a96
  1. 42
      main.cpp

42
main.cpp

@ -7,51 +7,53 @@
#include <CL/cl2.hpp>
#include <QDebug>
QString readFile(const QString& directory)
{
QFile cl_file(directory);
if(!cl_file.open(QIODevice::ReadOnly))
{
qDebug() << cl_file.errorString();
return QString("");
}
QString script = cl_file.readAll();
cl_file.close();
return script;
}
/*********************************************************************************************************************/
int main(int argc, char* argv[])
{
QCoreApplication a(argc, argv);
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();
qDebug() << "- Platform name: " << 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();
qDebug() << "- Device Info: " << device.getInfo<CL_DEVICE_NAME>().data();
}
cl::Context main_context(all_devices.front());
QFile cl_file("../OpenCL/test1.cl");
if(!cl_file.open(QIODevice::ReadOnly))
{
qDebug() << cl_file.errorString();
}
auto script = cl_file.readAll();
qDebug() << script;
cl_file.close();
auto script = readFile("../OpenCL/test1.cl");
cl_int error;
cl::Program program(main_context, script.toStdString(), CL_TRUE, &error);
qDebug() << error;
qDebug() << "Program error code: " << error;
cl::Kernel kernel(program, "myVeryFirstFinction", &error);
qDebug() << error;
qDebug() << "Kernel error code: " << error;
cl::KernelFunctor<> Functor(kernel);
cl::CommandQueue queue(main_context, all_devices.front());
cl::EnqueueArgs enargs(queue, cl::NDRange(5));
cl::NDRange range(5,2);
cl::EnqueueArgs enargs(queue, range);
Functor(enargs);
return a.exec();

Loading…
Cancel
Save