-
Notifications
You must be signed in to change notification settings - Fork 197
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
Add warp-aggregated atomic increment #735
Merged
rapids-bot
merged 1 commit into
rapidsai:branch-22.08
from
ahendriksen:fea-add-warp-aggregated-atomic-increment
Jul 14, 2022
Merged
Changes from all commits
Commits
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
atomics: Add warp-aggregated atomic increment
Faster atomic counter increment using warp-aggregated atomics. Useful for filtering. Adapted from: https://developer.nvidia.com/blog/cuda-pro-tip-optimized-filtering-warp-aggregated-atomics/
- Loading branch information
commit 04ea9a72f8406245d5b6ed0b8a1934edc6a87865
There are no files selected for viewing
This file contains 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 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 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,70 @@ | ||
/* | ||
* Copyright (c) 2022, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <algorithm> | ||
#include <array> | ||
#include <cstddef> | ||
#include <gtest/gtest.h> | ||
#include <iostream> | ||
#include <memory> | ||
#include <numeric> | ||
#include <raft/cudart_utils.h> | ||
#include <raft/device_atomics.cuh> | ||
#include <rmm/cuda_stream_pool.hpp> | ||
#include <rmm/device_scalar.hpp> | ||
#include <rmm/device_uvector.hpp> | ||
|
||
namespace raft { | ||
|
||
__global__ void test_atomic_inc_warp_kernel(int* counter, int* out_array) | ||
{ | ||
int global_tid = blockDim.x * blockIdx.x + threadIdx.x; | ||
out_array[atomicIncWarp(counter)] = global_tid; | ||
} | ||
|
||
TEST(Raft, AtomicIncWarp) | ||
{ | ||
const int num_blocks = 1024; | ||
const int threads_per_block = 1024; | ||
const int num_elts = num_blocks * threads_per_block; | ||
|
||
rmm::cuda_stream_pool pool{1}; | ||
auto s = pool.get_stream(); | ||
|
||
rmm::device_scalar<int> counter{0, s}; | ||
rmm::device_uvector<int> out_device{num_elts, s}; | ||
std::array<int, num_elts> out_host{0}; | ||
|
||
// Write all 1M thread indices to a unique location in `out_device` | ||
test_atomic_inc_warp_kernel<<<num_blocks, threads_per_block, 0, s>>>(counter.data(), | ||
out_device.data()); | ||
|
||
// Copy data to host | ||
RAFT_CUDA_TRY(cudaMemcpy(out_host.data(), | ||
(const void*)out_device.data(), | ||
num_elts * sizeof(int), | ||
cudaMemcpyDeviceToHost)); | ||
|
||
// Check that count is correct and that each thread index is contained in the | ||
// array exactly once. | ||
ASSERT_EQ(num_elts, counter.value(s)); | ||
std::sort(out_host.begin(), out_host.end()); | ||
for (int i = 0; i < num_elts; ++i) { | ||
ASSERT_EQ(i, out_host[i]); | ||
} | ||
} | ||
|
||
} // namespace raft |
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.
Can we use
raft::copy
here?