xref: /aosp_15_r20/external/pytorch/aten/src/ATen/core/DeprecatedTypePropertiesRegistry.cpp (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #include <ATen/core/DeprecatedTypePropertiesRegistry.h>
2 
3 #include <ATen/core/DeprecatedTypeProperties.h>
4 #include <c10/util/irange.h>
5 
6 namespace at {
7 
operator ()(DeprecatedTypeProperties * ptr)8 void DeprecatedTypePropertiesDeleter::operator()(DeprecatedTypeProperties * ptr) {
9   delete ptr;
10 }
11 
DeprecatedTypePropertiesRegistry()12 DeprecatedTypePropertiesRegistry::DeprecatedTypePropertiesRegistry() {
13   for (const auto b : c10::irange(static_cast<int>(Backend::NumOptions))) {
14     for (const auto s : c10::irange(static_cast<int>(ScalarType::NumOptions))) {
15       registry[b][s] = std::make_unique<DeprecatedTypeProperties>(
16               static_cast<Backend>(b),
17               static_cast<ScalarType>(s));
18     }
19   }
20 }
21 
getDeprecatedTypeProperties(Backend p,ScalarType s) const22 DeprecatedTypeProperties& DeprecatedTypePropertiesRegistry::getDeprecatedTypeProperties(
23     Backend p, ScalarType s) const {
24   return *registry[static_cast<int>(p)][static_cast<int>(s)];
25 }
26 
27 // TODO: This could be bad juju if someone calls globalContext() in the
28 // destructor of an object with static lifetime.
globalDeprecatedTypePropertiesRegistry()29 DeprecatedTypePropertiesRegistry & globalDeprecatedTypePropertiesRegistry() {
30   static DeprecatedTypePropertiesRegistry singleton;
31   return singleton;
32 }
33 
34 }
35