Skip to content

[SYCL] Enable algorithm support for sub_group #1392

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

Merged
merged 17 commits into from
Mar 27, 2020
Merged
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
8 changes: 3 additions & 5 deletions sycl/include/CL/sycl/detail/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
#endif

#if __cplusplus >= 201402
#define __SYCL_DEPRECATED__ \
[[deprecated("Replaced by in_order queue property")]]
#define __SYCL_DEPRECATED__(message) [[deprecated(message)]]
#elif !defined _MSC_VER
#define __SYCL_DEPRECATED__ \
__attribute__((deprecated("Replaced by in_order queue property")))
#define __SYCL_DEPRECATED__(message) __attribute__((deprecated(message)))
#else
#define __SYCL_DEPRECATED__
#define __SYCL_DEPRECATED__(message)
#endif
31 changes: 26 additions & 5 deletions sycl/include/CL/sycl/detail/spirv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,46 @@
#ifdef __SYCL_DEVICE_ONLY__
__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace intel {
struct sub_group;
} // namespace intel
namespace detail {
namespace spirv {

template <typename Group> struct group_scope {};

template <int Dimensions> struct group_scope<group<Dimensions>> {
static constexpr __spv::Scope::Flag value = __spv::Scope::Flag::Workgroup;
};

template <> struct group_scope<intel::sub_group> {
static constexpr __spv::Scope::Flag value = __spv::Scope::Flag::Subgroup;
};

template <typename Group> bool GroupAll(bool pred) {
return __spirv_GroupAll(group_scope<Group>::value, pred);
}

template <typename Group> bool GroupAny(bool pred) {
return __spirv_GroupAny(group_scope<Group>::value, pred);
}

// Broadcast with scalar local index
template <__spv::Scope::Flag S, typename T, typename IdT>
template <typename Group, typename T, typename IdT>
detail::enable_if_t<std::is_integral<IdT>::value, T>
GroupBroadcast(T x, IdT local_id) {
using OCLT = detail::ConvertToOpenCLType_t<T>;
using OCLIdT = detail::ConvertToOpenCLType_t<IdT>;
OCLT ocl_x = detail::convertDataToType<T, OCLT>(x);
OCLIdT ocl_id = detail::convertDataToType<IdT, OCLIdT>(local_id);
return __spirv_GroupBroadcast(S, ocl_x, ocl_id);
return __spirv_GroupBroadcast(group_scope<Group>::value, ocl_x, ocl_id);
}

// Broadcast with vector local index
template <__spv::Scope::Flag S, typename T, int Dimensions>
template <typename Group, typename T, int Dimensions>
T GroupBroadcast(T x, id<Dimensions> local_id) {
if (Dimensions == 1) {
return GroupBroadcast<S>(x, local_id[0]);
return GroupBroadcast<Group>(x, local_id[0]);
}
using IdT = vec<size_t, Dimensions>;
using OCLT = detail::ConvertToOpenCLType_t<T>;
Expand All @@ -45,7 +66,7 @@ T GroupBroadcast(T x, id<Dimensions> local_id) {
}
OCLT ocl_x = detail::convertDataToType<T, OCLT>(x);
OCLIdT ocl_id = detail::convertDataToType<IdT, OCLIdT>(vec_id);
return __spirv_GroupBroadcast(S, ocl_x, ocl_id);
return __spirv_GroupBroadcast(group_scope<Group>::value, ocl_x, ocl_id);
}

} // namespace spirv
Expand Down
Loading