[Beignet] [PATCH 1/2] GBE: change GEN binary format.
Yang Rong
rong.r.yang at intel.com
Mon Jun 6 09:48:31 UTC 2016
Change all size_t to uint32_t when generate GEN binary, size_t is
non compat between 32bit system and 64bit system, and uint32_t is
enough.
Signed-off-by: Yang Rong <rong.r.yang at intel.com>
---
backend/src/backend/gen_program.cpp | 2 +-
backend/src/backend/gen_program.hpp | 2 +-
backend/src/backend/program.cpp | 76 ++++++++++++++++++++-----------------
backend/src/backend/program.hpp | 12 +++---
backend/src/ir/constant.cpp | 51 +++++++++++++------------
backend/src/ir/constant.hpp | 4 +-
backend/src/ir/image.cpp | 21 +++++-----
backend/src/ir/image.hpp | 4 +-
backend/src/ir/sampler.cpp | 16 ++++----
backend/src/ir/sampler.hpp | 4 +-
backend/src/sys/platform.hpp | 8 ++--
11 files changed, 107 insertions(+), 93 deletions(-)
diff --git a/backend/src/backend/gen_program.cpp b/backend/src/backend/gen_program.cpp
index 0abe54e..69ddb22 100644
--- a/backend/src/backend/gen_program.cpp
+++ b/backend/src/backend/gen_program.cpp
@@ -80,7 +80,7 @@ namespace gbe {
insns = (GenInstruction *)ins;
insnNum = size / sizeof(GenInstruction);
}
- size_t GenKernel::getCodeSize(void) const { return insnNum * sizeof(GenInstruction); }
+ uint32_t GenKernel::getCodeSize(void) const { return insnNum * sizeof(GenInstruction); }
void GenKernel::printStatus(int indent, std::ostream& outs) {
#ifdef GBE_COMPILER_AVAILABLE
diff --git a/backend/src/backend/gen_program.hpp b/backend/src/backend/gen_program.hpp
index 00b484a..076f617 100644
--- a/backend/src/backend/gen_program.hpp
+++ b/backend/src/backend/gen_program.hpp
@@ -46,7 +46,7 @@ namespace gbe
/*! Set the instruction stream (to be implemented) */
virtual void setCode(const char *, size_t size);
/*! Implements get the code size */
- virtual size_t getCodeSize(void) const;
+ virtual uint32_t getCodeSize(void) const;
/*! Implements printStatus*/
virtual void printStatus(int indent, std::ostream& outs);
uint32_t deviceID; //!< Current device ID
diff --git a/backend/src/backend/program.cpp b/backend/src/backend/program.cpp
index 4f8167c..d13cba5 100644
--- a/backend/src/backend/program.cpp
+++ b/backend/src/backend/program.cpp
@@ -198,17 +198,17 @@ namespace gbe {
#define OUT_UPDATE_SZ(elt) SERIALIZE_OUT(elt, outs, ret_size)
#define IN_UPDATE_SZ(elt) DESERIALIZE_IN(elt, ins, total_size)
- size_t Program::serializeToBin(std::ostream& outs) {
- size_t ret_size = 0;
- size_t ker_num = kernels.size();
- int has_constset = 0;
+ uint32_t Program::serializeToBin(std::ostream& outs) {
+ uint32_t ret_size = 0;
+ uint32_t ker_num = kernels.size();
+ uint32_t has_constset = 0;
OUT_UPDATE_SZ(magic_begin);
if (constantSet) {
has_constset = 1;
OUT_UPDATE_SZ(has_constset);
- size_t sz = constantSet->serializeToBin(outs);
+ uint32_t sz = constantSet->serializeToBin(outs);
if (!sz)
return 0;
@@ -219,7 +219,7 @@ namespace gbe {
OUT_UPDATE_SZ(ker_num);
for (map<std::string, Kernel*>::iterator it = kernels.begin(); it != kernels.end(); ++it) {
- size_t sz = it->second->serializeToBin(outs);
+ uint32_t sz = it->second->serializeToBin(outs);
if (!sz)
return 0;
@@ -232,10 +232,10 @@ namespace gbe {
return ret_size;
}
- size_t Program::deserializeFromBin(std::istream& ins) {
- size_t total_size = 0;
+ uint32_t Program::deserializeFromBin(std::istream& ins) {
+ uint32_t total_size = 0;
int has_constset = 0;
- size_t ker_num;
+ uint32_t ker_num;
uint32_t magic;
IN_UPDATE_SZ(magic);
@@ -245,19 +245,18 @@ namespace gbe {
IN_UPDATE_SZ(has_constset);
if(has_constset) {
constantSet = new ir::ConstantSet;
- size_t sz = constantSet->deserializeFromBin(ins);
+ uint32_t sz = constantSet->deserializeFromBin(ins);
- if (sz == 0) {
+ if (sz == 0)
return 0;
- }
total_size += sz;
}
IN_UPDATE_SZ(ker_num);
- for (size_t i = 0; i < ker_num; i++) {
- size_t ker_serial_sz;
+ for (uint32_t i = 0; i < ker_num; i++) {
+ uint32_t ker_serial_sz;
std::string ker_name; // Just a empty name here.
Kernel* ker = allocateKernel(ker_name);
@@ -272,7 +271,7 @@ namespace gbe {
if (magic != magic_end)
return 0;
- size_t total_bytes;
+ uint32_t total_bytes;
IN_UPDATE_SZ(total_bytes);
if (total_bytes + sizeof(total_size) != total_size)
return 0;
@@ -280,15 +279,17 @@ namespace gbe {
return total_size;
}
- size_t Kernel::serializeToBin(std::ostream& outs) {
+ uint32_t Kernel::serializeToBin(std::ostream& outs) {
unsigned int i;
- size_t ret_size = 0;
+ uint32_t ret_size = 0;
int has_samplerset = 0;
int has_imageset = 0;
+ uint32_t sz = 0;
OUT_UPDATE_SZ(magic_begin);
- OUT_UPDATE_SZ(name.size());
+ sz = name.size();
+ OUT_UPDATE_SZ(sz);
outs.write(name.c_str(), name.size());
ret_size += sizeof(char)*name.size();
@@ -302,25 +303,30 @@ namespace gbe {
OUT_UPDATE_SZ(arg.info.addrSpace);
- OUT_UPDATE_SZ(arg.info.typeName.size());
+ sz = arg.info.typeName.size();
+ OUT_UPDATE_SZ(sz);
outs.write(arg.info.typeName.c_str(), arg.info.typeName.size());
ret_size += sizeof(char)*arg.info.typeName.size();
- OUT_UPDATE_SZ(arg.info.accessQual.size());
+ sz = arg.info.accessQual.size();
+ OUT_UPDATE_SZ(sz);
outs.write(arg.info.accessQual.c_str(), arg.info.accessQual.size());
ret_size += sizeof(char)*arg.info.accessQual.size();
- OUT_UPDATE_SZ(arg.info.typeQual.size());
+ sz = arg.info.typeQual.size();
+ OUT_UPDATE_SZ(sz);
outs.write(arg.info.typeQual.c_str(), arg.info.typeQual.size());
ret_size += sizeof(char)*arg.info.typeQual.size();
- OUT_UPDATE_SZ(arg.info.argName.size());
+ sz = arg.info.argName.size();
+ OUT_UPDATE_SZ(sz);
outs.write(arg.info.argName.c_str(), arg.info.argName.size());
ret_size += sizeof(char)*arg.info.argName.size();
}
- OUT_UPDATE_SZ(patches.size());
- for (size_t i = 0; i < patches.size(); ++i) {
+ sz = patches.size();
+ OUT_UPDATE_SZ(sz);
+ for (uint32_t i = 0; i < patches.size(); ++i) {
const PatchInfo& patch = patches[i];
unsigned int tmp;
tmp = patch.type;
@@ -344,7 +350,7 @@ namespace gbe {
if (!samplerSet->empty()) { //samplerSet is always valid, allocated in Function::Function
has_samplerset = 1;
OUT_UPDATE_SZ(has_samplerset);
- size_t sz = samplerSet->serializeToBin(outs);
+ uint32_t sz = samplerSet->serializeToBin(outs);
if (!sz)
return 0;
@@ -357,7 +363,7 @@ namespace gbe {
if (!imageSet->empty()) { //imageSet is always valid, allocated in Function::Function
has_imageset = 1;
OUT_UPDATE_SZ(has_imageset);
- size_t sz = imageSet->serializeToBin(outs);
+ uint32_t sz = imageSet->serializeToBin(outs);
if (!sz)
return 0;
@@ -378,19 +384,19 @@ namespace gbe {
return ret_size;
}
- size_t Kernel::deserializeFromBin(std::istream& ins) {
- size_t total_size = 0;
+ uint32_t Kernel::deserializeFromBin(std::istream& ins) {
+ uint32_t total_size = 0;
int has_samplerset = 0;
int has_imageset = 0;
- size_t code_size = 0;
+ uint32_t code_size = 0;
uint32_t magic = 0;
- size_t patch_num = 0;
+ uint32_t patch_num = 0;
IN_UPDATE_SZ(magic);
if (magic != magic_begin)
return 0;
- size_t name_len;
+ uint32_t name_len;
IN_UPDATE_SZ(name_len);
char* c_name = new char[name_len+1];
ins.read(c_name, name_len*sizeof(char));
@@ -410,7 +416,7 @@ namespace gbe {
IN_UPDATE_SZ(arg.info.addrSpace);
- size_t len;
+ uint32_t len;
char* a_name = NULL;
IN_UPDATE_SZ(len);
@@ -473,7 +479,7 @@ namespace gbe {
IN_UPDATE_SZ(has_samplerset);
if (has_samplerset) {
samplerSet = GBE_NEW(ir::SamplerSet);
- size_t sz = samplerSet->deserializeFromBin(ins);
+ uint32_t sz = samplerSet->deserializeFromBin(ins);
if (sz == 0) {
return 0;
}
@@ -486,7 +492,7 @@ namespace gbe {
IN_UPDATE_SZ(has_imageset);
if (has_imageset) {
imageSet = GBE_NEW(ir::ImageSet);
- size_t sz = imageSet->deserializeFromBin(ins);
+ uint32_t sz = imageSet->deserializeFromBin(ins);
if (sz == 0) {
return 0;
}
@@ -508,7 +514,7 @@ namespace gbe {
if (magic != magic_end)
return 0;
- size_t total_bytes;
+ uint32_t total_bytes;
IN_UPDATE_SZ(total_bytes);
if (total_bytes + sizeof(total_size) != total_size)
return 0;
diff --git a/backend/src/backend/program.hpp b/backend/src/backend/program.hpp
index 9570806..1f0ec55 100644
--- a/backend/src/backend/program.hpp
+++ b/backend/src/backend/program.hpp
@@ -90,7 +90,7 @@ namespace gbe {
/*! Set the instruction stream.*/
virtual void setCode(const char *, size_t size) = 0;
/*! Return the instruction stream size (to be implemented) */
- virtual size_t getCodeSize(void) const = 0;
+ virtual uint32_t getCodeSize(void) const = 0;
/*! Get the kernel name */
INLINE const char *getName(void) const { return name.c_str(); }
/*! Return the number of arguments for the kernel call */
@@ -225,8 +225,8 @@ namespace gbe {
*/
/*! Implements the serialization. */
- virtual size_t serializeToBin(std::ostream& outs);
- virtual size_t deserializeFromBin(std::istream& ins);
+ virtual uint32_t serializeToBin(std::ostream& outs);
+ virtual uint32_t deserializeFromBin(std::istream& ins);
virtual void printStatus(int indent, std::ostream& outs);
protected:
@@ -247,7 +247,7 @@ namespace gbe {
ir::ImageSet *imageSet; //!< Copy from the corresponding function.
ir::PrintfSet *printfSet; //!< Copy from the corresponding function.
ir::ProfilingInfo *profilingInfo; //!< Copy from the corresponding function.
- size_t compileWgSize[3]; //!< required work group size by kernel attribute.
+ uint32_t compileWgSize[3]; //!< required work group size by kernel attribute.
std::string functionAttributes; //!< function attribute qualifiers combined.
GBE_CLASS(Kernel); //!< Use custom allocators
};
@@ -312,8 +312,8 @@ namespace gbe {
*/
/*! Implements the serialization. */
- virtual size_t serializeToBin(std::ostream& outs);
- virtual size_t deserializeFromBin(std::istream& ins);
+ virtual uint32_t serializeToBin(std::ostream& outs);
+ virtual uint32_t deserializeFromBin(std::istream& ins);
virtual void printStatus(int indent, std::ostream& outs);
uint32_t fast_relaxed_math : 1;
diff --git a/backend/src/ir/constant.cpp b/backend/src/ir/constant.cpp
index fa4e14a..54ae3f1 100644
--- a/backend/src/ir/constant.cpp
+++ b/backend/src/ir/constant.cpp
@@ -43,31 +43,34 @@ namespace ir {
#define OUT_UPDATE_SZ(elt) SERIALIZE_OUT(elt, outs, ret_size)
#define IN_UPDATE_SZ(elt) DESERIALIZE_IN(elt, ins, total_size)
- size_t ConstantSet::serializeToBin(std::ostream& outs) {
- size_t ret_size = 0;
+ uint32_t ConstantSet::serializeToBin(std::ostream& outs) {
+ uint32_t ret_size = 0;
OUT_UPDATE_SZ(magic_begin);
/* output the const data. */
- OUT_UPDATE_SZ((data.size()*sizeof(char)));
+ uint32_t sz = data.size()*sizeof(char);
+ OUT_UPDATE_SZ(sz);
if(data.size() > 0) {
- outs.write(data.data(), data.size()*sizeof(char));
- ret_size += data.size()*sizeof(char);
+ outs.write(data.data(), sz);
+ ret_size += sz;
}
- OUT_UPDATE_SZ(constants.size());
- for (size_t i = 0; i < constants.size(); ++i) {
+ sz = constants.size();
+ OUT_UPDATE_SZ(sz);
+ for (uint32_t i = 0; i < constants.size(); ++i) {
Constant& cnst = constants[i];
- size_t bytes = sizeof(cnst.getName().size()) //name length self
- + cnst.getName().size()*sizeof(char) //name
- + sizeof(cnst.getSize()) //size
- + sizeof(cnst.getAlignment()) //alignment
- + sizeof(cnst.getOffset()); //offset
+ sz = cnst.getName().size()*sizeof(char);
+ uint32_t bytes = sizeof(sz) //name length self
+ + sz //name
+ + sizeof(cnst.getSize()) //size
+ + sizeof(cnst.getAlignment()) //alignment
+ + sizeof(cnst.getOffset()); //offset
OUT_UPDATE_SZ(bytes);
- OUT_UPDATE_SZ(cnst.getName().size());
- outs.write(cnst.getName().c_str(), cnst.getName().size());
- ret_size += sizeof(char)*cnst.getName().size();
+ OUT_UPDATE_SZ(sz);
+ outs.write(cnst.getName().c_str(), sz);
+ ret_size += sz;
OUT_UPDATE_SZ(cnst.getSize());
OUT_UPDATE_SZ(cnst.getAlignment());
OUT_UPDATE_SZ(cnst.getOffset());
@@ -79,10 +82,10 @@ namespace ir {
return ret_size;
}
- size_t ConstantSet::deserializeFromBin(std::istream& ins) {
- size_t total_size = 0;
- size_t global_data_sz = 0;
- size_t const_num;
+ uint32_t ConstantSet::deserializeFromBin(std::istream& ins) {
+ uint32_t total_size = 0;
+ uint32_t global_data_sz = 0;
+ uint32_t const_num;
uint32_t magic;
IN_UPDATE_SZ(magic);
@@ -90,18 +93,18 @@ namespace ir {
return 0;
IN_UPDATE_SZ(global_data_sz);
- for (size_t i = 0; i < global_data_sz; i++) {
+ for (uint32_t i = 0; i < global_data_sz; i++) {
char elt;
IN_UPDATE_SZ(elt);
data.push_back(elt);
}
IN_UPDATE_SZ(const_num);
- for (size_t i = 0; i < const_num; i++) {
- size_t bytes;
+ for (uint32_t i = 0; i < const_num; i++) {
+ uint32_t bytes;
IN_UPDATE_SZ(bytes);
- size_t name_len;
+ uint32_t name_len;
IN_UPDATE_SZ(name_len);
char* c_name = new char[name_len+1];
@@ -129,7 +132,7 @@ namespace ir {
if (magic != magic_end)
return 0;
- size_t total_bytes;
+ uint32_t total_bytes;
IN_UPDATE_SZ(total_bytes);
if (total_bytes + sizeof(total_size) != total_size)
return 0;
diff --git a/backend/src/ir/constant.hpp b/backend/src/ir/constant.hpp
index 0891d7b..c9080b8 100644
--- a/backend/src/ir/constant.hpp
+++ b/backend/src/ir/constant.hpp
@@ -119,8 +119,8 @@ namespace ir {
*/
/*! Implements the serialization. */
- virtual size_t serializeToBin(std::ostream& outs);
- virtual size_t deserializeFromBin(std::istream& ins);
+ virtual uint32_t serializeToBin(std::ostream& outs);
+ virtual uint32_t deserializeFromBin(std::istream& ins);
private:
vector<char> data; //!< The constant data serialized in one array
diff --git a/backend/src/ir/image.cpp b/backend/src/ir/image.cpp
index e006087..eaf6be7 100644
--- a/backend/src/ir/image.cpp
+++ b/backend/src/ir/image.cpp
@@ -107,12 +107,14 @@ namespace ir {
#define IN_UPDATE_SZ(elt) DESERIALIZE_IN(elt, ins, total_size)
/*! Implements the serialization. */
- size_t ImageSet::serializeToBin(std::ostream& outs) {
- size_t ret_size = 0;
+ uint32_t ImageSet::serializeToBin(std::ostream& outs) {
+ uint32_t ret_size = 0;
+ uint32_t sz = 0;
OUT_UPDATE_SZ(magic_begin);
- OUT_UPDATE_SZ(regMap.size());
+ sz = regMap.size();
+ OUT_UPDATE_SZ(sz);
for (map<Register, struct ImageInfo *>::const_iterator it = regMap.begin(); it != regMap.end(); ++it) {
OUT_UPDATE_SZ(it->first);
OUT_UPDATE_SZ(it->second->arg_idx);
@@ -125,7 +127,8 @@ namespace ir {
OUT_UPDATE_SZ(it->second->dimOrderSlot);
}
- OUT_UPDATE_SZ(indexMap.size());
+ sz = indexMap.size();
+ OUT_UPDATE_SZ(sz);
for (map<uint32_t, struct ImageInfo *>::iterator it = indexMap.begin(); it != indexMap.end(); ++it) {
OUT_UPDATE_SZ(it->first);
OUT_UPDATE_SZ(it->second->arg_idx);
@@ -144,17 +147,17 @@ namespace ir {
return ret_size;
}
- size_t ImageSet::deserializeFromBin(std::istream& ins) {
- size_t total_size = 0;
+ uint32_t ImageSet::deserializeFromBin(std::istream& ins) {
+ uint32_t total_size = 0;
uint32_t magic;
- size_t image_map_sz = 0;
+ uint32_t image_map_sz = 0;
IN_UPDATE_SZ(magic);
if (magic != magic_begin)
return 0;
IN_UPDATE_SZ(image_map_sz); //regMap
- for (size_t i = 0; i < image_map_sz; i++) {
+ for (uint32_t i = 0; i < image_map_sz; i++) {
ir::Register reg;
ImageInfo *img_info = GBE_NEW(struct ImageInfo);;
@@ -193,7 +196,7 @@ namespace ir {
if (magic != magic_end)
return 0;
- size_t total_bytes;
+ uint32_t total_bytes;
IN_UPDATE_SZ(total_bytes);
if (total_bytes + sizeof(total_size) != total_size)
return 0;
diff --git a/backend/src/ir/image.hpp b/backend/src/ir/image.hpp
index a93a4b6..ca616c1 100644
--- a/backend/src/ir/image.hpp
+++ b/backend/src/ir/image.hpp
@@ -86,8 +86,8 @@ namespace ir {
*/
/*! Implements the serialization. */
- virtual size_t serializeToBin(std::ostream& outs);
- virtual size_t deserializeFromBin(std::istream& ins);
+ virtual uint32_t serializeToBin(std::ostream& outs);
+ virtual uint32_t deserializeFromBin(std::istream& ins);
virtual void printStatus(int indent, std::ostream& outs);
private:
diff --git a/backend/src/ir/sampler.cpp b/backend/src/ir/sampler.cpp
index a4e1ddd..1987344 100644
--- a/backend/src/ir/sampler.cpp
+++ b/backend/src/ir/sampler.cpp
@@ -65,12 +65,14 @@ namespace ir {
#define IN_UPDATE_SZ(elt) DESERIALIZE_IN(elt, ins, total_size)
/*! Implements the serialization. */
- size_t SamplerSet::serializeToBin(std::ostream& outs) {
- size_t ret_size = 0;
+ uint32_t SamplerSet::serializeToBin(std::ostream& outs) {
+ uint32_t ret_size = 0;
+ uint32_t sz = 0;
OUT_UPDATE_SZ(magic_begin);
- OUT_UPDATE_SZ(samplerMap.size());
+ sz = samplerMap.size();
+ OUT_UPDATE_SZ(sz);
for (map<uint32_t, uint32_t>::iterator it = samplerMap.begin(); it != samplerMap.end(); ++it) {
OUT_UPDATE_SZ(it->first);
OUT_UPDATE_SZ(it->second);
@@ -82,10 +84,10 @@ namespace ir {
return ret_size;
}
- size_t SamplerSet::deserializeFromBin(std::istream& ins) {
- size_t total_size = 0;
+ uint32_t SamplerSet::deserializeFromBin(std::istream& ins) {
+ uint32_t total_size = 0;
uint32_t magic;
- size_t sampler_map_sz = 0;
+ uint32_t sampler_map_sz = 0;
IN_UPDATE_SZ(magic);
if (magic != magic_begin)
@@ -105,7 +107,7 @@ namespace ir {
if (magic != magic_end)
return 0;
- size_t total_bytes;
+ uint32_t total_bytes;
IN_UPDATE_SZ(total_bytes);
if (total_bytes + sizeof(total_size) != total_size)
return 0;
diff --git a/backend/src/ir/sampler.hpp b/backend/src/ir/sampler.hpp
index 85e6d54..036fa69 100644
--- a/backend/src/ir/sampler.hpp
+++ b/backend/src/ir/sampler.hpp
@@ -79,8 +79,8 @@ namespace ir {
*/
/*! Implements the serialization. */
- virtual size_t serializeToBin(std::ostream& outs);
- virtual size_t deserializeFromBin(std::istream& ins);
+ virtual uint32_t serializeToBin(std::ostream& outs);
+ virtual uint32_t deserializeFromBin(std::istream& ins);
virtual void printStatus(int indent, std::ostream& outs);
private:
diff --git a/backend/src/sys/platform.hpp b/backend/src/sys/platform.hpp
index 803ce21..9ed9b2d 100644
--- a/backend/src/sys/platform.hpp
+++ b/backend/src/sys/platform.hpp
@@ -339,12 +339,12 @@ public:
INLINE Serializable(const Serializable&) = default;
INLINE Serializable& operator= (const Serializable&) = default;
- virtual size_t serializeToBin(std::ostream& outs) = 0;
- virtual size_t deserializeFromBin(std::istream& ins) = 0;
+ virtual uint32_t serializeToBin(std::ostream& outs) = 0;
+ virtual uint32_t deserializeFromBin(std::istream& ins) = 0;
/* These two will follow LLVM's ABI. */
- virtual size_t serializeToLLVM(void) { return 0;/* not implemented now. */}
- virtual size_t deserializeFromLLVM(void) { return 0;/* not implemented now. */}
+ virtual uint32_t serializeToLLVM(void) { return 0;/* not implemented now. */}
+ virtual uint32_t deserializeFromLLVM(void) { return 0;/* not implemented now. */}
virtual void printStatus(int indent = 0, std::ostream& outs = std::cout) { }
--
2.1.4
More information about the Beignet
mailing list