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

Conversation

karthdmg-xilinx
Copy link
Collaborator

Problem solved by the commit

The existing code reads/assumes ps kernel slot at 0th index by default when loading the xclbin based on UUID.
Made changes such that User queries based on UUID using IOCTL and reads the appropriate AXLF buffer.

Bug / issue (if any) fixed, which PR introduced the bug, how it was discovered

Program PS kernel on latest XRT.

How problem was solved, alternative solutions (if any) and why they were rejected

eliminate hard codes changes of loading ps kernel.

Risks (if any) associated the changes in the commit

None

What has been tested and how, request additional testing if necessary

Program PS, PL/PS and AIE kernels and verify the behavior.

Documentation impact (if any)

Need to update multi slot behavior for ps kernels.

Signed-off-by: rave <karthik>
Comment on lines 149 to 173
#ifdef XCLBIN_FULL_READ
auto xclbin_full = xrt_core::device_query<xrt_core::query::xclbin_full>(this);
if (xclbin_full.empty())
throw error(ENODEV, "no cached xclbin data");

const axlf* top = reinterpret_cast<axlf *>(xclbin_full.data());
const axlf* skd_axlf_ptr = reinterpret_cast<axlf *>(xclbin_full.data());
#else
uint64_t ps_uuid_ptr = reinterpret_cast<uint64_t>(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<axlf*> (buf);
xrt_core::query::aie_skd_xclbin::args arg = {reinterpret_cast<uint64_t>(ps_uuid_ptr), reinterpret_cast<uint64_t>(skd_axlf_ptr)};

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);
}
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs commenting and cannot use new.

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 another query to read axlf size, please review

@@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks random. What is this and why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed

Copy link
Collaborator

Choose a reason for hiding this comment

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

i Still see this macro

@@ -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
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

Copy link
Collaborator

@chvamshi-xilinx chvamshi-xilinx left a comment

Choose a reason for hiding this comment

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

As discussed offline, Please simplify the logic and update existing load_xclbin to support this case also.
No new #ifdefs . We are already struggling to remove AIE* defines

rave added 2 commits July 12, 2024 22:17
Signed-off-by: rave <karthik>
@@ -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

}
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++)


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->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];
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(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);

Signed-off-by: rave <karthik>
@@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

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

i Still see this macro

@@ -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?

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))
Copy link
Collaborator

Choose a reason for hiding this comment

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

please dont call ioctls from here. create shim function and call it..

struct drm_zocl_skd_axlf_size aie_arg;
aie_arg.ps_uuid_ptr = std::any_cast<xrt_core::query::skd_axlf_size::ps_uuid_ptr_type>(skd_uuid_ptr);

const std::string zocl_device = "/dev/dri/" + get_render_devname();
Copy link
Collaborator

Choose a reason for hiding this comment

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

shim function should take care of this. please dont repeat the logic

aie_arg.ps_uuid_ptr = std::any_cast<xrt_core::query::aie_skd_xclbin::ps_uuid_ptr_type>(args.ps_uuid_ptr);
aie_arg.skd_axlf_ptr = std::any_cast<xrt_core::query::aie_skd_xclbin::skd_axlf_ptr_type>(args.skd_axlf_ptr);

const std::string zocl_device = "/dev/dri/" + get_render_devname();
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as below. create shim function to handle this

@@ -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.

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.


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.

Signed-off-by: rave <karthik>

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;

Signed-off-by: rave <karthik>
@chvamshi-xilinx
Copy link
Collaborator

Hi @karthdmg-xilinx ,
As discussed offline, Please close this PR and make modifications to choose slot 0 for all of these cases.

@karthdmg-xilinx
Copy link
Collaborator Author

Not handling the multi slot changes for now, hence rejecting this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants