Skip to content

[SYCL][NFC] Refactor includes in DPC++ headers #10458

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

Merged
merged 7 commits into from
Jul 19, 2023
Merged
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
23 changes: 23 additions & 0 deletions sycl/include/sycl/async_handler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//===- async_handler.hpp --------------------------------------------------===//
//
// 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

#include <sycl/detail/defines_elementary.hpp>

#include <functional>

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {

// Forward declaration
class exception_list;

using async_handler = std::function<void(sycl::exception_list)>;
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
} // namespace sycl
5 changes: 3 additions & 2 deletions sycl/include/sycl/backend_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

#pragma once

#include <sycl/detail/defines.hpp>
#include <sycl/detail/iostream_proxy.hpp>
#include <sycl/detail/defines_elementary.hpp>

#include <ostream>

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
Expand Down
1 change: 1 addition & 0 deletions sycl/include/sycl/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <sycl/exception.hpp>
#include <sycl/ext/oneapi/accessor_property_list.hpp>
#include <sycl/ext/oneapi/weak_object_base.hpp>
#include <sycl/id.hpp>
#include <sycl/property_list.hpp>
#include <sycl/range.hpp>
#include <sycl/stl.hpp>
Expand Down
10 changes: 3 additions & 7 deletions sycl/include/sycl/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@

#pragma once

#include <sycl/detail/backend_traits.hpp>
#include <sycl/detail/cl.h>
#include <sycl/detail/common.hpp>
#include <sycl/async_handler.hpp>
#include <sycl/backend_types.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/detail/info_desc_helpers.hpp>
#include <sycl/detail/owner_less_base.hpp>
#include <sycl/detail/stl_type_traits.hpp>
#include <sycl/exception_list.hpp>
#include <sycl/ext/oneapi/weak_object_base.hpp>
#include <sycl/info/info_desc.hpp>
#include <sycl/property_list.hpp>

