Skip to content
Draft
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
42 changes: 42 additions & 0 deletions src/shambackends/include/shambackends/kernel_call.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,50 @@ namespace sham {
in_out.complete_event_state(e);
}

template<typename Signature>
struct expected_kernel_signature;

template<typename Ret, typename... Ts>
struct expected_kernel_signature<Ret(Ts...)> {};

template<typename Tuple>
struct tuple_to_signature;

template<typename... Ts>
struct tuple_to_signature<std::tuple<Ts...>> {
using type = void(Ts...);
};

template<class index_t, class RefIn, class RefOut>
struct kernel_gen_args {

using args_types = decltype(std::tuple_cat(
std::tuple<index_t>{},

std::declval<decltype(std::declval<RefIn>().get_read_access(
std::declval<sham::EventList &>()))>(),

std::declval<decltype(std::declval<RefOut>().get_write_access(
std::declval<sham::EventList &>()))>()));
};

template<class index_t, class RefIn, class RefOut>
using kernel_expected_signature = expected_kernel_signature<typename tuple_to_signature<
typename kernel_gen_args<index_t, RefIn, RefOut>::args_types>::type>;

template<typename F, typename Signature>
struct is_kernel_invocable;

template<typename F, typename Ret, typename... Ts>
struct is_kernel_invocable<F, expected_kernel_signature<Ret(Ts...)>>
: std::bool_constant<std::invocable<F, Ts...>> {};

template<typename F, typename Signature>
concept kernel_invocable = is_kernel_invocable<F, Signature>::value;

/// internal implementation of typed_index_kernel_call
template<class index_t, class RefIn, class RefOut, class Functor>
requires kernel_invocable<Functor, kernel_expected_signature<index_t, RefIn, RefOut>>
void typed_index_kernel_call(
sham::DeviceQueue &q,
RefIn in,
Expand Down
11 changes: 11 additions & 0 deletions src/tests/shambackends/kernel_call_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ TestStart(Unittest, "shambackends/kernel_call", testing_func_kernel_call_base, 1
P[i] = r;
cs[i] = u;
});
sham::kernel_call(
dev_sched->get_queue(),
sham::MultiRef{rho_field_const, uint_field_const},
sham::MultiRef{P_field, cs_field},
size,
[](u32 i, const T *__restrict rho, T *__restrict U, T *__restrict P, T *__restrict cs) {
T r = rho[i];
T u = U[i];

P[i] = r;
cs[i] = u;
});
Comment on lines +68 to +79

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.

high

This sham::kernel_call block is redundant as it performs the same operation as the previous call (lines 52-67). Please refactor this duplicated logic into a helper function or lambda to improve readability and maintainability. Additionally, it contains a type mismatch: uint_field_const is a const buffer providing a const T*, but the lambda signature expects a non-const T*. This mismatch will cause a compilation error with the kernel_invocable concept, preventing the test suite from compiling.

References
  1. Refactor duplicated logic into a helper function or lambda to improve readability and maintainability.

REQUIRE_EQUAL(P_field.copy_to_stdvec(), P_ref);
REQUIRE_EQUAL(cs_field.copy_to_stdvec(), cs_ref);
}
Expand Down
Loading