KhronosGroup / NNEF-Tools

The NNEF Tools repository contains tools to generate and consume NNEF documents
https://www.khronos.org/nnef
222 stars 57 forks source link

Can't correctly fill TensorHeader #42

Closed igsha closed 6 years ago

igsha commented 6 years ago

I use TensorHeader struct to parse dat-files of tensor weights coefficients. Its definition is in file parser/cpp/common/binary.h.

This is my code to write tensor weights:

std::ofstream file(filename, std::ios::binary);
nnef::Shape nnef_shape(...);
...

nnef::TensorHeader header;
size_t version[] = {1, 0};
nnef::fill_tensor_header(header, version, nnef_shape.rank(), nnef_shape.extents(), 8 * sizeof(float), nnef::TensorHeader::Float);

file.write(reinterpret_cast<const char*>(&header), sizeof(header));
file.write(reinterpret_cast<const char*>(data), sizeof(float) * nnef_shape.volume());

But it writes incomplete header: there is no extents (dimentsions) values in the file. That's why I have to add something like this in my code (before calling file.write):

std::copy_n(nnef_shape.extents(), nnef.shape.rank(), header.extents);

It seems there is some problem in nnef::fill_tensor_header function.

gyenesvi commented 6 years ago

You are right, there was a bug in the copy, fixed just now.

igsha commented 6 years ago

Checked your last commit. It works. Thanks!