Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Xilinx/XRT into 2024.2_CRs_5
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Schumacher committed Oct 10, 2024
2 parents c8d09ba + 76b9e7d commit dfe921c
Show file tree
Hide file tree
Showing 25 changed files with 1,103 additions and 58 deletions.
4 changes: 4 additions & 0 deletions src/runtime_src/core/common/api/module_int.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ sync(const xrt::module&);
ert_cmd_opcode
get_ert_opcode(const xrt::module& module);

// Dump scratch pad mem buffer
void
dump_scratchpad_mem(const xrt::module& module);

} // xrt_core::module_int

#endif
7 changes: 7 additions & 0 deletions src/runtime_src/core/common/api/xrt_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2478,6 +2478,9 @@ class run_impl
}

m_usage_logger->log_kernel_run_info(kernel.get(), this, state);
static bool dump = xrt_core::config::get_feature_toggle("Debug.dump_scratchpad_mem");
if (dump)
xrt_core::module_int::dump_scratchpad_mem(m_module);

return state;
}
Expand All @@ -2504,6 +2507,10 @@ class run_impl

if (state == ERT_CMD_STATE_COMPLETED) {
m_usage_logger->log_kernel_run_info(kernel.get(), this, state);
static bool dump = xrt_core::config::get_feature_toggle("Debug.dump_scratchpad_mem");
if (dump)
xrt_core::module_int::dump_scratchpad_mem(m_module);

return std::cv_status::no_timeout;
}

Expand Down
34 changes: 33 additions & 1 deletion src/runtime_src/core/common/api/xrt_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,13 @@ struct patcher
void
patch57_aie4(uint32_t* bd_data_ptr, uint64_t patch)
{
constexpr uint64_t ddr_aie_addr_offset = 0x80000000;

uint64_t base_address =
((static_cast<uint64_t>(bd_data_ptr[0]) & 0x1FFFFFF) << 32) | // NOLINT
bd_data_ptr[1];

base_address += patch;
base_address += patch + ddr_aie_addr_offset; //2G offset
bd_data_ptr[1] = (uint32_t)(base_address & 0xFFFFFFFF); // NOLINT
bd_data_ptr[0] = (bd_data_ptr[0] & 0xFE000000) | ((base_address >> 32) & 0x1FFFFFF);// NOLINT
}
Expand Down Expand Up @@ -1392,6 +1394,26 @@ class module_sram : public module_impl
{
return m_scratch_pad_mem;
}

void
dump_scratchpad_mem()
{
if (m_scratch_pad_mem.size() == 0) {
xrt_core::message::send(xrt_core::message::severity_level::debug, "xrt_module",
"preemption scratchpad memory is not available");
return;
}

// sync data from device before dumping into file
m_scratch_pad_mem.sync(XCL_BO_SYNC_BO_FROM_DEVICE);

std::string dump_file_name = "preemption_scratchpad_mem" + std::to_string(get_id()) + ".bin";
dump_bo(m_scratch_pad_mem, dump_file_name);

std::string msg {"dumped file "};
msg.append(dump_file_name);
xrt_core::message::send(xrt_core::message::severity_level::debug, "xrt_module", msg);
}
};

} // namespace xrt
Expand Down Expand Up @@ -1468,6 +1490,16 @@ get_ert_opcode(const xrt::module& module)
return module.get_handle()->get_ert_opcode();
}

void
dump_scratchpad_mem(const xrt::module& module)
{
auto module_sram = std::dynamic_pointer_cast<xrt::module_sram>(module.get_handle());
if (!module_sram)
throw std::runtime_error("Getting module_sram failed, wrong module object passed\n");

module_sram->dump_scratchpad_mem();
}

} // xrt_core::module_int

////////////////////////////////////////////////////////////////
Expand Down
14 changes: 14 additions & 0 deletions src/runtime_src/core/common/config_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@ get_ml_timeline_buffer_size()
return value;
}

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

inline std::string
get_aie_pc_settings()
{
static std::string value = detail::get_string_value("AIE_pc_settings.addresses", "");
return value;
}

inline bool
get_aie_halt()
{
Expand Down
30 changes: 30 additions & 0 deletions src/runtime_src/core/common/info_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,35 @@ add_clock_info(const xrt_core::device* device, ptree_type& pt)
}
}

