Halide 22.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
20 class ObjectInstanceRegistry {
21 public:
22 enum Kind {
23 Invalid,
24 Generator,
25 GeneratorParam,
26 GeneratorInput,
27 GeneratorOutput,
28 FilterParam
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:
69 ObjectInstanceRegistry(const ObjectInstanceRegistry &) = delete;
70 ObjectInstanceRegistry &operator=(const ObjectInstanceRegistry &) = delete;
71 ObjectInstanceRegistry(ObjectInstanceRegistry &&) = delete;
72 ObjectInstanceRegistry &operator=(ObjectInstanceRegistry &&) = delete;
73};
74
75} // namespace Internal
76} // namespace Halide
77
78#endif // HALIDE_OBJECT_INSTANCE_REGISTRY_H
Halide::Internal::ObjectInstanceRegistry
Definition: ObjectInstanceRegistry.h:20
Halide::Internal::ObjectInstanceRegistry::Kind
Kind
Definition: ObjectInstanceRegistry.h:22
Halide::Internal::ObjectInstanceRegistry::Generator
@ Generator
Definition: ObjectInstanceRegistry.h:24
Halide::Internal::ObjectInstanceRegistry::FilterParam
@ FilterParam
Definition: ObjectInstanceRegistry.h:28
Halide::Internal::ObjectInstanceRegistry::GeneratorParam
@ GeneratorParam
Definition: ObjectInstanceRegistry.h:25
Halide::Internal::ObjectInstanceRegistry::GeneratorOutput
@ GeneratorOutput
Definition: ObjectInstanceRegistry.h:27
Halide::Internal::ObjectInstanceRegistry::Invalid
@ Invalid
Definition: ObjectInstanceRegistry.h:23
Halide::Internal::ObjectInstanceRegistry::GeneratorInput
@ GeneratorInput
Definition: ObjectInstanceRegistry.h:26
Halide::Internal::ObjectInstanceRegistry::ObjectInstanceRegistry
ObjectInstanceRegistry(const ObjectInstanceRegistry &)=delete
Halide::Internal::ObjectInstanceRegistry::operator=
ObjectInstanceRegistry & operator=(const ObjectInstanceRegistry &)=delete
Halide::Internal::ObjectInstanceRegistry::instances_in_range
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 ...
Halide::Internal::ObjectInstanceRegistry::unregister_instance
static void unregister_instance(void *this_ptr)
Remove an instance from the registry.
Halide::Internal::ObjectInstanceRegistry::operator=
ObjectInstanceRegistry & operator=(ObjectInstanceRegistry &&)=delete
Halide::Internal::ObjectInstanceRegistry::ObjectInstanceRegistry
ObjectInstanceRegistry(ObjectInstanceRegistry &&)=delete
Halide::Internal::ObjectInstanceRegistry::register_instance
static void register_instance(void *this_ptr, size_t size, Kind kind, void *subject_ptr)
Add an instance to the registry.
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition: AbstractGenerator.h:19
Halide::LinkageType::Internal
@ Internal
Not visible externally, similar to 'static' linkage in C.