Skip to content

Commit bb3d960

Browse files
Use common api for all internal bo creations (#9373)
Signed-off-by: Rahul Bramandlapalli <rbramand@amd.com>
1 parent 5a48dc5 commit bb3d960

5 files changed

Lines changed: 50 additions & 37 deletions

File tree

src/runtime_src/core/common/api/bo_int.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ get_offset(const xrt::bo& bo);
2424
// enum for different buffer use flags
2525
// This is for internal use only
2626
enum class use_type {
27-
debug = XRT_BO_USE_DEBUG, // debug data
28-
kmd = XRT_BO_USE_KMD, // shared with kernel mode driver
29-
dtrace = XRT_BO_USE_DTRACE, // dynamic trace data
30-
log = XRT_BO_USE_LOG, // logging info
31-
debug_queue = XRT_BO_USE_DEBUG_QUEUE, // debug queue data
32-
uc_debug = XRT_BO_USE_UC_DEBUG, // microblaze debug data
33-
host_only = XRT_BO_USE_HOST_ONLY, // system memory buffer
34-
instruction = XRT_BO_USE_INSTRUCTION, // instruction (instructon buffer)
35-
preemption = XRT_BO_USE_PREEMPTION, // preemption data
36-
scratch_pad = XRT_BO_USE_SCRATCH_PAD, // scratch pad data
37-
pdi = XRT_BO_USE_PDI, // PDI data
38-
ctrlpkt = XRT_BO_USE_CTRLPKT // control packet
27+
debug = XRT_BO_USE_DEBUG, // debug data
28+
kmd = XRT_BO_USE_KMD, // shared with kernel mode driver
29+
dtrace = XRT_BO_USE_DTRACE, // dynamic trace data
30+
log = XRT_BO_USE_LOG, // logging info
31+
debug_queue = XRT_BO_USE_DEBUG_QUEUE, // debug queue data
32+
uc_debug = XRT_BO_USE_UC_DEBUG, // microblaze debug data
33+
host_only = XRT_BO_USE_HOST_ONLY, // system memory buffer
34+
instruction = XRT_BO_USE_INSTRUCTION, // instruction (instructon buffer)
35+
preemption = XRT_BO_USE_PREEMPTION, // preemption data
36+
scratch_pad = XRT_BO_USE_SCRATCH_PAD, // scratch pad data
37+
ctrl_scratch_pad = XRT_BO_USE_CTRL_SCRATCH_PAD, // ctrl scratchpad data
38+
pdi = XRT_BO_USE_PDI, // PDI data
39+
ctrlpkt = XRT_BO_USE_CTRLPKT // control packet
3940
};
4041

4142
// create_bo() - Create a buffer object within a device for specific use case

src/runtime_src/core/common/api/xrt_bo.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ compose_internal_bo_flags(use_type type)
17111711
case use_type::instruction:
17121712
case use_type::preemption:
17131713
case use_type::pdi:
1714-
case use_type::scratch_pad:
1714+
case use_type::ctrl_scratch_pad:
17151715
// client use case, create buffer in sram
17161716
flags.flags = XRT_BO_FLAGS_CACHEABLE;
17171717
break;
@@ -1720,6 +1720,7 @@ compose_internal_bo_flags(use_type type)
17201720
case use_type::host_only:
17211721
case use_type::uc_debug:
17221722
case use_type::log:
1723+
case use_type::scratch_pad:
17231724
flags.flags = XRT_BO_FLAGS_HOST_ONLY;
17241725
break;
17251726
default:

src/runtime_src/core/common/api/xrt_hw_context.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class hw_context_impl : public std::enable_shared_from_this<hw_context_impl>
7777
size_t size_per_uc,
7878
size_t num_uc)
7979
{
80-
auto bo = xrt_core::bo_int::
81-
create_bo(device, (size_per_uc * num_uc), xrt_core::bo_int::use_type::log);
80+
auto bo = xrt_core::bo_int::create_bo(
81+
device, (size_per_uc * num_uc), xrt_core::bo_int::use_type::log);
8282

8383
// Log buffers first 8 bytes are used for metadata
8484
// So make sure for each uC metadata bytes are initialized with
@@ -465,8 +465,9 @@ class hw_context_impl : public std::enable_shared_from_this<hw_context_impl>
465465
std::call_once(m_scratchpad_init_flag, [this, size_per_col] () {
466466
try {
467467
// create scratchpad memory buffer using this context
468-
m_scratchpad_buf = xrt::ext::bo{xrt::hw_context(get_shared_ptr()),
469-
size_per_col * m_partition_size};
468+
auto buf_size = size_per_col * m_partition_size;
469+
m_scratchpad_buf = xrt_core::bo_int::create_bo(
470+
m_core_device, buf_size, xrt_core::bo_int::use_type::scratch_pad);
470471
}
471472
catch (...) { /*do nothing*/ }
472473
});

src/runtime_src/core/common/api/xrt_kernel.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,8 @@ class argument
12781278
{ return arg.type; }
12791279
};
12801280

1281+
namespace xbi = xrt_core::bo_int;
1282+
12811283
// class buffer_cache - A thread safe cache to hold pre created buffers
12821284
//
12831285
// This class maintains a fixed size pool of reusable buffers to
@@ -1290,6 +1292,7 @@ class buffer_cache
12901292
xrt::hw_context m_hw_ctx;
12911293
std::vector<uint8_t> m_buf_data;
12921294
const std::size_t m_max_cache_size;
1295+
xbi::use_type m_use_flag;
12931296

12941297
mutable std::mutex m_mutex;
12951298
mutable std::vector<xrt::bo> m_bo_cache;
@@ -1303,7 +1306,7 @@ class buffer_cache
13031306
}
13041307

