Skip to content

Commit

Permalink
[pre-commit.ci] auto code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed May 6, 2024
1 parent e4ef13e commit 3f5b541
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 77 deletions.
15 changes: 6 additions & 9 deletions libcudacxx/test/libcudacxx/heterogeneous/atomic.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,15 @@ using basic_testers =
exchange_tester<-12, 17>>;

using arithmetic_atomic_testers =
append<basic_testers,
fetch_add_tester<17, 13, 30>,
fetch_sub_tester<30, 21, 9>,
fetch_sub_tester<9, 17, -8>>;
append<basic_testers, fetch_add_tester<17, 13, 30>, fetch_sub_tester<30, 21, 9>, fetch_sub_tester<9, 17, -8>>;

using bitwise_atomic_testers =
append<arithmetic_atomic_testers,
fetch_add_tester<-8, 10, 2>,
fetch_or_tester<2, 13, 15>,
fetch_and_tester<15, 8, 8>,
fetch_and_tester<8, 13, 8>,
fetch_xor_tester<8, 12, 4>>;
fetch_add_tester<-8, 10, 2>,
fetch_or_tester<2, 13, 15>,
fetch_and_tester<15, 8, 8>,
fetch_and_tester<8, 13, 8>,
fetch_xor_tester<8, 12, 4>>;

