nndeploy C++ API  0.2.0
nndeploy C++ API
half.h
Go to the documentation of this file.
1 
2 #ifndef _NNDEPLOY_BASE_HALF_H_
3 #define _NNDEPLOY_BASE_HALF_H_
4 
6 #include "nndeploy/base/macro.h"
7 
8 namespace nndeploy {
9 namespace base {
10 
11 typedef union {
12  float f;
13  uint32_t u;
14 } cvt_32b;
15 
16 typedef struct bfp16_struct {
17  public:
18  uint16_t w = 0;
19 
20  bfp16_struct() : w(0) {}
21 
22  bfp16_struct(float vf) {
23  cvt_32b c;
24  c.f = vf;
25  w = c.u >> 16;
26  }
27 
28  operator const float() const {
29  cvt_32b c;
30  c.u = w << 16;
31  return c.f;
32  }
34 
35 extern NNDEPLOY_CC_API bool convertFromFloatToBfp16(float *fp32, void *bfp16,
36  int count);
37 
38 extern NNDEPLOY_CC_API bool convertFromBfp16ToFloat(void *bfp16, float *fp32,
39  int count);
40 
41 extern NNDEPLOY_CC_API bool convertFromFloatToFp16(float *fp32, void *fp16,
42  int count);
43 
44 extern NNDEPLOY_CC_API bool convertFromFp16ToFloat(void *fp16, float *fp32,
45  int count);
46 
47 } // namespace base
48 } // namespace nndeploy
49 
50 #endif
#define NNDEPLOY_CC_API
api
Definition: macro.h:29
bool convertFromBfp16ToFloat(void *bfp16, float *fp32, int count)
bool convertFromFloatToFp16(float *fp32, void *fp16, int count)
bool convertFromFloatToBfp16(float *fp32, void *bfp16, int count)
bool convertFromFp16ToFloat(void *fp16, float *fp32, int count)
struct nndeploy::base::bfp16_struct bfp16_t
bfp16_struct(float vf)
Definition: half.h:22