Skip to content

Better memory management #50

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

Merged
merged 17 commits into from
Nov 7, 2024
Merged

Better memory management #50

merged 17 commits into from
Nov 7, 2024

Conversation

alphaville
Copy link
Member

@alphaville alphaville commented Nov 7, 2024

This is an alternative to PR #49; this is still WIP.

Main Changes

  • Introduce T** m_d_ptrMatrices, which is a raw pointer to the matrices of the tensor (to replace pointersToMatrices)

TODOs

  • New memory management scheme (malloc/free)
  • addAB: use gemm when nMats=1
  • Slicing: set m_d_ptrMatrix = nullptr when slicing with axis=0 or axis=1
  • Remove unit test tensorPointersToMatrices (method deprecation)
  • Get rid of pointersToMatrices() in leastSquaresBatched
  • CholeskyBatchFactoriser: get rid of pointersToMatrices
  • CholeskyBatchFactoriser: throw error if nMats=1
  • Reshaping: new test needed (e.g., reshape + multiply with addAB)
  • Unit test with reshaping and slicing

Note

It probably makes sense to always have m_d_ptrMatrix = nullptr whenever nMats=1 and throw an error when the user attempts to use any batched method with nMats=1.

Associated Issues

Allocating and destroying memory
No memory leaks evident atm
Introduce initialisePointersToMatricesData to initialise
m_d_ptrMatrices; appropriate checks for safety.
Also in the slice constructor, keep m_d_ptrMatrices=nullptr
when we dont slice along axis=2
use cublasDGemm if nMats=1
@alphaville alphaville mentioned this pull request Nov 7, 2024
5 tasks
When necessary, memory is reallocated for m_d_ptrMatrices
within reshape
No need to free/reallocate when we can reuse the already
allocated memory space (when the number of matrices
decreases); no new memory allocation when numMats=1
Copy link
Collaborator

@ruairimoran ruairimoran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check comments. Looks great

Unit test: Slice along axis=2 and reshape
Write documentation for DTensor<T>::reshape
Fix formatting issues in testTensor
Copy link
Collaborator

@ruairimoran ruairimoran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@ruairimoran ruairimoran marked this pull request as ready for review November 7, 2024 17:46
Free all allocated memory if allocation fails
Fix code formatting in testTensor
allocateOnDevice made void
@alphaville alphaville merged commit 43da320 into main Nov 7, 2024
2 checks passed
@alphaville alphaville deleted the fix/48-better-mem-mgmt branch December 3, 2024 15:18
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.

Do not allocate new memory from within a method
2 participants