clover: Calculate the serialized size of a module efficiently.
Tested-by: Tom Stellard <thomas.stellard@amd.com>
This commit is contained in:
@@ -190,10 +190,7 @@ clGetProgramInfo(cl_program d_prog, cl_program_info param,
|
|||||||
|
|
||||||
case CL_PROGRAM_BINARY_SIZES:
|
case CL_PROGRAM_BINARY_SIZES:
|
||||||
buf.as_vector<size_t>() = map([&](const device &dev) {
|
buf.as_vector<size_t>() = map([&](const device &dev) {
|
||||||
compat::ostream::buffer_t bin;
|
return prog.binary(dev).size();
|
||||||
compat::ostream s(bin);
|
|
||||||
prog.binary(dev).serialize(s);
|
|
||||||
return bin.size();
|
|
||||||
},
|
},
|
||||||
prog.devices());
|
prog.devices());
|
||||||
break;
|
break;
|
||||||
|
@@ -52,6 +52,13 @@ namespace {
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Calculate the size of the specified object.
|
||||||
|
template<typename T>
|
||||||
|
void
|
||||||
|
_proc(module::size_t &sz, const T &x) {
|
||||||
|
_serializer<T>::proc(sz, x);
|
||||||
|
}
|
||||||
|
|
||||||
/// (De)serialize a scalar value.
|
/// (De)serialize a scalar value.
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct _serializer<T, typename std::enable_if<
|
struct _serializer<T, typename std::enable_if<
|
||||||
@@ -65,6 +72,11 @@ namespace {
|
|||||||
proc(compat::istream &is, T &x) {
|
proc(compat::istream &is, T &x) {
|
||||||
is.read(reinterpret_cast<char *>(&x), sizeof(x));
|
is.read(reinterpret_cast<char *>(&x), sizeof(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
proc(module::size_t &sz, const T &x) {
|
||||||
|
sz += sizeof(x);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// (De)serialize a vector.
|
/// (De)serialize a vector.
|
||||||
@@ -87,6 +99,14 @@ namespace {
|
|||||||
for (size_t i = 0; i < v.size(); i++)
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
new(&v[i]) T(_proc<T>(is));
|
new(&v[i]) T(_proc<T>(is));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
proc(module::size_t &sz, const compat::vector<T> &v) {
|
||||||
|
sz += sizeof(uint32_t);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < v.size(); i++)
|
||||||
|
_proc<T>(sz, v[i]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
@@ -106,6 +126,11 @@ namespace {
|
|||||||
is.read(reinterpret_cast<char *>(v.begin()),
|
is.read(reinterpret_cast<char *>(v.begin()),
|
||||||
v.size() * sizeof(T));
|
v.size() * sizeof(T));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
proc(module::size_t &sz, const compat::vector<T> &v) {
|
||||||
|
sz += sizeof(uint32_t) + sizeof(T) * v.size();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// (De)serialize a module::section.
|
/// (De)serialize a module::section.
|
||||||
@@ -170,4 +195,11 @@ namespace clover {
|
|||||||
module::deserialize(compat::istream &is) {
|
module::deserialize(compat::istream &is) {
|
||||||
return _proc<module>(is);
|
return _proc<module>(is);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module::size_t
|
||||||
|
module::size() const {
|
||||||
|
size_t sz = 0;
|
||||||
|
_proc(sz, *this);
|
||||||
|
return sz;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -105,6 +105,7 @@ namespace clover {
|
|||||||
|
|
||||||
void serialize(compat::ostream &os) const;
|
void serialize(compat::ostream &os) const;
|
||||||
static module deserialize(compat::istream &is);
|
static module deserialize(compat::istream &is);
|
||||||
|
size_t size() const;
|
||||||
|
|
||||||
compat::vector<symbol> syms;
|
compat::vector<symbol> syms;
|
||||||
compat::vector<section> secs;
|
compat::vector<section> secs;
|
||||||
|
Reference in New Issue
Block a user