Skip to content

Commit

Permalink
conflict (Xilinx#8534)
Browse files Browse the repository at this point in the history
enabled hw_context reset_array support
Signed-off-by: ch vamshi krishna <[email protected]>
Co-authored-by: ch vamshi krishna <[email protected]>
  • Loading branch information
chvamshi-xilinx authored Oct 17, 2024
1 parent 56d452c commit 4b44252
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 41 deletions.
14 changes: 14 additions & 0 deletions src/runtime_src/core/common/api/xrt_hw_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,17 @@ hw_context::
{}

} // xrt

////////////////////////////////////////////////////////////////
// xrt_aie_hw_context C++ API implmentations (xrt_aie.h)
////////////////////////////////////////////////////////////////
namespace xrt::aie {

void
hw_context::
reset_array()
{
auto core_handle = get_handle()->get_hwctx_handle();
core_handle->reset_array();
}
} //xrt::aie
6 changes: 6 additions & 0 deletions src/runtime_src/core/common/shim/hwctx_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ class hwctx_handle
{
throw xrt_core::error(std::errc::not_supported, __func__);
}

virtual void
reset_array() const
{
throw xrt_core::error(std::errc::not_supported, __func__);
}
};

} // xrt_core
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 @@ -193,7 +193,7 @@ static void zocl_pr_slot_fini(struct drm_zocl_dev *zdev)
zocl_slot = zdev->pr_slot[i];
if (zocl_slot) {
zocl_free_sections(zdev, zocl_slot);
zocl_destroy_aie(zocl_slot);
zocl_cleanup_aie(zocl_slot);
mutex_destroy(&zocl_slot->slot_xclbin_lock);
mutex_destroy(&zocl_slot->aie_lock);
zocl_xclbin_fini(zdev, zocl_slot);
Expand Down
56 changes: 29 additions & 27 deletions src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ get_slot(struct drm_zocl_dev * zdev, struct kds_client* client, int hw_ctx_id)
mutex_unlock(&client->lock);
return slot;
}

int
zocl_aie_request_part_fd(struct drm_zocl_dev *zdev, void *data, struct drm_file *filp)
{
Expand Down Expand Up @@ -290,7 +291,7 @@ zocl_aie_reset_work(struct work_struct *aie_work)
slot->aie->fd_cnt = 0;
}