// 4.6.2 Context class
Expand All @@ -27,6 +22,7 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) {
// Forward declarations
class device;
class platform;

namespace detail {
class context_impl;
}
Expand Down
35 changes: 0 additions & 35 deletions sycl/include/sycl/detail/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,41 +259,6 @@ inline std::string codeToString(pi_int32 code) {
namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
namespace detail {

// Helper function for extracting implementation from SYCL's interface objects.
// Note! This function relies on the fact that all SYCL interface classes
// contain "impl" field that points to implementation object. "impl" field
// should be accessible from this function.
//
// Note that due to a bug in MSVC compilers (including MSVC2019 v19.20), it
// may not recognize the usage of this function in friend member declarations
// if the template parameter name there is not equal to the name used here,
// i.e. 'Obj'. For example, using 'Obj' here and 'T' in such declaration
// would trigger that error in MSVC:
// template <class T>
// friend decltype(T::impl) detail::getSyclObjImpl(const T &SyclObject);
template <class Obj> decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject) {
assert(SyclObject.impl && "every constructor should create an impl");
return SyclObject.impl;
}

// Returns the raw pointer to the impl object of given face object. The caller
// must make sure the returned pointer is not captured in a field or otherwise
// stored - i.e. must live only as on-stack value.
template <class T>
typename std::add_pointer_t<typename decltype(T::impl)::element_type>
getRawSyclObjImpl(const T &SyclObject) {
return SyclObject.impl.get();
}

// Helper function for creation SYCL interface objects from implementations.
// Note! This function relies on the fact that all SYCL interface classes
// contain "impl" field that points to implementation object. "impl" field
// should be accessible from this function.
template <class T> T createSyclObjFromImpl(decltype(T::impl) ImplObj) {
return T(ImplObj);
}

// Produces N-dimensional object of type T whose all components are initialized
// to given integer value.
template <int N, template <int> class T> struct InitializedVal {
Expand Down
55 changes: 55 additions & 0 deletions sycl/include/sycl/detail/impl_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//===- impl_utils.hpp -----------------------------------------------------===//
//
// 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

#include <sycl/detail/defines_elementary.hpp>

#include <cassert>

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
namespace detail {

// Helper function for extracting implementation from SYCL's interface objects.
// Note! This function relies on the fact that all SYCL interface classes
// contain "impl" field that points to implementation object. "impl" field
// should be accessible from this function.
//
// Note that due to a bug in MSVC compilers (including MSVC2019 v19.20), it
// may not recognize the usage of this function in friend member declarations
// if the template parameter name there is not equal to the name used here,
// i.e. 'Obj'. For example, using 'Obj' here and 'T' in such declaration
// would trigger that error in MSVC:
// template <class T>
// friend decltype(T::impl) detail::getSyclObjImpl(const T &SyclObject);
template <class Obj> decltype(Obj::impl) getSyclObjImpl(const Obj &SyclObject) {
assert(SyclObject.impl && "every constructor should create an impl");
return SyclObject.impl;
}

// Returns the raw pointer to the impl object of given face object. The caller
// must make sure the returned pointer is not captured in a field or otherwise
// stored - i.e. must live only as on-stack value.
template <class T>
typename std::add_pointer_t<typename decltype(T::impl)::element_type>
getRawSyclObjImpl(const T &SyclObject) {
return SyclObject.impl.get();
}

// Helper function for creation SYCL interface objects from implementations.
// Note! This function relies on the fact that all SYCL interface classes
// contain "impl" field that points to implementation object. "impl" field
// should be accessible from this function.
template <class T> T createSyclObjFromImpl(decltype(T::impl) ImplObj) {
return T(ImplObj);
}

} // namespace detail
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
} // namespace sycl
3 changes: 2 additions & 1 deletion sycl/include/sycl/detail/info_desc_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#pragma once

#include <sycl/aspects.hpp>
#include <sycl/detail/pi.hpp>
#include <sycl/detail/pi.h>
#include <sycl/id.hpp>
#include <sycl/info/info_desc.hpp>

namespace sycl {
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/detail/owner_less_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#pragma once

#include <sycl/detail/common.hpp>
#include <sycl/detail/defines_elementary.hpp>
#include <sycl/detail/impl_utils.hpp>
#include <sycl/ext/oneapi/weak_object_base.hpp>

namespace sycl {
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/detail/property_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#pragma once

#include <sycl/detail/common.hpp>
#include <sycl/detail/defines_elementary.hpp>

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/detail/property_list_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#pragma once

#include <sycl/detail/common.hpp>
#include <sycl/detail/property_helper.hpp>
#include <sycl/detail/stl_type_traits.hpp>
#include <sycl/exception.hpp>

#include <bitset>
#include <memory>
Expand Down
4 changes: 2 additions & 2 deletions sycl/include/sycl/detail/stl_type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

#pragma once

#include <sycl/detail/defines_elementary.hpp>

#include <iterator>
#include <memory>
#include <sycl/detail/defines.hpp>
#include <type_traits>

namespace sycl {
Expand Down
1 change: 1 addition & 0 deletions sycl/include/sycl/device_selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ __SYCL_INLINE_VER_NAMESPACE(_V1) {

// Forward declarations
class device;
class context;
enum class aspect;

namespace ext::oneapi {
Expand Down
3 changes: 1 addition & 2 deletions sycl/include/sycl/exception_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

// 4.9.2 Exception Class Interface

#include <sycl/async_handler.hpp>
#include <sycl/detail/defines.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/detail/iostream_proxy.hpp>
Expand Down Expand Up @@ -52,8 +53,6 @@ class __SYCL_EXPORT exception_list {
std::vector<std::exception_ptr> MList;
};

using async_handler = std::function<void(sycl::exception_list)>;

namespace detail {
// Default implementation of async_handler used by queue and context when no
// user-defined async_handler is specified.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
//===- device_architecture.hpp --------------------------------------------===//
//
// 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

#include <sycl/detail/defines_elementary.hpp>
Expand Down
1 change: 1 addition & 0 deletions sycl/include/sycl/ext/oneapi/experimental/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <sycl/detail/common.hpp>
#include <sycl/detail/defines_elementary.hpp>
#include <sycl/detail/impl_utils.hpp>
#include <sycl/property_list.hpp>

#include <functional>
Expand Down
6 changes: 3 additions & 3 deletions sycl/include/sycl/info/info_desc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
#pragma once

#include <sycl/aspects.hpp>
#include <sycl/detail/common.hpp>
#include <sycl/detail/pi.hpp>
#include <sycl/detail/pi.h>
#include <sycl/ext/oneapi/experimental/device_architecture.hpp>
#include <sycl/id.hpp>
#include <sycl/range.hpp>

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
Expand All @@ -21,6 +20,7 @@ class device;
class platform;
class kernel_id;
enum class memory_scope;
enum class memory_order;

// TODO: stop using OpenCL directly, use PI.
namespace info {
Expand Down
1 change: 0 additions & 1 deletion sycl/include/sycl/property_list.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#pragma once

#include <sycl/detail/common.hpp>
#include <sycl/detail/property_list_base.hpp>
#include <sycl/properties/property_traits.hpp>

Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/queue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#pragma once

#include <sycl/detail/assert_happened.hpp>
#include <sycl/detail/common.hpp>
#include <sycl/detail/service_kernel_names.hpp>
#include <sycl/device_selector.hpp>
#include <sycl/exception_list.hpp>
#include <sycl/handler.hpp>
#include <sycl/property_list.hpp>

Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <sycl/detail/defines.hpp>
#include <sycl/detail/device_filter.hpp>
#include <sycl/detail/pi.hpp>
#include <sycl/exception.hpp>
#include <sycl/info/info_desc.hpp>

#include <algorithm>
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/posix_pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//

#include <sycl/detail/defines.hpp>
#include <sycl/detail/iostream_proxy.hpp>
#include <sycl/detail/pi.hpp>

#include <dlfcn.h>
Expand Down
1 change: 1 addition & 0 deletions sycl/source/detail/sampler_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <CL/__spirv/spirv_types.hpp>
#include <sycl/context.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/detail/pi.hpp>
#include <sycl/property_list.hpp>

#include <mutex>
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/detail/sycl_mem_obj_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <sycl/properties/buffer_properties.hpp>
#include <sycl/properties/image_properties.hpp>
#include <sycl/property_list.hpp>
#include <sycl/stl.hpp>
#include <sycl/range.hpp>

#include <cstring>
#include <memory>
Expand Down