Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert operators to use tensor pool, part 2 #110

Merged
merged 10 commits into from
Apr 24, 2024
Merged

Conversation

robertknight
Copy link
Owner

@robertknight robertknight commented Apr 24, 2024

Convert the Reshape, MatMul, Where, Tile and ConvTranspose operators to allocate from the shared pool.

In the process, add some general new facilities to TensorPool:

  • The ability to allocate an empty Vec with a given capacity
  • A PoolRef smart pointer which wraps a tensor and returns it to the pool when it goes out of scope. This is useful for temporary buffers allocate within operators, such as the col2im matrix in ConvTranspose.

See #109

This bound was referenced in a safety comment, but was missing.
Some operators built up their output by filling a `Vec<T>` and passing that to
`Tensor::from_data`. Being able to allocate an empty Vec from the pool with a
given capacity supports this.
Use the new `alloc_vec` API to allocate the output buffer, avoiding unsafe code
in `Concat` itself.
This operator still uses the global allocator internally for the `col2im_mat`
temporary buffer.
…ropped

This is useful for operators which allocate temporary buffers from the pool and
need to return them at the end.
@robertknight robertknight merged commit 9a8e901 into main Apr 24, 2024
2 checks passed
@robertknight robertknight deleted the pool-alloc-pt2 branch April 24, 2024 06:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant