Skip to content

Commit

Permalink
Refactored the AIE Trace Plugin to support both Edge and x86 devices (X…
Browse files Browse the repository at this point in the history
  • Loading branch information
nishraptor authored Nov 10, 2022
1 parent 5879b2b commit 7e30665
Show file tree
Hide file tree
Showing 23 changed files with 2,049 additions and 382 deletions.
21 changes: 0 additions & 21 deletions src/runtime_src/core/common/config_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,20 +313,6 @@ get_aie_trace()
return value;
}

inline bool
get_aie_trace_flush()
{
static bool value = detail::get_bool_value("Debug.aie_trace_flush", false);
return value;
}

inline std::string
get_aie_trace_counter_scheme()
{
static std::string value = detail::get_string_value("Debug.aie_trace_counter_scheme", "es2");
return value;
}

inline std::string
get_aie_trace_metrics()
{
Expand Down Expand Up @@ -358,13 +344,6 @@ get_aie_trace_buffer_offload_interval_ms()
return value;
}

inline unsigned int
get_aie_trace_file_dump_interval_s()
{
static unsigned int value = detail::get_uint_value("Debug.aie_trace_file_dump_interval_s", 5);
return value;
}

inline std::string
get_aie_profile_core_metrics()
{
Expand Down
8 changes: 5 additions & 3 deletions src/runtime_src/xdp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,10 @@ file(GLOB XRT_XDP_AIE_TRACE_PLUGIN_FILES
"${XRT_XDP_PROFILE_DEVICE_AIE_TRACE_DIR}/*.cpp"
"${XRT_XDP_PROFILE_HAL_DEVICE_DIR}/*.h"
"${XRT_XDP_PROFILE_HAL_DEVICE_DIR}/*.cpp"
"${XRT_XDP_AIE_TRACE_PLUGIN_DIR}/*.h"
"${XRT_XDP_AIE_TRACE_PLUGIN_DIR}/*.cpp"
"${XRT_XDP_AIE_TRACE_NEW_PLUGIN_DIR}/*.h"
"${XRT_XDP_AIE_TRACE_NEW_PLUGIN_DIR}/*.cpp"
"${XRT_XDP_AIE_TRACE_NEW_PLUGIN_DIR}/edge/*.h"
"${XRT_XDP_AIE_TRACE_NEW_PLUGIN_DIR}/edge/*.cpp"
"${XRT_XDP_AIE_TRACE_WRITER_DIR}/*.h"
"${XRT_XDP_AIE_TRACE_WRITER_DIR}/*.cpp"
)
Expand Down Expand Up @@ -453,7 +455,7 @@ if (${XRT_NATIVE_BUILD} STREQUAL "yes")
add_library(xdp_aie_trace_plugin MODULE ${XRT_XDP_AIE_TRACE_NEW_PLUGIN_FILES})
target_link_libraries(xdp_aie_trace_plugin PRIVATE xdp_core xrt_core)
set_target_properties(xdp_aie_trace_plugin PROPERTIES VERSION ${XRT_VERSION_STRING} SOVERSION ${XRT_SOVERSION})
target_compile_definitions(xdp_aie_trace_plugin PRIVATE XRT_NATIVE_BUILD=1)
target_compile_definitions(xdp_aie_trace_plugin PRIVATE XRT_X86_BUILD=1)
install (TARGETS xdp_aie_trace_plugin
LIBRARY DESTINATION ${XRT_INSTALL_LIB_DIR}/xrt/module
)
Expand Down
61 changes: 57 additions & 4 deletions src/runtime_src/xdp/profile/database/static_info_database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,35 @@ namespace xdp {
else
return xclbin->aie.clockRateAIEMHz ;
}

void VPStaticDatabase::setAIEClockRateMHz(std::shared_ptr<xrt_core::device> device, uint64_t deviceId){
std::lock_guard<std::mutex> lock(deviceLock) ;

void
VPStaticDatabase::setDeviceName(uint64_t deviceId, const std::string& name)
if (deviceInfo.find(deviceId) == deviceInfo.end())
return;

XclbinInfo* xclbin = deviceInfo[deviceId]->currentXclbin() ;
if (!xclbin)
return;

auto data = device->get_axlf_section(AIE_METADATA);
if (!data.first || !data.second)
return;

boost::property_tree::ptree aie_meta;

std::stringstream aie_stream;
aie_stream.write(data.first, data.second);
boost::property_tree::read_json(aie_stream,aie_meta);

//read_aie_metadata(data.first, data.second, aie_meta);
auto dev_node = aie_meta.get_child("aie_metadata.DeviceData");

xclbin->aie.clockRateAIEMHz = dev_node.get<double>("AIEFrequency");
}


void VPStaticDatabase::setDeviceName(uint64_t deviceId, const std::string& name)
{
std::lock_guard<std::mutex> lock(deviceLock) ;

Expand Down Expand Up @@ -389,6 +415,33 @@ namespace xdp {
return xclbin->deviceIntf ;
}

DeviceIntf* VPStaticDatabase::createDeviceIntf(uint64_t deviceId,
xdp::Device* dev)
{
std::lock_guard<std::mutex> lock(deviceLock);

if (deviceInfo.find(deviceId) == deviceInfo.end())
return nullptr;
XclbinInfo* xclbin = deviceInfo[deviceId]->currentXclbin();
if (xclbin == nullptr)
return nullptr;
if (xclbin->deviceIntf != nullptr)
return xclbin->deviceIntf;

xclbin->deviceIntf = new DeviceIntf();
xclbin->deviceIntf->setDevice(dev);
try {
xclbin->deviceIntf->readDebugIPlayout();
}
catch (std::exception& /* e */) {
// If reading the debug ip layout fails, we shouldn't have
// any device interface at all
delete xclbin->deviceIntf;
xclbin->deviceIntf = nullptr;
}
return xclbin->deviceIntf;
}

void VPStaticDatabase::setKDMACount(uint64_t deviceId, uint64_t num)
{
std::lock_guard<std::mutex> lock(deviceLock) ;
Expand Down Expand Up @@ -1352,8 +1405,8 @@ namespace xdp {

XclbinInfo* currentXclbin = new XclbinInfo() ;
currentXclbin->uuid = device->get_xclbin_uuid() ;
currentXclbin->pl.clockRatePLMHz = findClockRate(device) ;

currentXclbin->pl.clockRatePLMHz = findClockRate(device) ;
setAIEClockRateMHz(device,deviceId);
/* Configure AMs if context monitoring is supported
* else disable alll AMs on this device
*/
Expand Down
7 changes: 6 additions & 1 deletion src/runtime_src/xdp/profile/database/static_info_database.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ namespace xdp {
struct DeviceInfo ;
struct XclbinInfo ;

//Forward declaration of XDP's device structure
class Device;

// The VPStaticDatabase contains information that is expected to not change
// throughout the execution of the program. For device information,
// we keep track of the structure of the hardware in all the xclbins
Expand Down Expand Up @@ -233,10 +236,12 @@ namespace xdp {
XDP_EXPORT void deleteCurrentlyUsedDeviceInterface(uint64_t deviceId) ;
XDP_EXPORT bool isDeviceReady(uint64_t deviceId) ;
XDP_EXPORT double getClockRateMHz(uint64_t deviceId, bool PL = true) ;
XDP_EXPORT void setDeviceName(uint64_t deviceId, const std::string& name) ;
XDP_EXPORT void setAIEClockRateMHz(std::shared_ptr<xrt_core::device> device, uint64_t deviceId) ;
XDP_EXPORT void setDeviceName(uint64_t deviceId, const std::string& name) ;
XDP_EXPORT std::string getDeviceName(uint64_t deviceId) ;
XDP_EXPORT void setDeviceIntf(uint64_t deviceId, DeviceIntf* devIntf) ;
XDP_EXPORT DeviceIntf* getDeviceIntf(uint64_t deviceId) ;
XDP_EXPORT DeviceIntf* createDeviceIntf(uint64_t deviceId, xdp::Device* dev);
XDP_EXPORT void setKDMACount(uint64_t deviceId, uint64_t num) ;
XDP_EXPORT uint64_t getKDMACount(uint64_t deviceId) ;
XDP_EXPORT void setHostMaxReadBW(uint64_t deviceId, double bw) ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
#include "xdp/profile/plugin/aie_trace_new/x86/aie_trace_kernel_config.h"

/*
* XRT_NATIVE_BUILD is set only for x86 builds
* XRT_X86_BUILD is set only for x86 builds
* Only compile this on edge+versal build
*/
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_NATIVE_BUILD)
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_X86_BUILD)
#include <sys/mman.h>
#include "core/include/xrt.h"
#include "core/edge/user/shim.h"
Expand Down Expand Up @@ -146,16 +146,16 @@ bool AIETraceOffload::initReadTrace()
} else {
memIndex = 0; // for now

#if defined (XRT_ENABLE_AIE) && defined (XRT_NATIVE_BUILD)
#if defined (XRT_ENABLE_AIE) && defined (XRT_X86_BUILD)
bool success = setupPSKernel();
return success;
#endif

/*
* XRT_NATIVE_BUILD is set only for x86 builds
* XRT_X86_BUILD is set only for x86 builds
* Only compile this on edge+versal build
*/
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_NATIVE_BUILD)
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_X86_BUILD)
gmioDMAInsts.clear();
gmioDMAInsts.resize(numStream);
#endif
Expand All @@ -180,10 +180,10 @@ bool AIETraceOffload::initReadTrace()
deviceIntf->initAIETs2mm(bufAllocSz, bufAddr, i, mEnCircularBuf);
} else {
/*
* XRT_NATIVE_BUILD is set only for x86 builds
* XRT_X86_BUILD is set only for x86 builds
* Only compile this on edge+versal build
*/
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_NATIVE_BUILD)
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_X86_BUILD)
VPDatabase* db = VPDatabase::Instance();
TraceGMIO* traceGMIO = (db->getStaticInfo()).getTraceGMIO(deviceId, i);

