Skip to content

[SYCL][ABI-Break] Remove sycl::exception error code member workaround #6578

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
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
2 changes: 1 addition & 1 deletion sycl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ set(SYCL_MINOR_VERSION 7)
set(SYCL_PATCH_VERSION 0)
# Don't forget to re-enable sycl_symbols_windows.dump once we leave ABI-breaking
# window!
set(SYCL_DEV_ABI_VERSION 7)
set(SYCL_DEV_ABI_VERSION 8)
if (SYCL_ADD_DEV_VERSION_POSTFIX)
set(SYCL_VERSION_POSTFIX "-${SYCL_DEV_ABI_VERSION}")
endif()
Expand Down
1 change: 1 addition & 0 deletions sycl/include/sycl/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class __SYCL_EXPORT exception : public std::exception {
std::shared_ptr<std::string> MMsg;
pi_int32 MPIErr;
std::shared_ptr<context> MContext;
std::error_code MErrC = make_error_code(sycl::errc::invalid);

protected:
// these two constructors are no longer used. Kept for ABI compatability.
Expand Down
36 changes: 3 additions & 33 deletions sycl/source/exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@
namespace sycl {
__SYCL_INLINE_VER_NAMESPACE(_V1) {

namespace { // anonymous
constexpr char ReservedForErrorcode[] =
"01234567812345678"; // 17 (string terminator plus error code)
std::error_code SYCL121ProxyErrorcode = make_error_code(sycl::errc::invalid);
} // namespace

exception::exception(std::error_code EC, const char *Msg)
: exception(EC, nullptr, Msg) {}

Expand Down Expand Up @@ -65,35 +59,11 @@ 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)
: MMsg(std::make_shared<std::string>(WhatArg + ReservedForErrorcode)),
MPIErr(PI_ERROR_INVALID_VALUE), MContext(SharedPtrCtx) {
// For compatibility with previous implementation, we are "hiding" the
// std::error_code in the MMsg string, behind the null string terminator
const int StringTermPoint = MMsg->length() - strlen(ReservedForErrorcode);
char *ReservedPtr = &(*MMsg)[StringTermPoint];
ReservedPtr[0] = '\0';
ReservedPtr++;
// insert error code
std::error_code *ECPtr = reinterpret_cast<std::error_code *>(ReservedPtr);
memcpy(ECPtr, &EC, sizeof(std::error_code));
}
: MMsg(std::make_shared<std::string>(WhatArg)),
MPIErr(PI_ERROR_INVALID_VALUE), MContext(SharedPtrCtx), MErrC(EC) {}

const std::error_code &exception::code() const noexcept {
const char *WhatStr = MMsg->c_str();
// advance to inner string-terminator
int StringTermPoint = MMsg->length() - strlen(ReservedForErrorcode);
if (StringTermPoint >= 0) {
const char *ReservedPtr = &WhatStr[StringTermPoint];
// check for string terminator, which denotes a SYCL 2020 exception
if (ReservedPtr[0] == '\0') {
ReservedPtr++;
const std::error_code *ECPtr =
reinterpret_cast<const std::error_code *>(ReservedPtr);
return *ECPtr;
}
}
// else the exception originates from some SYCL 1.2.1 source
return SYCL121ProxyErrorcode;
return MErrC;
}

const std::error_category &exception::category() const noexcept {
Expand Down