You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.4 KiB

2 years ago
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
#define CL_HPP_TARGET_OPENCL_VERSION 120
#include <QCoreApplication>
#include <QFile>
#include <QTextStream>
2 years ago
#include <CL/cl2.hpp>
#include <QDebug>
int main(int argc, char* argv[])
{
QCoreApplication a(argc, argv);
std::vector<cl::Platform> all_platforms;
cl::Platform::get(&all_platforms);
2 years ago
qDebug() << "Number of platforms found:" << all_platforms.size();
2 years ago
foreach(auto platform, all_platforms)
{
qDebug() << platform.getInfo<CL_PLATFORM_NAME>().data();
}
2 years ago
std::vector<cl::Device> all_devices;
all_platforms.front().getDevices(CL_DEVICE_TYPE_GPU, &all_devices);
2 years ago
foreach(auto device, all_devices)
{
qDebug() << device.getInfo<CL_DEVICE_NAME>().data();
}
2 years ago
cl::Context main_context(all_devices.front());
2 years ago
QFile cl_file("../OpenCL/test1.cl");
if(!cl_file.open(QIODevice::ReadOnly))
2 years ago
{
qDebug() << cl_file.errorString();
}
auto script = cl_file.readAll();
qDebug() << script;
cl_file.close();
2 years ago
cl_int error;
cl::Program program(main_context, script.toStdString(), CL_TRUE, &error);
qDebug() << error;
2 years ago
cl::Kernel kernel(program, "myVeryFirstFinction", &error);
qDebug() << error;
2 years ago
cl::KernelFunctor<> Functor(kernel);
2 years ago
cl::CommandQueue queue(main_context, all_devices.front());
cl::EnqueueArgs enargs(queue, cl::NDRange(5));
2 years ago
Functor(enargs);
2 years ago
return a.exec();
}