diff options
author | James Ward <james.ward@arm.com> | 2022-08-05 13:48:37 +0100 |
---|---|---|
committer | James Ward <james.ward@arm.com> | 2022-10-04 13:02:00 +0100 |
commit | 485a11d8cb67c8062c632f0987cd31cedbe93d6d (patch) | |
tree | c12841ac81114120428418f1c359c3d145610804 /src/numpy_utils.cpp | |
parent | c92710d7259558fb0cd9e9b38d0c78da21c6e2d4 (diff) | |
download | serialization_lib-485a11d8cb67c8062c632f0987cd31cedbe93d6d.tar.gz |
FP16 support in serialization
* Allow serialization of fp16 data
* Add package to support integrated half data-type (half_float::half), independent of native float: http://half.sourceforge.net/
* Allow passing of accumulate data-type in serialization
Signed-off-by: James Ward <james.ward@arm.com>
Change-Id: I54357f02e3776d81958228f699ea5044f2014f4b
Diffstat (limited to 'src/numpy_utils.cpp')
-rw-r--r-- | src/numpy_utils.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/numpy_utils.cpp b/src/numpy_utils.cpp index 80c680f..c770d45 100644 --- a/src/numpy_utils.cpp +++ b/src/numpy_utils.cpp @@ -14,6 +14,7 @@ // limitations under the License. #include "numpy_utils.h" +#include "half.hpp" // Magic NUMPY header static const char NUMPY_HEADER_STR[] = "\x93NUMPY\x1\x0\x76\x0{"; @@ -45,6 +46,13 @@ NumpyUtilities::NPError NumpyUtilities::readFromNpyFile(const char* filename, co return readFromNpyFileCommon(filename, dtype_str, sizeof(float), elems, databuf, false); } +NumpyUtilities::NPError + NumpyUtilities::readFromNpyFile(const char* filename, const uint32_t elems, half_float::half* databuf) +{ + const char dtype_str[] = "'<f2'"; + return readFromNpyFileCommon(filename, dtype_str, sizeof(half_float::half), elems, databuf, false); +} + NumpyUtilities::NPError NumpyUtilities::readFromNpyFileCommon(const char* filename, const char* dtype_str, const size_t elementsize, @@ -307,6 +315,14 @@ NumpyUtilities::NPError return writeToNpyFileCommon(filename, dtype_str, sizeof(float), shape, databuf, false); } +NumpyUtilities::NPError NumpyUtilities::writeToNpyFile(const char* filename, + const std::vector<int32_t>& shape, + const half_float::half* databuf) +{ + const char dtype_str[] = "'<f2'"; + return writeToNpyFileCommon(filename, dtype_str, sizeof(half_float::half), shape, databuf, false); +} + NumpyUtilities::NPError NumpyUtilities::writeToNpyFileCommon(const char* filename, const char* dtype_str, const size_t elementsize, |