From 1942490bae01d44a08f263ea2dc747d11c82acfe Mon Sep 17 00:00:00 2001 From: Francisco Jerez Date: Tue, 17 May 2016 16:03:13 +0200 Subject: [PATCH] clover: Unify program::build_* into a single method returning a struct. This gets rid of the program::build_* query methods and replaces them with the program::build() method that returns a single data structure containing all parameters for the last build done on the given target device (including build logs, options and the binary itself). [ Serge Martin: Fix inverted opts and log build ctor args ] Reviewed-by: Serge Martin Tested-by: Jan Vesely --- .../state_trackers/clover/api/program.cpp | 10 ++-- .../state_trackers/clover/core/kernel.cpp | 6 +-- .../state_trackers/clover/core/program.cpp | 53 +++++++------------ .../state_trackers/clover/core/program.hpp | 20 ++++--- 4 files changed, 39 insertions(+), 50 deletions(-) diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp index 848d2d0329c..91a81dfcc85 100644 --- a/src/gallium/state_trackers/clover/api/program.cpp +++ b/src/gallium/state_trackers/clover/api/program.cpp @@ -287,7 +287,7 @@ clGetProgramInfo(cl_program d_prog, cl_program_info param, case CL_PROGRAM_BINARY_SIZES: buf.as_vector() = map([&](const device &dev) { - return prog.binary(dev).size(); + return prog.build(dev).binary.size(); }, prog.devices()); break; @@ -296,7 +296,7 @@ clGetProgramInfo(cl_program d_prog, cl_program_info param, buf.as_matrix() = 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()); @@ -335,15 +335,15 @@ clGetProgramBuildInfo(cl_program d_prog, cl_device_id d_dev, switch (param) { case CL_PROGRAM_BUILD_STATUS: - buf.as_scalar() = prog.build_status(dev); + buf.as_scalar() = 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: diff --git a/src/gallium/state_trackers/clover/core/kernel.cpp b/src/gallium/state_trackers/clover/core/kernel.cpp index d9bda6c712c..962f55507f6 100644 --- a/src/gallium/state_trackers/clover/core/kernel.cpp +++ b/src/gallium/state_trackers/clover/core/kernel.cpp @@ -51,7 +51,7 @@ kernel::launch(command_queue &q, const std::vector &grid_offset, const std::vector &grid_size, const std::vector &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); @@ -142,7 +142,7 @@ kernel::args() const { 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) : @@ -160,7 +160,7 @@ kernel::exec_context::bind(intrusive_ptr _q, 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(); diff --git a/src/gallium/state_trackers/clover/core/program.cpp b/src/gallium/state_trackers/clover/core/program.cpp index 2c511701e43..87a97cb1bff 100644 --- a/src/gallium/state_trackers/clover/core/program.cpp +++ b/src/gallium/state_trackers/clover/core/program.cpp @@ -35,7 +35,7 @@ program::program(clover::context &ctx, 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); } @@ -47,25 +47,17 @@ program::build(const ref_vector &devs, const std::string &opts, _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; } } @@ -82,37 +74,28 @@ program::devices() const { 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 & 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 diff --git a/src/gallium/state_trackers/clover/core/program.hpp b/src/gallium/state_trackers/clover/core/program.hpp index 8a7be7a29c8..ade225d29ae 100644 --- a/src/gallium/state_trackers/clover/core/program.hpp +++ b/src/gallium/state_trackers/clover/core/program.hpp @@ -55,10 +55,18 @@ namespace clover { 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 &symbols() const; @@ -70,9 +78,7 @@ namespace clover { private: std::vector> _devices; - std::map _binaries; - std::map _logs; - std::map _opts; + std::map _builds; std::string _source; ref_counter _kernel_ref_counter; }; -- 2.30.2