Skip to content

[SYCL] Prepare for remove of cl namespace #4847

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

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion sycl/.clang-format
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BasedOnStyle: LLVM
NamespaceMacros: ['__SYCL_INLINE_NAMESPACE']
NamespaceMacros: ['__SYCL_INT_HEADER_OPEN_NS','__SYCL_OPEN_NS_BUILTINS','__SYCL_OPEN_NS','__SYCL_INLINE_NAMESPACE']
1 change: 1 addition & 0 deletions sycl/include/CL/sycl/detail/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <CL/sycl/detail/cl.h>
#include <CL/sycl/detail/defines.hpp>
#include <CL/sycl/detail/defines_elementary.hpp>
#include <CL/sycl/detail/defines_sycl_ns.hpp>
#include <CL/sycl/detail/export.hpp>
#include <CL/sycl/detail/stl_type_traits.hpp>

Expand Down
1 change: 1 addition & 0 deletions sycl/include/CL/sycl/detail/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include <CL/sycl/detail/defines_elementary.hpp>
#include <CL/sycl/detail/defines_sycl_ns.hpp>

#include <climits>

Expand Down
11 changes: 11 additions & 0 deletions sycl/include/CL/sycl/detail/defines_elementary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@
#define __SYCL_INLINE_NAMESPACE(X) namespace X
#endif // __SYCL_DISABLE_NAMESPACE_INLINE__

