aboutsummaryrefslogtreecommitdiff
path: root/src/armnnUtils
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnnUtils')
-rw-r--r--src/armnnUtils/BFloat16.hpp2
-rw-r--r--src/armnnUtils/FloatingPointConverter.cpp31
2 files changed, 32 insertions, 1 deletions
diff --git a/src/armnnUtils/BFloat16.hpp b/src/armnnUtils/BFloat16.hpp
index bb56b7d37c..965fc31c17 100644
--- a/src/armnnUtils/BFloat16.hpp
+++ b/src/armnnUtils/BFloat16.hpp
@@ -6,7 +6,7 @@
#pragma once
#include <ostream>
-#include <math.h>
+#include <cmath>
#include <stdint.h>
namespace armnn
diff --git a/src/armnnUtils/FloatingPointConverter.cpp b/src/armnnUtils/FloatingPointConverter.cpp
index 3bdde11eb8..e9b338ac7c 100644
--- a/src/armnnUtils/FloatingPointConverter.cpp
+++ b/src/armnnUtils/FloatingPointConverter.cpp
@@ -5,6 +5,7 @@
#include <armnnUtils/FloatingPointConverter.hpp>
+#include "BFloat16.hpp"
#include "Half.hpp"
#include <boost/assert.hpp>
@@ -42,4 +43,34 @@ void FloatingPointConverter::ConvertFloat16To32(const void* srcFloat16Buffer,
}
}
+void FloatingPointConverter::ConvertFloat32ToBFloat16(const float* srcFloat32Buffer,
+ size_t numElements,
+ void* dstBFloat16Buffer)
+{
+ BOOST_ASSERT(srcFloat32Buffer != nullptr);
+ BOOST_ASSERT(dstBFloat16Buffer != nullptr);
+
+ armnn::BFloat16* bf16 = reinterpret_cast<armnn::BFloat16*>(dstBFloat16Buffer);
+
+ for (size_t i = 0; i < numElements; i++)
+ {
+ bf16[i] = armnn::BFloat16(srcFloat32Buffer[i]);
+ }
+}
+
+void FloatingPointConverter::ConvertBFloat16ToFloat32(const void* srcBFloat16Buffer,
+ size_t numElements,
+ float* dstFloat32Buffer)
+{
+ BOOST_ASSERT(srcBFloat16Buffer != nullptr);
+ BOOST_ASSERT(dstFloat32Buffer != nullptr);
+
+ const armnn::BFloat16* bf16 = reinterpret_cast<const armnn::BFloat16*>(srcBFloat16Buffer);
+
+ for (size_t i = 0; i < numElements; i++)
+ {
+ dstFloat32Buffer[i] = bf16[i].toFloat32();
+ }
+}
+
} //namespace armnnUtils