clover: Unify program::build_* into a single method returning a struct.
authorFrancisco Jerez <currojerez@riseup.net>
Tue, 17 May 2016 14:03:13 +0000 (16:03 +0200)
committerFrancisco Jerez <currojerez@riseup.net>
Tue, 12 Jul 2016 03:34:34 +0000 (20:34 -0700)
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 <edb+mesa@sigluy.net>
Tested-by: Jan Vesely <jan.vesely@rutgers.edu>
src/gallium/state_trackers/clover/api/program.cpp
src/gallium/state_trackers/clover/core/kernel.cpp
src/gallium/state_trackers/clover/core/program.cpp
src/gallium/state_trackers/clover/core/program.hpp

index 848d2d0329c6d9de0dd69969cd17e4555c228e94..91a81dfcc855173960f5376b92315ad13cc996d7 100644 (file)
@@ -287,7 +287,7 @@ clGetProgramInfo(cl_program d_prog, cl_program_info param,
 
    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;
@@ -296,7 +296,7 @@ clGetProgramInfo(cl_program d_prog, cl_program_info param,
       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());
@@ -335,15 +335,15 @@ clGetProgramBuildInfo(cl_program d_prog, cl_device_id d_dev,
 
    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:
index d9bda6c712c4805cc503dae24e2bc05e56577f52..962f55507f66ee31c2b4705c5ec7febfd20e6179 100644 (file)
@@ -51,7 +51,7 @@ kernel::launch(command_queue &q,
                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);
@@ -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<command_queue> _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();
index 2c511701e43fcd709157c4f84f379b1ccaefcaea..87a97cb1bffb477e164abfd00dd7d001cc270432 100644 (file)
@@ -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<device> &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<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
index 8a7be7a29c86f4bc88bbda75eb030f754635a826..ade225d29ae585cf86601306c3237a865c3f0005 100644 (file)
@@ -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<module::symbol> &symbols() const;
 
@@ -70,9 +78,7 @@ namespace clover {
 
    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;
    };