Skip to content

Commit

Permalink
[XDP] First cut implementation of AIE Debug feature for all devices (X…
Browse files Browse the repository at this point in the history
  • Loading branch information
pgschuey authored and rchane committed Jan 24, 2025
1 parent b1efa19 commit b667ded
Show file tree
Hide file tree
Showing 44 changed files with 25,545 additions and 302 deletions.
9 changes: 4 additions & 5 deletions src/runtime_src/core/common/config_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -769,32 +769,31 @@ get_device_offline_timer()
return value;
}

// Configurations under AIE_debug_settings section
inline std::string
get_aie_debug_settings_core_registers()
{
static std::string value = detail::get_string_value("AIE_debug_settings.core_registers", "");
static std::string value = detail::get_string_value("AIE_debug_settings.core_registers", "all");
return value;
}

inline std::string
get_aie_debug_settings_memory_registers()
{
static std::string value = detail::get_string_value("AIE_debug_settings.memory_registers", "");
static std::string value = detail::get_string_value("AIE_debug_settings.memory_registers", "all");
return value;
}

inline std::string
get_aie_debug_settings_interface_registers()
{
static std::string value = detail::get_string_value("AIE_debug_settings.interface_registers", "");
static std::string value = detail::get_string_value("AIE_debug_settings.interface_registers", "all");
return value;
}

inline std::string
get_aie_debug_settings_memory_tile_registers()
{
static std::string value = detail::get_string_value("AIE_debug_settings.memory_tile_registers", "");
static std::string value = detail::get_string_value("AIE_debug_settings.memory_tile_registers", "all");
return value;
}

Expand Down
3 changes: 3 additions & 0 deletions src/runtime_src/core/edge/hw_emu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ file(GLOB XDP_PLUGIN_HW_EM_FILES
"${XDP_PLUGIN_DIR}/aie_status.cpp"
"${XDP_PLUGIN_DIR}/aie_profile.h"
"${XDP_PLUGIN_DIR}/aie_profile.cpp"
"${XDP_PLUGIN_DIR}/aie_debug.h"
"${XDP_PLUGIN_DIR}/aie_debug.cpp"

)

if (DEFINED XRT_AIE_BUILD)
Expand Down
72 changes: 72 additions & 0 deletions src/runtime_src/core/edge/user/plugin/xdp/aie_debug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright (C) 2024-2025 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
* License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#include "aie_debug.h"
#include "core/common/module_loader.h"
#include "core/common/dlfcn.h"
#include <iostream>

namespace xdp {
namespace aie {
namespace debug {
void load()
{
//#ifdef XRT_ENABLE_AIE
static xrt_core::module_loader xdp_aie_loader("xdp_aie_debug_plugin",
register_callbacks,
warning_callbacks);
//#endif
}
std::function<void (void*)> update_device_cb;
std::function<void (void*)> end_poll_cb;

void register_callbacks(void* handle)
{
using ftype = void (*)(void*); // Device handle

update_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "updateAIEDebugDevice"));
if (xrt_core::dlerror() != nullptr)
update_device_cb = nullptr;

end_poll_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "endAIEDebugRead"));
if (xrt_core::dlerror() != nullptr)
end_poll_cb = nullptr;
}

void warning_callbacks()
{
// No warnings for AIE debug plugin
}

} // end namespace debug

namespace dbg {
void update_device(void* handle)
{
if (debug::update_device_cb != nullptr) {
debug::update_device_cb(handle) ;
}
}

void end_poll(void* handle)
{
if (debug::end_poll_cb != nullptr) {
debug::end_poll_cb(handle) ;
}
}
} // end namespace dbg
} // end namespace aie
} // end namespace xdp
37 changes: 37 additions & 0 deletions src/runtime_src/core/edge/user/plugin/xdp/aie_debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* Copyright (C) 2024-2025 Advanced Micro Devices, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may
* not use this file except in compliance with the License. A copy of the
* License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

#ifndef AIE_DEBUG_DOT_H
#define AIE_DEBUG_DOT_H

namespace xdp {
namespace aie {

namespace debug {
void load();
void register_callbacks(void* handle);
void warning_callbacks();
} // end namespace debug

namespace dbg {
void update_device(void* handle);
void end_poll(void* handle);
} // end namespace dbg

} // end namespace aie
} // end namespace xdp

#endif
5 changes: 5 additions & 0 deletions src/runtime_src/core/edge/user/plugin/xdp/plugin_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#include "aie_status.h"
#include "aie_profile.h"
#include "aie_debug.h"

#ifndef __HWEM__
#include "aie_trace.h"
Expand Down Expand Up @@ -56,6 +57,8 @@ bool load()

