1#pragma once
2
3#include <c10/util/BFloat16.h>
4#include <c10/util/Half.h>
5#include <torch/csrc/Export.h>
6#include <cstddef>
7#include <cstdint>
8
9namespace torch {
10namespace utils {
11
12enum THPByteOrder { THP_LITTLE_ENDIAN = 0, THP_BIG_ENDIAN = 1 };
13
14TORCH_API THPByteOrder THP_nativeByteOrder();
15
16TORCH_API void THP_decodeInt16Buffer(
17 int16_t* dst,
18 const uint8_t* src,
19 bool do_byte_swap,
20 size_t len);
21TORCH_API void THP_decodeInt32Buffer(
22 int32_t* dst,
23 const uint8_t* src,
24 bool do_byte_swap,
25 size_t len);
26TORCH_API void THP_decodeInt64Buffer(
27 int64_t* dst,
28 const uint8_t* src,
29 bool do_byte_swap,
30 size_t len);
31TORCH_API void THP_decodeHalfBuffer(
32 c10::Half* dst,
33 const uint8_t* src,
34 bool do_byte_swap,
35 size_t len);
36TORCH_API void THP_decodeFloatBuffer(
37 float* dst,
38 const uint8_t* src,
39 bool do_byte_swap,
40 size_t len);
41TORCH_API void THP_decodeDoubleBuffer(
42 double* dst,
43 const uint8_t* src,
44 bool do_byte_swap,
45 size_t len);
46TORCH_API void THP_decodeBoolBuffer(
47 bool* dst,
48 const uint8_t* src,
49 bool do_byte_swap,
50 size_t len);
51TORCH_API void THP_decodeBFloat16Buffer(
52 at::BFloat16* dst,
53 const uint8_t* src,
54 bool do_byte_swap,
55 size_t len);
56TORCH_API void THP_decodeComplexFloatBuffer(
57 c10::complex<float>* dst,
58 const uint8_t* src,
59 bool do_byte_swap,
60 size_t len);
61TORCH_API void THP_decodeComplexDoubleBuffer(
62 c10::complex<double>* dst,
63 const uint8_t* src,
64 bool do_byte_swap,
65 size_t len);
66
67TORCH_API void THP_decodeInt16Buffer(
68 int16_t* dst,
69 const uint8_t* src,
70 THPByteOrder order,
71 size_t len);
72TORCH_API void THP_decodeInt32Buffer(
73 int32_t* dst,
74 const uint8_t* src,
75 THPByteOrder order,
76 size_t len);
77TORCH_API void THP_decodeInt64Buffer(
78 int64_t* dst,
79 const uint8_t* src,
80 THPByteOrder order,
81 size_t len);
82TORCH_API void THP_decodeHalfBuffer(
83 c10::Half* dst,
84 const uint8_t* src,
85 THPByteOrder order,
86 size_t len);
87TORCH_API void THP_decodeFloatBuffer(
88 float* dst,
89 const uint8_t* src,
90 THPByteOrder order,
91 size_t len);
92TORCH_API void THP_decodeDoubleBuffer(
93 double* dst,
94 const uint8_t* src,
95 THPByteOrder order,
96 size_t len);
97TORCH_API void THP_decodeBoolBuffer(
98 bool* dst,
99 const uint8_t* src,
100 THPByteOrder order,
101 size_t len);
102TORCH_API void THP_decodeBFloat16Buffer(
103 at::BFloat16* dst,
104 const uint8_t* src,
105 THPByteOrder order,
106 size_t len);
107TORCH_API void THP_decodeComplexFloatBuffer(
108 c10::complex<float>* dst,
109 const uint8_t* src,
110 THPByteOrder order,
111 size_t len);
112TORCH_API void THP_decodeComplexDoubleBuffer(
113 c10::complex<double>* dst,
114 const uint8_t* src,
115 THPByteOrder order,
116 size_t len);
117
118TORCH_API void THP_encodeInt16Buffer(
119 uint8_t* dst,
120 const int16_t* src,
121 THPByteOrder order,
122 size_t len);
123TORCH_API void THP_encodeInt32Buffer(
124 uint8_t* dst,
125 const int32_t* src,
126 THPByteOrder order,
127 size_t len);
128TORCH_API void THP_encodeInt64Buffer(
129 uint8_t* dst,
130 const int64_t* src,
131 THPByteOrder order,
132 size_t len);
133TORCH_API void THP_encodeFloatBuffer(
134 uint8_t* dst,
135 const float* src,
136 THPByteOrder order,
137 size_t len);
138TORCH_API void THP_encodeDoubleBuffer(
139 uint8_t* dst,
140 const double* src,
141 THPByteOrder order,
142 size_t len);
143TORCH_API void THP_encodeComplexloatBuffer(
144 uint8_t* dst,
145 const c10::complex<float>* src,
146 THPByteOrder order,
147 size_t len);
148TORCH_API void THP_encodeComplexDoubleBuffer(
149 uint8_t* dst,
150 const c10::complex<double>* src,
151 THPByteOrder order,
152 size_t len);
153
154} // namespace utils
155} // namespace torch
156