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

Performance Optimizations for Tape Operations #154

Closed
wants to merge 5 commits into from

Conversation

rghouzra
Copy link
Contributor

@rghouzra rghouzra commented Nov 30, 2024

Title

Optimize memory usage in Tape operations

Description

While profiling our tape operations, I noticed some opportunities to reduce memory allocations and copying. This PR makes targeted optimizations to callback handling and adjoint resets without changing the core behavior.

What Changed

  • Changed insertCallback() to use emplace_back() to construct elements in-place
  • Updated getAndResetOutputAdjoint() to use move semantics for derivative transfers

Why

The previous implementation was doing unnecessary memory allocations during callback insertions and making copies of derivative values where moves would suffice. These changes should help reduce memory

. use emplace_back for efficient checkpoint and statement insertion
. implement move semantics for adjoint reset operations
- it should use const refernce to avoid copies but apparently it cant be build on other compilers
perf: optimize' callback insertion and adjoint reset operations
@boring-cyborg boring-cyborg bot added benchmarks Run benchmark workflow src labels Nov 30, 2024
@coveralls
Copy link
Collaborator

coveralls commented Nov 30, 2024

Pull Request Test Coverage Report for Build 12105754388

Details

  • 8 of 8 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 98.961%

Totals Coverage Status
Change from base Build 12099899696: 0.0%
Covered Lines: 2763
Relevant Lines: 2792

💛 - Coveralls

Copy link
Collaborator

@xcelerit-team xcelerit-team left a comment

Choose a reason for hiding this comment

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

Could you also please update the description of the pull request please? Thanks.

src/Tape.cpp Show resolved Hide resolved
src/Tape.cpp Outdated Show resolved Hide resolved
@rghouzra
Copy link
Contributor Author

rghouzra commented Dec 1, 2024

Could you also please update the description of the pull request please? Thanks.

done

Copy link

github-actions bot commented Dec 1, 2024

Test Results

    29 files  ±0      29 suites  ±0   9m 29s ⏱️ +3s
 1 359 tests ±0   1 359 ✅ ±0  0 💤 ±0  0 ❌ ±0 
39 279 runs  ±0  39 279 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit b3a07e6. ± Comparison against base commit 5fedca2.

@auto-differentiation-dev
Copy link
Collaborator

Hi @rghouzra ,

Thank you for this PR and for your effort in contributing to the project - it's great to see your interest in improving the codebase!

After reviewing the changes, I noticed:

  • insertCallback(): Switching to emplace doesn’t provide a performance gain in this case, as copying or moving is the same for a pointer.
  • getAndResetOutputAdjoint(): The move semantics won’t significantly improve performance here, particularly because the function is rarely called (once per checkpoint) and there is no impact for first-order derivatives as copy or move is the same for double values.

Given these points, I don’t think merging this particular PR would benefit the repository right now. However, we truly appreciate your enthusiasm, and there are several open issues in the repo where your skills and ideas could make a significant impact. I’d love for you to take a look and see if anything catches your interest: https://github.com/auto-differentiation/xad/issues.

Thanks again for your contribution, and I hope to see more of your work in the future! Let me know if you have any questions or would like guidance on specific issues.

@rghouzra
Copy link
Contributor Author

rghouzra commented Dec 2, 2024

Hi @rghouzra ,

Thank you for this PR and for your effort in contributing to the project - it's great to see your interest in improving the codebase!

After reviewing the changes, I noticed:

* **`insertCallback()`**: Switching to `emplace` doesn’t provide a performance gain in this case, as copying or moving is the same for a pointer.

* **`getAndResetOutputAdjoint()`**: The move semantics won’t significantly improve performance here, particularly because the function is rarely called (once per checkpoint) and there is no impact for first-order derivatives as copy or move is the same for `double` values.

Given these points, I don’t think merging this particular PR would benefit the repository right now. However, we truly appreciate your enthusiasm, and there are several open issues in the repo where your skills and ideas could make a significant impact. I’d love for you to take a look and see if anything catches your interest: https://github.com/auto-differentiation/xad/issues.

Thanks again for your contribution, and I hope to see more of your work in the future! Let me know if you have any questions or would like guidance on specific issues.

Hi @rghouzra ,

Thank you for this PR and for your effort in contributing to the project - it's great to see your interest in improving the codebase!

After reviewing the changes, I noticed:

* **`insertCallback()`**: Switching to `emplace` doesn’t provide a performance gain in this case, as copying or moving is the same for a pointer.

* **`getAndResetOutputAdjoint()`**: The move semantics won’t significantly improve performance here, particularly because the function is rarely called (once per checkpoint) and there is no impact for first-order derivatives as copy or move is the same for `double` values.

Given these points, I don’t think merging this particular PR would benefit the repository right now. However, we truly appreciate your enthusiasm, and there are several open issues in the repo where your skills and ideas could make a significant impact. I’d love for you to take a look and see if anything catches your interest: https://github.com/auto-differentiation/xad/issues.

Thanks again for your contribution, and I hope to see more of your work in the future! Let me know if you have any questions or would like guidance on specific issues.

Hi @auto-differentiation-dev
Thanks for the feedback! I’ll check out the open issues.

@rghouzra rghouzra closed this Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmarks Run benchmark workflow src
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants