Skip to content

Commit b85229f

Browse files
Get XDP init and exit runs using a callback from XDP code
Signed-off-by: Rahul Bramandlapalli <[email protected]>
1 parent 9bff812 commit b85229f

File tree

5 files changed

+36
-81
lines changed

5 files changed

+36
-81
lines changed

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

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// This file defines implementation extensions to the XRT XCLBIN APIs.
99
#include "core/include/xrt/xrt_hw_context.h"
1010
#include "core/include/xrt/experimental/xrt_module.h"
11-
#include "core/include/xrt/xrt_kernel.h"
1211

1312
#include <cstdint>
1413

@@ -71,23 +70,6 @@ get_scratchpad_mem_buf(const xrt::hw_context& hwctx, size_t size_per_col);
7170
void
7271
dump_scratchpad_mem(const xrt::hw_context& hwctx);
7372

74-
// APIs used by XDP to register init and exit runs
75-
// These runs will be used to initialize AI array and collect profile/trace data
76-
// These runs are added to runlist at the beginning and end respectively
77-
XRT_CORE_COMMON_EXPORT
78-
void
79-
register_xdp_init_run(const xrt::hw_context& ctx, const xrt::run& run);
80-
81-
XRT_CORE_COMMON_EXPORT
82-
void
83-
register_xdp_exit_run(const xrt::hw_context& ctx, const xrt::run& run);
84-
85-
const std::vector<xrt::run>&
86-
get_xdp_init_runs(const xrt::hw_context& ctx);
87-
88-
const std::vector<xrt::run>&
89-
get_xdp_exit_runs(const xrt::hw_context& ctx);
90-
9173
}} // hw_context_int, xrt_core
9274

9375
#endif

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

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "core/common/time.h"
1313
#include "core/common/utils.h"
1414
#include "core/include/xrt/xrt_hw_context.h"
15-
#include "core/include/xrt/xrt_kernel.h"
1615
#include "core/include/xrt/experimental/xrt_ext.h"
1716
#include "core/include/xrt/experimental/xrt_module.h"
1817
#include "bo_int.h"
@@ -153,11 +152,6 @@ class hw_context_impl : public std::enable_shared_from_this<hw_context_impl>
153152
// are saved to a scratchpad memory allocated specifically for that context.
154153
std::once_flag m_scratchpad_init_flag; // used for thread safe lazy init of scratchpad
155154
xrt::bo m_scratchpad_buf;
156-
// Vector of XDP runs to be added at beginning and end of runlist
157-
// These runs initializes/configures AI array and collects the profile/trace data
158-
std::vector<xrt::run> m_xdp_init_runs;
159-
std::vector<xrt::run> m_xdp_exit_runs;
160-
161155
std::shared_ptr<xrt_core::usage_metrics::base_logger> m_usage_logger =
162156
xrt_core::usage_metrics::get_usage_metrics_logger();
163157
bool m_elf_flow = false;
@@ -471,33 +465,6 @@ class hw_context_impl : public std::enable_shared_from_this<hw_context_impl>
471465
msg.append(dump_file_name);
472466
xrt_core::message::send(xrt_core::message::severity_level::debug, "xrt_hw_context", msg);
473467
}
474-
475-
// Callback Functions for XDP to register init and exit runs
476-
// that are added to xrt::runlist at start and end respectively
477-
void
478-
register_xdp_init_run(const xrt::run& run)
479-
{
480-
m_xdp_init_runs.push_back(run);
481-
}
482-
483-
void
484-
register_xdp_exit_run(const xrt::run& run)
485-
{
486-
m_xdp_exit_runs.push_back(run);
487-
}
488-
489-
// Functions to get XDP init and exit run vectors
490-
const std::vector<xrt::run>&
491-
get_xdp_init_runs() const
492-
{
493-
return m_xdp_init_runs;
494-
}
495-
496-
const std::vector<xrt::run>&
497-
get_xdp_exit_runs() const
498-
{
499-
return m_xdp_exit_runs;
500-
}
501468
};
502469

503470
} // xrt
@@ -565,31 +532,6 @@ dump_scratchpad_mem(const xrt::hw_context& hwctx)
565532
return hwctx.get_handle()->dump_scratchpad_mem();
566533
}
567534

568-
void
569-
register_xdp_init_run(const xrt::hw_context& ctx, const xrt::run& run)
570-
{
571-
ctx.get_handle()->register_xdp_init_run(run);
572-
}
573-
574-
XRT_CORE_COMMON_EXPORT
575-
void
576-
register_xdp_exit_run(const xrt::hw_context& ctx, const xrt::run& run)
577-
{
578-
ctx.get_handle()->register_xdp_exit_run(run);
579-
}
580-
581-
const std::vector<xrt::run>&
582-
get_xdp_init_runs(const xrt::hw_context& ctx)
583-
{
584-
return ctx.get_handle()->get_xdp_init_runs();
585-
}
586-
587-
const std::vector<xrt::run>&
588-
get_xdp_exit_runs(const xrt::hw_context& ctx)
589-
{
590-
return ctx.get_handle()->get_xdp_exit_runs();
591-
}
592-
593535
} // xrt_core::hw_context_int
594536

