From 8d2ca734165a068478df7cffa46185680b05cd20 Mon Sep 17 00:00:00 2001 From: Nikhil Raj Date: Fri, 24 Feb 2023 10:28:19 +0000 Subject: Update Doxygen docu for 23.02 Signed-off-by: Nikhil Raj Change-Id: Ie6c19a27d50fefab2796b2b5875374e81f5bf971 --- 23.02/_b_float16_8hpp_source.xhtml | 129 +++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 23.02/_b_float16_8hpp_source.xhtml (limited to '23.02/_b_float16_8hpp_source.xhtml') diff --git a/23.02/_b_float16_8hpp_source.xhtml b/23.02/_b_float16_8hpp_source.xhtml new file mode 100644 index 0000000000..ce37aa6204 --- /dev/null +++ b/23.02/_b_float16_8hpp_source.xhtml @@ -0,0 +1,129 @@ + + + + + + + + + + + + + +ArmNN: src/armnnUtils/BFloat16.hpp Source File + + + + + + + + + + + + + + + + +
+
+ + + + ArmNN + + + +
+
+  23.02 +
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+
+
BFloat16.hpp
+
+
+Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <ostream>
9 #include <cmath>
10 #include <cstring>
11 #include <stdint.h>
12 
13 namespace armnn
14 {
15 class BFloat16
16 {
17 public:
19  : m_Value(0)
20  {}
21 
22  BFloat16(const BFloat16& v) = default;
23 
24  explicit BFloat16(uint16_t v)
25  : m_Value(v)
26  {}
27 
28  explicit BFloat16(float v)
29  {
30  m_Value = Float32ToBFloat16(v).Val();
31  }
32 
33  operator float() const
34  {
35  return ToFloat32();
36  }
37 
38  BFloat16& operator=(const BFloat16& other) = default;
39 
40  BFloat16& operator=(float v)
41  {
42  m_Value = Float32ToBFloat16(v).Val();
43  return *this;
44  }
45 
46  bool operator==(const BFloat16& r) const
47  {
48  return m_Value == r.Val();
49  }
50 
51  static BFloat16 Float32ToBFloat16(const float v)
52  {
53  if (std::isnan(v))
54  {
55  return Nan();
56  }
57  else
58  {
59  // Round value to the nearest even
60  // Float32
61  // S EEEEEEEE MMMMMMLRMMMMMMMMMMMMMMM
62  // BFloat16
63  // S EEEEEEEE MMMMMML
64  // LSB (L): Least significat bit of BFloat16 (last bit of the Mantissa of BFloat16)
65  // R: Rounding bit
66  // LSB = 0, R = 0 -> round down
67  // LSB = 1, R = 0 -> round down
68  // LSB = 0, R = 1, all the rest = 0 -> round down
69  // LSB = 1, R = 1 -> round up
70  // LSB = 0, R = 1 -> round up
71  const uint32_t* u32 = reinterpret_cast<const uint32_t*>(&v);
72  uint16_t u16 = static_cast<uint16_t>(*u32 >> 16u);
73  // Mark the LSB
74  const uint16_t lsb = u16 & 0x0001;
75  // Mark the error to be truncate (the rest of 16 bits of FP32)
76  const uint16_t error = static_cast<uint16_t>((*u32 & 0x0000FFFF));
77  if ((error > 0x8000 || (error == 0x8000 && lsb == 1)))
78  {
79  u16++;
80  }
81  BFloat16 b(u16);
82  return b;
83  }
84  }
85 
86  float ToFloat32() const
87  {
88  const uint32_t u32 = static_cast<uint32_t>(m_Value << 16u);
89  float f32;
90  static_assert(sizeof u32 == sizeof f32, "");
91  std::memcpy(&f32, &u32, sizeof u32);
92  return f32;
93  }
94 
95  uint16_t Val() const
96  {
97  return m_Value;
98  }
99 
100  static BFloat16 Max()
101  {
102  uint16_t max = 0x7F7F;
103  return BFloat16(max);
104  }
105 
106  static BFloat16 Nan()
107  {
108  uint16_t nan = 0x7FC0;
109  return BFloat16(nan);
110  }
111 
112  static BFloat16 Inf()
113  {
114  uint16_t infVal = 0x7F80;
115  return BFloat16(infVal);
116  }
117 
118 private:
119  uint16_t m_Value;
120 };
121 
122 inline std::ostream& operator<<(std::ostream& os, const BFloat16& b)
123 {
124  os << b.ToFloat32() << "(0x" << std::hex << b.Val() << ")";
125  return os;
126 }
127 
128 } //namespace armnn
float ToFloat32() const
Definition: BFloat16.hpp:86
+
BFloat16(float v)
Definition: BFloat16.hpp:28
+ +
std::ostream & operator<<(std::ostream &os, const std::vector< Compute > &compute)
Deprecated function that will be removed together with the Compute enum.
Definition: BackendId.hpp:47
+
BFloat16 & operator=(float v)
Definition: BFloat16.hpp:40
+
static BFloat16 Max()
Definition: BFloat16.hpp:100
+
Copyright (c) 2021 ARM Limited and Contributors.
+ +
static BFloat16 Inf()
Definition: BFloat16.hpp:112
+
uint16_t Val() const
Definition: BFloat16.hpp:95
+
static BFloat16 Float32ToBFloat16(const float v)
Definition: BFloat16.hpp:51
+ +
bool operator==(const BFloat16 &r) const
Definition: BFloat16.hpp:46
+
BFloat16 & operator=(const BFloat16 &other)=default
+
static BFloat16 Nan()
Definition: BFloat16.hpp:106
+
BFloat16(uint16_t v)
Definition: BFloat16.hpp:24
+
+
+ + + + -- cgit v1.2.1