Skip to content

[SYCL] Fix include loop and use-before-def #8407

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 3 commits into from
Mar 9, 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
7 changes: 2 additions & 5 deletions sycl/include/sycl/bit_cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#pragma once

#include <sycl/detail/memcpy.hpp>

#include <type_traits>

#if __cpp_lib_bit_cast
Expand All @@ -17,11 +19,6 @@
namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {

// forward decl
namespace detail {
inline void memcpy(void *Dst, const void *Src, std::size_t Size);
}

template <typename To, typename From>
#if __cpp_lib_bit_cast || __has_builtin(__builtin_bit_cast)
constexpr
Expand Down
5 changes: 1 addition & 4 deletions sycl/include/sycl/detail/generic_type_lists.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <sycl/access/access.hpp>
#include <sycl/detail/stl_type_traits.hpp>
#include <sycl/detail/type_list.hpp>
#include <sycl/half_type.hpp>

#include <cstddef>

Expand All @@ -22,10 +23,6 @@ namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
template <typename T, int N> class vec;
template <typename Type, std::size_t NumElements> class marray;
namespace detail::half_impl {
class half;
} // namespace detail::half_impl
using half = detail::half_impl::half;
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
} // namespace sycl

Expand Down
8 changes: 1 addition & 7 deletions sycl/include/sycl/detail/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <sycl/access/access.hpp>
#include <sycl/detail/common.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/detail/memcpy.hpp>
#include <sycl/detail/pi.hpp>
#include <sycl/detail/type_traits.hpp>

Expand All @@ -35,13 +36,6 @@ template <typename Type, std::size_t NumElements> class marray;
enum class memory_order;

namespace detail {
inline void memcpy(void *Dst, const void *Src, size_t Size) {
char *Destination = reinterpret_cast<char *>(Dst);
const char *Source = reinterpret_cast<const char *>(Src);
for (size_t I = 0; I < Size; ++I) {
Destination[I] = Source[I];
}
}

class context_impl;
// The function returns list of events that can be passed to OpenCL API as
Expand Down
25 changes: 25 additions & 0 deletions sycl/include/sycl/detail/memcpy.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//==---------------- memcpy.hpp - SYCL memcpy --------------------------==//
//
// 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 <cstddef>

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
namespace detail {
inline void memcpy(void *Dst, const void *Src, size_t Size) {
char *Destination = reinterpret_cast<char *>(Dst);
const char *Source = reinterpret_cast<const char *>(Src);
for (size_t I = 0; I < Size; ++I) {
Destination[I] = Source[I];
}
}
} // namespace detail
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
} // namespace sycl
12 changes: 1 addition & 11 deletions sycl/include/sycl/detail/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <sycl/detail/generic_type_lists.hpp>
#include <sycl/detail/stl_type_traits.hpp>
#include <sycl/detail/type_list.hpp>
#include <sycl/detail/vector_traits.hpp>

#include <array>
#include <tuple>
Expand Down Expand Up @@ -85,7 +86,6 @@ template <typename T, typename R>
using copy_cv_qualifiers_t = typename copy_cv_qualifiers<T, R>::type;

template <int V> using int_constant = std::integral_constant<int, V>;

// vector_size
// scalars are interpreted as a vector of 1 length.
template <typename T> struct vector_size_impl : int_constant<1> {};
Expand All @@ -94,16 +94,6 @@ struct vector_size_impl<vec<T, N>> : int_constant<N> {};
template <typename T>
struct vector_size : vector_size_impl<remove_cv_t<remove_reference_t<T>>> {};

// 4.10.2.6 Memory layout and alignment
template <typename T, int N>
struct vector_alignment_impl
: conditional_t<N == 3, int_constant<sizeof(T) * 4>,
int_constant<sizeof(T) * N>> {};

template <typename T, int N>
struct vector_alignment
: vector_alignment_impl<remove_cv_t<remove_reference_t<T>>, N> {};

// vector_element
template <typename T> struct vector_element_impl;
template <typename T>
Expand Down
30 changes: 30 additions & 0 deletions sycl/include/sycl/detail/vector_traits.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//==----------- vector_traits.hpp - SYCL vector size queries --------------===//
//
// 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/stl_type_traits.hpp>

#include <type_traits>

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
namespace detail {

// 4.10.2.6 Memory layout and alignment
template <typename T, int N>
struct vector_alignment_impl
: conditional_t<N == 3, std::integral_constant<int, sizeof(T) * 4>,
std::integral_constant<int, sizeof(T) * N>> {};

template <typename T, int N>
struct vector_alignment
: vector_alignment_impl<remove_cv_t<remove_reference_t<T>>, N> {};
} // namespace detail
} // __SYCL_INLINE_VER_NAMESPACE(_V1)
} // namespace sycl
1 change: 1 addition & 0 deletions sycl/include/sycl/ext/intel/esimd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#pragma clang diagnostic ignored "-Wpsabi"
#endif // !defined(__SYCL_DEVICE_ONLY__) && defined(__clang__)

#include <sycl/detail/type_traits.hpp>
#include <sycl/ext/intel/esimd/alt_ui.hpp>
#include <sycl/ext/intel/esimd/common.hpp>
#include <sycl/ext/intel/esimd/detail/bfloat16_type_traits.hpp>
Expand Down
11 changes: 8 additions & 3 deletions sycl/include/sycl/half_type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
#pragma once

#include <sycl/aspects.hpp>
#include <sycl/bit_cast.hpp>
#include <sycl/detail/defines.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/detail/iostream_proxy.hpp>
#include <sycl/detail/type_traits.hpp>
#include <sycl/detail/vector_traits.hpp>

#include <functional>
#include <limits>
Expand All @@ -33,6 +34,10 @@

namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {
namespace detail::half_impl {
class half;
}
using half = detail::half_impl::half;

namespace ext::intel::esimd::detail {
class WrapperElementTypeProxy;
Expand Down Expand Up @@ -248,8 +253,8 @@ using BIsRepresentationT = half;
// hood. As a result half values will be converted to the integer and passed
// as a kernel argument which is expected to be floating point number.
template <int NumElements> struct half_vec {
alignas(detail::vector_alignment<StorageT, NumElements>::value)
StorageT s[NumElements];
alignas(
vector_alignment<StorageT, NumElements>::value) StorageT s[NumElements];

__SYCL_CONSTEXPR_HALF half_vec() : s{0.0f} { initialize_data(); }
constexpr void initialize_data() {
Expand Down