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

Removed hardcoded check in zocl. #8332

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 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 @@ -86,6 +86,8 @@ zocl_info_cu_ioctl(struct drm_device *ddev, void *data, struct drm_file *filp)
args->paddr = addr;
args->apt_idx = apt_idx;
args->cu_idx = cu_idx;
//update cu size based on the apt_index
args->cu_size = apts[apt_idx].size;
return 0;
}

Expand Down
17 changes: 15 additions & 2 deletions src/runtime_src/core/edge/drm/zocl/common/zocl_xclbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ zocl_update_apertures(struct drm_zocl_dev *zdev, struct drm_zocl_slot *slot)
int total = 0;
int apt_idx = 0;
int i = 0;
char kname[64] = {0};
char *kname_p = NULL;
struct kernel_info *krnl_info = NULL;

/* Update aperture should only happen when loading xclbin */
if (slot->ip)
Expand Down Expand Up @@ -336,8 +339,18 @@ zocl_update_apertures(struct drm_zocl_dev *zdev, struct drm_zocl_slot *slot)
apt = &zdev->cu_subdev.apertures[apt_idx];

apt->addr = ip->m_base_address;
apt->size = CU_SIZE;
apt->prop = ip->properties;

strncpy(kname, ip->m_name, sizeof(kname));
kname[sizeof(kname)-1] = '\0';
kname_p = &kname[0];
strncpy(kname, strsep(&kname_p, ":"), sizeof(kname));
kname[sizeof(kname)-1] = '\0';
krnl_info = zocl_query_kernel(slot, kname);
if (krnl_info && krnl_info->range >= CU_SIZE)
apt->size = krnl_info->range;
else
apt->size = CU_SIZE;
apt->prop = ip->properties;
apt->cu_idx = -1;
apt->slot_idx = slot->slot_idx;
}
Expand Down
8 changes: 4 additions & 4 deletions src/runtime_src/core/edge/drm/zocl/edge/zocl_edge_xclbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,6 @@ zocl_xclbin_read_axlf(struct drm_zocl_dev *zdev, struct drm_zocl_axlf *axlf_obj,
if (ret)
goto out0;

ret = zocl_update_apertures(zdev, slot);
if (ret)
goto out0;

/* Kernels are slot specific. */
if (slot->kernels != NULL) {
vfree(slot->kernels);
Expand All @@ -399,6 +395,10 @@ zocl_xclbin_read_axlf(struct drm_zocl_dev *zdev, struct drm_zocl_axlf *axlf_obj,
slot->kernels = kernels;
}

ret = zocl_update_apertures(zdev, slot);
if (ret)
goto out0;

zocl_clear_mem_slot(zdev, slot->slot_idx);
/* Initialize the memory for the new xclbin */
zocl_init_mem(zdev, slot);
Expand Down
1 change: 1 addition & 0 deletions src/runtime_src/core/edge/include/zynq_ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ struct drm_zocl_info_cu {
uint64_t paddr;
int apt_idx;
int cu_idx;
uint64_t cu_size;
};

enum drm_zocl_ctx_code {
Expand Down
32 changes: 16 additions & 16 deletions src/runtime_src/core/edge/user/shim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ shim(unsigned index)
: mCoreDevice(xrt_core::edge_linux::get_userpf_device(this, index))
, mBoardNumber(index)
, mKernelClockFreq(100)
, mCuMaps(128, nullptr)
, mCuMaps(128, {nullptr, 0})
{
xclLog(XRT_INFO, "%s", __func__);

Expand Down Expand Up @@ -151,8 +151,8 @@ shim::
}

for (auto p : mCuMaps) {
if (p)
(void) munmap(p, mCuMapSize);
if (p.first)
(void) munmap(p.first, p.second);
}
}

Expand All @@ -177,16 +177,16 @@ mapKernelControl(const std::vector<std::pair<uint64_t, size_t>>& offsets)
if ((offset_it->first & (~0xFF)) != (-1UL & ~0xFF)) {
auto it = mKernelControl.find(offset_it->first);
if (it == mKernelControl.end()) {
drm_zocl_info_cu info = {offset_it->first, -1, -1};
drm_zocl_info_cu info = {offset_it->first, -1, -1, 0};
int result = ioctl(mKernelFD, DRM_IOCTL_ZOCL_INFO_CU, &info);
if (result) {
xclLog(XRT_ERROR, "%s: Failed to find CU info 0x%lx", __func__, offset_it->first);
return -errno;
}
size_t psize = getpagesize();
ptr = mmap(0, offset_it->second, PROT_READ | PROT_WRITE, MAP_SHARED, mKernelFD, info.apt_idx*psize);
ptr = mmap(0, info.cu_size, PROT_READ | PROT_WRITE, MAP_SHARED, mKernelFD, info.apt_idx*psize);
if (ptr == MAP_FAILED) {
xclLog(XRT_ERROR, "%s: Map failed for aperture 0x%lx, size 0x%lx", __func__, offset_it->first, offset_it->second);
xclLog(XRT_ERROR, "%s: Map failed for aperture 0x%lx, size 0x%lx", __func__, offset_it->first, info.cu_size);
return -1;
}
mKernelControl.insert(it, std::pair<uint64_t, uint32_t *>(offset_it->first, (uint32_t *)ptr));
Expand Down Expand Up @@ -766,7 +766,6 @@ xclLoadAxlf(const axlf *buffer)
krnl->name[sizeof(krnl->name)-1] = '\0';
krnl->range = kernel.range;
krnl->anums = kernel.args.size();

krnl->features = 0;
if (kernel.sw_reset)
krnl->features |= KRNL_SW_RESET;
Expand Down Expand Up @@ -1169,10 +1168,10 @@ xclCloseContext(const uuid_t xclbinId, unsigned int ipIndex)

if (ipIndex < mCuMaps.size()) {
// Make sure no MMIO register space access when CU is released.
uint32_t *p = mCuMaps[ipIndex];
uint32_t *p = mCuMaps[ipIndex].first;
if (p) {
(void) munmap(p, mCuMapSize);
mCuMaps[ipIndex] = nullptr;
(void) munmap(p, mCuMaps[ipIndex].second);
mCuMaps[ipIndex] = {nullptr, 0};
}
}

Expand All @@ -1196,21 +1195,22 @@ xclRegRW(bool rd, uint32_t ipIndex, uint32_t offset, uint32_t *datap)
xclLog(XRT_ERROR, "%s: invalid CU index: %d", __func__, ipIndex);
return -EINVAL;
}
if (offset >= mCuMapSize || (offset & (sizeof(uint32_t) - 1)) != 0) {
if (offset <= 0 || (offset & (sizeof(uint32_t) - 1)) != 0) {
xclLog(XRT_ERROR, "%s: invalid CU offset: %d", __func__, offset);
return -EINVAL;
}

if (mCuMaps[ipIndex] == nullptr) {
drm_zocl_info_cu info = {0, -1, (int)ipIndex};
if (mCuMaps[ipIndex].first == nullptr) {
drm_zocl_info_cu info = {0, -1, (int)ipIndex, 0};
int result = ioctl(mKernelFD, DRM_IOCTL_ZOCL_INFO_CU, &info);
void *p = mmap(0, mCuMapSize, PROT_READ | PROT_WRITE, MAP_SHARED,
void *p = mmap(0, info.cu_size, PROT_READ | PROT_WRITE, MAP_SHARED,
mKernelFD, info.apt_idx * getpagesize());
if (p != MAP_FAILED)
mCuMaps[ipIndex] = (uint32_t *)p;
mCuMaps[ipIndex].first = (uint32_t *)p;
mCuMaps[ipIndex].second = info.cu_size;
}

uint32_t *cumap = mCuMaps[ipIndex];
uint32_t *cumap = mCuMaps[ipIndex].first;
if (cumap == nullptr) {
xclLog(XRT_ERROR, "%s: can't map CU: %d", __func__, ipIndex);
return -EINVAL;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_src/core/edge/user/shim.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class shim {
* Mapped CU register space for xclRegRead/Write(). We support at most
* 128 CUs and each map is of 64k bytes. Does not support debug IP access.
*/
std::vector<uint32_t*> mCuMaps;
std::vector<std::pair<uint32_t*, uint32_t>> mCuMaps;
const size_t mCuMapSize = 64 * 1024;
std::mutex mCuMapLock;
int xclRegRW(bool rd, uint32_t cu_index, uint32_t offset, uint32_t *datap);
Expand Down
Loading