Expand Down Expand Up @@ -257,7 +257,7 @@ void AIETraceOffload::endReadTrace()
* XRT_NATIVE_BUILD is set only for x86 builds
* Only compile this on edge+versal build
*/
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_NATIVE_BUILD)
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_X86_BUILD)
VPDatabase* db = VPDatabase::Instance();
TraceGMIO* traceGMIO = (db->getStaticInfo()).getTraceGMIO(deviceId, i);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* 2. For GMIO offload, ps kernel needs to be used to initialize and read data
*/

#if defined (XRT_ENABLE_AIE) && ! defined (XRT_NATIVE_BUILD)
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_X86_BUILD)
#include "core/edge/user/aie/aie.h"
#endif

Expand Down Expand Up @@ -71,7 +71,7 @@ struct AIETraceBufferInfo
* XRT_NATIVE_BUILD is set only for x86 builds
* Only compile this on edge+versal build
*/
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_NATIVE_BUILD)
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_X86_BUILD)
struct AIETraceGmioDMAInst
{
// C_RTS Shim DMA to where this GMIO object is mapped
Expand Down Expand Up @@ -146,7 +146,7 @@ class AIETraceOffload
* XRT_NATIVE_BUILD is set only for x86 builds
* Only compile this on edge+versal build
*/
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_NATIVE_BUILD)
#if defined (XRT_ENABLE_AIE) && ! defined (XRT_X86_BUILD)
std::vector<AIETraceGmioDMAInst> gmioDMAInsts;
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
* under the License.
*/