if (xrt_core::config::get_aie_profile())
xdp::aie::profile::load();
if (xrt_core::config::get_aie_debug())
xdp::aie::debug::load();

if (xrt_core::config::get_noc_profile())
xdp::noc::profile::load();
Expand Down Expand Up @@ -103,6 +106,8 @@ bool load()

if (xrt_core::config::get_aie_profile())
xdp::aie::profile::load();
if (xrt_core::config::get_aie_debug())
xdp::aie::debug::load();
#endif
return true ;
}
Expand Down
16 changes: 10 additions & 6 deletions src/runtime_src/core/edge/user/plugin/xdp/shim_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "aie_profile.h"
#include "aie_status.h"
#include "hal_device_offload.h"
#include "aie_debug.h"

#ifdef __HWEM__
#include "hw_emu_device_offload.h"
Expand All @@ -45,14 +46,15 @@ inline
void update_device(void* handle)
{
#ifndef __HWEM__
hal::update_device(handle);
aie::update_device(handle);
hal::update_device(handle); //PL device offload
aie::update_device(handle); //trace
//aie::dbg::update_device(handle); //debug
#else
hal::hw_emu::update_device(handle);
hal::hw_emu::update_device(handle); //PL device offload
#endif

aie::ctr::update_device(handle);
aie::sts::update_device(handle);
aie::dbg::update_device(handle); //debug
aie::ctr::update_device(handle); //counters=profiling
aie::sts::update_device(handle); //status
}

// The flush_device callback should be called just before a new xclbin
Expand Down Expand Up @@ -84,8 +86,10 @@ void finish_flush_device(void* handle)
{
#ifndef __HWEM__
aie::finish_flush_device(handle);
//aie::dbg::end_poll(handle);
#endif
aie::ctr::end_poll(handle);
aie::dbg::end_poll(handle);
}

} // end namespace xdp
Expand Down
23 changes: 22 additions & 1 deletion src/runtime_src/xdp/profile/database/dynamic_event_database.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <iostream>

