11
11
#include " adapter.hpp"
12
12
#include " ur_level_zero.hpp"
13
13
14
- ur_adapter_handle_t_ Adapter{};
15
-
16
14
ur_result_t initPlatforms (PlatformVec &platforms) noexcept try {
17
15
uint32_t ZeDriverCount = 0 ;
18
16
ZE2UR_CALL (zeDriverGet, (&ZeDriverCount, nullptr ));
@@ -36,43 +34,45 @@ ur_result_t initPlatforms(PlatformVec &platforms) noexcept try {
36
34
return exceptionToResult (std::current_exception ());
37
35
}
38
36
39
- ur_result_t adapterStateInit () {
40
- static std::once_flag ZeCallCountInitialized;
41
- try {
42
- std::call_once (ZeCallCountInitialized, []() {
43
- if (UrL0LeaksDebug) {
44
- ZeCallCount = new std::map<std::string, int >;
45
- }
46
- });
47
- } catch (const std::bad_alloc &) {
48
- return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;
49
- } catch (...) {
50
- return UR_RESULT_ERROR_UNKNOWN;
51
- }
37
+ ur_result_t adapterStateInit () { return UR_RESULT_SUCCESS; }
52
38
53
- // initialize level zero only once.
54
- if (Adapter.ZeResult == std::nullopt) {
55
- // Setting these environment variables before running zeInit will enable the
56
- // validation layer in the Level Zero loader.
57
- if (UrL0Debug & UR_L0_DEBUG_VALIDATION) {
58
- setEnvVar (" ZE_ENABLE_VALIDATION_LAYER" , " 1" );
59
- setEnvVar (" ZE_ENABLE_PARAMETER_VALIDATION" , " 1" );
60
- }
39
+ ur_adapter_handle_t_::ur_adapter_handle_t_ () {
61
40
62
- if (getenv (" SYCL_ENABLE_PCI" ) != nullptr ) {
63
- urPrint (" WARNING: SYCL_ENABLE_PCI is deprecated and no longer needed.\n " );
41
+ Adapter.PlatformCache .Compute = [](Result<PlatformVec> &result) {
42
+ static std::once_flag ZeCallCountInitialized;
43
+ try {
44
+ std::call_once (ZeCallCountInitialized, []() {
45
+ if (UrL0LeaksDebug) {
46
+ ZeCallCount = new std::map<std::string, int >;
47
+ }
48
+ });
49
+ } catch (...) {
50
+ result = exceptionToResult (std::current_exception ());
51
+ return ;
64
52
}
65
53
66
- // TODO: We can still safely recover if something goes wrong during the
67
- // init. Implement handling segfault using sigaction.
54
+ // initialize level zero only once.
55
+ if (Adapter.ZeResult == std::nullopt) {
56
+ // Setting these environment variables before running zeInit will enable
57
+ // the validation layer in the Level Zero loader.
58
+ if (UrL0Debug & UR_L0_DEBUG_VALIDATION) {
59
+ setEnvVar (" ZE_ENABLE_VALIDATION_LAYER" , " 1" );
60
+ setEnvVar (" ZE_ENABLE_PARAMETER_VALIDATION" , " 1" );
61
+ }
68
62
69
- // We must only initialize the driver once, even if urPlatformGet() is
70
- // called multiple times. Declaring the return value as "static" ensures
71
- // it's only called once.
72
- Adapter.ZeResult = ZE_CALL_NOCHECK (zeInit, (ZE_INIT_FLAG_GPU_ONLY));
73
- }
63
+ if (getenv (" SYCL_ENABLE_PCI" ) != nullptr ) {
64
+ urPrint (
65
+ " WARNING: SYCL_ENABLE_PCI is deprecated and no longer needed.\n " );
66
+ }
74
67
75
- Adapter.PlatformCache .Compute = [](Result<PlatformVec> &result) {
68
+ // TODO: We can still safely recover if something goes wrong during the
69
+ // init. Implement handling segfault using sigaction.
70
+
71
+ // We must only initialize the driver once, even if urPlatformGet() is
72
+ // called multiple times. Declaring the return value as "static" ensures
73
+ // it's only called once.
74
+ Adapter.ZeResult = ZE_CALL_NOCHECK (zeInit, (ZE_INIT_FLAG_GPU_ONLY));
75
+ }
76
76
assert (Adapter.ZeResult !=
77
77
std::nullopt); // verify that level-zero is initialized
78
78
PlatformVec platforms;
@@ -95,9 +95,10 @@ ur_result_t adapterStateInit() {
95
95
result = err;
96
96
}
97
97
};
98
- return UR_RESULT_SUCCESS;
99
98
}
100
99
100
+ ur_adapter_handle_t_ Adapter{};
101
+
101
102
ur_result_t adapterStateTeardown () {
102
103
bool LeakFound = false ;
103
104
0 commit comments