Loading...
Searching...
No Matches
ObjectInstanceRegistry.h
Go to the documentation of this file.
#ifndef HALIDE_OBJECT_INSTANCE_REGISTRY_H
#define HALIDE_OBJECT_INSTANCE_REGISTRY_H
/** \file
*
* Provides a single global registry of Generators, GeneratorParams,
* and Params indexed by this pointer. This is used for finding the
* parameters inside of a Generator.
*/
#include <cstddef>
#include <cstdint>
#include <map>
#include <mutex>
#include <vector>
namespace Halide {
namespace Internal {
class ObjectInstanceRegistry {
public:
enum Kind {
Invalid,
Generator,
GeneratorParam,
GeneratorInput,
GeneratorOutput,
FilterParam
};
/** Add an instance to the registry. The size may be 0 for Param Kinds,
* but not for Generator. subject_ptr is the value actually associated
* with this instance; it is usually (but not necessarily) the same
* as this_ptr. Assert if this_ptr is already registered.
*/
static void register_instance(void *this_ptr, size_t size, Kind kind, void *subject_ptr);
/** Remove an instance from the registry. Assert if not found.
*/
static void unregister_instance(void *this_ptr);
/** Returns the list of subject pointers for objects that have
* been directly registered within the given range. If there is
* another containing object inside the range, instances within
* that object are skipped.
*/
static std::vector<std::pair<void *, Kind>> instances_in_range(void *start, size_t size);
private:
static ObjectInstanceRegistry &get_registry();
struct InstanceInfo {
void *subject_ptr = nullptr; // May be different from the this_ptr in the key
size_t size = 0; // May be 0 for params
Kind kind = Invalid;
InstanceInfo() = default;
InstanceInfo(size_t size, Kind kind, void *subject_ptr)
: subject_ptr(subject_ptr), size(size), kind(kind) {
}
};
std::mutex mutex;
std::map<uintptr_t, InstanceInfo> instances;
ObjectInstanceRegistry() = default;
public:
ObjectInstanceRegistry(const ObjectInstanceRegistry &) = delete;
ObjectInstanceRegistry &operator=(const ObjectInstanceRegistry &) = delete;
ObjectInstanceRegistry(ObjectInstanceRegistry &&) = delete;
ObjectInstanceRegistry &operator=(ObjectInstanceRegistry &&) = delete;
};
} // namespace Internal
} // namespace Halide
#endif // HALIDE_OBJECT_INSTANCE_REGISTRY_H
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::Internal
Definition AbstractGenerator.h:24
Halide
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
Definition AbstractGenerator.h:19