19
19
#include " ATen/core/IdWrapper.h"
20
20
21
21
namespace caffe2 {
22
- class CaffeTypeId ;
22
+ class TypeIdentifier ;
23
23
}
24
24
25
- std::ostream& operator <<(std::ostream& stream, caffe2::CaffeTypeId typeId);
25
+ std::ostream& operator <<(std::ostream& stream, caffe2::TypeIdentifier typeId);
26
26
27
27
namespace caffe2 {
28
28
29
29
class TypeMeta ;
30
30
31
31
/* *
32
32
* A type id is a unique id for a given C++ type.
33
- * You need to register your types using CAFFE_KNOWN_TYPE(MyType) to be able to use CaffeTypeId with custom types.
33
+ * You need to register your types using CAFFE_KNOWN_TYPE(MyType) to be able to use TypeIdentifier with custom types.
34
34
* This is for example used to store the dtype of tensors.
35
35
*/
36
- class CaffeTypeId final : public at::IdWrapper<CaffeTypeId , uint16_t > {
36
+ class TypeIdentifier final : public at::IdWrapper<TypeIdentifier , uint16_t > {
37
37
public:
38
- static CaffeTypeId createTypeId ();
38
+ static TypeIdentifier createTypeId ();
39
39
40
- friend std::ostream& ::operator <<(std::ostream& stream, CaffeTypeId typeId);
41
- friend bool operator <(CaffeTypeId lhs, CaffeTypeId rhs);
40
+ friend std::ostream& ::operator <<(std::ostream& stream, TypeIdentifier typeId);
41
+ friend bool operator <(TypeIdentifier lhs, TypeIdentifier rhs);
42
42
43
43
// This is 8, because 0 is uint8_t (due to ScalarType BC constraint)
44
- static constexpr CaffeTypeId uninitialized () {
45
- return CaffeTypeId (8 );
44
+ static constexpr TypeIdentifier uninitialized () {
45
+ return TypeIdentifier (8 );
46
46
}
47
47
48
48
private:
49
- constexpr explicit CaffeTypeId (uint16_t id): IdWrapper(id) {}
49
+ constexpr explicit TypeIdentifier (uint16_t id): IdWrapper(id) {}
50
50
friend class TypeMeta ;
51
51
};
52
52
53
53
// Allow usage in std::map / std::set
54
54
// TODO Disallow this and rather use std::unordered_map/set everywhere
55
- inline bool operator <(CaffeTypeId lhs, CaffeTypeId rhs) {
55
+ inline bool operator <(TypeIdentifier lhs, TypeIdentifier rhs) {
56
56
return lhs.underlyingId () < rhs.underlyingId ();
57
57
}
58
58
59
59
}
60
60
61
- AT_DEFINE_HASH_FOR_IDWRAPPER (caffe2::CaffeTypeId )
61
+ AT_DEFINE_HASH_FOR_IDWRAPPER (caffe2::TypeIdentifier )
62
62
63
- inline std::ostream& operator<<(std::ostream& stream, caffe2::CaffeTypeId typeId) {
63
+ inline std::ostream& operator<<(std::ostream& stream, caffe2::TypeIdentifier typeId) {
64
64
return stream << typeId.underlyingId ();
65
65
}
66
66
67
67
namespace caffe2 {
68
68
69
- std::unordered_map<CaffeTypeId , std::string>& gTypeNames ();
69
+ std::unordered_map<TypeIdentifier , std::string>& gTypeNames ();
70
70
std::unordered_set<std::string>& gRegisteredTypeNames ();
71
71
72
72
// A utility function to demangle a function name.
@@ -95,7 +95,7 @@ std::mutex& gTypeRegistrationMutex();
95
95
96
96
template <typename T>
97
97
struct TypeNameRegisterer {
98
- TypeNameRegisterer (CaffeTypeId id, const std::string& literal_name) {
98
+ TypeNameRegisterer (TypeIdentifier id, const std::string& literal_name) {
99
99
std::lock_guard<std::mutex> guard (gTypeRegistrationMutex ());
100
100
#ifdef __GXX_RTTI
101
101
(void )literal_name;
@@ -141,7 +141,7 @@ class TypeMeta {
141
141
* type, use TypeMeta::Make<T>().
142
142
*/
143
143
TypeMeta () noexcept
144
- : id_(CaffeTypeId ::uninitialized()), itemsize_(0 ), ctor_(nullptr ), copy_(nullptr ), dtor_(nullptr ) {}
144
+ : id_(TypeIdentifier ::uninitialized()), itemsize_(0 ), ctor_(nullptr ), copy_(nullptr ), dtor_(nullptr ) {}
145
145
146
146
/* *
147
147
* Copy constructor.
@@ -159,7 +159,7 @@ class TypeMeta {
159
159
// TypeMeta can only be created by Make, making sure that we do not
160
160
// create incorrectly mixed up TypeMeta objects.
161
161
TypeMeta (
162
- CaffeTypeId i,
162
+ TypeIdentifier i,
163
163
size_t s,
164
164
PlacementNew* ctor,
165
165
TypedCopy* copy,
@@ -176,7 +176,7 @@ class TypeMeta {
176
176
/* *
177
177
* Returns the type id.
178
178
*/
179
- const CaffeTypeId & id () const noexcept {
179
+ const TypeIdentifier & id () const noexcept {
180
180
return id_;
181
181
}
182
182
/* *
@@ -229,7 +229,7 @@ class TypeMeta {
229
229
* is generated during run-time. Do NOT serialize the id for storage.
230
230
*/
231
231
template <typename T>
232
- CAFFE2_API static CaffeTypeId Id ();
232
+ CAFFE2_API static TypeIdentifier Id ();
233
233
234
234
/* *
235
235
* Returns the item size of the type. This is equivalent to sizeof(T).
@@ -356,7 +356,7 @@ class TypeMeta {
356
356
}
357
357
358
358
private:
359
- CaffeTypeId id_;
359
+ TypeIdentifier id_;
360
360
size_t itemsize_;
361
361
PlacementNew* ctor_;
362
362
TypedCopy* copy_;
@@ -393,16 +393,16 @@ inline bool operator!=(const TypeMeta& lhs, const TypeMeta& rhs) noexcept {
393
393
#ifdef _MSC_VER
394
394
#define CAFFE_KNOWN_TYPE (T ) \
395
395
template <> \
396
- CAFFE2_EXPORT CaffeTypeId TypeMeta::Id<T>() { \
397
- static const CaffeTypeId type_id = CaffeTypeId ::createTypeId (); \
396
+ CAFFE2_EXPORT TypeIdentifier TypeMeta::Id<T>() { \
397
+ static const TypeIdentifier type_id = TypeIdentifier ::createTypeId (); \
398
398
static TypeNameRegisterer<T> registerer (type_id, #T); \
399
399
return type_id; \
400
400
}
401
401
#else // _MSC_VER
402
402
#define CAFFE_KNOWN_TYPE (T ) \
403
403
template <> \
404
- CaffeTypeId TypeMeta::Id<T>() { \
405
- static const CaffeTypeId type_id = CaffeTypeId ::createTypeId (); \
404
+ TypeIdentifier TypeMeta::Id<T>() { \
405
+ static const TypeIdentifier type_id = TypeIdentifier ::createTypeId (); \
406
406
static TypeNameRegisterer<T> registerer (type_id, #T); \
407
407
return type_id; \
408
408
}
@@ -417,14 +417,14 @@ inline bool operator!=(const TypeMeta& lhs, const TypeMeta& rhs) noexcept {
417
417
#ifdef _MSC_VER
418
418
#define CAFFE_DECLARE_KNOWN_TYPE (PreallocatedId, T ) \
419
419
template <> \
420
- inline CAFFE2_EXPORT CaffeTypeId TypeMeta::Id<T>() { \
421
- return CaffeTypeId (PreallocatedId); \
420
+ inline CAFFE2_EXPORT TypeIdentifier TypeMeta::Id<T>() { \
421
+ return TypeIdentifier (PreallocatedId); \
422
422
}
423
423
#else // _MSC_VER
424
424
#define CAFFE_DECLARE_KNOWN_TYPE (PreallocatedId, T ) \
425
425
template <> \
426
- inline CaffeTypeId TypeMeta::Id<T>() { \
427
- return CaffeTypeId (PreallocatedId); \
426
+ inline TypeIdentifier TypeMeta::Id<T>() { \
427
+ return TypeIdentifier (PreallocatedId); \
428
428
}
429
429
#endif
430
430
0 commit comments