-
Notifications
You must be signed in to change notification settings - Fork 751
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL] Initial changes for C++11 ABI=0 support (#12193)
This PR attempts to support the usage case where the user sets _GLIBCXX_USE_CXX11_ABI=0 to use pre-C++11 ABI. In fact, this change addresses a specific issue with using different versions of the libstdc++ library (https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html has more details on this issue). One of the major changes I made in this PR involves calling `get_info<>()` API, which can return `stdA::string` as the requested information. Due to the ABI incompatibility issues, this API internally splits into 3 cases depending on the template parameter `<T>`. 1. `<T>`s that return a `std::string`. 2. `<T>`s that return a `std::vector<std::string>` 3. `<T>`s that return something other than 1 or 2 above. The case 1 and 2 should return `detail::string` and `std::vector<detail::string>` instead and reconstruct `std::string`s. This is required because ABIs can be different between the header and CPP files. All these 3 cases are implemented using `get_info_impl<T>`. Then, I changed the macro definition of `__SYCL_PARAM_TRAITS_SPEC` to return different types depending on the `<T>` return_types. This way, we can only change the boundary between the header file and the entry point of the libsycl. --------- Signed-off-by: Byoungro So <byoungro.so@intel.com> Co-authored-by: Alexey Bader <alexey.bader@intel.com> Co-authored-by: Victor Perez <victor.perez@intel.com> Co-authored-by: Julian Oppermann <julian.oppermann@codeplay.com> Co-authored-by: aelovikov-intel <andrei.elovikov@intel.com> Co-authored-by: Sergey Semenov <sergey.semenov@intel.com>
- Loading branch information
1 parent
f639a20
commit 459e122
Showing
16 changed files
with
467 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//==----------------- 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 <cstring> | ||
#include <string> | ||
|
||
#pragma once | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
namespace detail { | ||
|
||
// This class and detail::string_view class are intended to support | ||
// different ABIs between libsycl and the user program. | ||
// This class is not inteded to replace std::string for general purpose usage. | ||
class string { | ||
char *str = nullptr; | ||
|
||
public: | ||
string() noexcept = default; | ||
~string() { delete[] str; } | ||
|
||
string(std::string_view strn) { | ||
size_t len = strn.length(); | ||
str = new char[len + 1]; | ||
strn.copy(str, len); | ||
str[len] = 0; | ||
} | ||
|
||
friend void swap(string &lhs, string &rhs) noexcept { | ||
std::swap(lhs.str, rhs.str); | ||
} | ||
|
||
string(string &&other) noexcept { swap(*this, other); } | ||
string(const string &other) { | ||
if (other.str == nullptr) | ||
return; | ||
*this = string{other.str}; | ||
} | ||
|
||
string &operator=(string &&other) noexcept { | ||
swap(*this, other); | ||
return *this; | ||
} | ||
string &operator=(const string &other) { | ||
*this = string{other}; | ||
return *this; | ||
} | ||
|
||
string &operator=(std::string_view strn) { | ||
*this = string{strn}; | ||
return *this; | ||
} | ||
|
||
const char *c_str() const noexcept { return str ? str : ""; } | ||
|
||
friend bool operator==(const string &lhs, std::string_view rhs) noexcept { | ||
return rhs == lhs.c_str(); | ||
} | ||
friend bool operator==(std::string_view lhs, const string &rhs) noexcept { | ||
return lhs == rhs.c_str(); | ||
} | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace _V1 | ||
} // namespace sycl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//==-------------- string_view.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 <string> | ||
|
||
#pragma once | ||
|
||
namespace sycl { | ||
inline namespace _V1 { | ||
namespace detail { | ||
|
||
// This class and detail::string class are intended to support | ||
// different ABIs between libsycl and the user program. | ||
// This class is not inteded to replace std::string_view for general purpose | ||
// usage. | ||
class string_view { | ||
const char *str = nullptr; | ||
|
||
public: | ||
string_view() noexcept = default; | ||
string_view(const string_view &strn) noexcept = default; | ||
string_view(string_view &&strn) noexcept = default; | ||
string_view(std::string_view strn) noexcept : str(strn.data()) {} | ||
|
||
string_view &operator=(string_view &&strn) noexcept = default; | ||
string_view &operator=(const string_view &strn) noexcept = default; | ||
|
||
string_view &operator=(std::string_view strn) noexcept { | ||
str = strn.data(); | ||
return *this; | ||
} | ||
|
||
const char *data() const noexcept { return str; } | ||
|
||
friend bool operator==(const string_view &lhs, | ||
std::string_view rhs) noexcept { | ||
return rhs == lhs.data(); | ||
} | ||
friend bool operator==(std::string_view lhs, | ||
const string_view &rhs) noexcept { | ||
return lhs == rhs.data(); | ||
} | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace _V1 | ||
} // namespace sycl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.