xref: /aosp_15_r20/external/pytorch/aten/src/ATen/core/interned_strings_class.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #include <mutex>
2 #include <string>
3 #include <unordered_map>
4 #include <vector>
5 #include <ATen/core/symbol.h>
6 #include <c10/util/Exception.h>
7 
8 namespace c10 {
9 
10 struct TORCH_API InternedStrings {
11   InternedStrings();
12   Symbol symbol(const std::string& s);
13   std::pair<const char*, const char*> string(Symbol sym);
14   Symbol ns(Symbol sym);
15 
16  private:
17   // prereq - holding mutex_
18   Symbol _symbol(const std::string& s);
19   std::pair<const char*, const char*> customString(Symbol sym);
20   std::unordered_map<std::string, Symbol> string_to_sym_;
21 
22   struct SymbolInfo {
23     Symbol ns;
24     std::string qual_name;
25     std::string unqual_name;
26   };
27   std::vector<SymbolInfo> sym_to_info_;
28 
29   std::mutex mutex_;
30 };
31 
32 } // namespace c10
33