Skip to content

Commit b1a8a11

Browse files
author
Alexander Batashev
committed
Address some feedback, implement barrier
1 parent 85c3c55 commit b1a8a11

File tree

6 files changed

+71
-9
lines changed

6 files changed

+71
-9
lines changed

sycl/include/CL/__spirv/spirv_ops.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,9 +567,6 @@ extern SYCL_EXTERNAL void
567567
__spirv_ocl_prefetch(const __attribute__((opencl_global)) char *Ptr,
568568
size_t NumBytes) noexcept;
569569

570-
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL __SYCL_EXPORT bool
571-
__spirv_GroupNonUniformElect(__spv::Scope::Flag) noexcept;
572-
573570
#else // if !__SYCL_DEVICE_ONLY__
574571

575572
template <typename dataT>

sycl/include/CL/sycl/ONEAPI/sub_group.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <CL/sycl/id.hpp>
2121
#include <CL/sycl/range.hpp>
2222
#include <CL/sycl/types.hpp>
23+
#include <CL/sycl/enums.hpp>
2324

2425
#include <type_traits>
2526

@@ -104,7 +105,7 @@ struct sub_group {
104105
using range_type = range<1>;
105106
using linear_id_type = uint32_t;
106107
static constexpr int dimensions = 1;
107-
static constexpr memory_scope fence_scope = memory_scope::sub_group;
108+
static constexpr sycl::memory_scope fence_scope = sycl::memory_scope::sub_group;
108109

109110
/* --- common interface members --- */
110111

@@ -720,7 +721,7 @@ struct sub_group {
720721

721722
bool leader() const {
722723
#ifdef __SYCL_DEVICE_ONLY__
723-
return detail::spirv::GroupNonUniformElect<sub_group>();
724+
return get_local_linear_id() == 0;
724725
#else
725726
throw runtime_error("Sub-groups are not supported on host device.",
726727
PI_INVALID_DEVICE);

sycl/include/CL/sycl/detail/spirv.hpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <CL/sycl/detail/helpers.hpp>
1616
#include <CL/sycl/detail/type_traits.hpp>
1717
#include <CL/sycl/id.hpp>
18+
#include <CL/sycl/enums.hpp>
1819

1920
#ifdef __SYCL_DEVICE_ONLY__
2021
__SYCL_INLINE_NAMESPACE(cl) {
@@ -259,6 +260,22 @@ getScope(ONEAPI::memory_scope Scope) {
259260
}
260261
}
261262

263+
constexpr __spv::Scope::Flag
264+
getScope(memory_scope Scope) {
265+
switch (Scope) {
266+
case memory_scope::work_item:
267+
return __spv::Scope::Invocation;
268+
case memory_scope::sub_group:
269+
return __spv::Scope::Subgroup;
270+
case memory_scope::work_group:
271+
return __spv::Scope::Workgroup;
272+
case memory_scope::device:
273+
return __spv::Scope::Device;
274+
case memory_scope::system:
275+
return __spv::Scope::CrossDevice;
276+
}
277+
}
278+
262279
template <typename T, access::address_space AddressSpace>
263280
inline typename detail::enable_if_t<std::is_integral<T>::value, T>
264281
AtomicCompareExchange(multi_ptr<T, AddressSpace> MPtr,
@@ -735,10 +752,6 @@ EnableIfGenericShuffle<T> SubgroupShuffleUp(T x, id<1> local_id) {
735752
return Result;
736753
}
737754

738-
template <typename Group> bool GroupNonUniformElect() {
739-
return __spirv_GroupNonUniformElect(group_scope<Group>::value);
740-
}
741-
742755
} // namespace spirv
743756
} // namespace detail
744757
} // namespace sycl

sycl/include/CL/sycl/enums.hpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//==-------------- enums.hpp --- SYCL enums --------------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#pragma once
10+
11+
__SYCL_INLINE_NAMESPACE(cl) {
12+
namespace sycl {
13+
enum class memory_scope : unsigned char {
14+
work_item = 0,
15+
sub_group = 1,
16+
work_group = 2,
17+
device = 3,
18+
system = 4
19+
};
20+
21+
#if __cplusplus >= 201703L
22+
inline constexpr auto memory_scope_work_item = memory_scope::work_item;
23+
inline constexpr auto memory_scope_sub_group = memory_scope::sub_group;
24+
inline constexpr auto memory_scope_work_group = memory_scope::work_group;
25+
inline constexpr auto memory_scope_device = memory_scope::device;
26+
inline constexpr auto memory_scope_system = memory_scope::system;
27+
#endif
28+
}
29+
}
30+

sycl/include/CL/sycl/group.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <CL/sycl/id.hpp>
2020
#include <CL/sycl/pointers.hpp>
2121
#include <CL/sycl/range.hpp>
22+
#include <CL/sycl/enums.hpp>
2223
#include <stdexcept>
2324
#include <type_traits>
2425

@@ -431,5 +432,8 @@ template <int Dims> group<Dims> this_group() {
431432
#endif
432433
}
433434

435+
template <typename Group>
436+
void group_barrier(Group G, memory_scope FenceScope = Group::fence_scope);
437+
434438
} // namespace sycl
435439
} // __SYCL_INLINE_NAMESPACE(cl)

sycl/include/CL/sycl/sub_group.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,29 @@
88

99
#pragma once
1010

11+
#include <CL/sycl/group.hpp>
1112
#include <CL/sycl/ONEAPI/sub_group.hpp>
1213

1314
__SYCL_INLINE_NAMESPACE(cl) {
1415
namespace sycl {
1516
using ONEAPI::sub_group;
1617
// TODO move the entire sub_group class implementation to this file once
1718
// breaking changes are allowed.
19+
20+
template <> inline void group_barrier<sub_group>(sub_group Group, memory_scope FenceScope) {
21+
(void)Group;
22+
(void)FenceScope;
23+
#ifdef __SYCL_DEVICE_ONLY__
24+
__spirv_ControlBarrier(
25+
__spv::Scope::Subgroup, detail::spirv::getScope(FenceScope),
26+
__spv::MemorySemanticsMask::AcquireRelease |
27+
__spv::MemorySemanticsMask::SubgroupMemory |
28+
__spv::MemorySemanticsMask::WorkgroupMemory |
29+
__spv::MemorySemanticsMask::CrossWorkgroupMemory);
30+
#else
31+
throw runtime_error("Sub-groups are not supported on host device.",
32+
PI_INVALID_DEVICE);
33+
#endif
34+
}
1835
} // namespace sycl
1936
} // __SYCL_INLINE_NAMESPACE(cl)

0 commit comments

Comments
 (0)