13051308
static std::vector<xrt::bo>
1306-
initialize_bo_cache(const xrt::hw_context& hwctx, size_t cache_size, size_t bo_size)
1309+
initialize_bo_cache(const xrt::hw_context& hwctx, size_t cache_size, size_t bo_size, xbi::use_type flag)
13071310
{
13081311
if (!cache_size)
13091312
return {};
@@ -1312,17 +1315,18 @@ class buffer_cache
13121315
cache.reserve(cache_size);
13131316

13141317
for (size_t i = 0; i < cache_size; ++i)
1315-
cache.push_back(xrt::ext::bo(hwctx, bo_size));
1318+
cache.push_back(xbi::create_bo(hwctx, bo_size, flag));
13161319

13171320
return cache;
13181321
}
13191322

13201323
public:
1321-
buffer_cache(xrt::hw_context ctx, std::vector<uint8_t>&& data, size_t max_size)
1324+
buffer_cache(xrt::hw_context ctx, std::vector<uint8_t>&& data, size_t max_size, xbi::use_type flag)
13221325
: m_hw_ctx(std::move(ctx))
13231326
, m_buf_data(std::move(data))
13241327
, m_max_cache_size(max_size)
1325-
, m_bo_cache{initialize_bo_cache(m_hw_ctx, m_max_cache_size, m_buf_data.size())}
1328+
, m_use_flag(flag)
1329+
, m_bo_cache{initialize_bo_cache(m_hw_ctx, m_max_cache_size, m_buf_data.size(), m_use_flag)}
13261330
{}
13271331

13281332
xrt::bo
@@ -1338,7 +1342,7 @@ class buffer_cache
13381342
}
13391343

13401344
if (!bo)
1341-
bo = xrt::ext::bo(m_hw_ctx, m_buf_data.size()); // create new bo if cache is empty
1345+
bo = xbi::create_bo(m_hw_ctx, m_buf_data.size(), m_use_flag); // create new bo if cache is empty
13421346

13431347
fill_bo_with_data(bo, m_buf_data);
13441348
return bo;
@@ -1360,6 +1364,7 @@ class buffer_cache
13601364
} // namespace
13611365

13621366
namespace xrt {
1367+
13631368
// struct kernel_impl - The internals of an xrtKernelHandle
13641369
//
13651370
// An single object of kernel_type can be shared with multiple
@@ -1648,7 +1653,8 @@ class kernel_impl : public std::enable_shared_from_this<kernel_impl>
16481653
size_t max_pool_size = std::max(pool_memory_size / ctrlpkt_buf_size, min_pool_size);
16491654

16501655
// Create and return buffer_cache with calculated pool size
1651-
return std::make_unique<buffer_cache>(ctx, std::move(ctrlpkt_data), max_pool_size);
1656+
// use ctrlpkt flag while creating buffers
1657+
return std::make_unique<buffer_cache>(ctx, std::move(ctrlpkt_data), max_pool_size, xbi::use_type::ctrlpkt);
16521658
}
16531659

16541660
public:

src/runtime_src/core/include/xrt/detail/xrt_mem.h

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ struct xcl_bo_flags
148148
* hold instructions for firmware.
149149
*
150150
* XRT_BO_USE_SCRATCH_PAD indicates that the buffer will be used as
151-
* scratch pad memory for firmware.
151+
* scratch pad memory to store L2 memory at time of preemption.
152+
*
153+
* XRT_BO_USE_CTRL_SCRATCH_PAD indicates that the buffer will be used
154+
* to store/retrieve control state information during model execution.
152155
*
153156
* XRT_BO_USE_PDI indicates that the buffer will be used to hold
154157
* PDI data for firmware.
@@ -161,19 +164,20 @@ struct xcl_bo_flags
161164
// constexpr and using NOLINT block to supress clng-tidy warnings
162165

163166
// NOLINTBEGIN
164-
#define XRT_BO_USE_UNUSED 0
165-
#define XRT_BO_USE_DEBUG 1
166-
#define XRT_BO_USE_KMD 2
167-
#define XRT_BO_USE_DTRACE 3
168-
#define XRT_BO_USE_LOG 4
169-
#define XRT_BO_USE_DEBUG_QUEUE 5
170-
#define XRT_BO_USE_UC_DEBUG 6
171-
#define XRT_BO_USE_PREEMPTION 7
172-
#define XRT_BO_USE_HOST_ONLY 8
173-
#define XRT_BO_USE_INSTRUCTION 9
174-
#define XRT_BO_USE_SCRATCH_PAD 10
175-
#define XRT_BO_USE_PDI 11
176-
#define XRT_BO_USE_CTRLPKT 12
167+
#define XRT_BO_USE_UNUSED 0
168+
#define XRT_BO_USE_DEBUG 1
169+
#define XRT_BO_USE_KMD 2
170+
#define XRT_BO_USE_DTRACE 3
171+
#define XRT_BO_USE_LOG 4
172+
#define XRT_BO_USE_DEBUG_QUEUE 5
173+
#define XRT_BO_USE_UC_DEBUG 6
174+
#define XRT_BO_USE_PREEMPTION 7
175+
#define XRT_BO_USE_HOST_ONLY 8
176+
#define XRT_BO_USE_INSTRUCTION 9
177+
#define XRT_BO_USE_SCRATCH_PAD 10
178+
#define XRT_BO_USE_CTRL_SCRATCH_PAD 11
179+
#define XRT_BO_USE_PDI 12
180+
#define XRT_BO_USE_CTRLPKT 13
177181
// NOLINTEND
178182

179183
/**

0 commit comments

Comments
 (0)