This repository was archived by the owner on Jan 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
mulit-GPU and CUDA Stream Support #60
Open
rubber-duck-debug
wants to merge
32
commits into
main
Choose a base branch
from
multigpu_and_streams
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
72ce285
Add CI config files
d463d21
added stream management to OPSA
rubber-duck-debug d81ec9c
x
rubber-duck-debug c8d8776
added support for other ops.
rubber-duck-debug 0b06e79
formatting.
rubber-duck-debug de5a3da
Merge branch 'main' into multigpu_and_streams
rubber-duck-debug b2c170a
fixed build issues.
rubber-duck-debug f78161c
fixed issue with opsaw instantiation
rubber-duck-debug e89350b
formatting.
rubber-duck-debug ea54e9a
add comments on the test job script
1bb35aa
insignificant commit for retriggering pipeline
497d811
Merge branch 'main' into cscs_ci
frostedoyster b9be358
Install tox
frostedoyster d9fc283
attempt addressing CI compiler errors and warnings
5b04a18
Merge branch 'cscs_ci' of github.com:lab-cosmo/mops into cscs_ci
af2ec60
remove polynomial order zero case to avoid divide by zero issue
9fee2a1
correct address of the atomic add operations in sap
fc80766
specify addresses with indices for atomic add operations to address C…
2ed5771
dummy implementation for polynomial order zero
62b73d8
removed bug in CUDA HPE.
rubber-duck-debug b6d4795
header change
rubber-duck-debug 68223e2
HPE divide by zero fix.
rubber-duck-debug 3b4527f
added in code for pre-sm60 atomicAdd(doubles)
rubber-duck-debug e3c70c2
macro to switch out the atomicAdds depending on ARCH
rubber-duck-debug ade1cd3
documentation.
rubber-duck-debug 263984d
changed macro to device function.
rubber-duck-debug e654289
Merge branch 'cscs_ci' into multigpu_and_streams
rubber-duck-debug 899ea94
fixed sap cstream
rubber-duck-debug 99cedf5
formatting.
rubber-duck-debug 21b6235
missing device guard in SAP
rubber-duck-debug dd29ac0
missing stream.
rubber-duck-debug 7f92034
Add stream benchmark
frostedoyster File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| FROM nvcr.io/nvidia/pytorch:23.10-py3 | ||
|
|
||
| RUN apt-get update | ||
|
|
||
| # install boost test framework | ||
| RUN apt-get install -y libboost-test-dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| include: | ||
| - remote: 'https://gitlab.com/cscs-ci/recipes/-/raw/master/templates/v2/.ci-ext.yml' | ||
|
|
||
| stages: | ||
| - build | ||
| - test | ||
|
|
||
| build_base_image_job: | ||
| stage: build | ||
| extends: .container-builder-dynamic-name | ||
| timeout: 2h | ||
| variables: | ||
| DOCKERFILE: ci/docker/Dockerfile.base | ||
| WATCH_FILECHANGES: $DOCKERFILE | ||
| PERSIST_IMAGE_NAME: $CSCS_REGISTRY_PATH/base/public/mops | ||
|
|
||
| test_job: | ||
| stage: test | ||
| extends: .container-runner-daint-gpu | ||
| image: $BASE_IMAGE | ||
| timeout: 2h | ||
| script: | ||
| - export CUDA_HOME="/usr/local/cuda" | ||
| - python3 -m pip install --upgrade pip | ||
| - echo "Install Tox" | ||
| - python3 -m pip install tox | ||
| - echo "Run the Tox Script" | ||
| - tox | ||
| - echo "Tox script completed" | ||
|
|
||
| variables: | ||
| SLURM_JOB_NUM_NODES: 1 | ||
| SLURM_PARTITION: normal | ||
| SLURM_NTASKS: 1 | ||
| SLURM_TIMELIMIT: '00:40:00' | ||
| GIT_STRATEGY: fetch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| #ifdef MOPS_CUDA_ENABLED | ||
| #include <c10/cuda/CUDAGuard.h> | ||
| #include <c10/cuda/CUDAStream.h> | ||
| #endif | ||
|
|
||
|
Comment on lines
+1
to
+5
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see that
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've fixed this for SAP. OPSAW and SASAW aren't implemented yet (SASAW is in a different branch) so when I get back to that I'll make it consistent. |
||
| #include "mops/torch/sap.hpp" | ||
| #include "mops/torch/utils.hpp" | ||
|
|
||
|
|
@@ -59,6 +64,14 @@ torch::Tensor SparseAccumulationOfProducts::forward( | |
| ); | ||
| }); | ||
| } else if (A.device().is_cuda()) { | ||
|
|
||
| #ifndef MOPS_CUDA_ENABLED | ||
| C10_THROW_ERROR(ValueError, "MOPS was not compiled with CUDA support " + A.device().str()); | ||
| #else | ||
| c10::cuda::CUDAGuard deviceGuard{A.device()}; | ||
| cudaStream_t currstream = c10::cuda::getCurrentCUDAStream(); | ||
| void* stream = reinterpret_cast<void*>(currstream); | ||
|
|
||
| output = torch::empty( | ||
| {A.size(0), output_size}, | ||
| torch::TensorOptions().dtype(A.scalar_type()).device(A.device()) | ||
|
|
@@ -72,9 +85,11 @@ torch::Tensor SparseAccumulationOfProducts::forward( | |
| details::torch_to_mops_1d<scalar_t>(C), | ||
| details::torch_to_mops_1d<int32_t>(indices_A), | ||
| details::torch_to_mops_1d<int32_t>(indices_B), | ||
| details::torch_to_mops_1d<int32_t>(indices_output) | ||
| details::torch_to_mops_1d<int32_t>(indices_output), | ||
| stream | ||
| ); | ||
| }); | ||
| #endif | ||
| } else { | ||
| C10_THROW_ERROR( | ||
| ValueError, | ||
|
|
@@ -170,6 +185,14 @@ std::vector<torch::Tensor> SparseAccumulationOfProductsBackward::forward( | |
| ); | ||
| }); | ||
| } else if (A.device().is_cuda()) { | ||
|
|
||
| #ifndef MOPS_CUDA_ENABLED | ||
| C10_THROW_ERROR(ValueError, "MOPS was not compiled with CUDA support " + A.device().str()); | ||
| #else | ||
| c10::cuda::CUDAGuard deviceGuard{A.device()}; | ||
| cudaStream_t currstream = c10::cuda::getCurrentCUDAStream(); | ||
| void* stream = reinterpret_cast<void*>(currstream); | ||
|
|
||
| AT_DISPATCH_FLOATING_TYPES(A.scalar_type(), "sparse_accumulation_of_products_vjp", [&]() { | ||
| auto mops_grad_A = mops::Tensor<scalar_t, 2>{nullptr, {0, 0}}; | ||
| if (A.requires_grad()) { | ||
|
|
@@ -192,9 +215,11 @@ std::vector<torch::Tensor> SparseAccumulationOfProductsBackward::forward( | |
| details::torch_to_mops_1d<scalar_t>(C), | ||
| details::torch_to_mops_1d<int32_t>(indices_A), | ||
| details::torch_to_mops_1d<int32_t>(indices_B), | ||
| details::torch_to_mops_1d<int32_t>(indices_output) | ||
| details::torch_to_mops_1d<int32_t>(indices_output), | ||
| stream | ||
| ); | ||
| }); | ||
| #endif | ||
| } else { | ||
| C10_THROW_ERROR( | ||
| ValueError, | ||
|
|
@@ -276,6 +301,10 @@ std::vector<torch::Tensor> SparseAccumulationOfProductsBackward::backward( | |
| #ifndef MOPS_CUDA_ENABLED | ||
| C10_THROW_ERROR(ValueError, "MOPS was not compiled with CUDA support " + A.device().str()); | ||
| #else | ||
| c10::cuda::CUDAGuard deviceGuard{A.device()}; | ||
| cudaStream_t currstream = c10::cuda::getCurrentCUDAStream(); | ||
| void* stream = reinterpret_cast<void*>(currstream); | ||
|
|
||
| AT_DISPATCH_FLOATING_TYPES(A.scalar_type(), "sparse_accumulation_of_products_vjp_vjp", [&]() { | ||
| auto mops_grad_grad_output = mops::Tensor<scalar_t, 2>{nullptr, {0, 0}}; | ||
| if (grad_output.requires_grad()) { | ||
|
|
@@ -317,7 +346,8 @@ std::vector<torch::Tensor> SparseAccumulationOfProductsBackward::backward( | |
| details::torch_to_mops_1d<scalar_t>(C), | ||
| details::torch_to_mops_1d<int32_t>(indices_A), | ||
| details::torch_to_mops_1d<int32_t>(indices_B), | ||
| details::torch_to_mops_1d<int32_t>(indices_output) | ||
| details::torch_to_mops_1d<int32_t>(indices_output), | ||
| stream | ||
| ); | ||
| }); | ||
| #endif | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this
deviceGuarddo? I see that it's not being used explicitlyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it sets the current CUDA device to be the same one as A.device()
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no easy way that I can see for us to test whether a kernel has launched on a specific stream from PyTorch. We can probably do this with the CUDA API but that seems a bit overkill.