-
Notifications
You must be signed in to change notification settings - Fork 80
Remove extra copy by assuming reduce tensor is symmetric #6040
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
Open
nsarka
wants to merge
2
commits into
NVIDIA:main
Choose a base branch
from
nsarka:nsarka/nvls-buffer
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.
+23
−23
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -857,7 +857,6 @@ void waitAllreduceWithCudaBackend( | |
|
|
||
| void postReduceWithCudaBackend( | ||
| Communication* communication, | ||
| at::Tensor input, | ||
| at::Tensor output, | ||
| SymmetricMemoryForReduce* reduce_handle, | ||
| CUstream stream, | ||
|
|
@@ -875,7 +874,7 @@ void postReduceWithCudaBackend( | |
| "Only SUM reduction is supported for multimem reduce; got ", | ||
| communication->reduceOp()); | ||
| NVF_CHECK( | ||
| input.scalar_type() == at::kFloat && | ||
| reduce_handle->inputBuffer().scalar_type() == at::kFloat && | ||
| (!output.defined() || output.scalar_type() == at::kFloat), | ||
|
Comment on lines
876
to
878
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. For better error reporting, can you split this into two NVF_CHECKs? The first one may use NVF_CHECK_EQ. |
||
| "Only float32 is supported for multimem reduce."); | ||
|
|
||
|
|
@@ -886,14 +885,6 @@ void postReduceWithCudaBackend( | |
| "size=", | ||
| size); | ||
|
|
||
| // Copy input to symmetric buffer | ||
| NVFUSER_CUDA_RT_SAFE_CALL(cudaMemcpyAsync( | ||
| reduce_handle->inputBuffer().data_ptr(), | ||
| input.data_ptr(), | ||
| size, | ||
| cudaMemcpyDeviceToDevice, | ||
| stream)); | ||
|
|
||
| const int64_t world_size = communicator.size(); | ||
| // All ranks signal ready by writing kInProgress to their own semaphore | ||
| NVFUSER_CUDA_SAFE_CALL(cuStreamWriteValue32( | ||
|
|
@@ -923,10 +914,10 @@ void postReduceWithCudaBackend( | |
| cuStreamBatchMemOp(stream, world_size - 1, ops.data(), 0)); | ||
|
|
||
| // Root launches the ld_reduce kernel | ||
| void* dst = output.defined() ? output.data_ptr() | ||
| : reduce_handle->inputBuffer().data_ptr(); | ||
| NVF_ERROR( | ||
| output.defined(), "Output must be defined for reduce on the root"); | ||
| launchMulticastReduceKernel( | ||
| reduce_handle->multicastPtr(), dst, size, stream); | ||
| reduce_handle->multicastPtr(), output.data_ptr(), size, stream); | ||
|
|
||
| // Root signals completion by writing kIdle to all non-root semaphores | ||
| std::vector<CUstreamBatchMemOpParams> write_complete_ops(world_size - 1); | ||
|
|
@@ -1267,7 +1258,7 @@ void postWithCudaBackend( | |
| dynamic_cast<SymmetricMemoryForReduce*>(symmetric_memory_handle); | ||
| NVF_ERROR(reduce_handle != nullptr, "Invalid reduce handle"); | ||
| postReduceWithCudaBackend( | ||
| communication, input, output, reduce_handle, stream, root); | ||
| communication, output, reduce_handle, stream, root); | ||
| break; | ||
| } | ||
| default: | ||
|
|
||
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.
I'm trying to figure out the contract here since the code is getting a bit too if-elsy.
(I'm trying to confirm my understanding I before proposing any cleanups -- thanks!)