#define XDP_SOURCE

#include "aie_trace_cb.h"
#include "aie_trace_plugin.h"


namespace xdp {

// AIE Trace Plugin has only a static instance of the plugin object and a callback
Expand All @@ -25,23 +28,20 @@ namespace xdp {

static void updateAIEDevice(void* handle)
{
if (AieTracePluginUnified::alive()) {
if (AieTracePluginUnified::alive())
aieTracePluginInstance.updateAIEDevice(handle);
}
}

static void flushAIEDevice(void* handle)
{
if (AieTracePluginUnified::alive()) {
if (AieTracePluginUnified::alive())
aieTracePluginInstance.flushAIEDevice(handle);
}
}

static void finishFlushAIEDevice(void* handle)
{
if (AieTracePluginUnified::alive()) {
if (AieTracePluginUnified::alive())
aieTracePluginInstance.finishFlushAIEDevice(handle);
}
}

} // end namespace xdp
Expand All @@ -58,7 +58,7 @@ void flushAIEDevice(void* handle)
xdp::flushAIEDevice(handle);
}

extern "C"
extern "C"
void finishFlushAIEDevice(void* handle)
{
xdp::finishFlushAIEDevice(handle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
#ifdef XDP_PLUGIN_AIE_TRACE_CB_H
#define XDP_PLUGIN_AIE_TRACE_CB_H

#include "xdp/config.h"

extern "C" {

void updateAIEDevice(void* handle) ;
void flushAIEDevice(void* handle) ;
void finishFlushAIEDevice(void* handle) ;
XDP_EXPORT void updateAIEDevice(void* handle) ;
XDP_EXPORT void flushAIEDevice(void* handle) ;
XDP_EXPORT void finishFlushAIEDevice(void* handle) ;

}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,12 @@
#define AIE_TRACE_IMPL_H

#include <cstdint>

#include "xdp/profile/plugin/vp_base/vp_base_plugin.h"
#include "xdp/profile/device/aie_trace/aie_trace_offload.h"
#include "xdp/profile/database/events/creator/aie_trace_data_logger.h"

#include <memory>
#include "aie_trace_metadata.h"

namespace xdp {

class VPDatabase;

// AIE trace configurations can be done in different ways depending
// on the platform. For example, platforms like the VCK5000 or
Expand All @@ -47,8 +45,6 @@ namespace xdp {
virtual ~AieTraceImpl() {};

virtual void updateDevice() = 0;
virtual void flushDevice() = 0;
virtual void finishFlushDevice() = 0;
virtual uint64_t checkTraceBufSize(uint64_t size) = 0;
};

Expand Down
Loading

0 comments on commit 7e30665

Please sign in to comment.