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.
58 lines
1.4 KiB
58 lines
1.4 KiB
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
|
|
#define CL_HPP_TARGET_OPENCL_VERSION 120
|
|
|
|
#include <QCoreApplication>
|
|
#include <QFile>
|
|
#include <QTextStream>
|
|
#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);
|
|
|
|
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());
|
|
|
|
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();
|
|
|
|
cl_int error;
|
|
cl::Program program(main_context, script.toStdString(), CL_TRUE, &error);
|
|
qDebug() << error;
|
|
|
|
cl::Kernel kernel(program, "myVeryFirstFinction", &error);
|
|
qDebug() << error;
|
|
|
|
cl::KernelFunctor<> Functor(kernel);
|
|
|
|
cl::CommandQueue queue(main_context, all_devices.front());
|
|
cl::EnqueueArgs enargs(queue, cl::NDRange(5));
|
|
|
|
Functor(enargs);
|
|
|
|
return a.exec();
|
|
}
|
|
|