Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions c2h/include/c2h/operator.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <cuda/functional>
#include <cuda/std/functional>
#include <cuda/std/limits>
#include <cuda/std/type_traits>
#include <cuda/type_traits>

#include <c2h/custom_type.h>
Expand Down Expand Up @@ -100,5 +101,25 @@ template <template <typename> class... Policies>
inline const c2h::custom_type_t<Policies...> identity_v<cuda::minimum<>, c2h::custom_type_t<Policies...>> =
cuda::std::numeric_limits<c2h::custom_type_t<Policies...>>::max();

/***********************************************************************************************************************
* Test operators
**********************************************************************************************************************/

template <class ExpectedOffsetT = void>
struct incrementer_t
{
int* d_counts;

template <class OffsetT, class... Args>
__device__ void operator()(OffsetT i, Args...)
{
static_assert(cuda::std::is_void_v<ExpectedOffsetT> || cuda::std::is_same_v<ExpectedOffsetT, OffsetT>,
"ExpectedOffsetT and OffsetT must be the same type");
atomicAdd(d_counts + i, 1); // Check if `i` was served more than once
}
Comment on lines +111 to +119

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

important: Declare the immutable member const, and use the required device API annotation and noexcept on this non-throwing callable.

-  int* d_counts;
+  int* const d_counts;

-  __device__ void operator()(OffsetT i, Args...)
+  _CCCL_DEVICE_API void operator()(OffsetT i, Args...) const noexcept

As per coding guidelines, “All variables that are not modified must be declared const,” “Functions must be marked with _CCCL_*_API,” and non-throwing functions must be marked noexcept.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
int* d_counts;
template <class OffsetT, class... Args>
__device__ void operator()(OffsetT i, Args...)
{
static_assert(cuda::std::is_void_v<ExpectedOffsetT> || cuda::std::is_same_v<ExpectedOffsetT, OffsetT>,
"ExpectedOffsetT and OffsetT must be the same type");
atomicAdd(d_counts + i, 1); // Check if `i` was served more than once
}
int* const d_counts;
template <class OffsetT, class... Args>
_CCCL_DEVICE_API void operator()(OffsetT i, Args...) const noexcept
{
static_assert(cuda::std::is_void_v<ExpectedOffsetT> || cuda::std::is_same_v<ExpectedOffsetT, OffsetT>,
"ExpectedOffsetT and OffsetT must be the same type");
atomicAdd(d_counts + i, 1); // Check if `i` was served more than once
}

Source: Coding guidelines

};

incrementer_t(int*) -> incrementer_t<>;

struct custom_plus : cuda::std::plus<>
{};
16 changes: 1 addition & 15 deletions cub/test/catch2_test_device_bulk.cu
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,16 @@
#include <thrust/count.h>
#include <thrust/detail/raw_pointer_cast.h>

#include <cuda/std/type_traits>

#include "catch2_test_launch_helper.h"
#include <c2h/catch2_test_helper.h>
#include <c2h/operator.cuh>

// %PARAM% TEST_LAUNCH lid 0:1:2

DECLARE_LAUNCH_WRAPPER(cub::DeviceFor::Bulk, device_bulk);

using offset_type = c2h::type_list<std::int32_t, std::uint32_t, std::uint64_t, std::int64_t>;

template <class T>
struct incrementer_t
{
int* d_counts;

template <class OffsetT>
__device__ void operator()(OffsetT i)
{
static_assert(cuda::std::is_same_v<T, OffsetT>, "T and OffsetT must be the same type");
atomicAdd(d_counts + i, 1); // Check if `i` was served more than once
}
};

C2H_TEST("Device bulk works", "[bulk][device]", offset_type)
{
using offset_t = c2h::get<0, TestType>;
Expand Down
12 changes: 1 addition & 11 deletions cub/test/catch2_test_device_for.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,13 @@

#include "catch2_test_launch_helper.h"
#include <c2h/catch2_test_helper.h>
#include <c2h/operator.cuh>

// %PARAM% TEST_LAUNCH lid 0:1:2

DECLARE_LAUNCH_WRAPPER(cub::DeviceFor::ForEach, device_for_each);
DECLARE_LAUNCH_WRAPPER(cub::DeviceFor::ForEachN, device_for_each_n);

struct incrementer_t
{
int* d_counts;

template <class OffsetT>
__device__ void operator()(OffsetT i)
{
atomicAdd(d_counts + i, 1); // Check if `i` was served more than once
}
};

template <class OffsetT>
class offset_proxy_t
{
Expand Down
12 changes: 1 addition & 11 deletions cub/test/catch2_test_device_for_copy.cu
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "catch2_test_launch_helper.h"
#include <c2h/catch2_test_helper.h>
#include <c2h/operator.cuh>

// %PARAM% TEST_LAUNCH lid 0:1:2

Expand All @@ -21,17 +22,6 @@ DECLARE_LAUNCH_WRAPPER(cub::DeviceFor::ForEachCopyN, device_for_each_copy_n);

using offset_type = c2h::type_list<std::int32_t, std::uint32_t, std::uint64_t, std::int64_t>;

struct incrementer_t
{
int* d_counts;

template <class OffsetT>
__device__ void operator()(OffsetT i)
{
atomicAdd(d_counts + i, 1); // Check if `i` was served more than once
}
};

template <class OffsetT>
class offset_proxy_t
{
Expand Down
12 changes: 1 addition & 11 deletions cub/test/catch2_test_device_for_each_in_extents.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <cuda/std/span>

#include <c2h/catch2_test_helper.h>
#include <c2h/operator.cuh>
#include <c2h/utility.h>
#include <catch2_test_launch_helper.h>

Expand Down Expand Up @@ -170,17 +171,6 @@ C2H_TEST("DeviceFor::ForEachInExtents 3D dynamic", "[ForEachInExtents][dynamic][
//----------------------------------------------------------------------------------------------------------------------
//

struct incrementer_t
{
int* d_counts;

template <class OffsetT>
__device__ void operator()(OffsetT i, OffsetT)
{
atomicAdd(d_counts + i, 1); // Check if `i` was served more than once
}
};

C2H_TEST("DeviceFor::ForEachInExtents works", "[ForEachInExtents]")
{
constexpr int max_items = 5000000;
Expand Down
12 changes: 1 addition & 11 deletions cub/test/catch2_test_device_for_each_in_layout.cu
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <cuda/std/span>

#include <c2h/catch2_test_helper.h>
#include <c2h/operator.cuh>
#include <c2h/utility.h>
#include <catch2_test_launch_helper.h>

Expand Down Expand Up @@ -194,17 +195,6 @@ C2H_TEST("DeviceFor::ForEachInLayout 3D dynamic", "[ForEachInLayout][dynamic][de
//----------------------------------------------------------------------------------------------------------------------
// No duplicates

struct incrementer_t
{
int* d_counts;

template <typename IndexType, class OffsetT>
__device__ void operator()(IndexType i, OffsetT)
{
atomicAdd(d_counts + i, 1); // Check if `i` was served more than once
}
};

C2H_TEST("DeviceFor::ForEachInLayout no duplicates", "[ForEachInLayout][no_duplicates][device]", layouts)
{
constexpr int min_items = 1;
Expand Down
Loading