[Mesa-dev] [PATCH] clover: Cache serialized binaries
Tom Stellard
thomas.stellard at amd.com
Fri Jun 13 11:35:22 PDT 2014
We were serializing the binaries once when clGetProgramInfo was called
with CL_PROGRAM_BINARY_SIZES and then again when it was called with
CL_PROGRAM_BINARIES. This was slowing down some OpenCV tests which were
building binary kernel caches.
This improves the run-time of OpenCV's OCL_ImgProc/CvtColor8u.*
test from 7 minutes to 1 minute.
---
src/gallium/state_trackers/clover/api/program.cpp | 10 ++--------
src/gallium/state_trackers/clover/core/program.cpp | 12 ++++++++++++
src/gallium/state_trackers/clover/core/program.hpp | 2 ++
3 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp
index fedc91d..68ef698 100644
--- a/src/gallium/state_trackers/clover/api/program.cpp
+++ b/src/gallium/state_trackers/clover/api/program.cpp
@@ -190,20 +190,14 @@ clGetProgramInfo(cl_program d_prog, cl_program_info param,
case CL_PROGRAM_BINARY_SIZES:
buf.as_vector<size_t>() = map([&](const device &dev) {
- compat::ostream::buffer_t bin;
- compat::ostream s(bin);
- prog.binary(dev).serialize(s);
- return bin.size();
+ return prog.serialized_binary(dev).size();
},
prog.devices());
break;
case CL_PROGRAM_BINARIES:
buf.as_matrix<unsigned char>() = map([&](const device &dev) {
- compat::ostream::buffer_t bin;
- compat::ostream s(bin);
- prog.binary(dev).serialize(s);
- return bin;
+ return prog.serialized_binary(dev);
},
prog.devices());
break;
diff --git a/src/gallium/state_trackers/clover/core/program.cpp b/src/gallium/state_trackers/clover/core/program.cpp
index 3aaa652..b0c902c 100644
--- a/src/gallium/state_trackers/clover/core/program.cpp
+++ b/src/gallium/state_trackers/clover/core/program.cpp
@@ -47,6 +47,7 @@ program::build(const ref_vector<device> &devs, const char *opts) {
for (auto &dev : devs) {
_binaries.erase(&dev);
+ _serialized_binaries.erase(&dev);
_logs.erase(&dev);
_opts.erase(&dev);
@@ -82,6 +83,17 @@ program::binary(const device &dev) const {
return _binaries.find(&dev)->second;
}
+compat::ostream::buffer_t
+program::serialized_binary(const device &dev) {
+ if (_serialized_binaries.count(&dev) == 0) {
+ compat::ostream::buffer_t bin;
+ compat::ostream s(bin);
+ binary(dev).serialize(s);
+ _serialized_binaries.insert({&dev, bin});
+ }
+ return _serialized_binaries.find(&dev)->second;
+}
+
cl_build_status
program::build_status(const device &dev) const {
if (_binaries.count(&dev))
diff --git a/src/gallium/state_trackers/clover/core/program.hpp b/src/gallium/state_trackers/clover/core/program.hpp
index 1081454..6edbe2a 100644
--- a/src/gallium/state_trackers/clover/core/program.hpp
+++ b/src/gallium/state_trackers/clover/core/program.hpp
@@ -54,6 +54,7 @@ namespace clover {
device_range devices() const;
const module &binary(const device &dev) const;
+ compat::ostream::buffer_t serialized_binary(const device &dev);
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;
@@ -65,6 +66,7 @@ namespace clover {
private:
std::vector<intrusive_ref<device>> _devices;
std::map<const device *, module> _binaries;
+ std::map<const device *, compat::ostream::buffer_t> _serialized_binaries;
std::map<const device *, std::string> _logs;
std::map<const device *, std::string> _opts;
std::string _source;
--
1.8.1.5
More information about the mesa-dev
mailing list