class big_not_lockfree_type
{
Expand Down
5 changes: 1 addition & 4 deletions libcudacxx/test/libcudacxx/heterogeneous/atomic_ref.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,7 @@ using basic_testers =
exchange_tester<-12, 17>>;

using arithmetic_atomic_testers =
append<basic_testers,
fetch_add_tester<17, 13, 30>,
fetch_sub_tester<30, 21, 9>,
fetch_sub_tester<9, 17, -8>>;
append<basic_testers, fetch_add_tester<17, 13, 30>, fetch_sub_tester<30, 21, 9>, fetch_sub_tester<9, 17, -8>>;

using bitwise_atomic_testers =
append<arithmetic_atomic_testers,
Expand Down
2 changes: 1 addition & 1 deletion libcudacxx/test/libcudacxx/heterogeneous/barrier.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// uncomment for a really verbose output detailing what test steps are being launched
// #define DEBUG_TESTERS

#include <cuda/std/cassert>
#include <cuda/barrier>
#include <cuda/std/cassert>

#include "helpers.h"

Expand Down
84 changes: 54 additions & 30 deletions libcudacxx/test/libcudacxx/heterogeneous/helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ DEFINE_ASYNC_TRAIT(_validate)
#undef DEFINE_ASYNC_TRAIT

template <typename T, typename = int>
struct has_threadcount : std::false_type { };
struct has_threadcount : std::false_type
{};
template <typename T>
struct has_threadcount <T, decltype((void) T::threadcount, (int)0)> : std::true_type {};
struct has_threadcount<T, decltype((void) T::threadcount, (int) 0)> : std::true_type
{};

template <typename T, bool = has_threadcount<T>::value>
struct threadcount_trait_impl
Expand Down Expand Up @@ -196,7 +198,8 @@ void device_destroy(T* object)
HETEROGENEOUS_SAFE_CALL(cudaDeviceSynchronize());
}
template <typename Fn>
void device_launch_async(Fn& launcher) {
void device_launch_async(Fn& launcher)
{
auto streamManager = [launcher]() {
cudaStream_t stream;
HETEROGENEOUS_SAFE_CALL(cudaStreamCreate(&stream));
Expand All @@ -221,7 +224,7 @@ void device_initialize(T& object)
auto kernel_launcher = [&object](cudaStream_t stream) {
constexpr auto tc = threadcount_trait<Tester>::value;
#ifdef DEBUG_TESTERS
printf("%i device init threads launched\r\n", (int)tc);
printf("%i device init threads launched\r\n", (int) tc);
fflush(stdout);
#endif
initialization_kernel<Tester><<<1, tc, 0, stream>>>(object);
Expand Down Expand Up @@ -251,7 +254,7 @@ void device_validate(T& object)
auto kernel_launcher = [&object](cudaStream_t stream) {
constexpr auto tc = threadcount_trait<Tester>::value;
#ifdef DEBUG_TESTERS
printf("%i device validate threads launched\r\n", (int)tc);
printf("%i device validate threads launched\r\n", (int) tc);
fflush(stdout);
#endif
validation_kernel<Tester><<<1, tc, 0, stream>>>(object);
Expand Down Expand Up @@ -280,11 +283,12 @@ void host_initialize(T& object)

constexpr auto tc = threadcount_trait<Tester>::value;
#ifdef DEBUG_TESTERS
printf("%i host init threads launched\r\n", (int)tc);
printf("%i host init threads launched\r\n", (int) tc);
fflush(stdout);
#endif

for (size_t i = 0; i < tc; i++) {
for (size_t i = 0; i < tc; i++)
{
host_threads().emplace_back([&] {
initialize<Tester>(object);
});
Expand All @@ -311,11 +315,12 @@ void host_validate(T& object)

constexpr auto tc = threadcount_trait<Tester>::value;
#ifdef DEBUG_TESTERS
printf("%i host validate threads launched\r\n", (int)tc);
fflush(stdout);
printf("%i host validate threads launched\r\n", (int) tc);
fflush(stdout);
#endif

for (size_t i = 0; i < tc; i++) {
for (size_t i = 0; i < tc; i++)
{
host_threads().emplace_back([&] {
validate<Tester>(object);
});
Expand All @@ -339,28 +344,34 @@ template <typename T>
using performer = void (*)(T&);

template <typename T>
struct initializer_validator {
struct initializer_validator
{
performer<T> initializer;
performer<T> validator;
};

struct host_launcher {
struct host_launcher
{
template <typename T, typename Tester>
static initializer_validator<T> get_exec() {
static initializer_validator<T> get_exec()
{
return initializer_validator<T>{host_initialize<Tester>, host_validate<Tester>};
}
};

struct device_launcher {
struct device_launcher
{
template <typename T, typename Tester>
static initializer_validator<T> get_exec() {
static initializer_validator<T> get_exec()
{
return initializer_validator<T>{device_initialize<Tester>, device_validate<Tester>};
}
};

template <typename T, typename ... Testers, typename ... Launchers, typename... Args>
void do_heterogeneous_test(type_list<Testers...>, type_list<Launchers...>, Args... args) {
void *pointer = nullptr;
template <typename T, typename... Testers, typename... Launchers, typename... Args>
void do_heterogeneous_test(type_list<Testers...>, type_list<Launchers...>, Args... args)
{
void* pointer = nullptr;
HETEROGENEOUS_SAFE_CALL(cudaMallocHost(&pointer, sizeof(T)));
T& object = *device_construct<T>(pointer, args...);

Expand All @@ -382,33 +393,46 @@ void do_heterogeneous_test(type_list<Testers...>, type_list<Launchers...>, Args.
}

template <size_t Idx>
using enable_if_permutations_remain = typename std::enable_if<Idx!=0, int>::type;
using enable_if_permutations_remain = typename std::enable_if<Idx != 0, int>::type;
template <size_t Idx>
using enable_if_no_permutations_remain = typename std::enable_if<Idx==0, int>::type;
using enable_if_no_permutations_remain = typename std::enable_if<Idx == 0, int>::type;

template <size_t Idx, typename T, typename ... Testers, typename ... Launchers, typename... Args, enable_if_permutations_remain<Idx> = 0>
void permute_tests(type_list<Testers...>, type_list<Launchers...>, Args... args) {
template <size_t Idx,
typename T,
typename... Testers,
typename... Launchers,
typename... Args,
enable_if_permutations_remain<Idx> = 0>
void permute_tests(type_list<Testers...>, type_list<Launchers...>, Args... args)
{
#ifdef DEBUG_TESTERS
printf("Testing permutation %zu of %zu\r\n", Idx, sizeof...(Testers));
fflush(stdout);
#endif
do_heterogeneous_test<T>(type_list<Testers...>{}, type_list<Launchers...>{}, args...);
permute_tests<Idx-1, T>(type_list<Testers...>{}, rotl<Launchers...>{}, args...);
permute_tests<Idx - 1, T>(type_list<Testers...>{}, rotl<Launchers...>{}, args...);
}

template <size_t Idx, typename T, typename ... Testers, typename ... Launchers, typename... Args, enable_if_no_permutations_remain<Idx> = 0>
void permute_tests(type_list<Testers...>, type_list<Launchers...>, Args... args) {}
template <size_t Idx,
typename T,
typename... Testers,
typename... Launchers,
typename... Args,
enable_if_no_permutations_remain<Idx> = 0>
void permute_tests(type_list<Testers...>, type_list<Launchers...>, Args... args)
{}

template <typename T, typename ... Testers, typename ... Launchers, typename... Args>
void permute_tests(type_list<Testers...>, type_list<Launchers...>, Args... args) {
template <typename T, typename... Testers, typename... Launchers, typename... Args>
void permute_tests(type_list<Testers...>, type_list<Launchers...>, Args... args)
{
permute_tests<sizeof...(Testers), T>(type_list<Testers...>{}, type_list<Launchers...>{}, args...);
}

template <typename T, typename... Testers, typename... Args>
void validate_device_dynamic(tester_list<Testers...>, Args... args)
{
// ex: type_list<device_launcher, host_launcher, host_launcher>
using initial_launcher_list = append_n<sizeof...(Testers)-1, type_list<device_launcher>, host_launcher>;
using initial_launcher_list = append_n<sizeof...(Testers) - 1, type_list<device_launcher>, host_launcher>;
permute_tests<T>(type_list<Testers...>{}, initial_launcher_list{}, args...);
}

Expand Down Expand Up @@ -638,7 +662,7 @@ struct performer_adapter<Performer, performer_side::initialize>
using async_initialize = async_trait<Performer>;
using async_validate = async_trait<Performer>;

static constexpr auto threadcount = threadcount_trait<Performer>::value;
static constexpr auto threadcount = threadcount_trait<Performer>::value;

template <typename T>
__host__ __device__ static void initialize(T& t)
Expand All @@ -653,7 +677,7 @@ struct performer_adapter<Performer, performer_side::validate>
using async_initialize = async_trait<Performer>;
using async_validate = async_trait<Performer>;

static constexpr auto threadcount = threadcount_trait<Performer>::value;
static constexpr auto threadcount = threadcount_trait<Performer>::value;

template <typename T>
__host__ __device__ static void initialize(T&)
Expand Down
4 changes: 2 additions & 2 deletions libcudacxx/test/libcudacxx/heterogeneous/latch.pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// uncomment for a really verbose output detailing what test steps are being launched
// #define DEBUG_TESTERS

#include <cuda/std/latch>
#include <cuda/std/cassert>
#include <cuda/std/latch>

#include "helpers.h"

Expand All @@ -31,7 +31,7 @@ struct count_down
template <int N>
struct arrive_and_wait
{
using async = cuda::std::true_type;
using async = cuda::std::true_type;
static constexpr size_t threadcount = N;

template <typename Latch>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#define _LIBCUDACXX_CUDA_ABI_VERSION 2

#include <cuda/std/latch>
#include <cuda/std/cassert>
#include <cuda/std/latch>

#include "helpers.h"

Expand Down
71 changes: 41 additions & 30 deletions libcudacxx/test/libcudacxx/heterogeneous/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,41 +17,48 @@
#ifndef HETEROGENEOUS_META_H
#define HETEROGENEOUS_META_H

template <typename ...Tx>
struct type_list{};
template <typename... Tx>
struct type_list
{};

// Rotates the typelist by removing the head and moving it to the tail
template <typename ...Tx>
struct rotl_impl {
// Empty or 1 element case
using type = type_list<Tx...>;
template <typename... Tx>
struct rotl_impl
{
// Empty or 1 element case
using type = type_list<Tx...>;
};
template <typename T, typename ...Tx>
struct rotl_impl<T, Tx...> {
using type = type_list<Tx..., T>;
template <typename T, typename... Tx>
struct rotl_impl<T, Tx...>
{
using type = type_list<Tx..., T>;
};
template <typename ...Tx>
struct rotl_impl<type_list<Tx...>> {
using type = typename rotl_impl<Tx...>::type;
template <typename... Tx>
struct rotl_impl<type_list<Tx...>>
{
using type = typename rotl_impl<Tx...>::type;
};

template <typename ...Tx>
template <typename... Tx>
using rotl = typename rotl_impl<Tx...>::type;

// static_assert(std::is_same<rotl<int, char>, type_list<char,int>>(), "");
// static_assert(std::is_same<rotl<int, char, short>, type_list<char,short,int>>(), "");

template <size_t Idx, typename T, template <typename> typename Fn>
struct for_n_impl {
using type = typename for_n_impl<Idx-1, Fn<T>, Fn>::type;
struct for_n_impl
{
using type = typename for_n_impl<Idx - 1, Fn<T>, Fn>::type;
};
template <typename T, template <typename> typename Fn>
struct for_n_impl<1, T, Fn> {
using type = Fn<T>;
struct for_n_impl<1, T, Fn>
{
using type = Fn<T>;
};
template <typename T, template <typename> typename Fn>
struct for_n_impl<0, T, Fn> {
using type = T;
struct for_n_impl<0, T, Fn>
{
using type = T;
};

template <size_t Idx, typename T, template <typename> typename Fn>
Expand All @@ -61,14 +68,16 @@ using for_n = typename for_n_impl<Idx, T, Fn>::type;
// static_assert(std::is_same<for_n<3, type_list<int, char, short>, rotl>, type_list<int, char, short>>(), "");

template <template <typename...> typename Fn, typename B>
struct bind_last_impl {
template <typename T>
struct bound {
using type = Fn<T, B>;
};

template <typename T>
using type = typename bound<T>::type;
struct bind_last_impl
{
template <typename T>
struct bound
{
using type = Fn<T, B>;
};

template <typename T>
using type = typename bound<T>::type;
};

template <template <typename> typename Fn, typename B>
Expand All @@ -77,11 +86,13 @@ using bind_last = bind_last_impl<Fn, B>;
template <typename TypeList, typename... Tx>
struct append_impl;
template <typename... Old, typename... New>
struct append_impl<type_list<Old...>, New...> {
struct append_impl<type_list<Old...>, New...>
{
using type = type_list<Old..., New...>;
};
template <typename... Old, typename... New>
struct append_impl<type_list<Old...>, type_list<New...>> {
struct append_impl<type_list<Old...>, type_list<New...>>
{
using type = type_list<Old..., New...>;
};

Expand All @@ -92,7 +103,7 @@ using append = typename append_impl<TypeList, Tx...>::type;
// static_assert(std::is_same<append<type_list<int>, int>, type_list<int,int>>(), "");

template <size_t Idx, typename TypeList, typename T>
using append_n = for_n<Idx, TypeList, bind_last<append,T>::template type>;
using append_n = for_n<Idx, TypeList, bind_last<append, T>::template type>;

// static_assert(std::is_same<append_n<3, type_list<char>, int>, type_list<char, int, int, int>>(), "");
// static_assert(std::is_same<append_n<5, type_list<char>, int>, type_list<char, int, int, int, int, int>>(), "");
Expand Down

0 comments on commit 3f5b541

Please sign in to comment.