Skip to content

Commit e94cfda

Browse files
[NFCI][SYCL] Remove boost::mp11 dependency from invoke_simd.hpp (#15713)
C++17 implementation is about as readable as boost-based one, and we want to drop the external boost dependency for upstreaming purposes.
1 parent dcb975d commit e94cfda

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

sycl/include/sycl/detail/helpers.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,11 @@ getSPIRVMemorySemanticsMask(const access::fence_space AccessSpace,
240240

241241
// To ensure loop unrolling is done when processing dimensions.
242242
template <size_t... Inds, class F>
243-
void loop_impl(std::integer_sequence<size_t, Inds...>, F &&f) {
243+
constexpr void loop_impl(std::integer_sequence<size_t, Inds...>, F &&f) {
244244
(f(std::integral_constant<size_t, Inds>{}), ...);
245245
}
246246

247-
template <size_t count, class F> void loop(F &&f) {
247+
template <size_t count, class F> constexpr void loop(F &&f) {
248248
loop_impl(std::make_index_sequence<count>{}, std::forward<F>(f));
249249
}
250250
inline constexpr bool is_power_of_two(int x) { return (x & (x - 1)) == 0; }

sycl/include/sycl/ext/oneapi/experimental/invoke_simd.hpp

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <sycl/ext/oneapi/experimental/detail/invoke_simd_types.hpp>
1515
#include <sycl/ext/oneapi/experimental/uniform.hpp>
1616

17-
#include <sycl/detail/boost/mp11.hpp>
1817
#include <sycl/sub_group.hpp>
1918

2019
#include <functional>
@@ -71,8 +70,6 @@ namespace ext::oneapi::experimental {
7170
// --- Helpers
7271
namespace detail {
7372

74-
namespace __MP11_NS = sycl::detail::boost::mp11;
75-
7673
// This structure performs the SPMD-to-SIMD parameter type conversion as defined
7774
// by the spec.
7875
template <class T, int N, class = void> struct spmd2simd;
@@ -154,8 +151,7 @@ struct is_simd_or_mask_type<simd_mask<T, N>> : std::true_type {};
154151
// Checks if all the types in the parameter pack are uniform<T>.
155152
template <class... SpmdArgs> struct all_uniform_types {
156153
constexpr operator bool() {
157-
using TypeList = __MP11_NS::mp_list<SpmdArgs...>;
158-
return __MP11_NS::mp_all_of<TypeList, is_uniform_type>::value;
154+
return ((is_uniform_type<SpmdArgs>::value && ...));
159155
}
160156
};
161157

@@ -193,26 +189,32 @@ constexpr void verify_return_type_matches_sg_size() {
193189
// as prescribed by the spec assuming this subgroup size. One and only one
194190
// subgroup size should conform.
195191
template <class SimdCallable, class... SpmdArgs> struct sg_size {
196-
template <class N>
197-
using IsInvocableSgSize = __MP11_NS::mp_bool<std::is_invocable_v<
198-
SimdCallable, typename spmd2simd<SpmdArgs, N::value>::type...>>;
199-
200192
__DPCPP_SYCL_EXTERNAL constexpr operator int() {
201-
using SupportedSgSizes = __MP11_NS::mp_list_c<int, 1, 2, 4, 8, 16, 32>;
202-
using InvocableSgSizes =
203-
__MP11_NS::mp_copy_if<SupportedSgSizes, IsInvocableSgSize>;
204-
constexpr auto found_invoke_simd_target =
205-
__MP11_NS::mp_empty<InvocableSgSizes>::value != 1;
206-
if constexpr (found_invoke_simd_target) {
207-
static_assert((__MP11_NS::mp_size<InvocableSgSizes>::value == 1) &&
208-
"multiple invoke_simd targets found");
209-
return __MP11_NS::mp_front<InvocableSgSizes>::value;
210-
}
211-
static_assert(
212-
found_invoke_simd_target,
213-
"No callable invoke_simd target found. Confirm the "
214-
"invoke_simd invocation argument types are convertible to the "
215-
"invoke_simd target argument types");
193+
constexpr auto x = []() constexpr {
194+
constexpr int supported_sg_sizes[] = {1, 2, 4, 8, 16, 32};
195+
int num_found = 0;
196+
int found_sg_size = 0;
197+
sycl::detail::loop<std::size(supported_sg_sizes)>([&](auto idx) {
198+
constexpr auto sg_size = supported_sg_sizes[idx];
199+
if (std::is_invocable_v<
200+
SimdCallable, typename spmd2simd<SpmdArgs, sg_size>::type...>) {
201+
++num_found;
202+
found_sg_size = sg_size;
203+
}
204+
});
205+
return std::pair{num_found, found_sg_size};
206+
}();
207+
208+
constexpr auto num_found = x.first;
209+
constexpr auto found_sg_size = x.second;
210+
211+
static_assert(num_found != 0,
212+
"No callable invoke_simd target found. Confirm the "
213+
"invoke_simd invocation argument types are convertible to "
214+
"the invoke_simd target argument types");
215+
static_assert(num_found == 1, "Multiple invoke_simd targets found!");
216+
217+
return found_sg_size;
216218
}
217219
};
218220

sycl/test/invoke_simd/no_callee_found.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ void foo() {
2626

2727
int main() {
2828
foo();
29-
// CHECK: {{.*}}error:{{.*}}static assertion failed due to requirement 'found_invoke_simd_target': No callable invoke_simd target found. Confirm the invoke_simd invocation argument types are convertible to the invoke_simd target argument types{{.*}}
29+
// CHECK: {{.*}}error:{{.*}}static assertion failed due to requirement 'num_found != 0': No callable invoke_simd target found. Confirm the invoke_simd invocation argument types are convertible to the invoke_simd target argument types{{.*}}
3030
}

0 commit comments

Comments
 (0)