Skip to content

Commit ed52c81

Browse files
authored
Fix xrt_hip.so static initialization order fiasco (Xilinx#9667)
Initialize global `device_cache` in same TU that uses it during static global initialiation of hip devices. Bug exposed in Debian upstreamed packages, compiled with `-flto=auto and -ffat-lto-objects`. This is likely not the final fix, complex initiaziation during static global initialization is not correct. Initialization of devices can throw, throw during static global initialiation is not kosher. Signed-off-by: Soren Soe <2106410+stsoe@users.noreply.github.com>
1 parent fefe649 commit ed52c81

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

src/runtime_src/hip/api/hip_device.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// Copyright (C) 2023-2025 Advanced Micro Devices, Inc. All rights reserved.
2+
// Copyright (C) 2023-2026 Advanced Micro Devices, Inc. All rights reserved.
33
#include "core/include/xrt/experimental/xrt_system.h"
44
#include "core/common/device.h"
55
#include "core/common/query_requests.h"
@@ -19,6 +19,10 @@
1919

2020
// forward declaration
2121
namespace xrt::core::hip {
22+
// Defined first so it is initialized before the global x below (same
23+
// TU order).
24+
xrt_core::handle_map<device_handle, std::unique_ptr<device>> device_cache; //NOLINT
25+
2226
static void
2327
device_init();
2428
}

src/runtime_src/hip/core/device.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
// SPDX-License-Identifier: Apache-2.0
2-
// Copyright (C) 2023-2024 Advanced Micro Devices, Inc. All rights reserved.
2+
// Copyright (C) 2023-2026 Advanced Micro Devices, Inc. All rights reserved.
33

44
#include "device.h"
55

66
namespace xrt::core::hip {
7-
// Implementation
8-
//we should override clang-tidy warning by adding NOLINT since device_cache is non-const parameter
9-
xrt_core::handle_map<device_handle, std::unique_ptr<device>> device_cache; //NOLINT
107

118
device::
129
device(uint32_t device_id)

0 commit comments

Comments
 (0)