Skip to content

Commit 67e4655

Browse files
baderromanovvlad
authored andcommitted
[SYCL] Inline cl namespace to simplify SYCL API usage (#974)
The inlining is enabled by default and make using SYCL API a little bit easier. In order to disable cl namespace inlining user should define __SYCL_DISABLE_NAMESPACE_INLINE__ macro. Signed-off-by: Alexey Bader <[email protected]>
1 parent b6806ea commit 67e4655

File tree

104 files changed

+181
-123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+181
-123
lines changed

clang/lib/AST/QualTypeNames.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static NestedNameSpecifier *createOuterNNS(const ASTContext &Ctx, const Decl *D,
197197
// Ignore inline namespace;
198198
NS = dyn_cast<NamespaceDecl>(NS->getDeclContext());
199199
}
200-
if (NS->getDeclName()) {
200+
if (NS && NS->getDeclName()) {
201201
return createNestedNameSpecifier(Ctx, NS, WithGlobalNsPrefix);
202202
}
203203
return nullptr; // no starting '::', no anonymous

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
16381638
O << "// This is auto-generated SYCL integration header.\n";
16391639
O << "\n";
16401640

1641+
O << "#include <CL/sycl/detail/defines.hpp>\n";
16411642
O << "#include <CL/sycl/detail/kernel_desc.hpp>\n";
16421643

16431644
O << "\n";
@@ -1651,7 +1652,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
16511652
}
16521653
O << "\n";
16531654

1654-
O << "namespace cl {\n";
1655+
O << "__SYCL_INLINE namespace cl {\n";
16551656
O << "namespace sycl {\n";
16561657
O << "namespace detail {\n";
16571658

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %clang_cc1 -triple spir64-unknown-linux-sycldevice -std=c++11 -fsycl-is-device -S -emit-llvm -x c++ %s -o - | FileCheck %s
2+
3+
inline namespace cl {
4+
namespace sycl {
5+
class kernel {};
6+
}
7+
}
8+
9+
using namespace cl::sycl;
10+
11+
template <typename name, typename Func>
12+
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
13+
kernelFunc();
14+
}
15+
16+
// CHECK: define spir_kernel {{.*}}2cl4sycl6kernel
17+
int main() {
18+
kernel_single_task<class kernel>([]() {});
19+
return 0;
20+
}

sycl/include/CL/sycl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040
#include <CL/sycl/types.hpp>
4141
#include <CL/sycl/usm.hpp>
4242
#include <CL/sycl/version.hpp>
43+

sycl/include/CL/sycl/access/access.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
//===----------------------------------------------------------------------===//
88
#pragma once
99

10-
namespace cl {
10+
#include <CL/sycl/detail/defines.hpp>
11+
12+
__SYCL_INLINE namespace cl {
1113
namespace sycl {
1214
namespace access {
1315

sycl/include/CL/sycl/accessor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
143143
// accessor_common contains several helpers common for both accessor(1) and
144144
// accessor(3)
145145

146-
namespace cl {
146+
__SYCL_INLINE namespace cl {
147147
namespace sycl {
148148

149149
template <typename DataT, int Dimensions, access::mode AccessMode,

sycl/include/CL/sycl/aliases.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <cstddef>
1414
#include <cstdint>
1515

16-
namespace cl {
16+
__SYCL_INLINE namespace cl {
1717
namespace sycl {
1818
template <typename T, int N> class vec;
1919
namespace detail {
@@ -69,7 +69,7 @@ using half = cl::sycl::detail::half_impl::half;
6969
MAKE_VECTOR_ALIASES_FOR_OPENCL_TYPES(N) \
7070
MAKE_VECTOR_ALIASES_FOR_SIGNED_AND_UNSIGNED_TYPES(N)
7171

72-
namespace cl {
72+
__SYCL_INLINE namespace cl {
7373
namespace sycl {
7474
using byte = std::uint8_t;
7575
using schar = signed char;

sycl/include/CL/sycl/atomic.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
static_assert(!std::is_same<T, float>::value, \
2424
"SYCL atomic function not available for float type")
2525

26-
namespace cl {
26+
__SYCL_INLINE namespace cl {
2727
namespace sycl {
2828

2929
enum class memory_order : int { relaxed };
@@ -66,7 +66,7 @@ template <> struct GetSpirvMemoryScope<access::address_space::local_space> {
6666

6767
#ifndef __SYCL_DEVICE_ONLY__
6868
// host implementation of SYCL atomics
69-
namespace cl {
69+
__SYCL_INLINE namespace cl {
7070
namespace sycl {
7171
namespace detail {
7272
// Translate cl::sycl::memory_order or __spv::MemorySemanticsMask
@@ -161,7 +161,7 @@ extern T __spirv_AtomicMax(std::atomic<T> *Ptr, __spv::Scope S,
161161

162162
#endif // !defined(__SYCL_DEVICE_ONLY__)
163163

164-
namespace cl {
164+
__SYCL_INLINE namespace cl {
165165
namespace sycl {
166166

167167
template <typename T, access::address_space addressSpace =

sycl/include/CL/sycl/buffer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
// TODO: 4.3.4 Properties
1616

17-
namespace cl {
17+
__SYCL_INLINE namespace cl {
1818
namespace sycl {
1919
class handler;
2020
class queue;

sycl/include/CL/sycl/builtins.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// TODO Decide whether to mark functions with this attribute.
1818
#define __NOEXC /*noexcept*/
1919

20-
namespace cl {
20+
__SYCL_INLINE namespace cl {
2121
namespace sycl {
2222
#ifdef __SYCL_DEVICE_ONLY__
2323
#define __sycl_std
@@ -27,7 +27,7 @@ namespace __sycl_std = __host_std;
2727
} // namespace sycl
2828
} // namespace cl
2929

30-
namespace cl {
30+
__SYCL_INLINE namespace cl {
3131
namespace sycl {
3232
/* ----------------- 4.13.3 Math functions. ---------------------------------*/
3333
// genfloat acos (genfloat x)

0 commit comments

Comments
 (0)