Skip to content

Commit

Permalink
Merge pull request #1201 from pbalcer/getenv-ur-hpp
Browse files Browse the repository at this point in the history
[common] remove the use of std::getenv from common code
  • Loading branch information
pbalcer authored Dec 22, 2023
2 parents 8c2d93d + f16d31d commit a05c96d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion source/common/ur_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include <vector>

#ifdef _WIN32
#define NOMINMAX

#include <windows.h>
inline int ur_getpid(void) { return static_cast<int>(GetCurrentProcessId()); }
#else
Expand Down Expand Up @@ -59,7 +61,6 @@ inline int ur_getpid(void) { return static_cast<int>(getpid()); }
#endif
///////////////////////////////////////////////////////////////////////////////
#if defined(_WIN32)
#include <Windows.h>
#define MAKE_LIBRARY_NAME(NAME, VERSION) NAME ".dll"
#else
#define HMODULE void *
Expand Down
9 changes: 6 additions & 3 deletions source/ur/ur.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

#include <ur_api.h>

#include "ur_util.hpp"

template <class To, class From> To ur_cast(From Value) {
// TODO: see if more sanity checks are possible.
assert(sizeof(From) == sizeof(To));
Expand Down Expand Up @@ -61,9 +63,10 @@ const ur_command_t UR_EXT_COMMAND_TYPE_USER =
// overhead from mutex locking. Default value is 0 which means that single
// thread mode is disabled.
static const bool SingleThreadMode = [] {
const char *UrRet = std::getenv("UR_L0_SINGLE_THREAD_MODE");
const char *PiRet = std::getenv("SYCL_PI_LEVEL_ZERO_SINGLE_THREAD_MODE");
const bool RetVal = UrRet ? std::stoi(UrRet) : (PiRet ? std::stoi(PiRet) : 0);
auto UrRet = ur_getenv("UR_L0_SINGLE_THREAD_MODE");
auto PiRet = ur_getenv("SYCL_PI_LEVEL_ZERO_SINGLE_THREAD_MODE");
const bool RetVal =
UrRet ? std::stoi(*UrRet) : (PiRet ? std::stoi(*PiRet) : 0);
return RetVal;
}();

Expand Down

0 comments on commit a05c96d

Please sign in to comment.