Skip to content

Commit

Permalink
final changes for multi-partition support (#8521)
Browse files Browse the repository at this point in the history
Signed-off-by: ch vamshi krishna <[email protected]>
Co-authored-by: ch vamshi krishna <[email protected]>
  • Loading branch information
chvamshi-xilinx and ch vamshi krishna authored Oct 13, 2024
1 parent ad4be07 commit 4d74e69
Show file tree
Hide file tree
Showing 9 changed files with 662 additions and 607 deletions.
28 changes: 15 additions & 13 deletions src/runtime_src/core/edge/user/aie/aie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ aie_array(const std::shared_ptr<xrt_core::device>& device)
dev_inst = &dev_inst_obj;

adf::aiecompiler_options aiecompiler_options = xrt_core::edge::aie::get_aiecompiler_options(device.get());
adf::config_manager::initialize(dev_inst, driver_config.mem_num_rows, aiecompiler_options.broadcast_enable_core);
m_config = std::make_shared<adf::config_manager>(dev_inst, driver_config.mem_num_rows, aiecompiler_options.broadcast_enable_core);

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

Expand All @@ -82,7 +82,7 @@ aie_array(const std::shared_ptr<xrt_core::device>& device)
gmio_configs = xrt_core::edge::aie::get_gmios(device.get());
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);
auto p_gmio_api = std::make_shared<adf::gmio_api>(&config_itr->second, m_config);
p_gmio_api->configure();
gmio_apis[config_itr->first] = p_gmio_api;
}
Expand Down Expand Up @@ -138,7 +138,7 @@ 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(), hwctx_obj);
adf::config_manager::initialize(dev_inst, driver_config.mem_num_rows, aiecompiler_options.broadcast_enable_core);
m_config = std::make_shared<adf::config_manager>(dev_inst, driver_config.mem_num_rows, aiecompiler_options.broadcast_enable_core);

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

Expand All @@ -149,7 +149,7 @@ aie_array(const std::shared_ptr<xrt_core::device>& device, const zynqaie::hwctx_
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);
auto p_gmio_api = std::make_shared<adf::gmio_api>(&config_itr->second, m_config);
p_gmio_api->configure();
gmio_apis[config_itr->first] = p_gmio_api;
}
Expand Down Expand Up @@ -228,15 +228,16 @@ sync_external_buffer(std::vector<xrt::bo>& bos, adf::external_buffer_config& con
prepare_bd(bd, bos[counter++]);
}

adf::dma_api dma_api_obj(m_config);
for (const auto& port_config : config.shim_port_configs) {
int start_bd = -1;
for (const auto& shim_bd_info : port_config.shim_bd_infos) {
auto buf_idx = shim_bd_info.buf_idx;
adf::dma_api::updateBDAddressLin(&bds[buf_idx].mem_inst, port_config.shim_column, 0, static_cast<uint8_t>(shim_bd_info.bd_id), shim_bd_info.offset * 4);
dma_api_obj.updateBDAddressLin(&bds[buf_idx].mem_inst, port_config.shim_column, 0, static_cast<uint8_t>(shim_bd_info.bd_id), shim_bd_info.offset * 4);
if (start_bd < 0)
start_bd = shim_bd_info.bd_id;
}
adf::dma_api::enqueueTask(1, port_config.shim_column, 0, port_config.direction, port_config.channel_number, port_config.task_repetition, port_config.enable_task_complete_token, static_cast<uint8_t>(start_bd));
dma_api_obj.enqueueTask(1, port_config.shim_column, 0, port_config.direction, port_config.channel_number, port_config.task_repetition, port_config.enable_task_complete_token, static_cast<uint8_t>(start_bd));
}

