Skip to content

Commit

Permalink
VITIS-11043 Convert map to vector for device caching. Add mutex to pr…
Browse files Browse the repository at this point in the history
…otect device initialization.

Signed-off-by: Daniel Benusovich <[email protected]>
  • Loading branch information
dbenusov committed Jan 8, 2024
1 parent e180ac9 commit 9a67bf3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/runtime_src/core/tools/common/XBUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,19 +283,22 @@ XBUtilities::xrt_version_cmp(bool isUserDomain)
static std::shared_ptr<xrt_core::device>
get_device_internal(int index, bool in_user_domain)
{
static std::mutex mutex;
std::lock_guard guard(mutex);

if (in_user_domain) {
static std::unordered_map<xrt_core::device::id_type, std::shared_ptr<xrt_core::device>> user_device_map;
if (user_device_map.find(index) == user_device_map.end())
user_device_map[index] = xrt_core::get_userpf_device(index);
static std::vector<std::shared_ptr<xrt_core::device>> user_devices(xrt_core::get_total_devices(true).second, nullptr);
if (!user_devices[index])
user_devices[index] = xrt_core::get_userpf_device(index);

return user_device_map[index];
return user_devices[index];
}

static std::unordered_map<xrt_core::device::id_type, std::shared_ptr<xrt_core::device>> mgmt_device_map;
if (mgmt_device_map.find(index) == mgmt_device_map.end())
mgmt_device_map[index] = xrt_core::get_mgmtpf_device(index);
static std::vector<std::shared_ptr<xrt_core::device>> mgmt_devices(xrt_core::get_total_devices(false).second, nullptr);
if (!mgmt_devices[index])
mgmt_devices[index] = xrt_core::get_mgmtpf_device(index);

return mgmt_device_map[index];
return mgmt_devices[index];
}

void
Expand Down

0 comments on commit 9a67bf3

Please sign in to comment.