From 4a39e5073a7d0cd8243c6f963567a9945265490c Mon Sep 17 00:00:00 2001 From: Francisco Jerez Date: Sat, 14 Jun 2014 21:03:02 +0200 Subject: clover: Calculate the serialized size of a module efficiently. Tested-by: Tom Stellard --- src/gallium/state_trackers/clover/api/program.cpp | 5 +--- src/gallium/state_trackers/clover/core/module.cpp | 32 +++++++++++++++++++++++ src/gallium/state_trackers/clover/core/module.hpp | 1 + 3 files changed, 34 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gallium/state_trackers/clover/api/program.cpp b/src/gallium/state_trackers/clover/api/program.cpp index fedc91d531a..a14baa30e06 100644 --- a/src/gallium/state_trackers/clover/api/program.cpp +++ b/src/gallium/state_trackers/clover/api/program.cpp @@ -190,10 +190,7 @@ clGetProgramInfo(cl_program d_prog, cl_program_info param, case CL_PROGRAM_BINARY_SIZES: buf.as_vector() = map([&](const device &dev) { - compat::ostream::buffer_t bin; - compat::ostream s(bin); - prog.binary(dev).serialize(s); - return bin.size(); + return prog.binary(dev).size(); }, prog.devices()); break; diff --git a/src/gallium/state_trackers/clover/core/module.cpp b/src/gallium/state_trackers/clover/core/module.cpp index 41de7344203..55ed91af799 100644 --- a/src/gallium/state_trackers/clover/core/module.cpp +++ b/src/gallium/state_trackers/clover/core/module.cpp @@ -52,6 +52,13 @@ namespace { return x; } + /// Calculate the size of the specified object. + template + void + _proc(module::size_t &sz, const T &x) { + _serializer::proc(sz, x); + } + /// (De)serialize a scalar value. template struct _serializer(&x), sizeof(x)); } + + static void + proc(module::size_t &sz, const T &x) { + sz += sizeof(x); + } }; /// (De)serialize a vector. @@ -87,6 +99,14 @@ namespace { for (size_t i = 0; i < v.size(); i++) new(&v[i]) T(_proc(is)); } + + static void + proc(module::size_t &sz, const compat::vector &v) { + sz += sizeof(uint32_t); + + for (size_t i = 0; i < v.size(); i++) + _proc(sz, v[i]); + } }; template @@ -106,6 +126,11 @@ namespace { is.read(reinterpret_cast(v.begin()), v.size() * sizeof(T)); } + + static void + proc(module::size_t &sz, const compat::vector &v) { + sz += sizeof(uint32_t) + sizeof(T) * v.size(); + } }; /// (De)serialize a module::section. @@ -170,4 +195,11 @@ namespace clover { module::deserialize(compat::istream &is) { return _proc(is); } + + module::size_t + module::size() const { + size_t sz = 0; + _proc(sz, *this); + return sz; + } } diff --git a/src/gallium/state_trackers/clover/core/module.hpp b/src/gallium/state_trackers/clover/core/module.hpp index 4a8dbcb4949..18a5bfb24c3 100644 --- a/src/gallium/state_trackers/clover/core/module.hpp +++ b/src/gallium/state_trackers/clover/core/module.hpp @@ -105,6 +105,7 @@ namespace clover { void serialize(compat::ostream &os) const; static module deserialize(compat::istream &is); + size_t size() const; compat::vector syms; compat::vector
secs; -- cgit v1.2.3