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] Remove some OSUtil::* funcs from ABI under -fpreview-breaking-changes #16177

Merged
merged 2 commits into from
Nov 26, 2024
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
16 changes: 13 additions & 3 deletions sycl/include/sycl/detail/os_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,22 @@ namespace detail {

/// Groups the OS-dependent services.
class __SYCL_EXPORT OSUtil {
#if !defined(__INTEL_PREVIEW_BREAKING_CHANGES)
#ifdef _WIN32
// Access control is part of the mangling on Windows, have to preserve this
// for backward ABI compatibility.
public:
/// Returns an absolute path to a directory where the object was found.
static std::string getCurrentDSODir();

#endif
/// Returns a directory component of a path.
static std::string getDirName(const char *Path);
#endif

public:
/// Returns an absolute path to a directory where the object was found.
#if defined(__INTEL_PREVIEW_BREAKING_CHANGES)
__SYCL_DLL_LOCAL
#endif
static std::string getCurrentDSODir();

#ifdef __SYCL_RT_OS_WINDOWS
static constexpr const char *DirSep = "\\";
Expand Down
27 changes: 17 additions & 10 deletions sycl/source/detail/os_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ bool procMapsAddressInRange(std::istream &Stream, uintptr_t Addr) {
return Addr >= Start && Addr < End;
}

#if defined(__INTEL_PREVIEW_BREAKING_CHANGES)
static std::string getDirName(const char *Path)
#else
std::string OSUtil::getDirName(const char *Path)
#endif
{
std::string Tmp(Path);
// dirname(3) needs a writable C string: a null-terminator is written where a
// path should split.
size_t TruncatedSize = strlen(dirname(const_cast<char *>(Tmp.c_str())));
Tmp.resize(TruncatedSize);
return Tmp;
}

/// Returns an absolute path to a directory where the object was found.
std::string OSUtil::getCurrentDSODir() {
// Examine /proc/self/maps and find where this function (getCurrendDSODir)
Expand Down Expand Up @@ -130,21 +144,12 @@ std::string OSUtil::getCurrentDSODir() {
char Path[PATH_MAX];
Stream.getline(Path, PATH_MAX - 1);
Path[PATH_MAX - 1] = '\0';
return OSUtil::getDirName(Path);
return getDirName(Path);
}
assert(false && "Unable to find the current function in /proc/self/maps");
return "";
}

std::string OSUtil::getDirName(const char *Path) {
std::string Tmp(Path);
// dirname(3) needs a writable C string: a null-terminator is written where a
// path should split.
size_t TruncatedSize = strlen(dirname(const_cast<char *>(Tmp.c_str())));
Tmp.resize(TruncatedSize);
return Tmp;
}

#elif defined(__SYCL_RT_OS_WINDOWS)

/// Returns an absolute path where the object was found.
Expand All @@ -169,6 +174,7 @@ std::string OSUtil::getCurrentDSODir() {
return Path;
}

#if !defined(__INTEL_PREVIEW_BREAKING_CHANGES)
std::string OSUtil::getDirName(const char *Path) {
std::string Tmp(Path);
// Remove trailing directory separators
Expand All @@ -181,6 +187,7 @@ std::string OSUtil::getDirName(const char *Path) {
// If no directory separator is present return initial path like dirname does
return Tmp;
}
#endif

#elif defined(__SYCL_RT_OS_DARWIN)
std::string OSUtil::getCurrentDSODir() {
Expand Down
4 changes: 0 additions & 4 deletions sycl/source/detail/persistent_device_code_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ namespace sycl {
inline namespace _V1 {
namespace detail {

/* This is temporary solution until std::filesystem is available when SYCL RT
* is moved to c++17 standard*/
std::string getDirName(const char *Path);

/* The class manages inter-process synchronization:
* - Path passed to the constructor is appended with .lock and used as lock
* file.
Expand Down
2 changes: 1 addition & 1 deletion sycl/tools/sycl-trace/collector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sycl::detail::SpinLock GlobalLock;

bool HasZEPrinter = false;

std::string getCurrentDSODir() {
static std::string getCurrentDSODir() {
auto CurrentFunc = reinterpret_cast<const void *>(&getCurrentDSODir);
Dl_info Info;
int RetCode = dladdr(CurrentFunc, &Info);
Expand Down
2 changes: 1 addition & 1 deletion sycl/ur_win_proxy_loader/ur_win_proxy_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static OSModuleHandle getOSModuleHandle(const void *VirtAddr) {

// cribbed from sycl/source/detail/os_util.cpp
/// Returns an absolute path where the object was found.
std::wstring getCurrentDSODir() {
static std::wstring getCurrentDSODir() {
wchar_t Path[MAX_PATH];
auto Handle = getOSModuleHandle(reinterpret_cast<void *>(&getCurrentDSODir));
DWORD Ret = GetModuleFileName(
Expand Down