int
static int
zocl_aie_slot_reset(struct drm_zocl_slot* slot)
{
if (!slot) {
Expand Down Expand Up @@ -364,6 +365,33 @@ zocl_aie_slot_reset(struct drm_zocl_slot* slot)

}

static void
zocl_destroy_aie(struct drm_zocl_slot* slot)
{
if (!slot->aie_information)
return;

mutex_lock(&slot->aie_lock);
vfree(slot->aie_information);
slot->aie_information = NULL;

if (!slot->aie) {
mutex_unlock(&slot->aie_lock);
return;
}

if (slot->aie->aie_dev)
aie_partition_release(slot->aie->aie_dev);

if (slot->aie->wq)
destroy_workqueue(slot->aie->wq);

vfree(slot->aie->err.errors);
vfree(slot->aie);
slot->aie = NULL;
mutex_unlock(&slot->aie_lock);
}

int
zocl_cleanup_aie(struct drm_zocl_slot *slot)
{
Expand Down Expand Up @@ -537,32 +565,6 @@ zocl_create_aie(struct drm_zocl_slot *slot, struct axlf *axlf, char __user *xclb
return rval;
}

void
zocl_destroy_aie(struct drm_zocl_slot* slot)
{
if (!slot->aie_information)
return;

mutex_lock(&slot->aie_lock);
vfree(slot->aie_information);
slot->aie_information = NULL;

if (!slot->aie) {
mutex_unlock(&slot->aie_lock);
return;
}

if (slot->aie->aie_dev)
aie_partition_release(slot->aie->aie_dev);

if (slot->aie->wq)
destroy_workqueue(slot->aie->wq);

vfree(slot->aie->err.errors);
vfree(slot->aie);
slot->aie = NULL;
mutex_unlock(&slot->aie_lock);
}



Expand Down
4 changes: 2 additions & 2 deletions src/runtime_src/core/edge/drm/zocl/edge/zocl_edge_xclbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ zocl_xclbin_read_axlf(struct drm_zocl_dev *zdev, struct drm_zocl_axlf *axlf_obj,
/* Free sections before load the new xclbin */
zocl_free_sections(zdev, slot);

/* Destroy the aie information from slot and create new */
zocl_destroy_aie(slot);
/* Cleanup the aie information from slot and create new */
zocl_cleanup_aie(slot);


#if KERNEL_VERSION(5, 4, 0) <= LINUX_VERSION_CODE
Expand Down
1 change: 0 additions & 1 deletion src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ int zocl_cleanup_aie(struct drm_zocl_slot *slot);
int zocl_create_aie(struct drm_zocl_slot *slot, struct axlf *axlf, char __user *xclbin,
void *aie_res, uint8_t hw_gen, uint32_t partition_id);
int zocl_init_aie(struct drm_zocl_slot* slot);
void zocl_destroy_aie(struct drm_zocl_slot *slot);
int zocl_aie_request_part_fd(struct drm_zocl_dev *zdev, void *data,struct drm_file* filp );
int zocl_aie_reset(struct drm_zocl_dev *zdev, void* data, struct drm_file* file);
int zocl_aie_freqscale(struct drm_zocl_dev *zdev, void *data, struct drm_file* filp);
Expand Down
8 changes: 2 additions & 6 deletions src/runtime_src/core/edge/user/aie/aie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ clear_bd(aie_bd& bd)

void
aie_array::
reset(const xrt_core::device* device)
reset(const xrt_core::device* device, uint32_t hw_context_id, uint32_t partition_id)
{
if (!dev_inst)
throw xrt_core::error(-EINVAL, "Can't Reset AIE: AIE is not initialized");
Expand All @@ -416,11 +416,7 @@ reset(const xrt_core::device* device)

auto drv = ZYNQ::shim::handleCheck(device->get_device_handle());

/* TODO get partition id and uid from XCLBIN or PDI */
uint32_t partition_id = 1;

//TODO create similar function for hw_context
drm_zocl_aie_reset reset = { 0 , partition_id };
drm_zocl_aie_reset reset = { hw_context_id , partition_id };
int ret = drv->resetAIEArray(reset);
if (ret)
throw xrt_core::error(ret, "Fail to reset AIE Array");
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/edge/user/aie/aie.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class aie_array {
wait_gmio(const std::string& gmioName);

void
reset(const xrt_core::device* device);
reset(const xrt_core::device* device, uint32_t hw_context_id, uint32_t partition_id);

int
start_profiling(int option, const std::string& port1_name, const std::string& port2_name, uint32_t value);
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/edge/user/device_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ reset_aie()
if (!aie_array->is_context_set())
aie_array->open_context(this, xrt::aie::access_mode::primary);

aie_array->reset(this);
aie_array->reset(this, 0 /*hw_context_id*/, xrt_core::edge::aie::full_array_id);
}

void
Expand Down
13 changes: 13 additions & 0 deletions src/runtime_src/core/edge/user/hwctx_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,17 @@ hwctx_object::open_aie_buffer_handle(const char* name)
#endif
}

void
hwctx_object::reset_array() const
{
if (!m_aie_array)
throw xrt_core::error(-EINVAL, "No AIE present in hw_context to reset");

auto device{xrt_core::get_userpf_device(m_shim)};
if (!m_aie_array->is_context_set())
m_aie_array->open_context(device.get(), xrt::aie::access_mode::primary);

m_aie_array->reset(device.get(), m_slot_idx, m_info.partition_id);
}

}
3 changes: 3 additions & 0 deletions src/runtime_src/core/edge/user/hwctx_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ namespace zynqaie {
std::unique_ptr<xrt_core::aie_buffer_handle>
open_aie_buffer_handle(const char* name) override;

void
reset_array() const override;

#ifdef XRT_ENABLE_AIE
std::shared_ptr<aie_array>
get_aie_array_shared();
Expand Down
2 changes: 0 additions & 2 deletions src/runtime_src/core/edge/user/shim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1283,8 +1283,6 @@ int shim::prepare_hw_axlf(const axlf *buffer, struct drm_zocl_axlf *axlf_obj)
}
off += sizeof(kernel_info) + sizeof(argument_info) * kernel.args.size();
}


return 0;
}

Expand Down
23 changes: 23 additions & 0 deletions src/runtime_src/core/include/xrt/xrt_aie.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,29 @@ class bo : public xrt::bo
}
};

class hw_context : public xrt::hw_context
{
public:

/**
* hw_context() - Constructor that is used for AIE hw_context.
*
* @param arg
* Arguments to construct hw_context (xrt_hw_context.h).
*/
template <typename ...Args>
hw_context(Args&&... args)
: xrt::hw_context(std::forward<Args>(args)...)
{}

/**
* reset_array() - reset the AIE Array used for this hw_context
*
*/
void
reset_array();
};

class profiling_impl;
class profiling : public detail::pimpl<profiling_impl>
{
Expand Down

0 comments on commit 4b44252

Please sign in to comment.