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] Initial changes for C++11 ABI=0 support #12193

Merged
merged 115 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
2d34c19
[SYCL] Initial change for C++11 ABI=0 support
bso-intel Dec 15, 2023
4dabfd3
clang-format fix
bso-intel Dec 15, 2023
108bf4d
Merge remote-tracking branch 'upstream/sycl' into abi
bso-intel Dec 15, 2023
d7f21ab
clang-format
bso-intel Dec 15, 2023
34cd0b9
format
bso-intel Dec 15, 2023
ded92db
fix mockup
bso-intel Dec 15, 2023
77aaeba
fix test
bso-intel Dec 15, 2023
fa6a931
fix test
bso-intel Dec 15, 2023
5709e28
fix test
bso-intel Dec 15, 2023
da8ab9f
address feedback
bso-intel Jan 4, 2024
841f042
clang-format
bso-intel Jan 4, 2024
a79d58f
guard preview-break-changes
bso-intel Jan 9, 2024
74bb97d
Update sycl/include/sycl/platform.hpp
bso-intel Jan 10, 2024
7cebd8d
guard
bso-intel Jan 10, 2024
20448f7
added comments
bso-intel Jan 11, 2024
95f48f8
adjusted comment
bso-intel Jan 11, 2024
f0aa89c
added support for get_kernel_id
bso-intel Jan 17, 2024
a1e4479
changed param type to reference
bso-intel Jan 23, 2024
312cda8
clang-format
bso-intel Jan 23, 2024
1db3ca8
separate string and string_view
bso-intel Jan 23, 2024
d83490d
address feedback
bso-intel Jan 24, 2024
273f4b0
removed marshall
bso-intel Jan 24, 2024
ac1ee03
address feedback
bso-intel Jan 24, 2024
436288b
fixed typo in comments
bso-intel Jan 24, 2024
84f8e2d
fixed again
bso-intel Jan 24, 2024
db67a87
address feedback
bso-intel Jan 25, 2024
66c0405
Update sycl/include/sycl/detail/string.hpp
bso-intel Jan 25, 2024
4823b25
Update sycl/include/sycl/detail/string.hpp
bso-intel Jan 25, 2024
cff7fae
remove
bso-intel Jan 25, 2024
3af523e
remove
bso-intel Jan 25, 2024
f918818
fix string_view
bso-intel Jan 25, 2024
316627a
address feedback
bso-intel Jan 25, 2024
741db80
include
bso-intel Jan 25, 2024
2db4e56
Update sycl/include/sycl/detail/string.hpp
bso-intel Jan 26, 2024
22a59c6
address feedback
bso-intel Jan 26, 2024
4e28f9f
address feedback
bso-intel Jan 31, 2024
e24da9c
missed char
bso-intel Jan 31, 2024
f707404
Merge branch 'sycl' into abi
bso-intel Jan 31, 2024
272e400
support return vec
bso-intel Feb 1, 2024
67ecf71
address feedback
bso-intel Feb 1, 2024
e385649
address feedback again
bso-intel Feb 5, 2024
8a9aaaf
pass std::string_view by value
bso-intel Feb 5, 2024
2adf0fb
more feedback
bso-intel Feb 6, 2024
a309a8d
ref removed
bso-intel Feb 6, 2024
537491d
fix
bso-intel Feb 6, 2024
8fc92b8
remove refs
bso-intel Feb 6, 2024
f9a9af4
return empty string
bso-intel Feb 6, 2024
0aa4158
default move
bso-intel Feb 7, 2024
b51cb8a
Update sycl/include/sycl/detail/string_view.hpp
bso-intel Feb 7, 2024
6e7da0a
feedback addressed
bso-intel Feb 7, 2024
05a0ca1
support exception
bso-intel Feb 8, 2024
ecb8ce9
Update sycl/include/sycl/handler.hpp
bso-intel Feb 9, 2024
6f36028
more feedback addressed
bso-intel Feb 9, 2024
f4655aa
fix get_info
bso-intel Feb 10, 2024
a04fc0c
fix platform prop
bso-intel Feb 11, 2024
a803e6d
replace string with enum
bso-intel Feb 12, 2024
a22fd4a
variant return struct
bso-intel Feb 13, 2024
429c7a3
fix errors
bso-intel Feb 14, 2024
b18eb02
added missing declaration
bso-intel Feb 14, 2024
4f0d634
fixed return type
bso-intel Feb 14, 2024
9d9cf42
cleanup comments
bso-intel Feb 14, 2024
921b754
silence the return type error
bso-intel Feb 14, 2024
bf313f1
fixed undefined reference
bso-intel Feb 14, 2024
32a0401
fixed undefined refs
bso-intel Feb 14, 2024
431ac8d
use template
bso-intel Feb 14, 2024
a4c2ffa
fix platform template
bso-intel Feb 15, 2024
273248b
fix duplicate
bso-intel Feb 15, 2024
182afc7
fix export
bso-intel Feb 15, 2024
0a97845
common returntype
bso-intel Feb 15, 2024
d62e175
unify preview
bso-intel Feb 16, 2024
3fdd985
revert
bso-intel Feb 16, 2024
8d1fa21
reduce to one method
bso-intel Feb 16, 2024
232e759
Update sycl/include/sycl/device.hpp
bso-intel Feb 16, 2024
019d30b
Update sycl/include/sycl/detail/util.hpp
bso-intel Feb 16, 2024
36e5dd8
Update sycl/include/sycl/detail/util.hpp
bso-intel Feb 16, 2024
b074631
Update sycl/include/sycl/platform.hpp
bso-intel Feb 16, 2024
524d53d
Update sycl/source/device.cpp
bso-intel Feb 16, 2024
4f9b8d4
Update sycl/source/platform.cpp
bso-intel Feb 16, 2024
fa1ae30
address feedback
bso-intel Feb 16, 2024
7095cf7
fix win abi symbols
bso-intel Feb 16, 2024
d6c7ddc
try alias
bso-intel Feb 19, 2024
82febee
missed #ifdef
bso-intel Feb 19, 2024
1748dea
fake detail::string
bso-intel Feb 19, 2024
5a37c73
Merge branch 'sergey2' into abi
bso-intel Feb 19, 2024
7780ca5
remove #ifdef
bso-intel Feb 20, 2024
3bc950d
add symbol
bso-intel Feb 20, 2024
0bf1237
windows symbol
bso-intel Feb 20, 2024
f31b89c
avoid duplicate body
bso-intel Feb 21, 2024
037a13b
Merge branch 'abi' of https://github.com/bso-intel/llvm into abi
bso-intel Feb 21, 2024
962fa26
try template
bso-intel Feb 22, 2024
d6ab3ca
template
bso-intel Feb 22, 2024
7eb7314
Merge remote-tracking branch 'upstream/sycl' into abi
bso-intel Feb 22, 2024
a11280e
rename
bso-intel Feb 22, 2024
f85a76a
remove param
bso-intel Feb 23, 2024
1327442
define ABINeutralT_t
bso-intel Feb 23, 2024
05dc42d
deduce
bso-intel Feb 23, 2024
050509e
moved namespace
bso-intel Feb 23, 2024
dd8e563
Update sycl/include/sycl/platform.hpp
bso-intel Feb 27, 2024
ffa36e1
Update sycl/source/device.cpp
bso-intel Feb 27, 2024
5c0b8a1
Update sycl/source/device.cpp
bso-intel Feb 27, 2024
28ad4fc
Update sycl/source/device.cpp
bso-intel Feb 27, 2024
823614d
Update sycl/include/sycl/platform.hpp
bso-intel Feb 27, 2024
c702858
change return type
bso-intel Feb 27, 2024
f1bf10d
WIP
aelovikov-intel Feb 27, 2024
43a7823
WIP2
aelovikov-intel Feb 27, 2024
37be2ba
WIP3
aelovikov-intel Feb 27, 2024
82908d5
WIP4
aelovikov-intel Feb 27, 2024
1ca910c
This is an ABI break
aelovikov-intel Feb 27, 2024
d88422a
But not anymore if do it like this.
aelovikov-intel Feb 27, 2024
b48f868
Merge remote-tracking branch 'andrei1/for-byoungro' into andrei3
bso-intel Feb 27, 2024
6e18644
merge
bso-intel Feb 27, 2024
0d19467
address feedback
bso-intel Feb 28, 2024
85b7d36
keep both
bso-intel Feb 28, 2024
b79a347
Update sycl/source/device.cpp
bso-intel Feb 29, 2024
1650d6d
Update sycl/include/sycl/device.hpp
bso-intel Feb 29, 2024
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
31 changes: 28 additions & 3 deletions sycl/include/sycl/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
#include <sycl/ext/oneapi/experimental/device_architecture.hpp> // for arch...
#include <sycl/info/info_desc.hpp> // for part...
#include <sycl/platform.hpp> // for plat...
#include <sycl/string.hpp> // for c++11 abi compatibility
bader marked this conversation as resolved.
Show resolved Hide resolved

