Skip to content

Commit

Permalink
Merge branch 'sycl' into improve-memset
Browse files Browse the repository at this point in the history
  • Loading branch information
callumfare committed Nov 15, 2024
2 parents 6721497 + 27dab62 commit 1910c7c
Show file tree
Hide file tree
Showing 84 changed files with 532 additions and 314 deletions.
2 changes: 1 addition & 1 deletion libdevice/nativecpu_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "device.h"
#include <cstdint>
#include <sycl/__spirv/spirv_ops.hpp>
#include <sycl/types.hpp>
#include <sycl/vector.hpp>

// including state definition from Native CPU UR adapter
#include "nativecpu_state.hpp"
Expand Down
1 change: 0 additions & 1 deletion sycl/include/sycl/aliases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#pragma once

#include <sycl/detail/defines_elementary.hpp> // for __SYCL2020_DEPRECATED
#include <sycl/half_type.hpp> // for half

#include <cstdint> // for uint8_t, int16_t, int32_t

Expand Down
17 changes: 2 additions & 15 deletions sycl/include/sycl/backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,17 @@
#include <sycl/buffer.hpp> // for buffer_allocator
#include <sycl/context.hpp> // for context, get_na...
#include <sycl/detail/backend_traits.hpp> // for InteropFeatureS...
#include <sycl/detail/cl.h> // for _cl_event
#include <sycl/detail/defines_elementary.hpp> // for __SYCL_DEPRECATED
#include <sycl/detail/export.hpp> // for __SYCL_EXPORT
#include <sycl/detail/impl_utils.hpp> // for createSyclObjFr...
#include <sycl/device.hpp> // for device, get_native
#include <sycl/event.hpp> // for event, get_native
#include <sycl/exception.hpp> // for make_error_code
#include <sycl/feature_test.hpp> // for SYCL_BACKEND_OP...
#include <sycl/handler.hpp> // for buffer
#include <sycl/image.hpp> // for image, image_al...
#include <sycl/kernel.hpp> // for kernel, get_native
#include <sycl/kernel_bundle.hpp> // for kernel_bundle
#include <sycl/kernel_bundle_enums.hpp> // for bundle_state
#include <sycl/platform.hpp> // for platform, get_n...
#include <sycl/property_list.hpp> // for property_list
#include <sycl/queue.hpp> // for queue, get_native
#include <ur_api.h> // for ur_native_handle_t

