xref: /aosp_15_r20/external/pytorch/c10/util/bits.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #pragma once
2 #include <cstdint>
3 
4 #include <c10/macros/Macros.h>
5 
6 namespace c10 {
7 
8 /**
9  * bits1x8 is an uninterpreted dtype of a tensor with 1 bit (packed to byte
10  * boundary), without any semantics defined.
11  */
12 struct alignas(1) bits1x8 {
13   using underlying = uint8_t;
14   uint8_t val_;
15   bits1x8() = default;
bits1x8bits1x816   C10_HOST_DEVICE explicit bits1x8(uint8_t val) : val_(val) {}
17 };
18 
19 /**
20  * bits2x4 is an uninterpreted dtype of a tensor with 2 bits (packed to byte
21  * boundary), without any semantics defined.
22  */
23 struct alignas(1) bits2x4 {
24   using underlying = uint8_t;
25   uint8_t val_;
26   bits2x4() = default;
bits2x4bits2x427   C10_HOST_DEVICE explicit bits2x4(uint8_t val) : val_(val) {}
28 };
29 
30 /**
31  * bits4x2 is an uninterpreted dtype of a tensor with 4 bits (packed to byte
32  * boundary), without any semantics defined.
33  */
34 struct alignas(1) bits4x2 {
35   using underlying = uint8_t;
36   uint8_t val_;
37   bits4x2() = default;
bits4x2bits4x238   C10_HOST_DEVICE explicit bits4x2(uint8_t val) : val_(val) {}
39 };
40 
41 /**
42  * bits8 is an uninterpreted dtype of a tensor with 8 bits, without any
43  * semantics defined.
44  */
45 struct alignas(1) bits8 {
46   uint8_t val_;
47   bits8() = default;
bits8bits848   C10_HOST_DEVICE explicit bits8(uint8_t val) : val_(val) {}
49 };
50 
51 /**
52  * bits16 is an uninterpreted dtype of a tensor with 16 bits, without any
53  * semantics defined.
54  */
55 struct alignas(2) bits16 {
56   uint16_t val_;
57   bits16() = default;
bits16bits1658   C10_HOST_DEVICE explicit bits16(uint16_t val) : val_(val) {}
59 };
60 
61 } // namespace c10
62