You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8df8edf
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/src/man/backends.md
+18-1Lines changed: 18 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -129,11 +129,14 @@ In particular, this means that the backend will be selected **first**, while onl
129
129
```@docs
130
130
TensorOperations.DefaultAllocator
131
131
TensorOperations.ManualAllocator
132
+
TensorOperations.BufferAllocator
132
133
```
133
134
134
135
By default, the `DefaultAllocator` is used, which uses Julia's built-in memory management system.
135
136
Optionally, it can be useful to use the `ManualAllocator`, as the manual memory management reduces the pressure on the garbage collector.
136
137
In particular in multi-threaded applications, this can sometimes lead to a significant performance improvement.
138
+
On the other hand, for often-repeated but thread-safe `@tensor` calls, the `BufferAllocator` is a lightweight slab allocator that pre-allocates a buffer for temporaries, falling back to Julia's default if needed.
139
+
Upon repeated use it will automatically resize the buffer to accommodate for the requested temporaries.
137
140
138
141
Finally, users can also opt to use the `Bumper.jl` system, which pre-allocates a slab of memory that can be re-used afterwards.
139
142
This is available through a package extension for `Bumper`.
Users can also define their own allocators, to facilitate experimentation with new implementations.
167
170
Here, no restriction is made on the type of the allocator, and any object can be passed as an allocator.
168
-
The required implemented methods are [`tensoralloc`](@ref) and [`tensorfree!`](@ref).
171
+
172
+
The core methods that can be customized for an allocator are:
173
+
174
+
*[`tensoralloc`](@ref): Allocate a tensor of a given type and structure. This method receives a flag indicating whether the tensor is temporary (will not persist outside the `@tensor` block) or permanent. Temporary tensors can be allocated from internal buffers or pools, while permanent tensors should use a standard allocation strategy.
175
+
*[`tensorfree!`](@ref): Explicitly free a tensor, if applicable. For custom allocators that manage internal pools or buffers, this can be used to track when temporaries are no longer needed.
176
+
177
+
Here we are guaranteeing that every `tensoralloc` call that has the temporary flag will be accompanied by exactly one matching call to `tensorfree!`, as soon as the temporary object is no longer needed.
178
+
179
+
For allocators that manage reusable buffers or maintain state across multiple contractions, the following helper methods can be useful:
180
+
181
+
*[`allocator_checkpoint!`](@ref): Save the current state of the allocator (e.g., the current offset in a buffer). This can be called before a sequence of tensor operations to capture the allocation state.
182
+
*[`allocator_reset!`](@ref): Restore the allocator to a previously saved checkpoint, effectively releasing all allocations made since the checkpoint was taken.
183
+
184
+
Here we are guaranteeing that every created checkpoint will be restored, and all temporary allocations that are inclosed within this scope will no longer be accessed.
185
+
Additionally, if multiple checkpoints are created, they will be restored in the reverse order of how they were created.
0 commit comments