Expand Down Expand Up @@ -60,13 +56,12 @@
namespace sycl {
inline namespace _V1 {

class property_list;

namespace detail {
// TODO each backend can have its own custom errc enumeration
// but the details for this are not fully specified yet
enum class backend_errc : unsigned int {};

// Convert from UR backend to SYCL backend enum
backend convertUrBackend(ur_platform_backend_t UrBackend);
} // namespace detail

template <backend Backend> class backend_traits {
Expand All @@ -78,14 +73,6 @@ template <backend Backend> class backend_traits {
using return_type = typename detail::BackendReturn<Backend, T>::type;
};

template <backend Backend, typename SyclType>
using backend_input_t =
typename backend_traits<Backend>::template input_type<SyclType>;

template <backend Backend, typename SyclType>
using backend_return_t =
typename backend_traits<Backend>::template return_type<SyclType>;

namespace detail {
template <backend Backend, typename DataT, int Dimensions, typename AllocatorT>
struct BufferInterop {
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/builtins_esimd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <sycl/detail/common.hpp>
#include <sycl/detail/generic_type_traits.hpp>
#include <sycl/ext/intel/esimd/detail/math_intrin.hpp>
#include <sycl/types.hpp>
#include <sycl/vector.hpp>

// TODO Decide whether to mark functions with this attribute.
#define __NOEXC /*noexcept*/
Expand Down
3 changes: 2 additions & 1 deletion sycl/include/sycl/builtins_utils_vec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
#include <sycl/builtins_utils_scalar.hpp>

#include <sycl/detail/type_traits.hpp>
#include <sycl/detail/vector_convert.hpp>
#include <sycl/marray.hpp> // for marray
#include <sycl/types.hpp> // for vec
#include <sycl/vector.hpp> // for vec

namespace sycl {
inline namespace _V1 {
Expand Down
3 changes: 1 addition & 2 deletions sycl/include/sycl/detail/backend_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

#pragma once

#include <sycl/backend_types.hpp>

namespace sycl {
inline namespace _V1 {
enum class backend : char;
namespace detail {

template <backend Backend, typename SYCLObjectT> struct interop;
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/detail/device_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#pragma once

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

Expand All @@ -18,6 +17,7 @@

namespace sycl {
inline namespace _V1 {
enum class backend : char;
namespace detail {

// ---------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/detail/image_accessor_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <sycl/image.hpp> // for image_channel_type
#include <sycl/range.hpp> // for range
#include <sycl/sampler.hpp> // for addressing_mode, coor...
#include <sycl/types.hpp> // for vec, operator*, round...
#include <sycl/vector.hpp> // for vec, operator*, round...

#include <cstdint> // for int32_t, uint16_t
#include <stddef.h> // for size_t
Expand Down
147 changes: 147 additions & 0 deletions sycl/include/sycl/detail/optional.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
//==-------- optional.hpp - limited variant of std::optional -------- C++ --==//
//
// 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 <optional>
#include <type_traits>

namespace sycl {
inline namespace _V1 {
namespace detail {

// ABI-stable implementation of optional to avoid reliance on potentially
// differing implementations of std::optional when crossing the library
// boundary.
template <typename T> class optional {
public:
constexpr optional() noexcept {}
constexpr optional(std::nullopt_t) noexcept : optional() {}

template <typename U>
constexpr optional(const optional<U> &Other)
: ContainsValue{Other.ContainsValue} {
new (Storage) T(Other.Value);
}
template <typename U>
constexpr optional(optional<U> &&Other)
: ContainsValue{std::move(Other.ContainsValue)} {
new (Storage) T(std::move(Other.Value));
}

constexpr optional(T &&Value) : ContainsValue{true} {
new (Storage) T(std::move(Value));
}

constexpr optional(const T &Value) : ContainsValue{true} {
new (Storage) T(Value);
}

template <typename U>
constexpr optional(const std::optional<U> &Other) : ContainsValue{Other} {
if (Other)
new (Storage) T(*Other);
}

~optional() {
if (has_value())
reinterpret_cast<T *>(Storage)->~T();
}

optional &operator=(std::nullopt_t) noexcept {
if (has_value())
reinterpret_cast<T *>(Storage)->~T();
ContainsValue = false;
return *this;
}

template <typename U> optional &operator=(const optional<U> &Other) {
if (has_value())
reinterpret_cast<T *>(Storage)->~T();
ContainsValue = Other;
new (Storage) T(Other.Value);
return *this;
}
template <typename U> optional &operator=(optional<U> &&Other) noexcept {
if (has_value())
reinterpret_cast<T *>(Storage)->~T();
ContainsValue = Other;
new (Storage) T(std::move(Other.Value));
return *this;
}

optional &operator=(T &&Value) {
if (has_value())
reinterpret_cast<T *>(Storage)->~T();
ContainsValue = true;
new (Storage) T(std::move(Value));
return *this;
}

optional &operator=(const T &Value) {
if (has_value())
reinterpret_cast<T *>(Storage)->~T();
ContainsValue = true;
new (Storage) T(Value);
return *this;
}

template <typename U> optional &operator=(const std::optional<U> &Other) {
if (has_value())
reinterpret_cast<T *>(Storage)->~T();
ContainsValue = Other;
if (Other)
new (Storage) T(*Other);
return *this;
}

constexpr bool has_value() const noexcept { return ContainsValue; }
constexpr explicit operator bool() const noexcept { return has_value(); }

constexpr T &value() & {
if (!has_value())
throw std::bad_optional_access{};
return *reinterpret_cast<T *>(Storage);
}
constexpr const T &value() const & {
if (!has_value())
throw std::bad_optional_access{};
return *reinterpret_cast<const T *>(Storage);
}
constexpr T &&value() && {
if (!has_value())
throw std::bad_optional_access{};
return std::move(*reinterpret_cast<T *>(Storage));
}
constexpr const T &&value() const && {
if (!has_value())
throw std::bad_optional_access{};
return std::move(*reinterpret_cast<const T *>(Storage));
}

template <class U> constexpr T value_or(U &&DefaultVal) {
return has_value() ? value() : static_cast<T>(std::forward<U>(DefaultVal));
}
template <class U> constexpr T value_or(U &&DefaultVal) const {
return has_value() ? std::move(value())
: static_cast<T>(std::forward<U>(DefaultVal));
}

constexpr T &operator*() & { return value(); }
constexpr const T &operator*() const & { return value(); }
constexpr T &&operator*() && { return value(); }
constexpr const T &&operator*() const && { return value(); }

private:
alignas(alignof(T)) char Storage[sizeof(T)] = {0};
bool ContainsValue = false;
};

} // namespace detail
} // namespace _V1
} // namespace sycl
2 changes: 1 addition & 1 deletion sycl/include/sycl/detail/ur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#pragma once

#include <sycl/backend_types.hpp>
#include <sycl/detail/export.hpp>
#include <sycl/detail/os_util.hpp>
#include <ur_api.h>
Expand Down Expand Up @@ -42,6 +41,7 @@ struct trace_event_data_t;
namespace sycl {
inline namespace _V1 {

enum class backend : char;
class context;

namespace detail {
Expand Down
37 changes: 37 additions & 0 deletions sycl/include/sycl/detail/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

#include <cstring>
#include <mutex>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>

namespace sycl {
Expand Down Expand Up @@ -83,6 +86,40 @@ template <> struct ABINeutralT<std::vector<std::string>> {
};

template <typename T> using ABINeutralT_t = typename ABINeutralT<T>::type;

template <typename ParamT> auto convert_to_abi_neutral(ParamT &&Info) {
using ParamNoRef = std::remove_reference_t<ParamT>;
if constexpr (std::is_same_v<ParamNoRef, std::string>) {
return detail::string{Info};
} else if constexpr (std::is_same_v<ParamNoRef, std::vector<std::string>>) {
std::vector<detail::string> Res;
Res.reserve(Info.size());
for (std::string &Str : Info) {
Res.push_back(detail::string{Str});
}
return Res;
} else {
return std::forward<ParamT>(Info);
}
}

template <typename ParamT> auto convert_from_abi_neutral(ParamT &&Info) {
using ParamNoRef = std::remove_reference_t<ParamT>;
if constexpr (std::is_same_v<ParamNoRef, detail::string>) {
return Info.c_str();
} else if constexpr (std::is_same_v<ParamNoRef,
std::vector<detail::string>>) {
std::vector<std::string> Res;
Res.reserve(Info.size());
for (detail::string &Str : Info) {
Res.push_back(Str.c_str());
}
return Res;
} else {
return std::forward<ParamT>(Info);
}
}

} // namespace detail
} // namespace _V1
} // namespace sycl
Expand Down
8 changes: 5 additions & 3 deletions sycl/include/sycl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#pragma once

#include <sycl/aspects.hpp>
#include <sycl/backend_types.hpp>
#include <sycl/detail/defines_elementary.hpp>
#include <sycl/detail/export.hpp>
Expand All @@ -21,9 +20,12 @@
#include <sycl/ext/oneapi/experimental/device_architecture.hpp>
#include <sycl/info/info_desc.hpp>
#include <sycl/kernel_bundle_enums.hpp>
#include <sycl/platform.hpp>
#include <ur_api.h>

#ifdef __SYCL_INTERNAL_API
#include <sycl/detail/cl.h>
#endif

#include <cstddef>
#include <memory>
#include <string>
Expand All @@ -35,7 +37,7 @@
namespace sycl {
inline namespace _V1 {
// Forward declarations
class device_selector;
class platform;
template <backend BackendName, class SyclObjectT>
auto get_native(const SyclObjectT &Obj)
-> backend_return_t<BackendName, SyclObjectT>;
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/ext/intel/esimd/detail/memory_intrin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <sycl/ext/intel/esimd/common.hpp>
#include <sycl/ext/intel/esimd/detail/types.hpp>
#include <sycl/ext/intel/esimd/detail/util.hpp>
#include <sycl/types.hpp>
#include <sycl/vector.hpp>

#include <cstdint>

Expand Down
1 change: 1 addition & 0 deletions sycl/include/sycl/ext/intel/fpga_device_selector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <sycl/device.hpp>
#include <sycl/device_selector.hpp>
#include <sycl/platform.hpp>

#include <string>
#include <string_view>
Expand Down
2 changes: 1 addition & 1 deletion sycl/include/sycl/ext/oneapi/backend/hip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#pragma once

#include <sycl/backend.hpp>
#include <sycl/backend_types.hpp>
#include <sycl/detail/backend_traits_hip.hpp>

namespace sycl {
Expand Down
Loading

0 comments on commit 1910c7c

Please sign in to comment.