for (auto& bd :bds) {
Expand All @@ -252,8 +253,9 @@ wait_external_buffer(adf::external_buffer_config& config)
if (config.shim_port_configs.empty() || config.num_bufs == 2)
return;

adf::dma_api dma_api_obj(m_config);
for (auto& port_config : config.shim_port_configs) {
adf::dma_api::waitDMAChannelDone(1 /*adf::tile_type::shim_tile*/, port_config.shim_column, 0/*shim row*/, port_config.direction, port_config.channel_number);
dma_api_obj.waitDMAChannelDone(1 /*adf::tile_type::shim_tile*/, port_config.shim_column, 0/*shim row*/, port_config.direction, port_config.channel_number);
}
}

Expand Down Expand Up @@ -462,7 +464,7 @@ read_profiling(int phdl)

uint64_t value = 0;
if (event_records.size() > phdl)
value = adf::profiling::read(event_records[phdl].acquired_resources, event_records[phdl].option == IO_STREAM_START_DIFFERENCE_CYCLES);
value = adf::profiling::read(get_dev(), event_records[phdl].acquired_resources, event_records[phdl].option == IO_STREAM_START_DIFFERENCE_CYCLES);
else
throw xrt_core::error(-EAGAIN, "Read profiling failed: invalid handle.");
return value;
Expand All @@ -475,7 +477,7 @@ stop_profiling(int phdl)
if (access_mode == xrt::aie::access_mode::shared)
throw xrt_core::error(-EPERM, "Shared AIE context can't do profiling");
if (event_records.size() > phdl)
adf::profiling::stop(event_records[phdl].acquired_resources);
adf::profiling::stop(get_dev(), event_records[phdl].acquired_resources);
else
throw xrt_core::error(-EINVAL, "Stop profiling failed: invalid handle.");
}
Expand Down Expand Up @@ -513,7 +515,7 @@ start_profiling_run_idle(const std::string& port_name)
{
int handle = -1;
std::vector<std::shared_ptr<xaiefal::XAieRsc>> acquired_resources;
if (adf::profiling::profile_stream_running_to_idle_cycles(get_shim_config(port_name), acquired_resources) == adf::err_code::ok)
if (adf::profiling::profile_stream_running_to_idle_cycles(get_dev(), get_shim_config(port_name), acquired_resources) == adf::err_code::ok)
{
handle = event_records.size();
event_records.push_back({ IO_TOTAL_STREAM_RUNNING_TO_IDLE_CYCLE, acquired_resources });
Expand All @@ -527,7 +529,7 @@ start_profiling_start_bytes(const std::string& port_name, uint32_t value)
{
int handle = -1;
std::vector<std::shared_ptr<xaiefal::XAieRsc>> acquired_resources;
if (adf::profiling::profile_stream_start_to_transfer_complete_cycles(get_shim_config(port_name), value, acquired_resources) == adf::err_code::ok)
if (adf::profiling::profile_stream_start_to_transfer_complete_cycles(get_dev(), get_shim_config(port_name), value, acquired_resources) == adf::err_code::ok)
{
handle = event_records.size();
event_records.push_back({ IO_STREAM_START_TO_BYTES_TRANSFERRED_CYCLES, acquired_resources });
Expand All @@ -541,7 +543,7 @@ start_profiling_diff_cycles(const std::string& port1_name, const std::string& po
{
int handle = -1;
std::vector<std::shared_ptr<xaiefal::XAieRsc>> acquired_resources;
if (adf::profiling::profile_start_time_difference_btw_two_streams(get_shim_config(port1_name), get_shim_config(port2_name), acquired_resources) == adf::err_code::ok)
if (adf::profiling::profile_start_time_difference_btw_two_streams(get_dev(), get_shim_config(port1_name), get_shim_config(port2_name), acquired_resources) == adf::err_code::ok)
{
handle = event_records.size();
event_records.push_back({ IO_STREAM_START_DIFFERENCE_CYCLES, acquired_resources });
Expand All @@ -555,7 +557,7 @@ start_profiling_event_count(const std::string& port_name)
{
int handle = -1;
std::vector<std::shared_ptr<xaiefal::XAieRsc>> acquired_resources;
if (adf::profiling::profile_stream_running_event_count(get_shim_config(port_name), acquired_resources) == adf::err_code::ok)
if (adf::profiling::profile_stream_running_event_count(get_dev(), get_shim_config(port_name), acquired_resources) == adf::err_code::ok)
{
handle = event_records.size();
event_records.push_back({ IO_STREAM_RUNNING_EVENT_COUNT, acquired_resources });
Expand Down
153 changes: 80 additions & 73 deletions src/runtime_src/core/edge/user/aie/aie.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,134 +50,141 @@ enum xrtProfilingOption {
namespace zynqaie {

struct aie_bd {
uint16_t bd_num;
int buf_fd;
uint16_t bd_num;
int buf_fd;
#ifdef __AIESIM__
char *vaddr;
size_t size;
char *vaddr;
size_t size;
#else
XAie_MemInst mem_inst;
XAie_MemInst mem_inst;
#endif
};

struct dma_channel {
std::queue<aie_bd> idle_bds;
std::queue<aie_bd> pend_bds;
std::queue<aie_bd> idle_bds;
std::queue<aie_bd> pend_bds;
};

struct shim_dma {
XAie_DmaDesc desc;
dma_channel dma_chan[XAIEDMA_SHIM_MAX_NUM_CHANNELS];
bool configured;
uint8_t maxq_size;
XAie_DmaDesc desc;
dma_channel dma_chan[XAIEDMA_SHIM_MAX_NUM_CHANNELS];
bool configured;
uint8_t maxq_size;
};

struct event_record {
int option;
std::vector<std::shared_ptr<xaiefal::XAieRsc>> acquired_resources;
int option;
std::vector<std::shared_ptr<xaiefal::XAieRsc>> acquired_resources;
};

class aie_array {
public:
~aie_array();
aie_array(const std::shared_ptr<xrt_core::device>& device);
~aie_array();
aie_array(const std::shared_ptr<xrt_core::device>& device);

aie_array(const std::shared_ptr<xrt_core::device>& device, const zynqaie::hwctx_object* hwctx_obj);
aie_array(const std::shared_ptr<xrt_core::device>& device, const zynqaie::hwctx_object* hwctx_obj);

std::vector<shim_dma> shim_dmas; // shim DMA // not used anymore, should be cleanedup
std::vector<shim_dma> shim_dmas; // shim DMA // not used anymore, should be cleanedup

/* This is the collections of gmios that are used. */
std::unordered_map<std::string, adf::gmio_config> gmio_configs;
std::unordered_map<std::string, std::shared_ptr<adf::gmio_api>> gmio_apis;
/* This is the collections of gmios that are used. */
std::unordered_map<std::string, adf::gmio_config> gmio_configs;
std::unordered_map<std::string, std::shared_ptr<adf::gmio_api>> gmio_apis;

std::unordered_map<std::string, adf::plio_config> plio_configs;
std::unordered_map<std::string, adf::plio_config> plio_configs;

std::unordered_map<std::string, adf::external_buffer_config> external_buffer_configs;
std::unordered_map<std::string, adf::external_buffer_config> external_buffer_configs;

XAie_DevInst *get_dev();
XAie_DevInst *get_dev();

void
open_context(const xrt_core::device* device, xrt::aie::access_mode am);
void
open_context(const xrt_core::device* device, xrt::aie::access_mode am);

void
open_context(const xrt_core::device* device, const zynqaie::hwctx_object* hwctx_obj, xrt::aie::access_mode am);
void
open_context(const xrt_core::device* device, const zynqaie::hwctx_object* hwctx_obj, xrt::aie::access_mode am);

bool
is_context_set();
bool
is_context_set();

void
sync_external_buffer(std::vector<xrt::bo>& bo, adf::external_buffer_config& ebuf_config, enum xclBOSyncDirection dir, size_t size, size_t offset);
void
sync_external_buffer(std::vector<xrt::bo>& bo, adf::external_buffer_config& ebuf_config, enum xclBOSyncDirection dir, size_t size, size_t offset);

void
wait_external_buffer(adf::external_buffer_config& ebuf_config);
void
wait_external_buffer(adf::external_buffer_config& ebuf_config);

void
sync_bo(std::vector<xrt::bo>& bos, const char *dmaID, enum xclBOSyncDirection dir, size_t size, size_t offset);
void
sync_bo(std::vector<xrt::bo>& bos, const char *dmaID, enum xclBOSyncDirection dir, size_t size, size_t offset);

void
sync_bo_nb(std::vector<xrt::bo>& bos, const char *gmioName, enum xclBOSyncDirection dir, size_t size, size_t offset);
void
sync_bo_nb(std::vector<xrt::bo>& bos, const char *gmioName, enum xclBOSyncDirection dir, size_t size, size_t offset);

void
wait_gmio(const std::string& gmioName);
void
wait_gmio(const std::string& gmioName);

void
reset(const xrt_core::device* device);
void
reset(const xrt_core::device* device);

int
start_profiling(int option, const std::string& port1_name, const std::string& port2_name, uint32_t value);
int
start_profiling(int option, const std::string& port1_name, const std::string& port2_name, uint32_t value);

uint64_t
read_profiling(int phdl);
uint64_t
read_profiling(int phdl);

void
stop_profiling(int phdl);
void
stop_profiling(int phdl);

void
prepare_bd(aie_bd& bd, xrt::bo& bo);
void
prepare_bd(aie_bd& bd, xrt::bo& bo);

void
clear_bd(aie_bd& bd);
void
clear_bd(aie_bd& bd);

bool
find_gmio(const std::string & port_name);
bool
find_gmio(const std::string & port_name);

bool
find_external_buffer(const std::string & port_name);
bool
find_external_buffer(const std::string & port_name);

std::shared_ptr<adf::config_manager>
get_config()
{
return m_config;
}

private:
int num_cols;
int fd;
xrt::aie::access_mode access_mode = xrt::aie::access_mode::none;
int num_cols;
int fd;
xrt::aie::access_mode access_mode = xrt::aie::access_mode::none;

XAie_DevInst* dev_inst; // AIE Device Instance pointer
XAie_DevInst* dev_inst; // AIE Device Instance pointer

// XAie_InstDeclare(DevInst, &ConfigPtr) is the interface
// to initialize DevInst by the AIE driver. But it does not
// work here because we can not make it as a member of Aie
// class to maintain its life cylce. So we declair it here.
//
// Note: need to evolve when XAie_InstDecalare() evolves.
XAie_DevInst dev_inst_obj;
XAie_DevInst dev_inst_obj;

std::vector<event_record> event_records;
std::vector<event_record> event_records;
std::shared_ptr<adf::config_manager> m_config;

void
submit_sync_bo(xrt::bo& bo, std::shared_ptr<adf::gmio_api>& gmio, adf::gmio_config& gmio_config, enum xclBOSyncDirection dir, size_t size, size_t offset);
void
submit_sync_bo(xrt::bo& bo, std::shared_ptr<adf::gmio_api>& gmio, adf::gmio_config& gmio_config, enum xclBOSyncDirection dir, size_t size, size_t offset);

adf::shim_config
get_shim_config(const std::string& port_name);
adf::shim_config
get_shim_config(const std::string& port_name);

int
start_profiling_run_idle(const std::string& port_name);
int
start_profiling_run_idle(const std::string& port_name);

int
start_profiling_start_bytes(const std::string& port_name, uint32_t value);
int
start_profiling_start_bytes(const std::string& port_name, uint32_t value);

int
start_profiling_diff_cycles(const std::string& port1_name, const std::string& port2_name);
int
start_profiling_diff_cycles(const std::string& port1_name, const std::string& port2_name);

int
start_profiling_event_count(const std::string& port_name);
int
start_profiling_event_count(const std::string& port_name);
};

}
Expand Down
Loading

0 comments on commit 4d74e69

Please sign in to comment.