void
add_tops_info(const xrt_core::device* device, ptree_type& pt)
{
ptree_type pt_tops_array;

try
{
auto res_info = xrt_core::device_query<xq::xrt_resource_raw>(device);
if (res_info.empty())
return;

for (auto &res : res_info)
{
if (res.type != xrt_core::query::xrt_resource_raw::resource_type::ipu_tops_max)
continue;

ptree_type pt_tops;
pt_tops.add("id", xq::xrt_resource_raw::get_name(res.type));
pt_tops.add("value", res.data_double);
pt_tops_array.push_back(std::make_pair("", pt_tops));
}
pt.put_child("tops", pt_tops_array);
}
catch (const xq::no_such_key &)
{
// ignoring if not available: Edge Case
}
}

void
add_electrical_info(const xrt_core::device* device, ptree_type& pt)
{
Expand Down Expand Up @@ -421,6 +450,7 @@ add_platform_info(const xrt_core::device* device, ptree_type& pt_platform_array)
ptree_type pt_platforms;

add_static_region_info(device, pt_platform);
add_tops_info(device, pt_platform);
add_status_info(device, pt_platform);

const auto device_class = xrt_core::device_query_default<xrt_core::query::device_class>(device, xrt_core::query::device_class::type::alveo);
Expand Down
60 changes: 59 additions & 1 deletion src/runtime_src/core/common/query_requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ enum class key_type
ip_layout_raw,
debug_ip_layout_raw,
clock_freq_topology_raw,
xrt_resource_raw,
dma_stream,
device_status,
kds_cu_info,
Expand Down Expand Up @@ -1185,6 +1186,63 @@ struct clock_freq_topology_raw : request
get(const device*) const = 0;
};

/**
* Return some of the resouces within a NPU device
*/
struct xrt_resource_raw : request
{
/**
* enum class resource_type - represents the different types of resources
*/
enum class resource_type
{
ipu_clk_max, // Max H-Clocks, query returns uint64 value
ipu_tops_max, // Max TOPs, query returns double value
ipu_task_max, // Max Tasks, query returns uint64 value
ipu_tops_curr, // Current TOPs, query returns double value
ipu_task_curr // Current Tasks, query returns uint64 value
};

/**
* The buffer that holds the resource query data
*/
struct xrt_resource_query
{
resource_type type;
union
{
uint64_t data_uint64; // holds the value represented as uint64
double data_double; // holds the value represented as double
};
};

using result_type = std::vector<xrt_resource_query>; // get value type
static const key_type key = key_type::xrt_resource_raw;

static std::string
get_name(xrt_core::query::xrt_resource_raw::resource_type type)
{
switch (type)
{
case resource_type::ipu_clk_max:
return "Max Supported H-Clocks";
case resource_type::ipu_tops_max:
return "Max Supported TOPs";
case resource_type::ipu_task_max:
return "Max Supported Tasks";
case resource_type::ipu_tops_curr:
return "Current TOPs";
case resource_type::ipu_task_curr:
return "Current Tasks";
default:
throw xrt_core::internal_error("enum value does not exists");
}
}

virtual std::any
get(const device *) const = 0;
};

struct xmc_version : request
{
using result_type = std::string;
Expand Down Expand Up @@ -3750,7 +3808,7 @@ struct performance_mode : request

/*
* this request force enables or disables pre-emption globally
* 0: enable; 1: disable
* 1: enable; 0: disable
*/
struct preemption : request
{
Expand Down
64 changes: 63 additions & 1 deletion src/runtime_src/core/common/xdp/profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,55 @@ finish_flush_device(void* handle)

} // end namespace xrt_core::xdp::ml_timeline

namespace xrt_core::xdp::aie_pc {

std::function<void (void*)> update_device_cb;
std::function<void (void*)> finish_flush_device_cb;

void
register_callbacks(void* handle)
{
#ifdef XDP_CLIENT_BUILD
using ftype = void (*)(void*);

update_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "updateDeviceAIEPC"));
finish_flush_device_cb = reinterpret_cast<ftype>(xrt_core::dlsym(handle, "finishflushDeviceAIEPC"));
#else
(void)handle;
#endif

}

void
warning_callbacks()
{
}

void
load()
{
static xrt_core::module_loader xdp_loader("xdp_aie_pc_plugin",
register_callbacks,
warning_callbacks);
}

// Make connections
void
update_device(void* handle)
{
if (update_device_cb)
update_device_cb(handle);
}

void
finish_flush_device(void* handle)
{
if (finish_flush_device_cb)
finish_flush_device_cb(handle);
}

} // end namespace xrt_core::xdp::aie_pc

