Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ps kernel hard code handling changes #8276

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions src/runtime_src/core/common/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -137,23 +136,48 @@ 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
auto xclbin_full = xrt_core::device_query<xrt_core::query::xclbin_full>(this);
if (xclbin_full.empty())
throw error(ENODEV, "no cached xclbin data");
uint64_t skd_uuid_ptr = reinterpret_cast<uint64_t>(xclbin_id.get());
const axlf* skd_axlf_ptr;
uint32_t axlf_size;

const axlf* top = reinterpret_cast<axlf *>(xclbin_full.data());
/* Query for axlf buffer size Ioctl for this UUID parameter */
try {
axlf_size = xrt_core::device_query<xrt_core::query::skd_axlf_size>(this, skd_uuid_ptr);
}
catch (const std::exception &e) {
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") % xclbin_id.get();
throw xrt_core::error(std::errc::operation_canceled);
}
/* Initialize the axlf buffer and query axlf for the specified UUID */
std::vector<char> buf(axlf_size, 0);

if (auto ret = xrt_core::device_query<xrt_core::query::aie_skd_xclbin>(this, skd_uuid_ptr, reinterpret_cast<uint64_t>(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);
}

skd_axlf_ptr = reinterpret_cast<axlf*> (buf.data());
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&) {
Expand Down
32 changes: 32 additions & 0 deletions src/runtime_src/core/common/query_requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,8 @@ enum class key_type
kernel_max_bandwidth_mbps,
sub_device_path,
read_trace_data,
aie_skd_xclbin,
skd_axlf_size,
noop
};

Expand Down Expand Up @@ -3819,6 +3821,36 @@ struct read_trace_data : request
virtual std::any
get(const device*, const std::any&) const = 0;
};

/* SKD Request to load xclbin for a specific UUID */
struct aie_skd_xclbin : request
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment about this request type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

{
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 skd_uuid_ptr;
uint64_t skd_axlf_ptr;
};

virtual std::any
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment for this too.

{
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& skd_uuid_ptr) const = 0;
};

} // query

} // xrt_core
Expand Down
5 changes: 5 additions & 0 deletions src/runtime_src/core/common/xrt_profiling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 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 @@ -1002,6 +1002,10 @@ 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),
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 = {
Expand Down
16 changes: 16 additions & 0 deletions src/runtime_src/core/edge/drm/zocl/common/zocl_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,19 @@ 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);
}

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);
}
96 changes: 95 additions & 1 deletion src/runtime_src/core/edge/drm/zocl/edge/zocl_aie.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "zocl_aie.h"
#include "xrt_xclbin.h"
#include "xclbin.h"
#include "zocl_xclbin.h"

#ifndef __NONE_PETALINUX__
#include <linux/xlnx-ai-engine.h>
Expand Down Expand Up @@ -552,6 +553,99 @@ 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->skd_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];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity Check required, before accessing the fields

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
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];
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_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->skd_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];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!slot)
continue;

mutex_lock(&zdev->pr_slot[i]->slot_xclbin_lock);
slot_uuid = zocl_xclbin_get_uuid(zdev->pr_slot[i]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sanity check for unused slot

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__);
mutex_unlock(&zdev->aie_lock);
return -ENODEV;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mutex_unlock(&zdev->aie_lock);

}
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)
Expand Down Expand Up @@ -843,4 +937,4 @@ zocl_init_aie(struct drm_zocl_dev *zdev)
zdev->aie_information = aie;

return 0;
}
}
2 changes: 2 additions & 0 deletions src/runtime_src/core/edge/drm/zocl/include/zocl_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ 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);
int zocl_skd_axlf_size(struct drm_zocl_dev *zdev, void *data);

/* zocl_kds.c */
int zocl_init_sched(struct drm_zocl_dev *zdev);
Expand Down
4 changes: 4 additions & 0 deletions src/runtime_src/core/edge/drm/zocl/include/zocl_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,8 @@ 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);
int
zocl_skd_axlf_size_ioctl(struct drm_device *dev, void *data, struct drm_file *filp);
#endif
13 changes: 7 additions & 6 deletions src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,17 @@ 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) {
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) {
Expand Down Expand Up @@ -129,10 +130,10 @@ 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
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);
// 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);
memcpy(kdata->uuid,phy_slot_uuid,sizeof(kdata->uuid));

snprintf(kdata->name, ZOCL_MAX_NAME_LENGTH, "%s",
Expand Down
18 changes: 18 additions & 0 deletions src/runtime_src/core/edge/include/zynq_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ enum drm_zocl_ops {
DRM_ZOCL_AIE_FREQSCALE,
/* Set CU read-only range */
DRM_ZOCL_SET_CU_READONLY_RANGE,
/* Read xclbin for a specific uuid */
DRM_ZOCL_AIE_SKD_XCLBIN,
/* Read Axlf size */
DRM_ZOCL_SKD_AXLF_SIZE,
DRM_ZOCL_NUM_IOCTLS
};

Expand Down Expand Up @@ -548,6 +552,16 @@ struct drm_zocl_error_inject {
uint16_t err_class;
};

struct drm_zocl_aie_skd_xclbin {
uint64_t skd_axlf_ptr;
uint64_t skd_uuid_ptr;
};

struct drm_zocl_skd_axlf_size {
uint64_t skd_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)
Expand Down Expand Up @@ -596,4 +610,8 @@ 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)
#define DRM_IOCTL_ZOCL_SKD_AXLF_SIZE DRM_IOWR(DRM_COMMAND_BASE + \
DRM_ZOCL_SKD_AXLF_SIZE, struct drm_zocl_skd_axlf_size)
#endif
Loading
Loading