case CL_PROGRAM_BINARY_SIZES:
buf.as_vector<size_t>() = map([&](const device &dev) {
- return prog.binary(dev).size();
+ return prog.build(dev).binary.size();
},
prog.devices());
break;
buf.as_matrix<unsigned char>() = map([&](const device &dev) {
std::stringbuf bin;
std::ostream s(&bin);
- prog.binary(dev).serialize(s);
+ prog.build(dev).binary.serialize(s);
return bin.str();
},
prog.devices());
switch (param) {
case CL_PROGRAM_BUILD_STATUS:
- buf.as_scalar<cl_build_status>() = prog.build_status(dev);
+ buf.as_scalar<cl_build_status>() = prog.build(dev).status();
break;
case CL_PROGRAM_BUILD_OPTIONS:
- buf.as_string() = prog.build_opts(dev);
+ buf.as_string() = prog.build(dev).opts;
break;
case CL_PROGRAM_BUILD_LOG:
- buf.as_string() = prog.build_log(dev);
+ buf.as_string() = prog.build(dev).log;
break;
default:
const std::vector<size_t> &grid_offset,
const std::vector<size_t> &grid_size,
const std::vector<size_t> &block_size) {
- const auto m = program().binary(q.device());
+ const auto m = program().build(q.device()).binary;
const auto reduced_grid_size =
map(divides(), grid_size, block_size);
void *st = exec.bind(&q, grid_offset);
const module &
kernel::module(const command_queue &q) const {
- return program().binary(q.device());
+ return program().build(q.device()).binary;
}
kernel::exec_context::exec_context(kernel &kern) :
std::swap(q, _q);
// Bind kernel arguments.
- auto &m = kern.program().binary(q->device());
+ auto &m = kern.program().build(q->device()).binary;
auto margs = find(name_equals(kern.name()), m.syms).args;
auto msec = find(type_equals(module::section::text), m.secs);
auto explicit_arg = kern._args.begin();
has_source(false), context(ctx),
_devices(devs), _kernel_ref_counter(0) {
for_each([&](device &dev, const module &bin) {
- _binaries.insert({ &dev, bin });
+ _builds[&dev] = { bin };
},
devs, binaries);
}
_devices = devs;
for (auto &dev : devs) {
- _binaries.erase(&dev);
- _logs.erase(&dev);
- _opts.erase(&dev);
-
- _opts.insert({ &dev, opts });
-
std::string log;
try {
- auto module = (dev.ir_format() == PIPE_SHADER_IR_TGSI ?
- tgsi::compile_program(_source, log) :
- compile_program_llvm(_source, headers,
- dev.ir_format(),
- dev.ir_target(), opts,
- log));
- _binaries.insert({ &dev, module });
- _logs.insert({ &dev, log });
- } catch (const error &) {
- _logs.insert({ &dev, log });
+ const module m = (dev.ir_format() == PIPE_SHADER_IR_TGSI ?
+ tgsi::compile_program(_source, log) :
+ compile_program_llvm(_source, headers,
+ dev.ir_format(),
+ dev.ir_target(), opts, log));
+ _builds[&dev] = { m, opts, log };
+ } catch (...) {
+ _builds[&dev] = { module(), opts, log };
throw;
}
}
return map(evals(), _devices);
}
-const module &
-program::binary(const device &dev) const {
- return _binaries.find(&dev)->second;
-}
-
cl_build_status
-program::build_status(const device &dev) const {
- if (_binaries.count(&dev))
+program::build::status() const {
+ if (!binary.secs.empty())
return CL_BUILD_SUCCESS;
- else if (_logs.count(&dev))
+ else if (log.size())
return CL_BUILD_ERROR;
else
return CL_BUILD_NONE;
}
-std::string
-program::build_opts(const device &dev) const {
- return _opts.count(&dev) ? _opts.find(&dev)->second : "";
-}
-
-std::string
-program::build_log(const device &dev) const {
- return _logs.count(&dev) ? _logs.find(&dev)->second : "";
+const struct program::build &
+program::build(const device &dev) const {
+ static const struct build null;
+ return _builds.count(&dev) ? _builds.find(&dev)->second : null;
}
const std::vector<module::symbol> &
program::symbols() const {
- if (_binaries.empty())
+ if (_builds.empty())
throw error(CL_INVALID_PROGRAM_EXECUTABLE);
- return _binaries.begin()->second.syms;
+ return _builds.begin()->second.binary.syms;
}
unsigned
device_range devices() const;
- const module &binary(const device &dev) const;
- cl_build_status build_status(const device &dev) const;
- std::string build_opts(const device &dev) const;
- std::string build_log(const device &dev) const;
+ struct build {
+ build(const module &m = {}, const std::string &opts = {},
+ const std::string &log = {}) : binary(m), opts(opts), log(log) {}
+
+ cl_build_status status() const;
+
+ module binary;
+ std::string opts;
+ std::string log;
+ };
+
+ const struct build &build(const device &dev) const;
const std::vector<module::symbol> &symbols() const;
private:
std::vector<intrusive_ref<device>> _devices;
- std::map<const device *, module> _binaries;
- std::map<const device *, std::string> _logs;
- std::map<const device *, std::string> _opts;
+ std::map<const device *, struct build> _builds;
std::string _source;
ref_counter _kernel_ref_counter;
};