Skip to content
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

[SYCL] Inline cl namespace to simplify SYCL API usage #974

Merged
merged 2 commits into from
Dec 26, 2019
Merged
Changes from 1 commit
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
Prev Previous commit
[SYCL] Inline cl namespace to simplify SYCL API usage
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]>
  • Loading branch information
bader committed Dec 25, 2019

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 315948f72f1712d0931ce827e42c6a13cf45dd58
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
@@ -1638,6 +1638,7 @@ void SYCLIntegrationHeader::emit(raw_ostream &O) {
O << "// This is auto-generated SYCL integration header.\n";
O << "\n";

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

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

O << "namespace cl {\n";
O << "__SYCL_INLINE namespace cl {\n";
O << "namespace sycl {\n";
O << "namespace detail {\n";

1 change: 1 addition & 0 deletions sycl/include/CL/sycl.hpp
Original file line number Diff line number Diff line change
@@ -40,3 +40,4 @@
#include <CL/sycl/types.hpp>
#include <CL/sycl/usm.hpp>
#include <CL/sycl/version.hpp>

4 changes: 3 additions & 1 deletion sycl/include/CL/sycl/access/access.hpp
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@
//===----------------------------------------------------------------------===//
#pragma once

namespace cl {
#include <CL/sycl/detail/defines.hpp>

__SYCL_INLINE namespace cl {
namespace sycl {
namespace access {

2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/accessor.hpp
Original file line number Diff line number Diff line change
@@ -143,7 +143,7 @@
// accessor_common contains several helpers common for both accessor(1) and
// accessor(3)

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {

template <typename DataT, int Dimensions, access::mode AccessMode,
4 changes: 2 additions & 2 deletions sycl/include/CL/sycl/aliases.hpp
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
#include <cstddef>
#include <cstdint>

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

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
using byte = std::uint8_t;
using schar = signed char;
6 changes: 3 additions & 3 deletions sycl/include/CL/sycl/atomic.hpp
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
static_assert(!std::is_same<T, float>::value, \
"SYCL atomic function not available for float type")

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {

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

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

#endif // !defined(__SYCL_DEVICE_ONLY__)

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {

template <typename T, access::address_space addressSpace =
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/buffer.hpp
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@

// TODO: 4.3.4 Properties

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
class handler;
class queue;
4 changes: 2 additions & 2 deletions sycl/include/CL/sycl/builtins.hpp
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
// TODO Decide whether to mark functions with this attribute.
#define __NOEXC /*noexcept*/

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
#ifdef __SYCL_DEVICE_ONLY__
#define __sycl_std
@@ -27,7 +27,7 @@ namespace __sycl_std = __host_std;
} // namespace sycl
} // namespace cl

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
/* ----------------- 4.13.3 Math functions. ---------------------------------*/
// genfloat acos (genfloat x)
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/context.hpp
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
#include <type_traits>
// 4.6.2 Context class

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
// Forward declarations
class device;
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/accessor_impl.hpp
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@

#include <memory>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {

2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/aligned_allocator.hpp
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@
#include <memory>
#include <vector>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {
template <typename T> class aligned_allocator {
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/array.hpp
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
#include <functional>
#include <stdexcept>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
template <int dimensions> class id;
template <int dimensions> class range;
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/boolean.hpp
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
#include <initializer_list>
#include <type_traits>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {

2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/buffer_impl.hpp
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
#include <memory>
#include <type_traits>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
// Forward declarations
template <typename DataT, int Dimensions, access::mode AccessMode,
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/builtins.hpp
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@
}

#ifndef __SYCL_DEVICE_ONLY__
namespace cl {
__SYCL_INLINE namespace cl {
namespace __host_std {
#endif // __SYCL_DEVICE_ONLY__
/* ----------------- 4.13.3 Math functions. ---------------------------------*/
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/cg.hpp
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
#include <type_traits>
#include <vector>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {

2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/clusm.hpp
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@
#include <mutex>
#include <vector>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {
namespace usm {
22 changes: 5 additions & 17 deletions sycl/include/CL/sycl/detail/common.hpp
Original file line number Diff line number Diff line change
@@ -8,6 +8,8 @@

#pragma once

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

// Suppress a compiler warning about undefined CL_TARGET_OPENCL_VERSION
// Khronos ICD supports only latest OpenCL version
#define CL_TARGET_OPENCL_VERSION 220
@@ -20,7 +22,7 @@
#define STRINGIFY_LINE_HELP(s) #s
#define STRINGIFY_LINE(s) STRINGIFY_LINE_HELP(s)

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {

@@ -85,21 +87,7 @@ static inline std::string codeToString(cl_int code){
#define CHECK_OCL_CODE_NO_EXC(X) REPORT_OCL_ERR_TO_STREAM(X)
#endif

#ifndef __has_attribute
#define __has_attribute(x) 0
#endif

#if __has_attribute(always_inline)
#define ALWAYS_INLINE __attribute__((always_inline))
#else
#define ALWAYS_INLINE
#endif

#ifndef SYCL_EXTERNAL
#define SYCL_EXTERNAL
#endif

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {

@@ -175,7 +163,7 @@ struct NDLoopIterateImpl {
}
};

// spcialization for DIM=0 to terminate recursion
// Specialization for DIM=0 to terminate recursion
template <int NDIMS, template <int> class LoopBoundTy, typename FuncTy,
template <int> class LoopIndexTy>
struct NDLoopIterateImpl<NDIMS, 0, LoopBoundTy, FuncTy, LoopIndexTy> {
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/common_info.hpp
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
#pragma once
#include <CL/sycl/stl.hpp>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {

2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/context_impl.hpp
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
#include <map>
#include <memory>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
// Forward declaration
class device;
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/context_info.hpp
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/info/info_desc.hpp>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {

29 changes: 29 additions & 0 deletions sycl/include/CL/sycl/detail/defines.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//==---------- defines.hpp ----- Preprocessor directives -------------------==//
//
// 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

#ifndef __SYCL_DISABLE_NAMESPACE_INLINE__
#define __SYCL_INLINE inline
#else
#define __SYCL_INLINE
#endif // __SYCL_DISABLE_NAMESPACE_INLINE__

#ifndef __has_attribute
#define __has_attribute(x) 0
#endif

#if __has_attribute(always_inline)
#define ALWAYS_INLINE __attribute__((always_inline))
#else
#define ALWAYS_INLINE
#endif

#ifndef SYCL_EXTERNAL
#define SYCL_EXTERNAL
#endif
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/device_impl.hpp
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
#include <CL/sycl/stl.hpp>
#include <memory>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {

// Forward declaration
3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/detail/device_info.hpp
Original file line number Diff line number Diff line change
@@ -8,12 +8,13 @@

#pragma once
#include <CL/sycl/detail/common_info.hpp>
#include <CL/sycl/detail/defines.hpp>
#include <CL/sycl/detail/pi.hpp>
#include <CL/sycl/detail/platform_impl.hpp>
#include <CL/sycl/info/info_desc.hpp>
#include <CL/sycl/platform.hpp>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {

2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/event_impl.hpp
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@

#include <cassert>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
class context;
namespace detail {
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/event_info.hpp
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
#include <CL/sycl/detail/common.hpp>
#include <CL/sycl/info/info_desc.hpp>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {

3 changes: 2 additions & 1 deletion sycl/include/CL/sycl/detail/force_device.hpp
Original file line number Diff line number Diff line change
@@ -8,9 +8,10 @@

#pragma once

#include <CL/sycl/detail/defines.hpp>
#include <CL/sycl/info/info_desc.hpp>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {

4 changes: 2 additions & 2 deletions sycl/include/CL/sycl/detail/generic_type_lists.hpp
Original file line number Diff line number Diff line change
@@ -15,13 +15,13 @@
// types of parameters to kernel functions

// Forward declaration
namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
template <typename T, int N> class vec;
} // namespace sycl
} // namespace cl

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {
namespace gtl {
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/generic_type_traits.hpp
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
#include <limits>
#include <type_traits>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {

2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/helpers.hpp
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@
#include <type_traits>
#include <vector>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
class context;
class event;
2 changes: 1 addition & 1 deletion sycl/include/CL/sycl/detail/image_accessor_util.hpp
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@
#include <cmath>
#include <iostream>

namespace cl {
__SYCL_INLINE namespace cl {
namespace sycl {
namespace detail {

Loading