Skip to content

[SYCL][Graph] async_malloc use allocation size for zeVirtualMemQueryPageSize #19402

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

Merged

Conversation

lslusarczyk
Copy link
Contributor

@lslusarczyk lslusarczyk commented Jul 11, 2025

In L0 we need to call zeVirtualMemQueryPageSize with the actual allocation size for the virtual/physical allocations to align correctly.

Right now we check alignment without passing any size: https://github.com/intel/llvm/blob/sycl/sycl/source/detail/graph/memory_pool.cpp#L45

This ends up translating to 1 byte in the call to L0: https://github.com/oneapi-src/unified-runtime/blob/de05f984aa19458a4993d2a2709e3b79d82f1a37/source/adapters/level_zero/virtual_mem.cpp#L32-L37 and for large allocations a wrong alignment is used and L0 reports ZE_RESULT_ERROR_UNSUPPORTED_SIZE upon zePhysicalMemCreate call (UR fails with UR_RESULT_ERROR_INVALID_VALUE then).

The UR API should change to accept a size.

This PR exposes this issue in a unittest and fixes it.

@lslusarczyk lslusarczyk requested a review from a team as a code owner July 11, 2025 12:19
@lslusarczyk lslusarczyk requested a review from reble July 11, 2025 12:19
@lslusarczyk lslusarczyk force-pushed the size_aware_urVirtualMemGranularityGetInfo branch from 0a4f4c7 to f9a4616 Compare July 11, 2025 12:22
@lslusarczyk lslusarczyk force-pushed the size_aware_urVirtualMemGranularityGetInfo branch from f9a4616 to 4befbf0 Compare July 11, 2025 12:47
@lslusarczyk lslusarczyk force-pushed the size_aware_urVirtualMemGranularityGetInfo branch from 4befbf0 to 9475527 Compare July 11, 2025 12:50
@EwanC EwanC changed the title test to expose zeVirtualMemQueryPageSize not using allocation size [SYCL][Graph] test to expose zeVirtualMemQueryPageSize not using allocation size Jul 11, 2025
@lslusarczyk lslusarczyk requested review from a team as code owners July 14, 2025 17:43
@lslusarczyk lslusarczyk changed the title [SYCL][Graph] test to expose zeVirtualMemQueryPageSize not using allocation size [SYCL][Graph] async_malloc use allocation size for zeVirtualMemQueryPageSize Jul 14, 2025
@lslusarczyk lslusarczyk force-pushed the size_aware_urVirtualMemGranularityGetInfo branch from 482ce66 to 2b622d3 Compare July 14, 2025 17:58
@lslusarczyk lslusarczyk force-pushed the size_aware_urVirtualMemGranularityGetInfo branch from 2b622d3 to 889a26a Compare July 14, 2025 18:51
Copy link
Contributor

@EwanC EwanC left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@reble
Copy link
Contributor

reble commented Jul 16, 2025

@intel/llvm-reviewers-runtime ping

Comment on lines 17 to 20
size_t get_mem_granularity_for_allocation_size(const device &SyclDevice,
const context &SyclContext,
granularity_mode Mode,
size_t AllocationSize);
Copy link
Contributor

Choose a reason for hiding this comment

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

On the one hand, I'd like us to move to a future where sycl::<object> aren't used inside source/detail and instead code there operates on <object>_impls only. On the other hand, implementation isn't under source/detail (why?) and get_ur_handles is designed to work on sycl::<object> so changing signature would probably make the code uglier.

As such, I think the "why?" above is what really matters here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not feel competent enough to answer. I've kept implementation in the place where it existed so far. I see no clear criteria why some .cpp files are in sycl/source and other in sycl/source/detail

@aelovikov-intel , do you want us to work on this further in this PR or can we merge without going deep into this? If we can merge, do you have permissions to do so or shall I ask someone else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, let's change this new overload to accept device_impl & and context_impl &. You'd need to add another overload to helpers at

// We're under sycl/source and these won't be exported but it's way more
// convenient to be able to reference them without extra `detail::`.
inline auto get_ur_handles(sycl::detail::context_impl &Ctx) {
ur_context_handle_t urCtx = Ctx.getHandleRef();
return std::tuple{urCtx, &Ctx.getAdapter()};
}
inline auto get_ur_handles(const sycl::context &syclContext) {
return get_ur_handles(*sycl::detail::getSyclObjImpl(syclContext));
}
inline auto get_ur_handles(const sycl::device &syclDevice,
const sycl::context &syclContext) {
auto [urCtx, Adapter] = get_ur_handles(syclContext);
ur_device_handle_t urDevice =
sycl::detail::getSyclObjImpl(syclDevice)->getHandleRef();
return std::tuple{urDevice, urCtx, Adapter};
}
inline auto get_ur_handles(const sycl::device &syclDevice) {
auto &implDevice = *sycl::detail::getSyclObjImpl(syclDevice);
ur_device_handle_t urDevice = implDevice.getHandleRef();
return std::tuple{urDevice, &implDevice.getAdapter()};
}
, but that would be trivial.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. I've applied. Please check the last commit if this is what you wanted.

@lslusarczyk
Copy link
Contributor Author

@intel/llvm-gatekeepers , could you please merge? There are all approvals and the only one failed job is validate_email, which is due to faulty CI change from yesterday (I've checked with @uditagarwal97 - author of the checker change that there is no problem with my email). Please merge.

@uditagarwal97 uditagarwal97 merged commit f5233fa into intel:sycl Jul 17, 2025
46 of 53 checks passed
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.