[llvm] [libsycl] add group_barrier function (PR #218971)
Kseniya Tikhomirova via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 9 07:51:56 PDT 2026
================
@@ -0,0 +1,85 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the SYCL 2020 group_barrier function (4.17.2.3.).
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef _LIBSYCL___IMPL_GROUP_BARRIER_HPP
+#define _LIBSYCL___IMPL_GROUP_BARRIER_HPP
+
+#include <sycl/__impl/detail/config.hpp>
+#include <sycl/__impl/group.hpp>
+#include <sycl/__impl/memory_enums.hpp>
+#include <sycl/__impl/sub_group.hpp>
+#include <sycl/__spirv/spirv_types.hpp>
+
+#include <type_traits>
+
+void __spirv_ControlBarrier(std::uint32_t Execution, std::uint32_t Memory,
+ std::uint32_t Semantics);
+
+_LIBSYCL_BEGIN_NAMESPACE_SYCL
+
+// 4.17.2.1. Group type trait.
+
+template <class T> struct is_group : std::false_type {};
+
+template <int Dimensions>
+struct is_group<group<Dimensions>> : std::true_type {};
+
+template <> struct is_group<sub_group> : std::true_type {};
+
+template <class T>
+inline constexpr bool is_group_v = is_group<std::decay_t<T>>::value;
+
+namespace detail {
+
+static constexpr __spirv::Scope getScope(memory_scope Scope) {
+ switch (Scope) {
+ case memory_scope::work_item:
+ return __spirv::Scope::Invocation;
+ case memory_scope::sub_group:
+ return __spirv::Scope::Subgroup;
+ case memory_scope::work_group:
+ return __spirv::Scope::Workgroup;
+ case memory_scope::device:
+ return __spirv::Scope::Device;
+ case memory_scope::system:
+ return __spirv::Scope::CrossDevice;
+ }
+}
----------------
KseniyaTikhomirova wrote:
this builtin is GCC/clang specific, MSVC has another syntax. I don't want to add extra conditional macro for this stuff. We are going to fix build warnings and enable warning as error feature. So I expect such cases to be catched with compiler error.
@sergey-semenov FYI
https://github.com/llvm/llvm-project/pull/218971
More information about the llvm-commits
mailing list