forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTHHalf.h
41 lines (31 loc) · 875 Bytes
/
THHalf.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef TH_HALF_H
#define TH_HALF_H
#include "THGeneral.h"
#include <stdint.h>
/* Neither built-in nor included from Cutorch, use our definition lifted from CUDA */
#if defined(__GNUC__)
#define __thalign__(n) __attribute__((aligned(n)))
#elif defined(_WIN32)
#define __thalign__(n) __declspec(align(n))
#else
#define __thalign__(n)
#endif
typedef struct __thalign__(2){
unsigned short x;
} __THHalf;
typedef struct __thalign__(4) {
unsigned int x;
} __THHalf2;
typedef __THHalf THHalf;
typedef __THHalf2 THHalf2;
TH_API void TH_float2halfbits(float*, unsigned short*);
TH_API void TH_halfbits2float(unsigned short*, float*);
TH_API THHalf TH_float2half(float);
TH_API float TH_half2float(THHalf);
#ifndef TH_HALF_BITS_TO_LITERAL
# define TH_HALF_BITS_TO_LITERAL(n) { n }
#endif
#define TH_HALF_ZERO 0x0U
#define TH_HALF_INF 0x7C00U
#undef __thalign__
#endif