using namespace std;
+#define UNUSED(x) ((void)(x))
+
static_assert(numeric_limits<float>::is_iec559, "Unsupported float type");
void readParameters(char *&data, size_t &len, const string &path,
// gather file info
int statRes = fstat(fd, &st);
- (void)statRes;
assert(statRes != -1);
+ UNUSED(statRes);
len = st.st_size;
assert(len >= params::HEADER_LEN);
// check magic correctness
char magic[params::MAGIC_LEN + 1] = {};
- read(fd, magic, params::MAGIC_LEN);
+ ssize_t magic_len = read(fd, magic, params::MAGIC_LEN);
+ assert(magic_len == params::MAGIC_LEN);
+ UNUSED(magic_len);
assert(strncmp(magic, params::MAGIC, params::MAGIC_LEN) == 0);
+ UNUSED(magic);
// checkversion correctness
decltype(expectedVersion) version;
- read(fd, &version, sizeof(version));
+ ssize_t version_len = read(fd, &version, sizeof(version));
+ assert(version_len == sizeof(version));
+ UNUSED(version_len);
assert(version == expectedVersion);
+ UNUSED(version);
// check hash correctness
decltype(expectedHash) hash;
- read(fd, &hash, sizeof(hash));
+ ssize_t hash_len = read(fd, &hash, sizeof(hash));
+ assert(hash_len == sizeof(hash));
+ UNUSED(hash_len);
assert(hash == expectedHash);
+ UNUSED(hash);
data = static_cast<char *>(mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0));
int is_error = close(fd);
assert(!is_error && "Can not close file!");
- (void)is_error;
+ UNUSED(is_error);
}
void releaseParameters(char *data, size_t len)
{
int res = munmap(data, len);
- (void)res;
assert(res == 0);
+ UNUSED(res);
}
template <int rank>
static inline Shape deserializeShape(const char *&buf)
{
Shape s;
- char rank = deserializeT<char>(buf);
+ int32_t rank = deserializeT<int32_t>(buf);
s.setDims(rank);
for (int i = 0; i < rank; ++i)
{
Dims<4> dims;
};
+static bool isAddrAligned(const void *data, int alignment)
+{
+ return (reinterpret_cast<uintptr_t>(data) % alignment) == 0;
+}
+
static inline Kernel deserializeKernel(const char *&buf)
{
- char dType = deserializeT<char>(buf);
+ int32_t dType = deserializeT<int32_t>(buf);
assert(dType == 1 && "Unknown data type");
- char eSize = deserializeT<char>(buf);
+ UNUSED(dType);
+ int32_t eSize = deserializeT<int32_t>(buf);
assert(eSize == 4 && "Unsupported element size");
+ UNUSED(eSize);
Kernel k;
k.dims = shapeToDims(deserializeShape(buf));
k.data = reinterpret_cast<const float *>(buf);
+ assert(isAddrAligned(buf, 4) && "data should be aligned to 4 bytes to use arm vector instructions");
buf += volume(k.dims) * eSize;
return k;
}
{
const float *input[] = {inputs.getData()...};
Dims<4> input_d[] = {shapeToDims(inputs.getShape())...};
- int axis = deserializeT<char>(params);
+ int axis = deserializeT<int32_t>(params);
Shape out_s = deserializeShape(params);
// because inner functions accepts axis in reverse order
axis = out_s.getDims() - 1 - axis;
Kernel kernel = deserializeKernel(params);
Shape strides = deserializeShape(params);
// pads type. unused for now
- char pt = deserializeT<char>(params);
- (void)pt;
+ int32_t pt = deserializeT<int32_t>(params);
+ UNUSED(pt);
Shape pads = deserializeShape(params);
Shape out_s = deserializeShape(params);
Kernel kernel = deserializeKernel(params);
Shape strides = deserializeShape(params);
// pads type. unused for now
- char pt = deserializeT<char>(params);
- (void)pt;
+ int32_t pt = deserializeT<int32_t>(params);
+ UNUSED(pt);
Shape pads = deserializeShape(params);
Shape out_s = deserializeShape(params);
const float *input = in.getData();
Dims<4> input_d = shapeToDims(in.getShape());
float beta = 1;
- char axis = deserializeT<char>(params);
+ int32_t axis = deserializeT<int32_t>(params);
assert(axis == in.getShape().getDims() - 1);
+ UNUSED(axis);
out.reShape(in.getShape());
Shape window = deserializeShape(params);
Shape strides = deserializeShape(params);
// pads type. unused for now
- char pt = deserializeT<char>(params);
- (void)pt;
+ int32_t pt = deserializeT<int32_t>(params);
+ UNUSED(pt);
Shape pads = deserializeShape(params);
Shape out_s = deserializeShape(params);
#include <algorithm>
+#define UNUSED(x) ((void)(x))
+
namespace nncc
{
namespace contrib
namespace
{
- const auto MAX_DIMS = numeric_limits<char>::max();
+ // Currently there are no operations with more then 4 dimensions in kernels/weights etc supported
+ const auto MAX_DIMS = 4;
const auto MAX_DIM_SIZE = numeric_limits<int32_t>::max();
+ // Assuming there are no large enums
const auto MAX_ENUM_VAL = numeric_limits<char>::max();
} // unnamed namespace
void Serializer::serializeShape(const Shape &s)
{
int32_t rank = s.rank();
- assert(rank < MAX_DIMS);
- serializeT<char>(s.rank());
+ assert(rank <= MAX_DIMS);
+ serializeT<int32_t>(s.rank());
for (int32_t i = 0; i < rank; ++i)
{
int32_t dim = s.dim(i);
{
// serialize type
assert(etoi(t.getDataType()) < MAX_ENUM_VAL);
- serializeT<char>(etoi(t.getDataType()));
+ serializeT<int32_t>(etoi(t.getDataType()));
// seriazlie data size
size_t eSize = t.getElementSize();
- assert(eSize < MAX_DIMS);
- serializeT<char>(eSize);
+ assert(eSize <= MAX_DIMS);
+ serializeT<int32_t>(eSize);
// serialize shape
const Shape &shape = t.getShape();
serializeShape(shape);
{
// serialize padding type
assert(etoi(op.getPaddingType()) < MAX_ENUM_VAL);
- serializeT<char>(etoi(op.getPaddingType()));
+ serializeT<int32_t>(etoi(op.getPaddingType()));
// serialize pads
- assert(padsRank < MAX_DIMS);
- serializeT<char>(padsRank);
+ assert(padsRank <= MAX_DIMS);
+ serializeT<int32_t>(padsRank);
for (int i = 0; i < static_cast<int>(padsRank); ++i)
{
auto pad = op.getPadding(i);
assert(pad <= MAX_DIM_SIZE);
assert(pad >= 0);
+ UNUSED(pad);
serializeT<int32_t>(op.getPadding(i));
}
}
{
_curOp->_paramStartOffset = _buffer.size();
// axis number should fit into one byte
- assert(op.getAxis() < MAX_DIMS);
- serializeT<char>(op.getAxis());
+ assert(op.getAxis() <= MAX_DIMS);
+ serializeT<int32_t>(op.getAxis());
serializeShape(op.getOutputShape(0));
}
{
_curOp->_paramStartOffset = _buffer.size();
// axis number should fit into one byte
- assert(op.getAxis() < MAX_DIMS);
- serializeT<char>(op.getAxis());
+ assert(op.getAxis() <= MAX_DIMS);
+ serializeT<int32_t>(op.getAxis());
}
void Serializer::visit(ADT::INode *node, ops::PoolOp &op)