Halide  19.0.0
Halide compiler and libraries
ObjectInstanceRegistry.h
Go to the documentation of this file.
1 #ifndef HALIDE_OBJECT_INSTANCE_REGISTRY_H
2 #define HALIDE_OBJECT_INSTANCE_REGISTRY_H
3 
4 /** \file
5  *
6  * Provides a single global registry of Generators, GeneratorParams,
7  * and Params indexed by this pointer. This is used for finding the
8  * parameters inside of a Generator.
9  */
10 
11 #include <cstddef>
12 #include <cstdint>
13 #include <map>
14 #include <mutex>
15 #include <vector>
16 
17 namespace Halide {
18 namespace Internal {
19 
21 public:
22  enum Kind {
29  };
30 
31  /** Add an instance to the registry. The size may be 0 for Param Kinds,
32  * but not for Generator. subject_ptr is the value actually associated
33  * with this instance; it is usually (but not necessarily) the same
34  * as this_ptr. Assert if this_ptr is already registered.
35  */
36  static void register_instance(void *this_ptr, size_t size, Kind kind, void *subject_ptr);
37 
38  /** Remove an instance from the registry. Assert if not found.
39  */
40  static void unregister_instance(void *this_ptr);
41 
42  /** Returns the list of subject pointers for objects that have
43  * been directly registered within the given range. If there is
44  * another containing object inside the range, instances within
45  * that object are skipped.
46  */
47  static std::vector<std::pair<void *, Kind>> instances_in_range(void *start, size_t size);
48 
49 private:
50  static ObjectInstanceRegistry &get_registry();
51 
52  struct InstanceInfo {
53  void *subject_ptr = nullptr; // May be different from the this_ptr in the key
54  size_t size = 0; // May be 0 for params
55  Kind kind = Invalid;
56 
57  InstanceInfo() = default;
58  InstanceInfo(size_t size, Kind kind, void *subject_ptr)
59  : subject_ptr(subject_ptr), size(size), kind(kind) {
60  }
61  };
62 
63  std::mutex mutex;
64  std::map<uintptr_t, InstanceInfo> instances;
65 
66  ObjectInstanceRegistry() = default;
67 
68 public:
73 };
74 
75 } // namespace Internal
76 } // namespace Halide
77 
78 #endif // HALIDE_OBJECT_INSTANCE_REGISTRY_H
static std::vector< std::pair< void *, Kind > > instances_in_range(void *start, size_t size)
Returns the list of subject pointers for objects that have been directly registered within the given ...
ObjectInstanceRegistry & operator=(ObjectInstanceRegistry &&)=delete
ObjectInstanceRegistry(const ObjectInstanceRegistry &)=delete
ObjectInstanceRegistry & operator=(const ObjectInstanceRegistry &)=delete
static void unregister_instance(void *this_ptr)
Remove an instance from the registry.
ObjectInstanceRegistry(ObjectInstanceRegistry &&)=delete
static void register_instance(void *this_ptr, size_t size, Kind kind, void *subject_ptr)
Add an instance to the registry.
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.