1
0
Fork 0

Ulozenie binarky do suboru takze nie je nutne kompilovat zo zdrojoveho kodu

master
Dušan Poizl 8 years ago
parent cf1746312b
commit b226b38fc5
  1. 63
      tracer.cpp

@ -8,6 +8,7 @@
#include <QThread>
#include <QFile>
#include <QElapsedTimer>
#include <QSettings>
#include <random>
#include "mwc64x.h"
@ -237,32 +238,60 @@ void Tracer::initWithDevice(cl::Device &device)
devices.push_back(device);
context = unique_ptr<cl::Context>(new cl::Context(devices, properties, 0, 0));
QFile fr(":/intersect_kernel.cl");
fr.open(QIODevice::ReadOnly);
string source = QString::fromUtf8(fr.readAll()).toStdString();
try
QSettings settings;
QByteArray binary = settings.value("opencl/binary").toByteArray();
if(!binary.isEmpty())
{
program = unique_ptr<cl::Program>(new cl::Program(*context, source, false));
cl_int err = program->build();
if(err!=CL_SUCCESS)
try
{
cl::Program::Binaries binaries;
binaries.push_back(pair<const void*, ::size_t>(binary.constData(), binary.size()));
vector<cl::Device> devices = {device};
program = unique_ptr<cl::Program>(new cl::Program(*context, devices, binaries));
program->build();
}
catch(cl::Error err)
{
string log;
program->getBuildInfo(device, CL_PROGRAM_BUILD_LOG, &log);
cout << log << endl;
program.reset();
}
}
catch(cl::Error err)
if(!program)
{
if(err.err()==CL_BUILD_PROGRAM_FAILURE)
QFile fr(":/intersect_kernel.cl");
fr.open(QIODevice::ReadOnly);
string source = QString::fromUtf8(fr.readAll()).toStdString();
try
{
program = unique_ptr<cl::Program>(new cl::Program(*context, source, false));
cl_int err = program->build();
if(err!=CL_SUCCESS)
{
string log;
program->getBuildInfo(device, CL_PROGRAM_BUILD_LOG, &log);
cout << log << endl;
}
}
catch(cl::Error err)
{
string log;
program->getBuildInfo(device, CL_PROGRAM_BUILD_LOG, &log);
cout << log << endl;
if(err.err()==CL_BUILD_PROGRAM_FAILURE)
{
string log;
program->getBuildInfo(device, CL_PROGRAM_BUILD_LOG, &log);
cout << log << endl;
}
throw err;
}
throw err;
vector<size_t> sizes;
vector<char*> binaries;
program->getInfo(CL_PROGRAM_BINARY_SIZES, &sizes);
binaries.push_back(new char[sizes[0]]);
program->getInfo(CL_PROGRAM_BINARIES, &binaries);
settings.setValue("opencl/binary", QByteArray(binaries[0], sizes[0]));
}
aabb_kernel = unique_ptr<cl::Kernel>(new cl::Kernel(*program, "aabb_traverse"));
get_image_kernel = unique_ptr<cl::Kernel>(new cl::Kernel(*program, "get_image"));
init_rays = unique_ptr<cl::Kernel>(new cl::Kernel(*program, "init_rays"));

Loading…
Cancel
Save