Skip to content

Commit 1732c6b

Browse files
committed
Merge branch 'main' into cooperative_kernel_functions
Signed-off-by: Michael Aziz <michael.aziz@intel.com>
2 parents dd7c94c + 92f44da commit 1732c6b

File tree

6 files changed

+60
-37
lines changed

6 files changed

+60
-37
lines changed

source/adapters/level_zero/event.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,13 +625,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventWait(
625625
///< events to wait for completion
626626
) {
627627
for (uint32_t I = 0; I < NumEvents; I++) {
628-
if (EventWaitList[I]->UrQueue->ZeEventsScope == OnDemandHostVisibleProxy) {
628+
auto e = EventWaitList[I];
629+
if (e->UrQueue && e->UrQueue->ZeEventsScope == OnDemandHostVisibleProxy) {
629630
// Make sure to add all host-visible "proxy" event signals if needed.
630631
// This ensures that all signalling commands are submitted below and
631632
// thus proxy events can be waited without a deadlock.
632633
//
633-
ur_event_handle_t_ *Event =
634-
ur_cast<ur_event_handle_t_ *>(EventWaitList[I]);
634+
ur_event_handle_t_ *Event = ur_cast<ur_event_handle_t_ *>(e);
635635
if (!Event->hasExternalRefs())
636636
die("urEventsWait must not be called for an internal event");
637637

@@ -782,6 +782,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle(
782782
Context, UR_EXT_COMMAND_TYPE_USER,
783783
Properties->isNativeHandleOwned);
784784

785+
UREvent->RefCountExternal++;
786+
785787
} catch (const std::bad_alloc &) {
786788
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
787789
} catch (...) {

source/common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ add_subdirectory(umf_pools)
99
add_ur_library(ur_common STATIC
1010
umf_helpers.hpp
1111
ur_pool_manager.hpp
12+
ur_util.cpp
13+
ur_util.hpp
1214
$<$<PLATFORM_ID:Windows>:windows/ur_lib_loader.cpp>
1315
$<$<PLATFORM_ID:Linux,Darwin>:linux/ur_lib_loader.cpp>
1416
)

source/common/ur_lib_loader.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
#include <memory>
1414

15-
#include "ur_util.hpp"
15+
#if _WIN32
16+
#include <windows.h>
17+
#else
18+
#define HMODULE void *
19+
#endif
1620

1721
namespace ur_loader {
1822

source/common/ur_util.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
*
3+
* Copyright (C) 2022-2023 Intel Corporation
4+
*
5+
* Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
6+
* See LICENSE.TXT
7+
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8+
*
9+
*/
10+
11+
#include "ur_util.hpp"
12+
13+
#ifdef _WIN32
14+
#include <windows.h>
15+
int ur_getpid(void) { return static_cast<int>(GetCurrentProcessId()); }
16+
#else
17+
18+
#include <unistd.h>
19+
int ur_getpid(void) { return static_cast<int>(getpid()); }
20+
#endif
21+
22+
std::optional<std::string> ur_getenv(const char *name) {
23+
#if defined(_WIN32)
24+
constexpr int buffer_size = 1024;
25+
char buffer[buffer_size];
26+
auto rc = GetEnvironmentVariableA(name, buffer, buffer_size);
27+
if (0 != rc && rc < buffer_size) {
28+
return std::string(buffer);
29+
} else if (rc >= buffer_size) {
30+
std::stringstream ex_ss;
31+
ex_ss << "Environment variable " << name << " value too long!"
32+
<< " Maximum length is " << buffer_size - 1 << " characters.";
33+
throw std::invalid_argument(ex_ss.str());
34+
}
35+
return std::nullopt;
36+
#else
37+
const char *tmp_env = getenv(name);
38+
if (tmp_env != nullptr) {
39+
return std::string(tmp_env);
40+
} else {
41+
return std::nullopt;
42+
}
43+
#endif
44+
}

source/common/ur_util.hpp

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,7 @@
2121
#include <string>
2222
#include <vector>
2323

24-
#ifdef _WIN32
25-
#include <windows.h>
26-
inline int ur_getpid(void) { return static_cast<int>(GetCurrentProcessId()); }
27-
#else
28-
29-
#include <unistd.h>
30-
inline int ur_getpid(void) { return static_cast<int>(getpid()); }
31-
#endif
24+
int ur_getpid(void);
3225

3326
/* for compatibility with non-clang compilers */
3427
#if defined(__has_feature)
@@ -61,7 +54,6 @@ inline int ur_getpid(void) { return static_cast<int>(getpid()); }
6154
#if defined(_WIN32)
6255
#define MAKE_LIBRARY_NAME(NAME, VERSION) NAME ".dll"
6356
#else
64-
#define HMODULE void *
6557
#if defined(__APPLE__)
6658
#define MAKE_LIBRARY_NAME(NAME, VERSION) "lib" NAME "." VERSION ".dylib"
6759
#else
@@ -93,29 +85,7 @@ inline std::string create_library_path(const char *name, const char *path) {
9385
#endif
9486

9587
///////////////////////////////////////////////////////////////////////////////
96-
inline std::optional<std::string> ur_getenv(const char *name) {
97-
#if defined(_WIN32)
98-
constexpr int buffer_size = 1024;
99-
char buffer[buffer_size];
100-
auto rc = GetEnvironmentVariableA(name, buffer, buffer_size);
101-
if (0 != rc && rc < buffer_size) {
102-
return std::string(buffer);
103-
} else if (rc >= buffer_size) {
104-
std::stringstream ex_ss;
105-
ex_ss << "Environment variable " << name << " value too long!"
106-
<< " Maximum length is " << buffer_size - 1 << " characters.";
107-
throw std::invalid_argument(ex_ss.str());
108-
}
109-
return std::nullopt;
110-
#else
111-
const char *tmp_env = getenv(name);
112-
if (tmp_env != nullptr) {
113-
return std::string(tmp_env);
114-
} else {
115-
return std::nullopt;
116-
}
117-
#endif
118-
}
88+
std::optional<std::string> ur_getenv(const char *name);
11989

12090
inline bool getenv_tobool(const char *name) {
12191
auto env = ur_getenv(name);

source/loader/layers/validation/backtrace_win.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
*/
1010
#include "backtrace.hpp"
1111

12-
#include <DbgHelp.h>
1312
#include <Windows.h>
13+
// Windows.h must be included before DbgHelp.h
14+
#include <DbgHelp.h>
1415
#include <vector>
1516

1617
namespace ur_validation_layer {

0 commit comments

Comments
 (0)