bits.h 1.4 KB

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