SMAUG
Simulating Machine Learning Applications on gem5-Aladdin
datatypes.h
1 #ifndef _CORE_DATATYPES_H_
2 #define _CORE_DATATYPES_H_
3 
4 #include <cstdint>
5 #include <vector>
6 #include "smaug/core/types.pb.h"
7 
8 namespace smaug {
9 
10 using float16 = uint16_t;
11 
17 template <typename T>
18 struct ToDataType {};
19 
20 template <>
21 struct ToDataType<float16> {
22  static const DataType dataType = Float16;
23 };
24 template <>
25 struct ToDataType<float> {
26  static const DataType dataType = Float32;
27 };
28 template <>
29 struct ToDataType<double> {
30  static const DataType dataType = Float64;
31 };
32 template <>
33 struct ToDataType<int32_t> {
34  static const DataType dataType = Int32;
35 };
36 template <>
37 struct ToDataType<uint32_t> {
38  static const DataType dataType = Int32;
39 };
40 template <>
41 struct ToDataType<int64_t> {
42  static const DataType dataType = Int64;
43 };
44 template <>
45 struct ToDataType<uint64_t> {
46  static const DataType dataType = Int64;
47 };
48 template <>
49 struct ToDataType<bool> {
50  static const DataType dataType = Bool;
51 };
52 
58 template <enum DataType>
59 struct FromDataType {};
60 
61 template<>
62 struct FromDataType<Int32> {
63  typedef int32_t type;
64 };
65 template<>
66 struct FromDataType<Int64> {
67  typedef int64_t type;
68 };
69 template<>
70 struct FromDataType<Float16> {
71  typedef uint16_t type;
72 };
73 template<>
74 struct FromDataType<Float32> {
75  typedef float type;
76 };
77 template<>
78 struct FromDataType<Float64> {
79  typedef double type;
80 };
81 template<>
82 struct FromDataType<Bool> {
83  typedef bool type;
84 };
85 
86 } // namespace smaug
87 
88 #endif
smaug::FromDataType
Provides compile-time conversion from SMAUG DataType to C type.
Definition: datatypes.h:59
smaug::ToDataType
Provides compile-time conversion from C types to SMAUG DataTypes.
Definition: datatypes.h:18
smaug
The smaug namespace is the parent namespace of all C++ code in SMAUG.
Definition: backend.cpp:38