namespace xrt_core::xdp::pl_deadlock {

std::function<void (void*)> update_device_cb;
Expand Down Expand Up @@ -338,7 +387,8 @@ update_device(void* handle)
|| xrt_core::config::get_aie_profile()
|| xrt_core::config::get_aie_trace()
|| xrt_core::config::get_aie_debug()
|| xrt_core::config::get_aie_halt()) {
|| xrt_core::config::get_aie_halt()
|| xrt_core::config::get_aie_pc()) {
/* All the above plugins are dependent on xdp_core library. So,
* explicitly load it to avoid library search issue in implicit loading.
*/
Expand Down Expand Up @@ -400,6 +450,16 @@ update_device(void* handle)
xrt_core::xdp::ml_timeline::update_device(handle);
}

if (xrt_core::config::get_aie_pc()) {
try {
xrt_core::xdp::aie_pc::load();
}
catch (...) {
return;
}
xrt_core::xdp::aie_pc::update_device(handle);
}

#else

if (xrt_core::config::get_pl_deadlock_detection()
Expand Down Expand Up @@ -431,6 +491,8 @@ finish_flush_device(void* handle)
xrt_core::xdp::aie::debug::end_debug(handle);
if (xrt_core::config::get_ml_timeline())
xrt_core::xdp::ml_timeline::finish_flush_device(handle);
if (xrt_core::config::get_aie_pc())
xrt_core::xdp::aie_pc::finish_flush_device(handle);

#else

Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/edge/drm/zocl/common/zocl_bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ zocl_create_bo(struct drm_device *dev, uint64_t unaligned_size, u32 user_flags)
struct sg_table *zocl_gem_prime_get_sg_table(struct drm_gem_object *obj)
{
struct drm_zocl_bo *zocl_obj = to_zocl_bo(obj);
if (zocl_obj && (zocl_obj->flags & ZOCL_BO_FLAGS_CMA)) {
if (zocl_obj && !(zocl_obj->mm_node)) {
return drm_gem_dma_get_sg_table(&zocl_obj->cma_base);
}
struct drm_device *drm = obj->dev;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ void zocl_free_bo(struct drm_gem_object *obj)
zocl_free_userptr_bo(obj);
else if (zocl_obj->flags & ZOCL_BO_FLAGS_HOST_BO)
zocl_free_host_bo(obj);
else if (zocl_obj->flags & ZOCL_BO_FLAGS_CMA) {
else if (!zocl_obj->mm_node) {
/* Update memory usage statistics */
zocl_update_mem_stat(zdev, obj->size, -1,
zocl_obj->mem_index);
Expand Down
10 changes: 5 additions & 5 deletions src/runtime_src/core/edge/user/aie/aie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ aie_array(const std::shared_ptr<xrt_core::device>& device, const zynqaie::hwctx_
{
dev_inst_obj = {0};
dev_inst = nullptr;
adf::driver_config driver_config = xrt_core::edge::aie::get_driver_config(device.get());
adf::driver_config driver_config = xrt_core::edge::aie::get_driver_config(device.get(), hwctx_obj);

XAie_SetupConfig(ConfigPtr,
driver_config.hw_gen,
Expand Down Expand Up @@ -136,23 +136,23 @@ aie_array(const std::shared_ptr<xrt_core::device>& device, const zynqaie::hwctx_

dev_inst = &dev_inst_obj;

adf::aiecompiler_options aiecompiler_options = xrt_core::edge::aie::get_aiecompiler_options(device.get());
adf::aiecompiler_options aiecompiler_options = xrt_core::edge::aie::get_aiecompiler_options(device.get(), hwctx_obj);
adf::config_manager::initialize(dev_inst, driver_config.mem_num_rows, aiecompiler_options.broadcast_enable_core);

fal_util::initialize(dev_inst); //resource manager initialization

/* Initialize PLIO metadata */
plio_configs = xrt_core::edge::aie::get_plios(device.get());
plio_configs = xrt_core::edge::aie::get_plios(device.get(), hwctx_obj);

/* Initialize gmio api instances */
gmio_configs = xrt_core::edge::aie::get_gmios(device.get());
gmio_configs = xrt_core::edge::aie::get_gmios(device.get(), hwctx_obj);
for (auto config_itr = gmio_configs.begin(); config_itr != gmio_configs.end(); config_itr++)
{
auto p_gmio_api = std::make_shared<adf::gmio_api>(&config_itr->second);
p_gmio_api->configure();
gmio_apis[config_itr->first] = p_gmio_api;
}
external_buffer_configs = xrt_core::edge::aie::get_external_buffers(device.get());
external_buffer_configs = xrt_core::edge::aie::get_external_buffers(device.get(), hwctx_obj);
}

aie_array::
Expand Down
Loading

0 comments on commit dfe921c

Please sign in to comment.