summaryrefslogtreecommitdiffstats
path: root/src/gallium
diff options
context:
space:
mode:
authorFrancisco Jerez <[email protected]>2016-05-17 16:03:13 +0200
committerFrancisco Jerez <[email protected]>2016-07-11 20:34:34 -0700
commit1942490bae01d44a08f263ea2dc747d11c82acfe (patch)
tree4e68c0ea0ad27d8430e37db5359aef51dc5bb913 /src/gallium
parent7f6a4a4342c1444990c55a77c60516c38738d203 (diff)
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 <[email protected]> Tested-by: Jan Vesely <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r--src/gallium/state_trackers/clover/api/program.cpp10
-rw-r--r--src/gallium/state_trackers/clover/core/kernel.cpp6
-rw-r--r--src/gallium/state_trackers/clover/core/program.cpp53
-rw-r--r--src/gallium/state_trackers/clover/core/program.hpp20
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<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:
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<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();
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<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
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<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;
};