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

Made address book fold indices buffers #335

Merged
merged 4 commits into from
Feb 5, 2025
Merged

Made address book fold indices buffers #335

merged 4 commits into from
Feb 5, 2025

Conversation

loreloc
Copy link
Member

@loreloc loreloc commented Dec 18, 2024

#330 momentarily made address book tensor indices stay on the CPU. This is because the previous to(device) override was not called when the circuit was a submodule of another PyTorch model.

This was still ok because PyTorch supports indexing tensors on the GPU using tensors on the CPU. However, this comes at the cost of additional transfer overhead between CPU and GPU.

A quick profilation (using the optimized circuit in compilation-options.ipynb) shows this, where aten::to, aten::_to_copy and aten::copy_ take ~31% of overall CPU time when calling the circuit forward method. See the screenshot below.

Screenshot from 2024-12-18 12-30-22

This PR makes the address book fold indices buffers in the AddressBook torch module. As such, they are automatically moved to the GPU only once (i.e., when calling the parent module to(device) method).
The profilation with these changes shows no aten::to operation at all, which also reduces the meaasured CUDA time. See screenshot below.

Screenshot from 2024-12-18 12-09-47

@loreloc loreloc self-assigned this Dec 18, 2024
@loreloc loreloc added the enhancement New feature or request label Dec 18, 2024
@loreloc loreloc added this to the cirkit 0.3.0 (reckoning) milestone Jan 10, 2025
@loreloc loreloc merged commit c446634 into main Feb 5, 2025
1 of 2 checks passed
@loreloc loreloc deleted the address-book-gpu branch February 5, 2025 16:41
@loreloc loreloc restored the address-book-gpu branch February 5, 2025 17:29
@loreloc loreloc deleted the address-book-gpu branch February 7, 2025 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant