Class IntermediateNamePool¶
Defined in File name_recycling.hpp
Nested Relationships¶
Nested Types¶
Class Documentation¶
-
class IntermediateNamePool¶
Keeps track of the names of intermediates and how often they are currently in use. Names that are no longer in use are handed out to new intermediates of compatible shape and fresh names are generated such that they don’t collide with any reserved or previously used name.
Tensors are identified by their label and their block, i.e. tensors with the same label but different blocks refer to different objects. Hence, the same label can be handed out for tensors of different blocks.
Public Types
-
using LabelGenerator = std::function<std::wstring(std::wstring_view basename, std::size_t)>¶
Generates a label from a basename and a counter (starting at 1).
Public Functions
-
inline explicit IntermediateNamePool(LabelGenerator label_gen = default_label_generator(), detail::TensorNormalizer normalize = {})¶
- Parameters:
label_gen – Generator for labels
normalize – If set, tensors are identified by the form produced by this normalizer, i.e. tensors whose normalized forms have the same label and block refer to the same object
-
inline void reserve(std::wstring label)¶
Marks
labelas being in use by something that isn’t managed by this pool such that it will never be handed out
-
inline void release(const Expr &object)¶
Ends a use of
object(a Tensor or Variable). Once all of its uses have ended, the object’s name is available for reuse.
-
inline std::wstring fresh_label(std::wstring_view basename, const Expr &candidate, const std::function<bool(const Expr&)> &acceptable = {})¶
- Parameters:
basename – The basename to derive the label from via the pool’s LabelGenerator
acceptable – Predicate invoked with
candidaterelabeled to the label under consideration
- Returns:
A label that has not been reserved, that, together with the block of
candidate, has not been known to this pool before and for whichacceptable(if provided) returns true. The respective object is marked as being in use.
-
template<typename T>
inline Allocation lowest_available(std::wstring_view basename, const T &candidate, const std::function<bool(const T&)> &acceptable = {}) const¶ Determines the first label (in the order of the pool’s LabelGenerator) that, together with the block of
candidate, refers to an object that is not in use and for whichacceptable(if provided) returns true. Contrary to fresh_label and acquire, the respective object is not marked as being in use (see occupy).
-
inline std::optional<RecycledTensor> acquire(const Tensor &candidate, ShapeCompatibility compatibility, const std::function<bool(const Tensor&)> &acceptable = {})¶
Searches for an object that is not in use, whose block is compatible with
candidateundercompatibilityand for whichacceptable(if provided) returns true. Of all such objects, the one that has become known to this pool first is chosen and marked as being in use.- Returns:
candidaterelabeled (and rearranged) to the recycled name, or std::nullopt if no suitable name is available
Public Static Functions
-
static inline LabelGenerator default_label_generator()¶
- Returns:
A LabelGenerator that appends the counter to the basename
-
struct RecycledTensor¶
A recycled tensor along with the description of how the slots of the original tensor have been rearranged
-
struct Allocation¶
The outcome of lowest_available.
-
using LabelGenerator = std::function<std::wstring(std::wstring_view basename, std::size_t)>¶