Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions profile/plugin/aie_dtrace/aie_dtrace_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ namespace xdp {
handleToAIEDtraceImpl.erase(itr);
}

void AieDtracePlugin::runConstructorHook(void* run_impl_ptr, void* hwctx, uint32_t run_uid,
void AieDtracePlugin::runConstructorImpl(void* run_impl_ptr, void* hwctx, uint32_t run_uid,
const std::string& kernel_name, void* elf_handle)
{
if (!xrt_core::config::get_aie_dtrace())
Expand All @@ -201,7 +201,7 @@ namespace xdp {
itr->second->generateCTForRun(run_impl_ptr, hwctx, run_uid, kernel_name, elf_handle);
}

void AieDtracePlugin::runStartHook(void* run_impl_ptr, void* hwctx, uint32_t run_uid,
void AieDtracePlugin::runStartImpl(void* run_impl_ptr, void* hwctx, uint32_t run_uid,
const std::string& kernel_name)
{
if (!xrt_core::config::get_aie_dtrace())
Expand All @@ -213,7 +213,7 @@ namespace xdp {
(void)kernel_name;
}

void AieDtracePlugin::runWaitHook(void* run_impl_ptr, void* hwctx, uint32_t run_uid,
void AieDtracePlugin::runWaitImpl(void* run_impl_ptr, void* hwctx, uint32_t run_uid,
const std::string& kernel_name, int ert_cmd_state)
{
if (!xrt_core::config::get_aie_dtrace())
Expand Down
19 changes: 14 additions & 5 deletions profile/plugin/aie_dtrace/aie_dtrace_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,23 @@ namespace xdp {
~AieDtracePlugin();
void updateAIEDtraceDevice(void* handle, bool hw_context_flow);
void endPollforDevice(void* handle);
void runConstructorHook(void* run_impl_ptr, void* hwctx, uint32_t run_uid,
const std::string& kernel_name, void* elf_handle);
void runStartHook(void* run_impl_ptr, void* hwctx, uint32_t run_uid, const std::string& kernel_name);
void runWaitHook(void* run_impl_ptr, void* hwctx, uint32_t run_uid, const std::string& kernel_name,
int ert_cmd_state);
static bool alive();
void broadcast(VPDatabase::MessageType msg, void* blob);

protected:
// Overrides of the XDPPlugin run-lifecycle hook implementations.
// aie_dtrace_cb.cpp must NOT call these directly; it calls the
// public XDPPlugin::run*Hook wrappers, which filter out runs
// submitted by XDP plugins themselves before delegating here.
void runConstructorImpl(void* run_impl_ptr, void* hwctx, uint32_t run_uid,
const std::string& kernel_name,
void* elf_handle) override;
void runStartImpl(void* run_impl_ptr, void* hwctx, uint32_t run_uid,
const std::string& kernel_name) override;
void runWaitImpl(void* run_impl_ptr, void* hwctx, uint32_t run_uid,
const std::string& kernel_name,
int ert_cmd_state) override;

private:
void writeAll(bool openNewFiles) override;
uint64_t getDeviceIDFromHandle(void* handle);
Expand Down
8 changes: 8 additions & 0 deletions profile/plugin/vp_base/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ namespace xdp {
XDP_CORE_EXPORT uint64_t getAlignedTraceBufSize(uint64_t totalBytes,
unsigned int numChunks);

// Returns true if the given kernel name identifies a run that an
// XDP plugin submitted itself (as opposed to a user-application
// run). The convention is a "XDP_KERNEL" prefix on the kernel name
// passed to xrt::ext::kernel; see vp_base_plugin.cpp for the
// canonical definition. Use this from any non-hook XDP code path
// (e.g. device-flow hooks) that needs the same filter.
XDP_CORE_EXPORT bool isXdpInternalKernel(const std::string& kernel_name);

enum Flow {
SW_EMU = 0,
HW_EMU = 1,
Expand Down
48 changes: 48 additions & 0 deletions profile/plugin/vp_base/vp_base_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
#define XDP_CORE_SOURCE

#include <cstdlib>
#include <string>

#include "xdp/profile/plugin/vp_base/utility.h"
#include "xdp/profile/plugin/vp_base/vp_base_plugin.h"
#include "xdp/profile/writer/vp_base/vp_run_summary.h"
#include "xdp/profile/database/database.h"
Expand All @@ -34,6 +36,23 @@

namespace xdp {

// Single source of truth for the convention that distinguishes a run
// submitted by an XDP plugin itself from a run submitted by user code.
// xrt_core::api kernel_impl::get_name() strips everything after the
// first ':' (see core/common/api/xrt_kernel.cpp), so an XDP plugin
// kernel constructed as e.g. "XDP_KERNEL:{IPUV1CNN}" arrives at the
// run-lifecycle hooks as exactly "XDP_KERNEL". A prefix match is used
// (rather than equality) to leave room for future internal kernels of
// the form "XDP_KERNEL_FOO" without changing this convention.
namespace {
constexpr const char* kXdpInternalKernelPrefix = "XDP_KERNEL";
} // namespace

bool isXdpInternalKernel(const std::string& kernel_name)
{
return kernel_name.rfind(kXdpInternalKernelPrefix, 0) == 0;
}

unsigned int XDPPlugin::trace_file_dump_int_s = 5;
bool XDPPlugin::trace_int_cached = false;

Expand Down Expand Up @@ -164,4 +183,33 @@ namespace xdp {
}
}

void XDPPlugin::runConstructorHook(void* run_impl_ptr, void* hwctx,
uint32_t run_uid,
const std::string& kernel_name,
void* elf_handle)
{
if (isXdpInternalKernel(kernel_name))
return;
runConstructorImpl(run_impl_ptr, hwctx, run_uid, kernel_name, elf_handle);
}

void XDPPlugin::runStartHook(void* run_impl_ptr, void* hwctx,
uint32_t run_uid,
const std::string& kernel_name)
{
if (isXdpInternalKernel(kernel_name))
return;
runStartImpl(run_impl_ptr, hwctx, run_uid, kernel_name);
}

void XDPPlugin::runWaitHook(void* run_impl_ptr, void* hwctx,
uint32_t run_uid,
const std::string& kernel_name,
int ert_cmd_state)
{
if (isXdpInternalKernel(kernel_name))
return;
runWaitImpl(run_impl_ptr, hwctx, run_uid, kernel_name, ert_cmd_state);
}

} // end namespace xdp
38 changes: 38 additions & 0 deletions profile/plugin/vp_base/vp_base_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef VP_BASE_PLUGIN_DOT_H
#define VP_BASE_PLUGIN_DOT_H

#include <cstdint>
#include <string>
#include <vector>

#include "xdp/profile/database/database.h"
Expand Down Expand Up @@ -73,6 +75,24 @@ namespace xdp {
XDP_CORE_EXPORT void endWrite();
XDP_CORE_EXPORT void trySafeWrite(const std::string& type, bool openNewFiles);

// Run-lifecycle hook implementations. Plugins that want to react to
// xrt::run construction / start / wait override one or more of these.
// Defaults are no-ops so plugins that don't care need no code.
// These are NEVER called directly by plugin _cb.cpp glue; the public
// non-virtual run*Hook wrappers below are the only entry point and
// they filter out XDP-internal runs first.
virtual void runConstructorImpl(void* /*run_impl_ptr*/, void* /*hwctx*/,
uint32_t /*run_uid*/,
const std::string& /*kernel_name*/,
void* /*elf_handle*/) {}
virtual void runStartImpl(void* /*run_impl_ptr*/, void* /*hwctx*/,
uint32_t /*run_uid*/,
const std::string& /*kernel_name*/) {}
virtual void runWaitImpl(void* /*run_impl_ptr*/, void* /*hwctx*/,
uint32_t /*run_uid*/,
const std::string& /*kernel_name*/,
int /*ert_cmd_state*/) {}

public:
XDP_CORE_EXPORT XDPPlugin() ;
XDP_CORE_EXPORT virtual ~XDPPlugin() ;
Expand All @@ -90,6 +110,24 @@ namespace xdp {

XDP_CORE_EXPORT
static unsigned int get_trace_file_dump_int_s ();

// Run-lifecycle hook entry points. Plugin _cb.cpp glue MUST call
// these (not the protected *Impl methods). Each one first skips
// runs that an XDP plugin itself submitted (kernels whose name has
// the "XDP_KERNEL" prefix) and otherwise delegates to the
// corresponding virtual *Impl. These are intentionally non-virtual
// so derived plugins cannot accidentally bypass the filter.
XDP_CORE_EXPORT void runConstructorHook(void* run_impl_ptr, void* hwctx,
uint32_t run_uid,
const std::string& kernel_name,
void* elf_handle);
XDP_CORE_EXPORT void runStartHook(void* run_impl_ptr, void* hwctx,
uint32_t run_uid,
const std::string& kernel_name);
XDP_CORE_EXPORT void runWaitHook(void* run_impl_ptr, void* hwctx,
uint32_t run_uid,
const std::string& kernel_name,
int ert_cmd_state);
} ;

}
Expand Down
Loading