1111#include " adapter.hpp"
1212#include " ur_level_zero.hpp"
1313
14- ur_adapter_handle_t_ Adapter{};
15-
1614ur_result_t initPlatforms (PlatformVec &platforms) noexcept try {
1715 uint32_t ZeDriverCount = 0 ;
1816 ZE2UR_CALL (zeDriverGet, (&ZeDriverCount, nullptr ));
@@ -36,43 +34,45 @@ ur_result_t initPlatforms(PlatformVec &platforms) noexcept try {
3634 return exceptionToResult (std::current_exception ());
3735}
3836
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; }
5238
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_ () {
6140
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 ;
6452 }
6553
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+ }
6862
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+ }
7467
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+ }
7676 assert (Adapter.ZeResult !=
7777 std::nullopt ); // verify that level-zero is initialized
7878 PlatformVec platforms;
@@ -95,9 +95,10 @@ ur_result_t adapterStateInit() {
9595 result = err;
9696 }
9797 };
98- return UR_RESULT_SUCCESS;
9998}
10099
100+ ur_adapter_handle_t_ Adapter{};
101+
101102ur_result_t adapterStateTeardown () {
102103 bool LeakFound = false ;
103104
0 commit comments