namespace xdp {

VPDynamicDatabase::VPDynamicDatabase(VPDatabase* d) :
db(d), eventId(1)
{
Expand Down Expand Up @@ -291,6 +291,27 @@ namespace xdp {
return device_db->moveAIESamples();
}

void VPDynamicDatabase::addAIEDebugSample(uint64_t deviceId, uint8_t col,
uint8_t row, uint32_t value, uint64_t offset, std::string name)
{
auto device_db = getDeviceDB(deviceId);
device_db->addAIEDebugSample(col, row, value, offset, name);
}

std::vector<xdp::aie::AIEDebugDataType>
VPDynamicDatabase::getAIEDebugSamples(uint64_t deviceId)
{
auto device_db = getDeviceDB(deviceId);
return device_db->getAIEDebugSamples();
}

std::vector<xdp::aie::AIEDebugDataType>
VPDynamicDatabase::moveAIEDebugSamples(uint64_t deviceId)
{
auto device_db = getDeviceDB(deviceId);
return device_db->moveAIEDebugSamples();
}

void VPDynamicDatabase::addAIETimerSample(uint64_t deviceId, unsigned long timestamp1,
unsigned long timestamp2, const std::vector<uint64_t>& values)
{
Expand Down
10 changes: 7 additions & 3 deletions src/runtime_src/xdp/profile/database/dynamic_event_database.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ namespace xdp {
XDP_CORE_EXPORT void addDependency(uint64_t id, uint64_t dependency) ;
XDP_CORE_EXPORT std::map<uint64_t, std::vector<uint64_t>> getDependencyMap() ;

// Add and get AIE Trace Data Buffer
// Add and get AIE Trace Data Buffer
XDP_CORE_EXPORT void addAIETraceData(uint64_t deviceId, uint64_t strmIndex, void* buffer, uint64_t bufferSz, bool copy);
XDP_CORE_EXPORT aie::TraceDataType* getAIETraceData(uint64_t deviceId, uint64_t strmIndex);

Expand All @@ -173,7 +173,11 @@ namespace xdp {
XDP_CORE_EXPORT std::vector<counters::Sample> getPowerSamples(uint64_t deviceId) ;

XDP_CORE_EXPORT void addAIESample(uint64_t deviceId, double timestamp,
const std::vector<uint64_t>& values) ;
const std::vector<uint64_t>& values);
XDP_CORE_EXPORT void addAIEDebugSample(uint64_t deviceId, uint8_t col,
uint8_t row, uint32_t value, uint64_t offset, std::string name);
XDP_CORE_EXPORT std::vector<xdp::aie::AIEDebugDataType> moveAIEDebugSamples(uint64_t deviceId);
XDP_CORE_EXPORT std::vector<xdp::aie::AIEDebugDataType> getAIEDebugSamples(uint64_t deviceId);
XDP_CORE_EXPORT std::vector<counters::Sample> getAIESamples(uint64_t deviceId) ;
XDP_CORE_EXPORT std::vector<counters::Sample> moveAIESamples(uint64_t deviceId);
XDP_CORE_EXPORT void addAIETimerSample(uint64_t deviceId, unsigned long timestamp1,
Expand All @@ -188,7 +192,7 @@ namespace xdp {
XDP_CORE_EXPORT void setPLDeadlockInfo(uint64_t deviceId, const std::string& str);
XDP_CORE_EXPORT std::string getPLDeadlockInfo();
} ;

}

#endif
15 changes: 14 additions & 1 deletion src/runtime_src/xdp/profile/database/dynamic_info/aie_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace xdp {

SampleContainer samples;
DoubleSampleContainer timerSamples;
AIEDebugContainer aieDebugSamples;

std::mutex traceLock; // Protects "traceData" vector

Expand All @@ -54,10 +55,14 @@ namespace xdp {
void addAIESample(double timestamp, const std::vector<uint64_t>& values);

inline
void addAIETimerSample(unsigned long timestamp1, unsigned long timestamp2,
void addAIETimerSample(unsigned long timestamp1, unsigned long timestamp2,
const std::vector<uint64_t>& values)
{ timerSamples.addSample({timestamp1, timestamp2, values}); }

inline
void addAIEDebugSample(uint8_t col, uint8_t row, uint32_t value, uint64_t offset, std::string name)
{ aieDebugSamples.addAIEDebugData({col, row, value, offset, name}); }

inline
std::vector<counters::Sample> getAIESamples()
{ return samples.getSamples(); }
Expand All @@ -69,6 +74,14 @@ namespace xdp {
inline
std::vector<counters::DoubleSample> getAIETimerSamples()
{ return timerSamples.getSamples(); }

inline
std::vector<xdp::aie::AIEDebugDataType> getAIEDebugSamples()
{ return aieDebugSamples.getAIEDebugData(); }

inline
std::vector<xdp::aie::AIEDebugDataType> moveAIEDebugSamples()
{ return aieDebugSamples.moveAIEDebugData(); }
};

} // end namespace xdp
Expand Down
14 changes: 13 additions & 1 deletion src/runtime_src/xdp/profile/database/dynamic_info/device_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,14 @@ namespace xdp {
void addAIESample(double timestamp, const std::vector<uint64_t>& values)
{ aie_db.addAIESample(timestamp, values); }

void addAIETimerSample(unsigned long timestamp1, unsigned long timestamp2,
void addAIETimerSample(unsigned long timestamp1, unsigned long timestamp2,
const std::vector<uint64_t>& values)
{ aie_db.addAIETimerSample(timestamp1, timestamp2, values); }

inline
void addAIEDebugSample(uint8_t col, uint8_t row, uint32_t value, uint64_t offset, std::string name)
{ aie_db.addAIEDebugSample(col, row, value, offset, name); }

inline std::vector<counters::Sample> getAIESamples()
{ return aie_db.getAIESamples(); }

Expand All @@ -126,6 +130,14 @@ namespace xdp {
inline std::string& getPLDeadlockInfo()
{ return pl_db.getDeadlockInfo(); }

inline
std::vector<xdp::aie::AIEDebugDataType> getAIEDebugSamples()
{ return aie_db.getAIEDebugSamples(); }

inline std::vector<xdp::aie::AIEDebugDataType> moveAIEDebugSamples()
{ return aie_db.moveAIEDebugSamples(); }


};

} // end namespace xdp
Expand Down
27 changes: 27 additions & 0 deletions src/runtime_src/xdp/profile/database/dynamic_info/samples.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,33 @@ namespace xdp {
}

};

class AIEDebugContainer
{
private:
std::vector<xdp::aie::AIEDebugDataType> samples;
std::mutex containerLock; // Protects the "samples" vector

public:
AIEDebugContainer() = default;
~AIEDebugContainer() = default;

inline void addAIEDebugData(const xdp::aie::AIEDebugDataType& s)
{
std::lock_guard<std::mutex> lock(containerLock);
samples.push_back(s);
}
inline std::vector<xdp::aie::AIEDebugDataType> getAIEDebugData()
{
std::lock_guard<std::mutex> lock(containerLock);
return samples;
}
inline std::vector<xdp::aie::AIEDebugDataType> moveAIEDebugData()
{
std::lock_guard<std::mutex> lock(containerLock);
return std::move(samples);
}
};
} // end namespace xdp

#endif
Loading

0 comments on commit b667ded

Please sign in to comment.