595537
////////////////////////////////////////////////////////////////

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "core/common/trace.h"
4646
#include "core/common/usage_metrics.h"
4747
#include "core/common/xclbin_parser.h"
48+
#include "core/common/xdp/profile.h"
4849

4950
#include <boost/format.hpp>
5051

@@ -3499,8 +3500,7 @@ class runlist_impl
34993500
// These runs initializes AI array for profile/trace data
35003501
// The list can be empty if profile/trace is not enabled
35013502
if (m_runlist.empty()) {
3502-
const auto& xdp_init_runs = xrt_core::hw_context_int::get_xdp_init_runs(m_hwctx);
3503-
for (const auto& init_run : xdp_init_runs) {
3503+
for (const auto& init_run : xrt_core::xdp::get_init_runs(m_hwctx.get_handle().get())) {
35043504
add_run_helper(init_run);
35053505
}
35063506
}
@@ -3521,8 +3521,7 @@ class runlist_impl
35213521
// Add XDP exit runs if any at the end of runlist before submitting
35223522
// These runs collect profile/trace data
35233523
// The list can be empty if profile/trace is not enabled
3524-
const auto& xdp_exit_runs = xrt_core::hw_context_int::get_xdp_exit_runs(m_hwctx);
3525-
for (const auto& exit_run : xdp_exit_runs) {
3524+
for (const auto& exit_run : xrt_core::xdp::get_exit_runs(m_hwctx.get_handle().get())) {
35263525
add_run_helper(exit_run);
35273526
}
35283527

@@ -3569,7 +3568,7 @@ class runlist_impl
35693568
// Remove any XDP exit runs added during execute
35703569
// This is done because runlist can be reused
35713570
// and XDP exit runs should be added at end
3572-
const auto& xdp_exit_runs = xrt_core::hw_context_int::get_xdp_exit_runs(m_hwctx);
3571+
const auto& xdp_exit_runs = xrt_core::xdp::get_exit_runs(m_hwctx.get_handle().get());
35733572
if (xdp_exit_runs.size() > 0) {
35743573
// remove the exit runs from the runlist
35753574
m_runlist.erase(m_runlist.end() - xdp_exit_runs.size(), m_runlist.end());

src/runtime_src/core/common/xdp/profile.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,4 +736,20 @@ finish_flush_device(void* handle)
736736
#endif
737737
}
738738

739+
const std::vector<xrt::run>&
740+
get_init_runs(void* /*hwctx_impl*/)
741+
{
742+
// placeholder, TODO : XDP to add implementation
743+
static std::vector<xrt::run> init_runs;
744+
return init_runs;
745+
}
746+
747+
const std::vector<xrt::run>&
748+
get_exit_runs(void* /*hwctx_impl*/)
749+
{
750+
// placeholder, TODO : XDP to add implementation
751+
static std::vector<xrt::run> exit_runs;
752+
return exit_runs;
753+
}
754+
739755
} // end namespace xrt_core::xdp

src/runtime_src/core/common/xdp/profile.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#ifndef CORE_COMMON_PROFILE_DOT_H
44
#define CORE_COMMON_PROFILE_DOT_H
55

6+
#include "core/include/xrt/xrt_kernel.h"
7+
68
// The functions here are the general interfaces for the XDP hooks that are
79
// called from the common coreutil library and not the specific shims.
810
namespace xrt_core::xdp {
@@ -22,6 +24,20 @@ update_device(void* handle, bool hw_context_flow);
2224
void
2325
finish_flush_device(void* handle);
2426

27+
// get_init_runs returns vector of init runs to be prepended to a runlist.
28+
// These runs initialize the AI array for profile/trace data collection.
29+
// handle passed is the hw_context_impl pointer that is used to create runlist
30+
// This call returns empty vector if no profile/trace options are enabled
31+
const std::vector<xrt::run>&
32+
get_init_runs(void* hwctx_impl);
33+
34+
// get_exit_runs returns vector of exit runs to be appended to a runlist.
35+
// These runs are used to flush out the AI array profile/trace data
36+
// handle passed is the hw_context_impl pointer that is used to create runlist.
37+
// This call returns empty vector if no profile/trace options are enabled
38+
const std::vector<xrt::run>&
39+
get_exit_runs(void* hwctx_impl);
40+
2541
} // end namespace xrt_core::xdp
2642

2743
#endif

0 commit comments

Comments
 (0)