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 3 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
36 changes: 30 additions & 6 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 @@ -146,14 +145,39 @@ load_xclbin(const uuid& xclbin_id)
throw error(ENODEV, "specified xclbin is not loaded");

#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 ps_uuid_ptr = reinterpret_cast<uint64_t>(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<xrt_core::query::skd_axlf_size>(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<char> buf(axlf_size, 0);

const axlf* top = reinterpret_cast<axlf *>(xclbin_full.data());
xrt_core::query::aie_skd_xclbin::args arg = {reinterpret_cast<uint64_t>(ps_uuid_ptr), reinterpret_cast<uint64_t>(buf.data())};
Copy link
Collaborator

Choose a reason for hiding this comment

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

ps_uuid_ptr is already uint64_t, dont call reinterpret cast.

try {
xrt_core::device_query<xrt_core::query::aie_skd_xclbin>(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);
}

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
31 changes: 31 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,35 @@ 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 = 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;
};

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 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
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);
}
2 changes: 1 addition & 1 deletion src/runtime_src/core/edge/drm/zocl/common/zocl_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Copy link
Collaborator

Choose a reason for hiding this comment

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

This index should come as an input.
Think about, if two or more PS XCLBINs are loaded

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is a dead code, sysfs functionality is being used anymore

if (!zocl_slot || !zocl_slot->axlf) {
read_unlock(&zdev->attr_rwlock);
return 0;
Expand Down
95 changes: 94 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,98 @@ 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++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please correct the format
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->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++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please correct the format

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__);
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 +936,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
9 changes: 5 additions & 4 deletions src/runtime_src/core/edge/drm/zocl/zert/zocl_sk.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
Expand Down
18 changes: 17 additions & 1 deletion src/runtime_src/core/edge/include/zynq_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ 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,
Copy link
Collaborator

Choose a reason for hiding this comment

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

NUM_IOCTL should be at the end. it should be last macro.

DRM_ZOCL_AIE_SKD_XCLBIN,
DRM_ZOCL_SKD_AXLF_SIZE
};

enum drm_zocl_sync_bo_dir {
Expand Down Expand Up @@ -548,6 +550,16 @@ 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;
};

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)
Expand Down Expand Up @@ -596,4 +608,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
1 change: 1 addition & 0 deletions src/runtime_src/core/edge/skd/xrt_skd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Copy link
Collaborator

Choose a reason for hiding this comment

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

remove the new line?

{
}

Expand Down
Loading
Loading