From 1e7e50f952a2571b9dd50e5c39493c6b3fbe95a0 Mon Sep 17 00:00:00 2001 From: rave Date: Mon, 8 Jul 2024 23:53:05 +0530 Subject: [PATCH 1/6] ps kernel hard code handling changes Signed-off-by: rave --- src/runtime_src/core/common/device.cpp | 28 ++++++++++- src/runtime_src/core/common/query_requests.h | 18 +++++++ .../core/edge/drm/zocl/common/zocl_drv.c | 2 + .../core/edge/drm/zocl/common/zocl_ioctl.c | 8 +++ .../core/edge/drm/zocl/common/zocl_sysfs.c | 2 +- .../core/edge/drm/zocl/edge/zocl_aie.c | 50 ++++++++++++++++++- .../core/edge/drm/zocl/include/zocl_drv.h | 1 + .../core/edge/drm/zocl/include/zocl_ioctl.h | 2 + .../core/edge/drm/zocl/zert/zocl_sk.c | 9 ++-- .../core/edge/include/zynq_ioctl.h | 10 +++- src/runtime_src/core/edge/skd/xrt_skd.cpp | 1 + .../core/edge/user/device_linux.cpp | 33 ++++++++++++ src/runtime_src/core/include/xclbin.h | 2 + 13 files changed, 157 insertions(+), 9 deletions(-) diff --git a/src/runtime_src/core/common/device.cpp b/src/runtime_src/core/common/device.cpp index 124793467d3..87460307668 100644 --- a/src/runtime_src/core/common/device.cpp +++ b/src/runtime_src/core/common/device.cpp @@ -146,20 +146,44 @@ load_xclbin(const uuid& xclbin_id) throw error(ENODEV, "specified xclbin is not loaded"); #ifdef XRT_ENABLE_AIE +#ifdef XCLBIN_FULL_READ auto xclbin_full = xrt_core::device_query(this); if (xclbin_full.empty()) throw error(ENODEV, "no cached xclbin data"); - const axlf* top = reinterpret_cast(xclbin_full.data()); + const axlf* skd_axlf_ptr = reinterpret_cast(xclbin_full.data()); +#else + uint64_t ps_uuid_ptr = reinterpret_cast(xclbin_id.get()); + const axlf* skd_axlf_ptr; + char* buf = new char[MAX_AXLF_BUF_SIZE]; + + if (!buf) + throw error(ENOMEM, "Cannot allocate axlf buffer"); + + skd_axlf_ptr = reinterpret_cast (buf); + xrt_core::query::aie_skd_xclbin::args arg = {reinterpret_cast(ps_uuid_ptr), reinterpret_cast(skd_axlf_ptr)}; + + try { + xrt_core::device_query(this, arg); + } + catch (const std::exception &e) { + std::cerr << boost::format("ERROR: Failed to get xclbin for uuid (%lx)\n %s\n") % uuid_loaded.get() % e.what(); + throw xrt_core::error(std::errc::operation_canceled); + } +#endif try { // set before register_axlf is called via load_axlf_meta - m_xclbin = xrt::xclbin{top}; + m_xclbin = xrt::xclbin{skd_axlf_ptr}; load_axlf_meta(m_xclbin.get_axlf()); } catch (const std::exception&) { m_xclbin = {}; throw; } +#ifndef XCLBIN_FULL_READ + delete skd_axlf_ptr; + skd_axlf_ptr = NULL; +#endif #else throw error(ENOTSUP, "load xclbin by uuid is not supported"); #endif diff --git a/src/runtime_src/core/common/query_requests.h b/src/runtime_src/core/common/query_requests.h index df9d0917fe5..36e9c5854fd 100644 --- a/src/runtime_src/core/common/query_requests.h +++ b/src/runtime_src/core/common/query_requests.h @@ -324,6 +324,7 @@ enum class key_type kernel_max_bandwidth_mbps, sub_device_path, read_trace_data, + aie_skd_xclbin, noop }; @@ -3819,6 +3820,23 @@ struct read_trace_data : request virtual std::any get(const device*, const std::any&) const = 0; }; + +struct aie_skd_xclbin : request +{ + using result_type = bool; + using ps_uuid_ptr_type = uint64_t; + using skd_axlf_ptr_type = uint64_t; + + static const key_type key = key_type::aie_skd_xclbin; + struct args { + uint64_t ps_uuid_ptr; + uint64_t skd_axlf_ptr; + }; + + virtual std::any + get(const device*, const std::any& arg) const = 0; +}; + } // query } // xrt_core diff --git a/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c b/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c index 1aefb7b0b7c..8fe1766a709 100644 --- a/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c +++ b/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c @@ -1002,6 +1002,8 @@ static const struct drm_ioctl_desc zocl_ioctls[] = { DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(ZOCL_SET_CU_READONLY_RANGE, zocl_set_cu_read_only_range_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW), + DRM_IOCTL_DEF_DRV(ZOCL_AIE_SKD_XCLBIN, zocl_aie_skd_xclbin_ioctl, + DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW), }; static const struct file_operations zocl_driver_fops = { diff --git a/src/runtime_src/core/edge/drm/zocl/common/zocl_ioctl.c b/src/runtime_src/core/edge/drm/zocl/common/zocl_ioctl.c index 17236415189..532ec86c071 100644 --- a/src/runtime_src/core/edge/drm/zocl/common/zocl_ioctl.c +++ b/src/runtime_src/core/edge/drm/zocl/common/zocl_ioctl.c @@ -150,3 +150,11 @@ zocl_set_cu_read_only_range_ioctl(struct drm_device *dev, void *data, ret = zocl_kds_set_cu_read_range(zdev, info->cu_index, info->start, info->size); return ret; } + +int +zocl_aie_skd_xclbin_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) +{ + struct drm_zocl_dev *zdev = ZOCL_GET_ZDEV(dev); + + return zocl_aie_skd_xclbin(zdev, data); +} diff --git a/src/runtime_src/core/edge/drm/zocl/common/zocl_sysfs.c b/src/runtime_src/core/edge/drm/zocl/common/zocl_sysfs.c index 86ad23bebb9..95772beaa75 100644 --- a/src/runtime_src/core/edge/drm/zocl/common/zocl_sysfs.c +++ b/src/runtime_src/core/edge/drm/zocl/common/zocl_sysfs.c @@ -600,7 +600,7 @@ static ssize_t read_xclbin_full(struct file *filp, struct kobject *kobj, read_lock(&zdev->attr_rwlock); // Only read slot 0's xclbin - TODO: extend to multi-slot - zocl_slot = zdev->pr_slot[0]; + zocl_slot = zdev->pr_slot[1]; if (!zocl_slot || !zocl_slot->axlf) { read_unlock(&zdev->attr_rwlock); return 0; diff --git a/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c b/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c index fe6b20c55e1..2647721efb3 100644 --- a/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c +++ b/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c @@ -17,6 +17,7 @@ #include "zocl_aie.h" #include "xrt_xclbin.h" #include "xclbin.h" +#include "zocl_xclbin.h" #ifndef __NONE_PETALINUX__ #include @@ -552,6 +553,53 @@ int zocl_aie_freqscale(struct drm_zocl_dev *zdev, void *data) } } +int zocl_aie_skd_xclbin(struct drm_zocl_dev *zdev, void *data) +{ + struct drm_zocl_aie_skd_xclbin *args = data; + struct drm_zocl_slot *zocl_slot = NULL; + uuid_t *slot_uuid = NULL; + uuid_t *skd_uuid = NULL; + int i, slot_id = MAX_PR_SLOT_NUM, ret = 0; + void *uuid_ptr = (void *)(uintptr_t)args->ps_uuid_ptr; + + skd_uuid = vmalloc(sizeof(uuid_t)); + if (!skd_uuid) + return -ENOMEM; + + ret = copy_from_user(skd_uuid, uuid_ptr, sizeof(uuid_t)); + if (ret) { + vfree(skd_uuid); + return ret; + } + mutex_lock(&zdev->aie_lock); + + for (i = 0;i < MAX_PR_SLOT_NUM;i++) { + struct drm_zocl_slot *slot = NULL; + slot = zdev->pr_slot[i]; + mutex_lock(&zdev->pr_slot[i]->slot_xclbin_lock); + slot_uuid = zocl_xclbin_get_uuid(zdev->pr_slot[i]); + if(slot_uuid) { + if(uuid_equal(slot_uuid, skd_uuid)) { + slot_id = i; + mutex_unlock(&zdev->pr_slot[i]->slot_xclbin_lock); + break; + } + } + mutex_unlock(&zdev->pr_slot[i]->slot_xclbin_lock); + } + zocl_slot = zdev->pr_slot[slot_id]; + // add validation to check if axlf_size is greater than 4k + ret = copy_to_user(args->skd_axlf_ptr, (char *)zocl_slot->axlf, zocl_slot->axlf_size); + if (ret) { + vfree(skd_uuid); + mutex_unlock(&zdev->aie_lock); + return ret; + } + mutex_unlock(&zdev->aie_lock); + vfree(skd_uuid); + return 0; +} + int zocl_aie_kds_add_graph_context(struct drm_zocl_dev *zdev, u32 gid, u32 ctx_code, struct kds_client *client) @@ -843,4 +891,4 @@ zocl_init_aie(struct drm_zocl_dev *zdev) zdev->aie_information = aie; return 0; -} +} \ No newline at end of file diff --git a/src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h b/src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h index edd1b517d67..f18e6f36b76 100644 --- a/src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h +++ b/src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h @@ -288,6 +288,7 @@ int zocl_inject_error(struct drm_zocl_dev *zdev, void *data, int zocl_init_error(struct drm_zocl_dev *zdev); void zocl_fini_error(struct drm_zocl_dev *zdev); int zocl_insert_error_record(struct drm_zocl_dev *zdev, xrtErrorCode err_code); +int zocl_aie_skd_xclbin(struct drm_zocl_dev *zdev, void *data); /* zocl_kds.c */ int zocl_init_sched(struct drm_zocl_dev *zdev); diff --git a/src/runtime_src/core/edge/drm/zocl/include/zocl_ioctl.h b/src/runtime_src/core/edge/drm/zocl/include/zocl_ioctl.h index 0200eb8657e..6279d1b979a 100644 --- a/src/runtime_src/core/edge/drm/zocl/include/zocl_ioctl.h +++ b/src/runtime_src/core/edge/drm/zocl/include/zocl_ioctl.h @@ -61,4 +61,6 @@ int zocl_aie_freqscale_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); int zocl_set_cu_read_only_range_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); +int +zocl_aie_skd_xclbin_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); #endif diff --git a/src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c b/src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c index 168ccd35100..0df25253980 100644 --- a/src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c +++ b/src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c @@ -64,12 +64,13 @@ zocl_sk_getcmd_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) mutex_lock(&zdev->pr_slot[i]->slot_xclbin_lock); slot_uuid = zocl_xclbin_get_uuid(zdev->pr_slot[i]); if(slot_uuid) { - mutex_unlock(&zdev->pr_slot[i]->slot_xclbin_lock); if(uuid_equal(slot_uuid,(xuid_t *)cmd->sk_uuid)) { slot_id = i; + mutex_unlock(&zdev->pr_slot[i]->slot_xclbin_lock); break; } } + mutex_unlock(&zdev->pr_slot[i]->slot_xclbin_lock); } if (slot_id == MAX_PR_SLOT_NUM) { @@ -130,9 +131,9 @@ zocl_sk_getcmd_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) kdata->bohdl = bohdl; kdata->meta_bohdl = meta_bohdl; // Pass physical slot 0 UUID to SKD - Currently we only support 1 physical slot - mutex_lock(&zdev->pr_slot[0]->slot_xclbin_lock); - phy_slot_uuid = zocl_xclbin_get_uuid(zdev->pr_slot[0]); - mutex_unlock(&zdev->pr_slot[0]->slot_xclbin_lock); + mutex_lock(&zdev->pr_slot[slot_id]->slot_xclbin_lock); + phy_slot_uuid = zocl_xclbin_get_uuid(zdev->pr_slot[slot_id]); + mutex_unlock(&zdev->pr_slot[slot_id]->slot_xclbin_lock); memcpy(kdata->uuid,phy_slot_uuid,sizeof(kdata->uuid)); snprintf(kdata->name, ZOCL_MAX_NAME_LENGTH, "%s", diff --git a/src/runtime_src/core/edge/include/zynq_ioctl.h b/src/runtime_src/core/edge/include/zynq_ioctl.h index 098dea39ad7..c2d2cd79c04 100644 --- a/src/runtime_src/core/edge/include/zynq_ioctl.h +++ b/src/runtime_src/core/edge/include/zynq_ioctl.h @@ -124,7 +124,8 @@ enum drm_zocl_ops { DRM_ZOCL_AIE_FREQSCALE, /* Set CU read-only range */ DRM_ZOCL_SET_CU_READONLY_RANGE, - DRM_ZOCL_NUM_IOCTLS + DRM_ZOCL_NUM_IOCTLS, + DRM_ZOCL_AIE_SKD_XCLBIN }; enum drm_zocl_sync_bo_dir { @@ -548,6 +549,11 @@ struct drm_zocl_error_inject { uint16_t err_class; }; +struct drm_zocl_aie_skd_xclbin { + uint64_t skd_axlf_ptr; + uint64_t ps_uuid_ptr; +}; + #define DRM_IOCTL_ZOCL_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + \ DRM_ZOCL_CREATE_BO, \ struct drm_zocl_create_bo) @@ -596,4 +602,6 @@ struct drm_zocl_error_inject { DRM_ZOCL_AIE_FREQSCALE, struct drm_zocl_aie_freq_scale) #define DRM_IOCTL_ZOCL_SET_CU_READONLY_RANGE DRM_IOWR(DRM_COMMAND_BASE + \ DRM_ZOCL_SET_CU_READONLY_RANGE, struct drm_zocl_set_cu_range) +#define DRM_IOCTL_ZOCL_AIE_SKD_XCLBIN DRM_IOWR(DRM_COMMAND_BASE + \ + DRM_ZOCL_AIE_SKD_XCLBIN, struct drm_zocl_aie_skd_xclbin) #endif diff --git a/src/runtime_src/core/edge/skd/xrt_skd.cpp b/src/runtime_src/core/edge/skd/xrt_skd.cpp index 57707943380..181b1755046 100644 --- a/src/runtime_src/core/edge/skd/xrt_skd.cpp +++ b/src/runtime_src/core/edge/skd/xrt_skd.cpp @@ -52,6 +52,7 @@ namespace xrt { m_parent_bo_handle(xrt::shim_int::get_buffer_handle(xrtDeviceToXclDevice(handle), parent_mem_bo_in)), m_mem_start_paddr(mem_start_paddr_in), m_mem_size(mem_size_in) + { } diff --git a/src/runtime_src/core/edge/user/device_linux.cpp b/src/runtime_src/core/edge/user/device_linux.cpp index 4c9d0aa52b4..791c4deff3c 100644 --- a/src/runtime_src/core/edge/user/device_linux.cpp +++ b/src/runtime_src/core/edge/user/device_linux.cpp @@ -10,6 +10,7 @@ #include "core/common/query_requests.h" #include "core/common/xrt_profiling.h" #include "shim.h" +#include "core/include/xrt/xrt_uuid.h" #include #include @@ -841,6 +842,37 @@ struct read_trace_data } }; +struct aie_skd_xclbin +{ + using result_type = query::aie_skd_xclbin::result_type; + + XAie_DevInst* devInst; // AIE Device Instance + + static result_type + get(const xrt_core::device* device, key_type key, const std::any& param) + { +#if defined(XRT_ENABLE_AIE) + struct drm_zocl_aie_skd_xclbin aie_arg; + auto args = std::any_cast(param); + + aie_arg.ps_uuid_ptr = std::any_cast(args.ps_uuid_ptr); + aie_arg.skd_axlf_ptr = std::any_cast(args.skd_axlf_ptr); + + const std::string zocl_device = "/dev/dri/" + get_render_devname(); + auto fd_obj = aie_get_drmfd(device, zocl_device); + if (fd_obj->fd < 0) + throw xrt_core::error(-EINVAL, boost::str(boost::format("Cannot open %s") % zocl_device)); + + if (ioctl(fd_obj->fd, DRM_IOCTL_ZOCL_AIE_SKD_XCLBIN, &aie_arg)) + throw xrt_core::error(-errno, boost::str(boost::format("Reading SKD XCLBIN for uuid (%s) failed") % aie_arg.ps_uuid_ptr)); + +#else + throw xrt_core::error(-EINVAL, "AIE is not enabled for this device"); +#endif + return true; + } +}; + // Specialize for other value types. template struct sysfs_fcn @@ -1046,6 +1078,7 @@ initialize_query_table() emplace_func0_request(); emplace_func4_request(); emplace_func4_request(); + emplace_func4_request(); emplace_func4_request(); emplace_func4_request(); } diff --git a/src/runtime_src/core/include/xclbin.h b/src/runtime_src/core/include/xclbin.h index 913c5db631d..3d45166fefd 100644 --- a/src/runtime_src/core/include/xclbin.h +++ b/src/runtime_src/core/include/xclbin.h @@ -108,6 +108,8 @@ typedef GUID xuid_t; #define SIZE_OF_STRUCT(s) \ char (*__fail)[sizeof(struct s)] = 1 +#define MAX_AXLF_BUF_SIZE (4096*1024) + #ifdef __cplusplus extern "C" { #endif From 25ecdb9a245fb69771ae57243751a503f6670133 Mon Sep 17 00:00:00 2001 From: rave Date: Fri, 12 Jul 2024 22:17:04 +0530 Subject: [PATCH 2/6] Addressed comments, defined new ioctl to query axlf size Signed-off-by: rave --- src/runtime_src/core/common/device.cpp | 38 +++++++------- src/runtime_src/core/common/query_requests.h | 13 +++++ .../core/edge/drm/zocl/common/zocl_drv.c | 2 + .../core/edge/drm/zocl/common/zocl_ioctl.c | 8 +++ .../core/edge/drm/zocl/edge/zocl_aie.c | 49 ++++++++++++++++++- .../core/edge/drm/zocl/include/zocl_drv.h | 1 + .../core/edge/drm/zocl/include/zocl_ioctl.h | 2 + .../core/edge/include/zynq_ioctl.h | 10 +++- .../core/edge/user/device_linux.cpp | 29 +++++++++++ .../core/edge/user/device_linux.cpp.rej | 13 +++++ 10 files changed, 143 insertions(+), 22 deletions(-) create mode 100644 src/runtime_src/core/edge/user/device_linux.cpp.rej diff --git a/src/runtime_src/core/common/device.cpp b/src/runtime_src/core/common/device.cpp index 87460307668..4e1279332ae 100644 --- a/src/runtime_src/core/common/device.cpp +++ b/src/runtime_src/core/common/device.cpp @@ -12,7 +12,6 @@ #include "utils.h" #include "xclbin_parser.h" #include "xclbin_swemu.h" - #include "core/include/ert.h" #include "core/include/xrt.h" #include "core/include/xclbin.h" @@ -146,23 +145,27 @@ load_xclbin(const uuid& xclbin_id) throw error(ENODEV, "specified xclbin is not loaded"); #ifdef XRT_ENABLE_AIE -#ifdef XCLBIN_FULL_READ - auto xclbin_full = xrt_core::device_query(this); - if (xclbin_full.empty()) - throw error(ENODEV, "no cached xclbin data"); - - const axlf* skd_axlf_ptr = reinterpret_cast(xclbin_full.data()); -#else uint64_t ps_uuid_ptr = reinterpret_cast(xclbin_id.get()); const axlf* skd_axlf_ptr; - char* buf = new char[MAX_AXLF_BUF_SIZE]; - - if (!buf) - throw error(ENOMEM, "Cannot allocate axlf buffer"); + uint32_t axlf_size; - skd_axlf_ptr = reinterpret_cast (buf); - xrt_core::query::aie_skd_xclbin::args arg = {reinterpret_cast(ps_uuid_ptr), reinterpret_cast(skd_axlf_ptr)}; + /* Query for axlf buffer size Ioctl for this UUID parameter */ + try { + axlf_size = xrt_core::device_query(this, ps_uuid_ptr); + } + catch (const std::exception &e) { + std::cerr << boost::format("ERROR: Failed to get axlf size (%lx)\n %s\n") % uuid_loaded.get() % e.what(); + throw xrt_core::error(std::errc::operation_canceled); + } + if(axlf_size == 0) + { + std::cerr << boost::format("ERROR: UUID not found (%lx)\n %s\n") % uuid_loaded.get(); + throw xrt_core::error(std::errc::operation_canceled); + } + /* Initialize the axlf buffer and query axlf for the specified UUID */ + std::vector buf(axlf_size, 0); + xrt_core::query::aie_skd_xclbin::args arg = {reinterpret_cast(ps_uuid_ptr), reinterpret_cast(buf.data())}; try { xrt_core::device_query(this, arg); } @@ -170,7 +173,8 @@ load_xclbin(const uuid& xclbin_id) std::cerr << boost::format("ERROR: Failed to get xclbin for uuid (%lx)\n %s\n") % uuid_loaded.get() % e.what(); throw xrt_core::error(std::errc::operation_canceled); } -#endif + + skd_axlf_ptr = reinterpret_cast (buf.data()); try { // set before register_axlf is called via load_axlf_meta m_xclbin = xrt::xclbin{skd_axlf_ptr}; @@ -180,10 +184,6 @@ load_xclbin(const uuid& xclbin_id) m_xclbin = {}; throw; } -#ifndef XCLBIN_FULL_READ - delete skd_axlf_ptr; - skd_axlf_ptr = NULL; -#endif #else throw error(ENOTSUP, "load xclbin by uuid is not supported"); #endif diff --git a/src/runtime_src/core/common/query_requests.h b/src/runtime_src/core/common/query_requests.h index 36e9c5854fd..bca1a06efc9 100644 --- a/src/runtime_src/core/common/query_requests.h +++ b/src/runtime_src/core/common/query_requests.h @@ -325,6 +325,7 @@ enum class key_type sub_device_path, read_trace_data, aie_skd_xclbin, + skd_axlf_size, noop }; @@ -3821,6 +3822,7 @@ struct read_trace_data : request get(const device*, const std::any&) const = 0; }; +/* SKD Request to load xclbin for a specific UUID */ struct aie_skd_xclbin : request { using result_type = bool; @@ -3837,6 +3839,17 @@ struct aie_skd_xclbin : request get(const device*, const std::any& arg) const = 0; }; +struct skd_axlf_size : request +{ + using ps_uuid_ptr_type = uint64_t; + using result_type = uint32_t; + + static const key_type key = key_type::skd_axlf_size; + + virtual std::any + get(const device*, const std::any& ps_uuid_ptr) const = 0; +}; + } // query } // xrt_core diff --git a/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c b/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c index 8fe1766a709..b727c09aa9d 100644 --- a/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c +++ b/src/runtime_src/core/edge/drm/zocl/common/zocl_drv.c @@ -1004,6 +1004,8 @@ static const struct drm_ioctl_desc zocl_ioctls[] = { DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW), DRM_IOCTL_DEF_DRV(ZOCL_AIE_SKD_XCLBIN, zocl_aie_skd_xclbin_ioctl, DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW), + DRM_IOCTL_DEF_DRV(ZOCL_SKD_AXLF_SIZE, zocl_skd_axlf_size_ioctl, + DRM_AUTH|DRM_UNLOCKED|DRM_RENDER_ALLOW), }; static const struct file_operations zocl_driver_fops = { diff --git a/src/runtime_src/core/edge/drm/zocl/common/zocl_ioctl.c b/src/runtime_src/core/edge/drm/zocl/common/zocl_ioctl.c index 532ec86c071..ceb9b3c8114 100644 --- a/src/runtime_src/core/edge/drm/zocl/common/zocl_ioctl.c +++ b/src/runtime_src/core/edge/drm/zocl/common/zocl_ioctl.c @@ -158,3 +158,11 @@ zocl_aie_skd_xclbin_ioctl(struct drm_device *dev, void *data, struct drm_file *f return zocl_aie_skd_xclbin(zdev, data); } + +int +zocl_skd_axlf_size_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) +{ + struct drm_zocl_dev *zdev = ZOCL_GET_ZDEV(dev); + + return zocl_skd_axlf_size(zdev, data); +} diff --git a/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c b/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c index 2647721efb3..26a465dc9a9 100644 --- a/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c +++ b/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c @@ -566,7 +566,7 @@ int zocl_aie_skd_xclbin(struct drm_zocl_dev *zdev, void *data) if (!skd_uuid) return -ENOMEM; - ret = copy_from_user(skd_uuid, uuid_ptr, sizeof(uuid_t)); + ret = copy_from_user(skd_uuid, uuid_ptr, sizeof(uuid_t)); if (ret) { vfree(skd_uuid); return ret; @@ -588,7 +588,6 @@ int zocl_aie_skd_xclbin(struct drm_zocl_dev *zdev, void *data) mutex_unlock(&zdev->pr_slot[i]->slot_xclbin_lock); } zocl_slot = zdev->pr_slot[slot_id]; - // add validation to check if axlf_size is greater than 4k ret = copy_to_user(args->skd_axlf_ptr, (char *)zocl_slot->axlf, zocl_slot->axlf_size); if (ret) { vfree(skd_uuid); @@ -600,6 +599,52 @@ int zocl_aie_skd_xclbin(struct drm_zocl_dev *zdev, void *data) return 0; } +int zocl_skd_axlf_size(struct drm_zocl_dev *zdev, void *data) +{ + struct drm_zocl_skd_axlf_size *args = data; + struct drm_zocl_slot *zocl_slot = NULL; + uuid_t *slot_uuid = NULL; + uuid_t *skd_uuid = NULL; + int i, slot_id = MAX_PR_SLOT_NUM, ret = 0; + void *uuid_ptr = (void *)(uintptr_t)args->ps_uuid_ptr; + + skd_uuid = vmalloc(sizeof(uuid_t)); + if (!skd_uuid) + return -ENOMEM; + + ret = copy_from_user(skd_uuid, uuid_ptr, sizeof(uuid_t)); + if (ret) { + vfree(skd_uuid); + return ret; + } + mutex_lock(&zdev->aie_lock); + + for (i = 0;i < MAX_PR_SLOT_NUM;i++) { + struct drm_zocl_slot *slot = NULL; + slot = zdev->pr_slot[i]; + mutex_lock(&zdev->pr_slot[i]->slot_xclbin_lock); + slot_uuid = zocl_xclbin_get_uuid(zdev->pr_slot[i]); + if(slot_uuid) { + if(uuid_equal(slot_uuid, skd_uuid)) { + slot_id = i; + mutex_unlock(&zdev->pr_slot[i]->slot_xclbin_lock); + break; + } + } + mutex_unlock(&zdev->pr_slot[i]->slot_xclbin_lock); + } + if(i == MAX_PR_SLOT_NUM) + { + DRM_ERROR(" %s: UUID not found \n",__func__); + return -ENODEV; + } + zocl_slot = zdev->pr_slot[slot_id]; + args->axlf_size = zocl_slot->axlf_size; + + mutex_unlock(&zdev->aie_lock); + return 0; +} + int zocl_aie_kds_add_graph_context(struct drm_zocl_dev *zdev, u32 gid, u32 ctx_code, struct kds_client *client) diff --git a/src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h b/src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h index f18e6f36b76..7c46a08bbb7 100644 --- a/src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h +++ b/src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h @@ -289,6 +289,7 @@ int zocl_init_error(struct drm_zocl_dev *zdev); void zocl_fini_error(struct drm_zocl_dev *zdev); int zocl_insert_error_record(struct drm_zocl_dev *zdev, xrtErrorCode err_code); int zocl_aie_skd_xclbin(struct drm_zocl_dev *zdev, void *data); +int zocl_skd_axlf_size(struct drm_zocl_dev *zdev, void *data); /* zocl_kds.c */ int zocl_init_sched(struct drm_zocl_dev *zdev); diff --git a/src/runtime_src/core/edge/drm/zocl/include/zocl_ioctl.h b/src/runtime_src/core/edge/drm/zocl/include/zocl_ioctl.h index 6279d1b979a..ff71d3d09e0 100644 --- a/src/runtime_src/core/edge/drm/zocl/include/zocl_ioctl.h +++ b/src/runtime_src/core/edge/drm/zocl/include/zocl_ioctl.h @@ -63,4 +63,6 @@ int zocl_set_cu_read_only_range_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); int zocl_aie_skd_xclbin_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); +int +zocl_skd_axlf_size_ioctl(struct drm_device *dev, void *data, struct drm_file *filp); #endif diff --git a/src/runtime_src/core/edge/include/zynq_ioctl.h b/src/runtime_src/core/edge/include/zynq_ioctl.h index c2d2cd79c04..0518ab3cb67 100644 --- a/src/runtime_src/core/edge/include/zynq_ioctl.h +++ b/src/runtime_src/core/edge/include/zynq_ioctl.h @@ -125,7 +125,8 @@ enum drm_zocl_ops { /* Set CU read-only range */ DRM_ZOCL_SET_CU_READONLY_RANGE, DRM_ZOCL_NUM_IOCTLS, - DRM_ZOCL_AIE_SKD_XCLBIN + DRM_ZOCL_AIE_SKD_XCLBIN, + DRM_ZOCL_SKD_AXLF_SIZE }; enum drm_zocl_sync_bo_dir { @@ -554,6 +555,11 @@ struct drm_zocl_aie_skd_xclbin { uint64_t ps_uuid_ptr; }; +struct drm_zocl_skd_axlf_size { + uint64_t ps_uuid_ptr; + uint32_t axlf_size; +}; + #define DRM_IOCTL_ZOCL_CREATE_BO DRM_IOWR(DRM_COMMAND_BASE + \ DRM_ZOCL_CREATE_BO, \ struct drm_zocl_create_bo) @@ -604,4 +610,6 @@ struct drm_zocl_aie_skd_xclbin { DRM_ZOCL_SET_CU_READONLY_RANGE, struct drm_zocl_set_cu_range) #define DRM_IOCTL_ZOCL_AIE_SKD_XCLBIN DRM_IOWR(DRM_COMMAND_BASE + \ DRM_ZOCL_AIE_SKD_XCLBIN, struct drm_zocl_aie_skd_xclbin) +#define DRM_IOCTL_ZOCL_SKD_AXLF_SIZE DRM_IOWR(DRM_COMMAND_BASE + \ + DRM_ZOCL_SKD_AXLF_SIZE, struct drm_zocl_skd_axlf_size) #endif diff --git a/src/runtime_src/core/edge/user/device_linux.cpp b/src/runtime_src/core/edge/user/device_linux.cpp index 791c4deff3c..bb7fecea04b 100644 --- a/src/runtime_src/core/edge/user/device_linux.cpp +++ b/src/runtime_src/core/edge/user/device_linux.cpp @@ -873,6 +873,34 @@ struct aie_skd_xclbin } }; +struct skd_axlf_size +{ + using result_type = query::skd_axlf_size::result_type; + + XAie_DevInst* devInst; // AIE Device Instance + + static result_type + get(const xrt_core::device* device, key_type key, const std::any& skd_uuid_ptr) + { +#if defined(XRT_ENABLE_AIE) + struct drm_zocl_skd_axlf_size aie_arg; + aie_arg.ps_uuid_ptr = std::any_cast(skd_uuid_ptr); + + const std::string zocl_device = "/dev/dri/" + get_render_devname(); + auto fd_obj = aie_get_drmfd(device, zocl_device); + if (fd_obj->fd < 0) + throw xrt_core::error(-EINVAL, boost::str(boost::format("Cannot open %s") % zocl_device)); + + if (ioctl(fd_obj->fd, DRM_IOCTL_ZOCL_SKD_AXLF_SIZE, &aie_arg)) + throw xrt_core::error(-errno, boost::str(boost::format("Reading SKD XCLBIN for uuid (%s) failed") % aie_arg.ps_uuid_ptr)); + +#else + throw xrt_core::error(-EINVAL, "AIE is not enabled for this device"); +#endif + return aie_arg.axlf_size; + } +}; + // Specialize for other value types. template struct sysfs_fcn @@ -1079,6 +1107,7 @@ initialize_query_table() emplace_func4_request(); emplace_func4_request(); emplace_func4_request(); + emplace_func4_request(); emplace_func4_request(); emplace_func4_request(); } diff --git a/src/runtime_src/core/edge/user/device_linux.cpp.rej b/src/runtime_src/core/edge/user/device_linux.cpp.rej new file mode 100644 index 00000000000..c287537b93d --- /dev/null +++ b/src/runtime_src/core/edge/user/device_linux.cpp.rej @@ -0,0 +1,13 @@ +diff a/src/runtime_src/core/edge/user/device_linux.cpp b/src/runtime_src/core/edge/user/device_linux.cpp (rejected hunks) +@@ -5,10 +5,10 @@ + #include "xrt.h" + #include "zynq_dev.h" + #include "aie_sys_parser.h" +- + #include "core/common/debug_ip.h" + #include "core/common/query_requests.h" + #include "core/common/xrt_profiling.h" ++#include "core/include/xrt/xrt_uuid.h" + + #include + #include From aace9716790ab16aa990dfad8e6313b62665a8f2 Mon Sep 17 00:00:00 2001 From: rave Date: Fri, 12 Jul 2024 22:22:43 +0530 Subject: [PATCH 3/6] deleted .rej file Signed-off-by: rave --- src/runtime_src/core/edge/user/device_linux.cpp.rej | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 src/runtime_src/core/edge/user/device_linux.cpp.rej diff --git a/src/runtime_src/core/edge/user/device_linux.cpp.rej b/src/runtime_src/core/edge/user/device_linux.cpp.rej deleted file mode 100644 index c287537b93d..00000000000 --- a/src/runtime_src/core/edge/user/device_linux.cpp.rej +++ /dev/null @@ -1,13 +0,0 @@ -diff a/src/runtime_src/core/edge/user/device_linux.cpp b/src/runtime_src/core/edge/user/device_linux.cpp (rejected hunks) -@@ -5,10 +5,10 @@ - #include "xrt.h" - #include "zynq_dev.h" - #include "aie_sys_parser.h" -- - #include "core/common/debug_ip.h" - #include "core/common/query_requests.h" - #include "core/common/xrt_profiling.h" -+#include "core/include/xrt/xrt_uuid.h" - - #include - #include From 1141d8cc9c4aae92af15676dcbc0c5197b7b22de Mon Sep 17 00:00:00 2001 From: rave Date: Sat, 13 Jul 2024 09:03:50 +0530 Subject: [PATCH 4/6] format changes Signed-off-by: rave --- src/runtime_src/core/edge/drm/zocl/common/zocl_sysfs.c | 2 +- src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c | 5 +++-- src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/runtime_src/core/edge/drm/zocl/common/zocl_sysfs.c b/src/runtime_src/core/edge/drm/zocl/common/zocl_sysfs.c index 95772beaa75..86ad23bebb9 100644 --- a/src/runtime_src/core/edge/drm/zocl/common/zocl_sysfs.c +++ b/src/runtime_src/core/edge/drm/zocl/common/zocl_sysfs.c @@ -600,7 +600,7 @@ static ssize_t read_xclbin_full(struct file *filp, struct kobject *kobj, read_lock(&zdev->attr_rwlock); // Only read slot 0's xclbin - TODO: extend to multi-slot - zocl_slot = zdev->pr_slot[1]; + zocl_slot = zdev->pr_slot[0]; if (!zocl_slot || !zocl_slot->axlf) { read_unlock(&zdev->attr_rwlock); return 0; diff --git a/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c b/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c index 26a465dc9a9..42b89a3184f 100644 --- a/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c +++ b/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c @@ -573,7 +573,7 @@ int zocl_aie_skd_xclbin(struct drm_zocl_dev *zdev, void *data) } mutex_lock(&zdev->aie_lock); - for (i = 0;i < MAX_PR_SLOT_NUM;i++) { + for (i = 0; i < MAX_PR_SLOT_NUM; i++) { struct drm_zocl_slot *slot = NULL; slot = zdev->pr_slot[i]; mutex_lock(&zdev->pr_slot[i]->slot_xclbin_lock); @@ -619,7 +619,7 @@ int zocl_skd_axlf_size(struct drm_zocl_dev *zdev, void *data) } mutex_lock(&zdev->aie_lock); - for (i = 0;i < MAX_PR_SLOT_NUM;i++) { + for (i = 0; i < MAX_PR_SLOT_NUM; i++) { struct drm_zocl_slot *slot = NULL; slot = zdev->pr_slot[i]; mutex_lock(&zdev->pr_slot[i]->slot_xclbin_lock); @@ -636,6 +636,7 @@ int zocl_skd_axlf_size(struct drm_zocl_dev *zdev, void *data) if(i == MAX_PR_SLOT_NUM) { DRM_ERROR(" %s: UUID not found \n",__func__); + mutex_unlock(&zdev->aie_lock); return -ENODEV; } zocl_slot = zdev->pr_slot[slot_id]; diff --git a/src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c b/src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c index 0df25253980..bb8f89d9aba 100644 --- a/src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c +++ b/src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c @@ -60,7 +60,7 @@ zocl_sk_getcmd_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) cmd = scmd->skc_packet; /* Look for slot_id corresponding to UUID */ - for (i = 0;i < MAX_PR_SLOT_NUM;i++) { + for (i = 0; i < MAX_PR_SLOT_NUM; i++) { mutex_lock(&zdev->pr_slot[i]->slot_xclbin_lock); slot_uuid = zocl_xclbin_get_uuid(zdev->pr_slot[i]); if(slot_uuid) { From 2eb8138fa3b2738cfa528f11d728b4d0618bb2b2 Mon Sep 17 00:00:00 2001 From: rave Date: Mon, 15 Jul 2024 15:16:26 +0530 Subject: [PATCH 5/6] shim changes Signed-off-by: rave --- src/runtime_src/core/common/device.cpp | 26 +++++------ src/runtime_src/core/common/query_requests.h | 13 +++--- src/runtime_src/core/common/xrt_profiling.h | 5 +++ .../core/edge/drm/zocl/edge/zocl_aie.c | 4 +- .../core/edge/drm/zocl/zert/zocl_sk.c | 2 +- .../core/edge/include/zynq_ioctl.h | 10 +++-- src/runtime_src/core/edge/skd/xrt_skd.cpp | 1 - .../core/edge/user/device_linux.cpp | 42 +++++------------- src/runtime_src/core/edge/user/shim.cpp | 44 +++++++++++++++++++ src/runtime_src/core/edge/user/shim.h | 2 + src/runtime_src/core/include/xclbin.h | 2 - 11 files changed, 91 insertions(+), 60 deletions(-) diff --git a/src/runtime_src/core/common/device.cpp b/src/runtime_src/core/common/device.cpp index 4e1279332ae..1e0981baf9f 100644 --- a/src/runtime_src/core/common/device.cpp +++ b/src/runtime_src/core/common/device.cpp @@ -136,41 +136,41 @@ load_xclbin(const xrt::xclbin& xclbin) } } +/* This function reads the axlf buffer + * for the specific uuid passed. + */ void device:: load_xclbin(const uuid& xclbin_id) { - auto uuid_loaded = get_xclbin_uuid(); - if (uuid_compare(uuid_loaded.get(), xclbin_id.get())) - throw error(ENODEV, "specified xclbin is not loaded"); + /* UUID comparision happens at low level where the + * the query for axlf buffer sent for this specific uuid. + */ #ifdef XRT_ENABLE_AIE - uint64_t ps_uuid_ptr = reinterpret_cast(xclbin_id.get()); + uint64_t skd_uuid_ptr = reinterpret_cast(xclbin_id.get()); const axlf* skd_axlf_ptr; uint32_t axlf_size; /* Query for axlf buffer size Ioctl for this UUID parameter */ try { - axlf_size = xrt_core::device_query(this, ps_uuid_ptr); + axlf_size = xrt_core::device_query(this, skd_uuid_ptr); } catch (const std::exception &e) { - std::cerr << boost::format("ERROR: Failed to get axlf size (%lx)\n %s\n") % uuid_loaded.get() % e.what(); + std::cerr << boost::format("ERROR: Failed to get axlf size (%lx)\n %s\n") % xclbin_id.get() % e.what(); throw xrt_core::error(std::errc::operation_canceled); } if(axlf_size == 0) { - std::cerr << boost::format("ERROR: UUID not found (%lx)\n %s\n") % uuid_loaded.get(); + std::cerr << boost::format("ERROR: UUID not found (%lx)\n %s\n") % xclbin_id.get(); throw xrt_core::error(std::errc::operation_canceled); } /* Initialize the axlf buffer and query axlf for the specified UUID */ std::vector buf(axlf_size, 0); - xrt_core::query::aie_skd_xclbin::args arg = {reinterpret_cast(ps_uuid_ptr), reinterpret_cast(buf.data())}; - try { - xrt_core::device_query(this, arg); - } - catch (const std::exception &e) { - std::cerr << boost::format("ERROR: Failed to get xclbin for uuid (%lx)\n %s\n") % uuid_loaded.get() % e.what(); + if (auto ret = xrt_core::device_query(this, skd_uuid_ptr, reinterpret_cast(buf.data()))) + { + std::cerr << boost::format("ERROR: Failed to get xclbin for uuid (%lx)\n %s\n") % xclbin_id.get(); throw xrt_core::error(std::errc::operation_canceled); } diff --git a/src/runtime_src/core/common/query_requests.h b/src/runtime_src/core/common/query_requests.h index bca1a06efc9..a1943a1ac8f 100644 --- a/src/runtime_src/core/common/query_requests.h +++ b/src/runtime_src/core/common/query_requests.h @@ -3825,29 +3825,30 @@ struct read_trace_data : request /* SKD Request to load xclbin for a specific UUID */ struct aie_skd_xclbin : request { - using result_type = bool; - using ps_uuid_ptr_type = uint64_t; + using result_type = uint32_t; + using skd_uuid_ptr_type = uint64_t; using skd_axlf_ptr_type = uint64_t; static const key_type key = key_type::aie_skd_xclbin; struct args { - uint64_t ps_uuid_ptr; + uint64_t skd_uuid_ptr; uint64_t skd_axlf_ptr; }; virtual std::any - get(const device*, const std::any& arg) const = 0; + get(const device*, const std::any& skd_uuid_ptr, const std::any& skd_axlf_ptr) const = 0; }; +/* SKD Request to read the axlf size for a specific uuid */ struct skd_axlf_size : request { - using ps_uuid_ptr_type = uint64_t; + using skd_uuid_ptr_type = uint64_t; using result_type = uint32_t; static const key_type key = key_type::skd_axlf_size; virtual std::any - get(const device*, const std::any& ps_uuid_ptr) const = 0; + get(const device*, const std::any& skd_uuid_ptr) const = 0; }; } // query diff --git a/src/runtime_src/core/common/xrt_profiling.h b/src/runtime_src/core/common/xrt_profiling.h index 35ee16e7c88..983c41ec7e8 100644 --- a/src/runtime_src/core/common/xrt_profiling.h +++ b/src/runtime_src/core/common/xrt_profiling.h @@ -56,6 +56,11 @@ XCL_DRIVER_DLLESPEC int xclReadTraceData(xclDeviceHandle handle, void* traceBuf, XCL_DRIVER_DLLESPEC int xclGetSubdevPath(xclDeviceHandle handle, const char* subdev, uint32_t idx, char* path, size_t size); +XCL_DRIVER_DLLESPEC int xclgetAIESkdXclbin(xclDeviceHandle handle, uint64_t skd_uuid_ptr, uint64_t skd_axlf_ptr); + +XCL_DRIVER_DLLESPEC int xclgetAIESkdAxlfSize(xclDeviceHandle handle, uint64_t skd_uuid_ptr); + + #ifdef __cplusplus } #endif diff --git a/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c b/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c index 42b89a3184f..2b17f1d6bc5 100644 --- a/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c +++ b/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c @@ -560,7 +560,7 @@ int zocl_aie_skd_xclbin(struct drm_zocl_dev *zdev, void *data) uuid_t *slot_uuid = NULL; uuid_t *skd_uuid = NULL; int i, slot_id = MAX_PR_SLOT_NUM, ret = 0; - void *uuid_ptr = (void *)(uintptr_t)args->ps_uuid_ptr; + void *uuid_ptr = (void *)(uintptr_t)args->skd_uuid_ptr; skd_uuid = vmalloc(sizeof(uuid_t)); if (!skd_uuid) @@ -606,7 +606,7 @@ int zocl_skd_axlf_size(struct drm_zocl_dev *zdev, void *data) uuid_t *slot_uuid = NULL; uuid_t *skd_uuid = NULL; int i, slot_id = MAX_PR_SLOT_NUM, ret = 0; - void *uuid_ptr = (void *)(uintptr_t)args->ps_uuid_ptr; + void *uuid_ptr = (void *)(uintptr_t)args->skd_uuid_ptr; skd_uuid = vmalloc(sizeof(uuid_t)); if (!skd_uuid) diff --git a/src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c b/src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c index bb8f89d9aba..a03c12f6d67 100644 --- a/src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c +++ b/src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c @@ -130,7 +130,7 @@ zocl_sk_getcmd_ioctl(struct drm_device *dev, void *data, struct drm_file *filp) kdata->cu_nums = cmd->num_cus; kdata->bohdl = bohdl; kdata->meta_bohdl = meta_bohdl; - // Pass physical slot 0 UUID to SKD - Currently we only support 1 physical slot + // Pass physical slot_id UUID to SKD - Currently we only support 1 physical slot mutex_lock(&zdev->pr_slot[slot_id]->slot_xclbin_lock); phy_slot_uuid = zocl_xclbin_get_uuid(zdev->pr_slot[slot_id]); mutex_unlock(&zdev->pr_slot[slot_id]->slot_xclbin_lock); diff --git a/src/runtime_src/core/edge/include/zynq_ioctl.h b/src/runtime_src/core/edge/include/zynq_ioctl.h index 0518ab3cb67..15fc51428be 100644 --- a/src/runtime_src/core/edge/include/zynq_ioctl.h +++ b/src/runtime_src/core/edge/include/zynq_ioctl.h @@ -124,9 +124,11 @@ enum drm_zocl_ops { DRM_ZOCL_AIE_FREQSCALE, /* Set CU read-only range */ DRM_ZOCL_SET_CU_READONLY_RANGE, - DRM_ZOCL_NUM_IOCTLS, + /* Read xclbin for a specific uuid */ DRM_ZOCL_AIE_SKD_XCLBIN, - DRM_ZOCL_SKD_AXLF_SIZE + /* Read Axlf size */ + DRM_ZOCL_SKD_AXLF_SIZE, + DRM_ZOCL_NUM_IOCTLS }; enum drm_zocl_sync_bo_dir { @@ -552,11 +554,11 @@ struct drm_zocl_error_inject { struct drm_zocl_aie_skd_xclbin { uint64_t skd_axlf_ptr; - uint64_t ps_uuid_ptr; + uint64_t skd_uuid_ptr; }; struct drm_zocl_skd_axlf_size { - uint64_t ps_uuid_ptr; + uint64_t skd_uuid_ptr; uint32_t axlf_size; }; diff --git a/src/runtime_src/core/edge/skd/xrt_skd.cpp b/src/runtime_src/core/edge/skd/xrt_skd.cpp index 181b1755046..57707943380 100644 --- a/src/runtime_src/core/edge/skd/xrt_skd.cpp +++ b/src/runtime_src/core/edge/skd/xrt_skd.cpp @@ -52,7 +52,6 @@ namespace xrt { m_parent_bo_handle(xrt::shim_int::get_buffer_handle(xrtDeviceToXclDevice(handle), parent_mem_bo_in)), m_mem_start_paddr(mem_start_paddr_in), m_mem_size(mem_size_in) - { } diff --git a/src/runtime_src/core/edge/user/device_linux.cpp b/src/runtime_src/core/edge/user/device_linux.cpp index bb7fecea04b..b007fbf07f7 100644 --- a/src/runtime_src/core/edge/user/device_linux.cpp +++ b/src/runtime_src/core/edge/user/device_linux.cpp @@ -845,59 +845,39 @@ struct read_trace_data struct aie_skd_xclbin { using result_type = query::aie_skd_xclbin::result_type; - XAie_DevInst* devInst; // AIE Device Instance static result_type - get(const xrt_core::device* device, key_type key, const std::any& param) + get(const xrt_core::device* device, key_type key, const std::any& skd_uuid_ptr, const std::any& skd_axlf_ptr) { #if defined(XRT_ENABLE_AIE) - struct drm_zocl_aie_skd_xclbin aie_arg; - auto args = std::any_cast(param); - - aie_arg.ps_uuid_ptr = std::any_cast(args.ps_uuid_ptr); - aie_arg.skd_axlf_ptr = std::any_cast(args.skd_axlf_ptr); - - const std::string zocl_device = "/dev/dri/" + get_render_devname(); - auto fd_obj = aie_get_drmfd(device, zocl_device); - if (fd_obj->fd < 0) - throw xrt_core::error(-EINVAL, boost::str(boost::format("Cannot open %s") % zocl_device)); - - if (ioctl(fd_obj->fd, DRM_IOCTL_ZOCL_AIE_SKD_XCLBIN, &aie_arg)) - throw xrt_core::error(-errno, boost::str(boost::format("Reading SKD XCLBIN for uuid (%s) failed") % aie_arg.ps_uuid_ptr)); - + result_type ret = 0; + /* Get the Axlf Buffer */ + ret = xclgetAIESkdXclbin(device->get_user_handle(), std::any_cast(skd_uuid_ptr), + std::any_cast(skd_axlf_ptr)); #else throw xrt_core::error(-EINVAL, "AIE is not enabled for this device"); #endif - return true; + return ret; } }; struct skd_axlf_size { using result_type = query::skd_axlf_size::result_type; - XAie_DevInst* devInst; // AIE Device Instance static result_type get(const xrt_core::device* device, key_type key, const std::any& skd_uuid_ptr) { #if defined(XRT_ENABLE_AIE) - struct drm_zocl_skd_axlf_size aie_arg; - aie_arg.ps_uuid_ptr = std::any_cast(skd_uuid_ptr); - - const std::string zocl_device = "/dev/dri/" + get_render_devname(); - auto fd_obj = aie_get_drmfd(device, zocl_device); - if (fd_obj->fd < 0) - throw xrt_core::error(-EINVAL, boost::str(boost::format("Cannot open %s") % zocl_device)); - - if (ioctl(fd_obj->fd, DRM_IOCTL_ZOCL_SKD_AXLF_SIZE, &aie_arg)) - throw xrt_core::error(-errno, boost::str(boost::format("Reading SKD XCLBIN for uuid (%s) failed") % aie_arg.ps_uuid_ptr)); - + result_type axlf_size = 0; + /* Read the Axlf size */ + axlf_size = xclgetAIESkdAxlfSize(device->get_user_handle(), std::any_cast(skd_uuid_ptr)); #else throw xrt_core::error(-EINVAL, "AIE is not enabled for this device"); #endif - return aie_arg.axlf_size; + return axlf_size; } }; @@ -1106,7 +1086,7 @@ initialize_query_table() emplace_func0_request(); emplace_func4_request(); emplace_func4_request(); - emplace_func4_request(); + emplace_func2_request(); emplace_func4_request(); emplace_func4_request(); emplace_func4_request(); diff --git a/src/runtime_src/core/edge/user/shim.cpp b/src/runtime_src/core/edge/user/shim.cpp index ceda5ffd43e..5bba4f9bf83 100644 --- a/src/runtime_src/core/edge/user/shim.cpp +++ b/src/runtime_src/core/edge/user/shim.cpp @@ -1862,6 +1862,35 @@ setAIEAccessMode(xrt::aie::access_mode am) access_mode = am; } +int +shim:: +xclgetAIESkdAxlfSize(uint64_t skd_uuid_ptr) +{ + int ret = 0; + struct drm_zocl_skd_axlf_size aie_arg = {skd_uuid_ptr, 0}; + + ret = ioctl(mKernelFD, DRM_IOCTL_ZOCL_SKD_AXLF_SIZE, &aie_arg); + if (ret) + { + xclLog(XRT_ERROR, "%s:ioctl return %d", __func__, ret); + return -errno; + } + return aie_arg.axlf_size; +} + +int +shim:: +xclgetAIESkdXclbin(uint64_t skd_uuid_ptr, uint64_t skd_axlf_ptr) +{ + int ret = 0; + struct drm_zocl_aie_skd_xclbin aie_arg; + + aie_arg.skd_uuid_ptr = skd_uuid_ptr; + aie_arg.skd_axlf_ptr = skd_axlf_ptr; + + ret = ioctl(mKernelFD, DRM_IOCTL_ZOCL_AIE_SKD_XCLBIN, &aie_arg); + return ret ? -errno : ret; +} #endif } // end namespace ZYNQ @@ -2827,3 +2856,18 @@ xclErrorClear(xclDeviceHandle handle) return drv->xclErrorClear(); } + +int +xclgetAIESkdXclbin(xclDeviceHandle handle, uint64_t skd_uuid_ptr, uint64_t skd_axlf_ptr) +{ + ZYNQ::shim *drv = ZYNQ::shim::handleCheck(handle); + return (drv) ? drv->xclgetAIESkdXclbin(skd_uuid_ptr, skd_axlf_ptr) : -EINVAL; +} + +int +xclgetAIESkdAxlfSize(xclDeviceHandle handle, uint64_t skd_uuid_ptr) +{ + ZYNQ::shim *drv = ZYNQ::shim::handleCheck(handle); + return (drv) ? drv->xclgetAIESkdAxlfSize(skd_uuid_ptr) : -EINVAL; +} + diff --git a/src/runtime_src/core/edge/user/shim.h b/src/runtime_src/core/edge/user/shim.h index 7d047ee1fc7..2b608fa75b5 100644 --- a/src/runtime_src/core/edge/user/shim.h +++ b/src/runtime_src/core/edge/user/shim.h @@ -423,6 +423,8 @@ class shim { static shim *handleCheck(void *handle, bool checkDrmFd = true); int xclIPName2Index(const char *name); int xclIPSetReadRange(uint32_t ipIndex, uint32_t start, uint32_t size); + int xclgetAIESkdAxlfSize(uint64_t skd_uuid_ptr); + int xclgetAIESkdXclbin(uint64_t skd_uuid_ptr, uint64_t skd_axlf_ptr); // Application debug path functionality for xbutil size_t xclDebugReadCheckers(xdp::LAPCCounterResults* aCheckerResults); diff --git a/src/runtime_src/core/include/xclbin.h b/src/runtime_src/core/include/xclbin.h index 3d45166fefd..913c5db631d 100644 --- a/src/runtime_src/core/include/xclbin.h +++ b/src/runtime_src/core/include/xclbin.h @@ -108,8 +108,6 @@ typedef GUID xuid_t; #define SIZE_OF_STRUCT(s) \ char (*__fail)[sizeof(struct s)] = 1 -#define MAX_AXLF_BUF_SIZE (4096*1024) - #ifdef __cplusplus extern "C" { #endif From 13230441aeeae8634f9131cc020cc6f9fc7cc65b Mon Sep 17 00:00:00 2001 From: rave Date: Tue, 16 Jul 2024 00:30:55 +0530 Subject: [PATCH 6/6] sanity check Signed-off-by: rave --- src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c b/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c index 2b17f1d6bc5..bc21f39a1e2 100644 --- a/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c +++ b/src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c @@ -576,6 +576,8 @@ int zocl_aie_skd_xclbin(struct drm_zocl_dev *zdev, void *data) for (i = 0; i < MAX_PR_SLOT_NUM; i++) { struct drm_zocl_slot *slot = NULL; slot = zdev->pr_slot[i]; + if (!slot) + continue; mutex_lock(&zdev->pr_slot[i]->slot_xclbin_lock); slot_uuid = zocl_xclbin_get_uuid(zdev->pr_slot[i]); if(slot_uuid) { @@ -622,6 +624,8 @@ int zocl_skd_axlf_size(struct drm_zocl_dev *zdev, void *data) for (i = 0; i < MAX_PR_SLOT_NUM; i++) { struct drm_zocl_slot *slot = NULL; slot = zdev->pr_slot[i]; + if (!slot) + continue; mutex_lock(&zdev->pr_slot[i]->slot_xclbin_lock); slot_uuid = zocl_xclbin_get_uuid(zdev->pr_slot[i]); if(slot_uuid) {