Skip to content

Commit

Permalink
Added hw ctx support for edge (#8305)
Browse files Browse the repository at this point in the history
* Registering the xclbin without loading it

Signed-off-by: bisingha <[email protected]>

* Added ioctl framework for create/destroy hw context for edge

Signed-off-by: bisingha <[email protected]>

* Added initial commit to create/destroy hw context

Signed-off-by: bisingha <[email protected]>

* Added open/close graph hw context calls

Signed-off-by: bisingha <[email protected]>

* Added graph open/close context

Signed-off-by: bisingha <[email protected]>

* Adjusted previous commits

Signed-off-by: bisingha <[email protected]>

* Adjusted previous commits

Signed-off-by: bisingha <[email protected]>

* Removed slot_id hardcoding for create/destroy hw_ctx

Signed-off-by: bisingha <[email protected]>

* Removed unnecessary function calls

Signed-off-by: bisingha <[email protected]>

* Added slot_id check

Signed-off-by: bisingha <[email protected]>

* Added cu open/close context support

Signed-off-by: bisingha <[email protected]>

* Added execbuf support with hw context

Signed-off-by: bisingha <[email protected]>

* Adjusted previous commits

Signed-off-by: bisingha <[email protected]>

---------

Signed-off-by: bisingha <[email protected]>
  • Loading branch information
bisingha-xilinx authored Aug 27, 2024
1 parent 52f4caf commit aafee62
Show file tree
Hide file tree
Showing 15 changed files with 1,004 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/CMake/dkms-edge.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ SET (XRT_DKMS_DRIVER_SRCS
zocl/edge/zocl_edge_kds.c
zocl/edge/zocl_error.c
zocl/edge/zocl_mailbox.c
zocl/edge/zocl_hwctx.c

zocl/include/zocl_aie.h
zocl/include/zocl_bo.h
Expand All @@ -76,6 +77,7 @@ SET (XRT_DKMS_DRIVER_SRCS
zocl/include/zocl_xclbin.h
zocl/include/zocl_xgq.h
zocl/include/zocl_xgq_plat.h
zocl/include/zocl_hwctx.h

zocl/zert/cu_scu.c
zocl/zert/scu.c
Expand Down
3 changes: 2 additions & 1 deletion src/runtime_src/core/edge/drm/zocl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ zocl_edge-y := $(zocl_edge_dir)/zocl_dma.o \
$(zocl_edge_dir)/zocl_edge_xclbin.o \
$(zocl_edge_dir)/zocl_edge_kds.o \
$(zocl_edge_dir)/zocl_error.o \
$(zocl_edge_dir)/zocl_aie.o
$(zocl_edge_dir)/zocl_aie.o \
$(zocl_edge_dir)/zocl_hwctx.o

zocl_zert_dir := $(make_dir)/zert
zocl_zert-y := $(zocl_zert_dir)/zocl_ert.o \
Expand Down
10 changes: 10 additions & 0 deletions src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,18 @@ static const struct drm_ioctl_desc zocl_ioctls[] = {
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(ZOCL_EXECBUF, zocl_execbuf_ioctl,
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(ZOCL_HW_CTX_EXECBUF, zocl_hw_ctx_execbuf_ioctl,
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(ZOCL_READ_AXLF, zocl_read_axlf_ioctl,
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(ZOCL_CREATE_HW_CTX, zocl_create_hw_ctx_ioctl,
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(ZOCL_DESTROY_HW_CTX, zocl_destroy_hw_ctx_ioctl,
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(ZOCL_OPEN_CU_CTX, zocl_open_cu_ctx_ioctl,
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(ZOCL_CLOSE_CU_CTX, zocl_close_cu_ctx_ioctl,
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(ZOCL_SK_GETCMD, zocl_sk_getcmd_ioctl,
DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW),
DRM_IOCTL_DEF_DRV(ZOCL_SK_CREATE, zocl_sk_create_ioctl,
Expand Down
72 changes: 71 additions & 1 deletion src/runtime_src/core/edge/drm/zocl/common/zocl_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "zocl_drv.h"
#include "zocl_xclbin.h"
#include "zocl_error.h"
#include "zocl_hwctx.h"

/*
* read_axlf and ctx should be protected by slot_xclbin_lock exclusively.
Expand All @@ -27,8 +28,68 @@ zocl_read_axlf_ioctl(struct drm_device *ddev, void *data, struct drm_file *filp)
struct drm_zocl_axlf *axlf_obj = data;
struct drm_zocl_dev *zdev = ZOCL_GET_ZDEV(ddev);
struct kds_client *client = filp->driver_priv;
int slot_id = -1;

return zocl_xclbin_read_axlf(zdev, axlf_obj, client);
return zocl_xclbin_read_axlf(zdev, axlf_obj, client, &slot_id);
}

/*
* IOCTL to create hw context on a slot on device for a xclbin.
*/
int zocl_create_hw_ctx_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
{
struct drm_zocl_dev *zdev = ZOCL_GET_ZDEV(dev);
struct drm_zocl_create_hw_ctx *drm_hw_ctx = data;
struct kds_client *client = filp->driver_priv;
struct drm_zocl_axlf axlf_obj = {};
int slot_id = -1;
int ret = 0;

if (copy_from_user(&axlf_obj, drm_hw_ctx->axlf_ptr, sizeof(struct drm_zocl_axlf))) {
DRM_WARN("copy_from_user failed for axlf_ptr");
return -EFAULT;
}

ret = zocl_xclbin_read_axlf(zdev, &axlf_obj, client, &slot_id);
if (ret) {
DRM_WARN("xclbin download FAILED.");
return ret;
}

return zocl_create_hw_ctx(zdev, drm_hw_ctx, filp, slot_id);
}

/*
* IOCTL to destroy hw context on a slot on device
*/
int zocl_destroy_hw_ctx_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
{
struct drm_zocl_dev *zdev = ZOCL_GET_ZDEV(dev);
struct drm_zocl_destroy_hw_ctx *drm_hw_ctx = (struct drm_zocl_destroy_hw_ctx *)data;

return zocl_destroy_hw_ctx(zdev, drm_hw_ctx, filp);
}

/*
* IOCTL to open a cu context under the given hw context
*/
int zocl_open_cu_ctx_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
{
struct drm_zocl_dev *zdev = ZOCL_GET_ZDEV(dev);
struct drm_zocl_open_cu_ctx *drm_cu_ctx = (struct drm_zocl_open_cu_ctx *)data;

return zocl_open_cu_ctx(zdev, drm_cu_ctx, filp);
}

/*
* IOCTL to close a opened cu context under the given hw context
*/
int zocl_close_cu_ctx_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
{
struct drm_zocl_dev *zdev = ZOCL_GET_ZDEV(dev);
struct drm_zocl_close_cu_ctx *drm_cu_ctx = (struct drm_zocl_close_cu_ctx *)data;

return zocl_close_cu_ctx(zdev, drm_cu_ctx, filp);
}

/*
Expand Down Expand Up @@ -99,6 +160,15 @@ zocl_execbuf_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
return zocl_command_ioctl(zdev, data, filp);
}

int
zocl_hw_ctx_execbuf_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
{
struct drm_zocl_dev *zdev = ZOCL_GET_ZDEV(dev);
struct drm_zocl_hw_ctx_execbuf *drm_hw_ctx_execbuf = (struct drm_zocl_hw_ctx_execbuf *)data;

return zocl_hw_ctx_execbuf(zdev, drm_hw_ctx_execbuf, filp);
}

int
zocl_error_ioctl(struct drm_device *dev, void *data, struct drm_file *filp)
{
Expand Down
6 changes: 5 additions & 1 deletion src/runtime_src/core/edge/drm/zocl/edge/zocl_edge_xclbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ zocl_resolver(struct drm_zocl_dev *zdev, struct axlf *axlf, xuid_t *xclbin_id,
// option "true" in xrt.ini under [Runtime] section
DRM_WARN("%s Force xclbin download", __func__);
} else {
*slot_id = s_id;
DRM_INFO("Exists xclbin %pUb to slot %d",
xclbin_id, s_id);
mutex_unlock(&slot->slot_xclbin_lock);
Expand Down Expand Up @@ -200,7 +201,7 @@ zocl_resolver(struct drm_zocl_dev *zdev, struct axlf *axlf, xuid_t *xclbin_id,
*/
int
zocl_xclbin_read_axlf(struct drm_zocl_dev *zdev, struct drm_zocl_axlf *axlf_obj,
struct kds_client *client)
struct kds_client *client, int *slot_idx)
{
struct axlf axlf_head;
struct axlf *axlf = NULL;
Expand Down Expand Up @@ -257,6 +258,8 @@ zocl_xclbin_read_axlf(struct drm_zocl_dev *zdev, struct drm_zocl_axlf *axlf_obj,
ret = zocl_resolver(zdev, axlf, &axlf_head.m_header.uuid, qos, &slot_id);
if (ret) {
if (ret == -EEXIST) {
DRM_INFO("xclbin already downloaded to slot=%d", slot_id);
*slot_idx = slot_id;
vfree(axlf);
return 0;
}
Expand All @@ -266,6 +269,7 @@ zocl_xclbin_read_axlf(struct drm_zocl_dev *zdev, struct drm_zocl_axlf *axlf_obj,
goto out0;
}

*slot_idx = slot_id;
slot = zdev->pr_slot[slot_id];
mutex_lock(&slot->slot_xclbin_lock);
/*
Expand Down
Loading

0 comments on commit aafee62

Please sign in to comment.