//#define __SYCL_INT_HEADER_NS() __sycl_integraion_header_ns
//#define __SYCL_INT_HEADER_OPEN_NS() namespace __SYCL_INT_HEADER_NS()
//#define __SYCL_INT_HEADER_CLOSE_NS()
//
#define __SYCL_INT_HEADER_NS() cl::sycl
#define __SYCL_INT_HEADER_OPEN_NS() \
__SYCL_INLINE_NAMESPACE(cl) { \
namespace sycl

#define __SYCL_INT_HEADER_CLOSE_NS() }

#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
Expand Down
84 changes: 84 additions & 0 deletions sycl/include/CL/sycl/detail/defines_sycl_ns.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//==--- defines_elementary.hpp ---- Preprocessor directives (simplified) ---==//
//
// 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
//
//===----------------------------------------------------------------------===//

#pragma once

//#ifdef __SYCL_ENABLE_SYCL121_NAMESPACE
// Old SYCL1.2.1 namespace scheme
//#define __SYCL_NS_OPEN_1 __SYCL_INLINE_NAMESPACE(cl)
//#define __SYCL_NS_OPEN_2 namespace sycl
//#define __SYCL_NS cl::sycl
//#else
// New SYCL2020 friendly namespace scheme, defaulted to __v1
#define __SYCL_NS_OPEN_1 namespace __SYCL_INLINE_NAMESPACE(cl)
#define __SYCL_NS_OPEN_2 namespace sycl
#define __SYCL_NS cl::sycl
//#endif

#ifdef __SYCL_ENABLE_SYCL121_NAMESPACE

#define __SYCL_OPEN_NS() \
__SYCL_NS_OPEN_1 { \
__SYCL_NS_OPEN_2 {} \
} \
namespace __sycl_ns = __SYCL_NS; \
__SYCL_INLINE_NAMESPACE(cl) { \
namespace sycl { \
using namespace __SYCL_NS; \
} \
} \
__SYCL_NS_OPEN_1 { \
__SYCL_NS_OPEN_2

#define __SYCL_OPEN_NS_BUILTINS() \
__SYCL_NS_OPEN_1 { \
__SYCL_NS_OPEN_2 { \
namespace __host_std {} \
} \
} \
__SYCL_INLINE_NAMESPACE(cl) { \
namespace __host_std = __SYCL_NS::__host_std; \
} \
__SYCL_NS_OPEN_1 { \
__SYCL_NS_OPEN_2

#define __SYCL_CLOSE_NS_BUILTINS() }

#else

// The macro:
// 1. Forward declares an empty "target" namespace for the alias
// 2. An alias which will be used to refer to "target" namepsace outside of
// namespace itself
// 3. Opens "target" namespace
#define __SYCL_OPEN_NS() \
__SYCL_NS_OPEN_1 { \
__SYCL_NS_OPEN_2 {} \
} \
namespace sycl { \
using namespace __SYCL_NS; \
} \
namespace __sycl_ns = __SYCL_NS; \
__SYCL_NS_OPEN_1 { \
__SYCL_NS_OPEN_2

#define __SYCL_OPEN_NS_BUILTINS() \
__SYCL_NS_OPEN_1 { \
__SYCL_NS_OPEN_2 {} \
} \
namespace sycl { \
using namespace __SYCL_NS; \
} \
__SYCL_NS_OPEN_1 { \
__SYCL_NS_OPEN_2

#define __SYCL_CLOSE_NS_BUILTINS() }

#endif

#define __SYCL_CLOSE_NS() }
7 changes: 3 additions & 4 deletions sycl/include/CL/sycl/detail/kernel_desc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
#include <CL/sycl/detail/defines_elementary.hpp>
#include <CL/sycl/detail/export.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
__SYCL_INT_HEADER_OPEN_NS() {
namespace detail {

#ifndef __SYCL_DEVICE_ONLY__
Expand Down Expand Up @@ -137,5 +136,5 @@ template <class KernelNameType> struct KernelInfo {
#endif //__SYCL_UNNAMED_LAMBDA__

} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
} // __SYCL_INT_HEADER_OPEN_NS()
__SYCL_INT_HEADER_CLOSE_NS()
7 changes: 3 additions & 4 deletions sycl/include/CL/sycl/detail/spec_const_integration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
// This header file must not be included to any DPC++ headers.
// This header file should only be included to integration footer.

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
__SYCL_INT_HEADER_OPEN_NS() {
namespace detail {

#if __cplusplus >= 201703L
Expand All @@ -24,5 +23,5 @@ template <auto &SpecName> const char *get_spec_constant_symbolic_ID() {
#endif

} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
} // __SYCL_INT_HEADER_OPEN_NS()
__SYCL_INT_HEADER_CLOSE_NS()
3 changes: 3 additions & 0 deletions sycl/include/CL/sycl/detail/sycl_mem_obj_allocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

#pragma once

#include <CL/sycl/detail/defines_elementary.hpp>
#include <CL/sycl/detail/defines_sycl_ns.hpp>

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
namespace detail {
Expand Down
1 change: 1 addition & 0 deletions sycl/include/CL/sycl/detail/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#pragma once

#include <CL/sycl/detail/defines_elementary.hpp>
#include <CL/sycl/detail/defines_sycl_ns.hpp>

#include <cassert>
#include <iterator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

#pragma once

#include <CL/sycl/detail/defines_elementary.hpp>
#include <CL/sycl/detail/defines_sycl_ns.hpp>

// <cstdint> for 'uint32_t' type is included in upper-level device
// interface file ('esimdemu_device_interface.hpp')

Expand Down
9 changes: 4 additions & 5 deletions sycl/unittests/SYCL2020/KernelBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//
//===----------------------------------------------------------------------===//

#include <CL/sycl.hpp>
#include <detail/kernel_bundle_impl.hpp>
#include <sycl/sycl.hpp>

#include <helpers/CommonRedefinitions.hpp>
#include <helpers/PiImage.hpp>
Expand All @@ -18,8 +18,7 @@
class TestKernel;
class TestKernelExeOnly;

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
__SYCL_INT_HEADER_OPEN_NS() {
namespace detail {
template <> struct KernelInfo<TestKernel> {
static constexpr unsigned getNumParams() { return 0; }
Expand All @@ -46,8 +45,8 @@ template <> struct KernelInfo<TestKernelExeOnly> {
};

} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
} // __SYCL_INT_HEADER_OPEN_NS()
__SYCL_INT_HEADER_CLOSE_NS()

static sycl::unittest::PiImage
generateDefaultImage(std::initializer_list<std::string> KernelNames,
Expand Down
9 changes: 4 additions & 5 deletions sycl/unittests/SYCL2020/KernelID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include <CL/sycl.hpp>
#include <sycl/sycl.hpp>

#include <helpers/CommonRedefinitions.hpp>
#include <helpers/PiImage.hpp>
Expand All @@ -19,8 +19,7 @@ class TestKernel2;
class TestKernel3;
class ServiceKernel1;

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
__SYCL_INT_HEADER_OPEN_NS() {
namespace detail {
template <> struct KernelInfo<TestKernel1> {
static constexpr unsigned getNumParams() { return 0; }
Expand Down Expand Up @@ -72,8 +71,8 @@ template <> struct KernelInfo<ServiceKernel1> {
static constexpr bool callsAnyThisFreeFunction() { return false; }
};
} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
} // __SYCL_INT_HEADER_OPEN_NS()
__SYCL_INT_HEADER_CLOSE_NS()

static sycl::unittest::PiImage
generateDefaultImage(std::initializer_list<std::string> Kernels) {
Expand Down
9 changes: 4 additions & 5 deletions sycl/unittests/assert/assert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

// Enable use of interop kernel c-tor
#define __SYCL_INTERNAL_API
#include <CL/sycl.hpp>
#include <CL/sycl/backend/opencl.hpp>
#include <sycl/sycl.hpp>

#include <helpers/CommonRedefinitions.hpp>
#include <helpers/PiImage.hpp>
Expand All @@ -36,8 +36,7 @@

class TestKernel;

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
__SYCL_INT_HEADER_OPEN_NS() {
namespace detail {
template <> struct KernelInfo<TestKernel> {
static constexpr unsigned getNumParams() { return 0; }
Expand Down Expand Up @@ -69,8 +68,8 @@ struct KernelInfo<::sycl::detail::__sycl_service_kernel__::AssertInfoCopier> {
static constexpr bool callsAnyThisFreeFunction() { return 0; }
};
} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
} // __SYCL_INT_HEADER_OPEN_NS()
__SYCL_INT_HEADER_CLOSE_NS()

static sycl::unittest::PiImage generateDefaultImage() {
using namespace sycl::unittest;
Expand Down
9 changes: 4 additions & 5 deletions sycl/unittests/kernel-and-program/Cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#include "detail/context_impl.hpp"
#include "detail/kernel_program_cache.hpp"
#include "detail/program_impl.hpp"
#include <CL/sycl.hpp>
#include <helpers/CommonRedefinitions.hpp>
#include <helpers/PiImage.hpp>
#include <helpers/PiMock.hpp>
#include <sycl/sycl.hpp>

#include <gtest/gtest.h>

Expand All @@ -34,8 +34,7 @@ class TestKernel2 {
void operator()(cl::sycl::item<1>){};
};

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
__SYCL_INT_HEADER_OPEN_NS() {
namespace detail {
struct MockKernelInfo {
static constexpr unsigned getNumParams() { return 0; }
Expand All @@ -57,8 +56,8 @@ template <> struct KernelInfo<TestKernel2> : public MockKernelInfo {
};

} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
} // __SYCL_INT_HEADER_OPEN_NS()
__SYCL_INT_HEADER_CLOSE_NS()

static sycl::unittest::PiImage generateDefaultImage() {
using namespace sycl::unittest;
Expand Down
9 changes: 4 additions & 5 deletions sycl/unittests/misc/KernelBuildOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
#define __SYCL_INTERNAL_API
#endif

#include <CL/sycl.hpp>
#include <helpers/PiImage.hpp>
#include <helpers/PiMock.hpp>
#include <sycl/sycl.hpp>

#include <gtest/gtest.h>

class TestKernel;

static std::string BuildOpts;
__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
__SYCL_INT_HEADER_OPEN_NS() {
namespace detail {
template <> struct KernelInfo<TestKernel> {
static constexpr unsigned getNumParams() { return 0; }
Expand All @@ -36,8 +35,8 @@ template <> struct KernelInfo<TestKernel> {
};

} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
} // __SYCL_INT_HEADER_OPEN_NS()
__SYCL_INT_HEADER_CLOSE_NS()

static pi_result redefinedProgramCreate(pi_context, const void *, size_t,
pi_program *) {
Expand Down
9 changes: 4 additions & 5 deletions sycl/unittests/program_manager/EliminatedArgMask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
//
//===----------------------------------------------------------------------===//

#include <CL/sycl.hpp>
#include <detail/kernel_bundle_impl.hpp>
#include <detail/queue_impl.hpp>
#include <detail/scheduler/commands.hpp>
#include <sycl/sycl.hpp>

#include <helpers/CommonRedefinitions.hpp>
#include <helpers/PiImage.hpp>
Expand All @@ -23,8 +23,7 @@ const char EAMTestKernelName[] = "EAMTestKernel";
const char EAMTestKernel2Name[] = "EAMTestKernel2";
constexpr unsigned EAMTestKernelNumArgs = 4;

__SYCL_INLINE_NAMESPACE(cl) {
namespace sycl {
__SYCL_INT_HEADER_OPEN_NS() {
namespace detail {
template <> struct KernelInfo<EAMTestKernel> {
static constexpr unsigned getNumParams() { return EAMTestKernelNumArgs; }
Expand All @@ -51,8 +50,8 @@ template <> struct KernelInfo<EAMTestKernel2> {
};

} // namespace detail
} // namespace sycl
} // __SYCL_INLINE_NAMESPACE(cl)
} // __SYCL_INT_HEADER_OPEN_NS()
__SYCL_INT_HEADER_CLOSE_NS()

static sycl::unittest::PiImage generateEAMTestKernelImage() {
using namespace sycl::unittest;
Expand Down
Loading