#include <cstddef> // for size_t
#include <memory> // for shar...
#include <string> // for string
#include <type_traits> // for add_...
#include <variant> // for hash
#include <vector> // for vector
#include <typeinfo>
#include <variant> // for hash
#include <vector> // for vector

namespace sycl {
inline namespace _V1 {
Expand Down Expand Up @@ -215,7 +217,24 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase<device> {
///
/// \return device info of type described in Table 4.20.
template <typename Param>
typename detail::is_device_info_desc<Param>::return_type get_info() const;
typename detail::is_device_info_desc<Param>::return_type get_info() const {
// For C++11_ABI compatibility, we handle these string Param types
// separately.
if constexpr (std::is_same_v<Param, info::device::name> ||
std::is_same_v<Param, info::device::vendor> ||
std::is_same_v<Param, info::device::driver_version> ||
std::is_same_v<Param, info::device::version> ||
std::is_same_v<Param, info::device::profile>) {

string Info = typeid(Param).name();
Info.allocate(100);
get_device_info(Info);
std::string DeviceInfo = Info.marshall();
Info.deallocate();
return DeviceInfo;
}
return get_info_internal<Param>();
}

/// Check SYCL extension support by device
///
Expand Down Expand Up @@ -291,6 +310,12 @@ class __SYCL_EXPORT device : public detail::OwnerLessBase<device> {
template <backend BackendName, class SyclObjectT>
friend auto get_native(const SyclObjectT &Obj)
-> backend_return_t<BackendName, SyclObjectT>;

template <typename Param>
typename detail::is_device_info_desc<Param>::return_type
get_info_internal() const;
// proxy of get_info_internal() to handle C++11-ABI compatibility separately.
void get_device_info(string &Type) const;
};

} // namespace _V1
Expand Down
5 changes: 4 additions & 1 deletion sycl/include/sycl/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ class __SYCL_EXPORT exception : public virtual std::exception {
// exception(context *ctxPtr, std::error_code ec, const std::string
// &what_arg);
exception(std::error_code ec, std::shared_ptr<context> SharedPtrCtx,
bso-intel marked this conversation as resolved.
Show resolved Hide resolved
const std::string &what_arg);
const std::string &what_arg)
: exception(ec, SharedPtrCtx, what_arg.c_str()) {}
exception(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,
const char *WhatArg);
};

class __SYCL2020_DEPRECATED(
Expand Down
25 changes: 19 additions & 6 deletions sycl/include/sycl/handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#include <sycl/property_list.hpp>
#include <sycl/range.hpp>
#include <sycl/sampler.hpp>
#include <sycl/string.hpp>
#include <sycl/types.hpp>
#include <sycl/usm/usm_enums.hpp>
#include <sycl/usm/usm_pointer_info.hpp>
Expand Down Expand Up @@ -548,7 +549,7 @@ class __SYCL_EXPORT handler {
bool IsKernelCreatedFromSource, bool IsESIMD);

/// \return a string containing name of SYCL kernel.
std::string getKernelName();
string getKernelName();

template <typename LambdaNameT> bool lambdaAndKernelHaveEqualName() {
// TODO It is unclear a kernel and a lambda/functor must to be equal or not
Expand All @@ -558,8 +559,8 @@ class __SYCL_EXPORT handler {
// values of arguments for the kernel.
assert(MKernel && "MKernel is not initialized");
const std::string LambdaName = detail::KernelInfo<LambdaNameT>::getName();
const std::string KernelName = getKernelName();
return LambdaName == KernelName;
string KernelName = getKernelName();
return LambdaName == KernelName.marshall();
}

/// Saves the location of user's code passed in \p CodeLoc for future usage in
Expand Down Expand Up @@ -842,7 +843,11 @@ class __SYCL_EXPORT handler {
///
/// \param KernelName is the name of the SYCL kernel to check that the used
/// kernel bundle contains.
void verifyUsedKernelBundle(const std::string &KernelName);
void verifyUsedKernelBundle(const std::string &KernelName) {
string Name = string(KernelName);
verifyUsedKernelBundleInternal(Name);
}
void verifyUsedKernelBundleInternal(string &KernelName);

/// Stores lambda to the template-free object
///
Expand Down Expand Up @@ -3294,7 +3299,7 @@ class __SYCL_EXPORT handler {
std::vector<detail::ArgDesc> MAssociatedAccesors;
/// Struct that encodes global size, local size, ...
detail::NDRDescT MNDRDesc;
std::string MKernelName;
string MKernelName;
/// Storage for a sycl::kernel object.
std::shared_ptr<detail::kernel_impl> MKernel;
/// Type of the command group, e.g. kernel, fill. Can also encode version.
Expand Down Expand Up @@ -3397,6 +3402,10 @@ class __SYCL_EXPORT handler {
/// \param Size the size of data getting read back / to.
/// \param Block if read operation is blocking, default to false.
void ext_intel_read_host_pipe(const std::string &Name, void *Ptr, size_t Size,
bool Block = false) {
ext_intel_read_host_pipe(string(Name), Ptr, Size, Block);
}
void ext_intel_read_host_pipe(string Name, void *Ptr, size_t Size,
bool Block = false);

/// Write to host pipes given a host address and
Expand All @@ -3406,7 +3415,11 @@ class __SYCL_EXPORT handler {
/// \param Size the size of data getting read back / to.
/// \param Block if write opeartion is blocking, default to false.
void ext_intel_write_host_pipe(const std::string &Name, void *Ptr,
size_t Size, bool Block = false);
size_t Size, bool Block = false) {
ext_intel_write_host_pipe(string(Name), Ptr, Size, Block);
}
void ext_intel_write_host_pipe(string Name, void *Ptr, size_t Size,
bool Block = false);
friend class ext::oneapi::experimental::detail::graph_impl;

bool DisableRangeRounding();
Expand Down
25 changes: 24 additions & 1 deletion sycl/include/sycl/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <sycl/detail/pi.h> // for pi_native_handle
#include <sycl/device_selector.hpp> // for EnableIfSYCL2020DeviceS...
#include <sycl/info/info_desc.hpp> // for device_type
#include <sycl/string.hpp>

#ifdef __SYCL_INTERNAL_API
#include <sycl/detail/cl.h>
Expand Down Expand Up @@ -145,7 +146,23 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
///
/// The return type depends on information being queried.
template <typename Param>
typename detail::is_platform_info_desc<Param>::return_type get_info() const;
typename detail::is_platform_info_desc<Param>::return_type get_info() const {
// For C++11_ABI compatibility, we handle these string Param types
bso-intel marked this conversation as resolved.
Show resolved Hide resolved
// separately.
if constexpr (std::is_same_v<Param, info::platform::name> ||
std::is_same_v<Param, info::platform::vendor> ||
std::is_same_v<Param, info::platform::version> ||
std::is_same_v<Param, info::platform::profile>) {

string Info = typeid(Param).name();
Info.allocate(100);
get_platform_info(Info);
std::string PlatformInfo = Info.marshall();
Info.deallocate();
return PlatformInfo;
}
return get_info_internal<Param>();
}

/// Returns all available SYCL platforms in the system.
///
Expand Down Expand Up @@ -204,6 +221,12 @@ class __SYCL_EXPORT platform : public detail::OwnerLessBase<platform> {
template <backend BackendName, class SyclObjectT>
friend auto get_native(const SyclObjectT &Obj)
-> backend_return_t<BackendName, SyclObjectT>;

template <typename Param>
typename detail::is_platform_info_desc<Param>::return_type
get_info_internal() const;
// proxy of get_info_internal() to handle C++11-ABI compatibility separately.
void get_platform_info(string &Type) const;
}; // class platform
} // namespace _V1
} // namespace sycl
Expand Down
42 changes: 42 additions & 0 deletions sycl/include/sycl/string.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//==----------------- string.hpp - SYCL standard header file ---------------==//
//
// 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
//
//===----------------------------------------------------------------------===//
#include <iostream>
bader marked this conversation as resolved.
Show resolved Hide resolved

#pragma once

namespace sycl {
inline namespace _V1 {

class string {
const char *str; // used to send existing std::string to libsycl
char *ret_str; // set from libsycl
bader marked this conversation as resolved.
Show resolved Hide resolved

public:
string() : str(nullptr), ret_str(nullptr) {}
string(const char *ptr) : str(ptr) {}
string(std::string strn) : str(strn.c_str()) {}

bool operator==(const char *st) { return strcmp(str, st) == 0; }

std::string marshall() { return std::string(ret_str); }

std::string marshall() const { return std::string(ret_str); }

void unmarshall(std::string &strn) { strcpy(ret_str, strn.c_str()); }

void allocate(int size) { ret_str = new char[size]; }

void deallocate() { delete[] ret_str; }

const char *getPtr() { return str; }

char *getRetPtr() { return ret_str; }
};

} // namespace _V1
} // namespace sycl
bader marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions sycl/include/sycl/sycl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <sycl/sampler.hpp>
#include <sycl/specialization_id.hpp>
#include <sycl/stream.hpp>
#include <sycl/string.hpp>
#include <sycl/sub_group.hpp>
#include <sycl/types.hpp>
#include <sycl/usm.hpp>
Expand Down
6 changes: 3 additions & 3 deletions sycl/source/detail/queue_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,9 @@ class queue_impl {

if (IsKernel)
// Kernel only uses assert if it's non interop one
KernelUsesAssert =
!(Handler.MKernel && Handler.MKernel->isInterop()) &&
ProgramManager::getInstance().kernelUsesAssert(Handler.MKernelName);
KernelUsesAssert = !(Handler.MKernel && Handler.MKernel->isInterop()) &&
ProgramManager::getInstance().kernelUsesAssert(
Handler.MKernelName.marshall());

finalizeHandler(Handler, Type, Event);

Expand Down
35 changes: 29 additions & 6 deletions sycl/source/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <sycl/info/info_desc.hpp>

#include <algorithm>
#include <typeinfo>
bso-intel marked this conversation as resolved.
Show resolved Hide resolved

namespace sycl {
inline namespace _V1 {
Expand Down Expand Up @@ -133,13 +134,33 @@ bool device::has_extension(const std::string &extension_name) const {

template <typename Param>
typename detail::is_device_info_desc<Param>::return_type
device::get_info() const {
device::get_info_internal() const {
return impl->template get_info<Param>();
bso-intel marked this conversation as resolved.
Show resolved Hide resolved
}

bso-intel marked this conversation as resolved.
Show resolved Hide resolved
void device::get_device_info(string &Type) const {
std::string Info;
if (Type == typeid(info::device::name).name()) {
Info = impl->template get_info<info::device::name>();
} else if (Type == typeid(info::device::vendor).name()) {
Info = impl->template get_info<info::device::vendor>();
} else if (Type == typeid(info::device::driver_version).name()) {
Info = impl->template get_info<info::device::driver_version>();
} else if (Type == typeid(info::device::version).name()) {
Info = impl->template get_info<info::device::version>();
} else if (Type == typeid(info::device::profile).name()) {
Info = impl->template get_info<info::device::profile>();
} else {
throw sycl::invalid_parameter_error("unsupported device info requested",
PI_ERROR_INVALID_OPERATION);
}
Type.unmarshall(Info);
}

// Explicit override. Not fulfilled by #include device_traits.def below.
template <>
__SYCL_EXPORT device device::get_info<info::device::parent_device>() const {
__SYCL_EXPORT device
device::get_info_internal<info::device::parent_device>() const {
// With ONEAPI_DEVICE_SELECTOR the impl.MRootDevice is preset and may be
// overridden (ie it may be nullptr on a sub-device) The PI of the sub-devices
// have parents, but we don't want to return them. They must pretend to be
Expand All @@ -154,7 +175,7 @@ __SYCL_EXPORT device device::get_info<info::device::parent_device>() const {

template <>
__SYCL_EXPORT std::vector<sycl::aspect>
device::get_info<info::device::aspects>() const {
device::get_info_internal<info::device::aspects>() const {
std::vector<sycl::aspect> DeviceAspects{
#define __SYCL_ASPECT(ASPECT, ID) aspect::ASPECT,
#include <sycl/info/aspects.def>
Expand All @@ -178,14 +199,16 @@ device::get_info<info::device::aspects>() const {
}

template <>
__SYCL_EXPORT bool device::get_info<info::device::image_support>() const {
__SYCL_EXPORT bool
device::get_info_internal<info::device::image_support>() const {
// Explicit specialization is needed due to the class of info handle. The
// implementation is done in get_device_info_impl.
return impl->template get_info<info::device::image_support>();
}

#define __SYCL_PARAM_TRAITS_SPEC(DescType, Desc, ReturnT, PiCode) \
template __SYCL_EXPORT ReturnT device::get_info<info::device::Desc>() const;
template __SYCL_EXPORT ReturnT \
device::get_info_internal<info::device::Desc>() const;

#define __SYCL_PARAM_TRAITS_SPEC_SPECIALIZED(DescType, Desc, ReturnT, PiCode)

Expand All @@ -195,7 +218,7 @@ __SYCL_EXPORT bool device::get_info<info::device::image_support>() const {

#define __SYCL_PARAM_TRAITS_SPEC(Namespace, DescType, Desc, ReturnT, PiCode) \
template __SYCL_EXPORT ReturnT \
device::get_info<Namespace::info::DescType::Desc>() const;
device::get_info_internal<Namespace::info::DescType::Desc>() const;

#include <sycl/info/ext_codeplay_device_traits.def>
#include <sycl/info/ext_intel_device_traits.def>
Expand Down
2 changes: 1 addition & 1 deletion sycl/source/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ exception::exception(context Ctx, int EV, const std::error_category &ECat)

// protected base constructor for all SYCL 2020 constructors
exception::exception(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,
const std::string &WhatArg)
const char *WhatArg)
: MMsg(std::make_shared<std::string>(WhatArg)),
MPIErr(PI_ERROR_INVALID_VALUE), MContext(SharedPtrCtx), MErrC(EC) {
detail::GlobalHandler::instance().TraceEventXPTI(MMsg->c_str());
Expand Down
Loading
Loading