|
1 | 1 | // SPDX-License-Identifier: Apache-2.0 |
2 | | -// Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved. |
| 2 | +// Copyright (C) 2022-2026 Advanced Micro Devices, Inc. All rights reserved. |
3 | 3 |
|
4 | 4 | // This file implements XRT xclbin APIs as declared in |
5 | 5 | // core/include/experimental/xrt_queue.h |
@@ -146,6 +146,11 @@ class hw_context_impl : public std::enable_shared_from_this<hw_context_impl> |
146 | 146 | // using kernel name. |
147 | 147 | std::map<std::string, xrt::elf> m_elf_map; |
148 | 148 |
|
| 149 | + // map b/w kernel name and xrt::module |
| 150 | + // For xrt::kernel object created in this hw_context, they |
| 151 | + // should share the same xrt::module. |
| 152 | + std::map<std::string, xrt::module> m_kernel_mod_map; |
| 153 | + |
149 | 154 | // No. of cols in the AIE partition managed by this hw ctx |
150 | 155 | // Devices with no AIE will have partition size as 0 |
151 | 156 | uint32_t m_partition_size = 0; |
@@ -393,12 +398,17 @@ class hw_context_impl : public std::enable_shared_from_this<hw_context_impl> |
393 | 398 | } |
394 | 399 |
|
395 | 400 | xrt::module |
396 | | - get_module(const std::string& kname) const |
| 401 | + get_module(const std::string& kname) |
397 | 402 | { |
398 | | - if (auto itr = m_elf_map.find(kname); itr != m_elf_map.end()) |
399 | | - return xrt::module{itr->second}; // create module from the ELF that has this kernel |
| 403 | + auto itr = m_elf_map.find(kname); |
| 404 | + if (itr == m_elf_map.end()) |
| 405 | + throw std::runtime_error("no module found with given kernel name in ctx"); |
| 406 | + |
| 407 | + auto [kmitr, inserted] = m_kernel_mod_map.try_emplace(kname, xrt::module{}); |
| 408 | + if (inserted) |
| 409 | + kmitr->second = xrt::module{itr->second}; // create module from the ELF that has this kernel |
400 | 410 |
|
401 | | - throw std::runtime_error("no module found with given kernel name in ctx"); |
| 411 | + return kmitr->second; |
402 | 412 | } |
403 | 413 |
|
404 | 414 | bool |
|
0 commit comments