#define CL_HPP_MINIMUM_OPENCL_VERSION 120 #define CL_HPP_TARGET_OPENCL_VERSION 120 #include #include #include #include #include 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 all_platforms; cl::Platform::get(&all_platforms); qDebug() << "- Number of platforms found: " << all_platforms.size(); foreach(auto platform, all_platforms) { qDebug() << "- Platform name: " << platform.getInfo().data(); } std::vector all_devices; all_platforms.front().getDevices(CL_DEVICE_TYPE_GPU, &all_devices); foreach(auto device, all_devices) { qDebug() << "- Device Info: " << device.getInfo().data(); } cl::Context main_context(all_devices.front()); auto script = readFile("../OpenCL/test1.cl"); cl_int error; cl::Program program(main_context, script.toStdString(), CL_TRUE, &error); qDebug() << "Program error code: " << error; cl::Kernel kernel(program, "myVeryFirstFinction", &error); qDebug() << "Kernel error code: " << error; cl::KernelFunctor<> Functor(kernel); cl::CommandQueue queue(main_context, all_devices.front()); cl::NDRange range(5,2); cl::EnqueueArgs enargs(queue, range); Functor(enargs); return a.exec(); }