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

Open
wants to merge 2 commits into
base: sycl
Choose a base branch
from

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
asyncAllocWorksWithSize(131);
asyncAllocWorksWithSize(10071);
asyncAllocWorksWithSize(1007177);
// asyncAllocWorksWithSize(191439360); // BUG
Copy link
Contributor

@pbalcer pbalcer Jul 11, 2025

Choose a reason for hiding this comment

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

You should uncomment this and add an expected failure for L0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

uncommented, bug is fixed, test passes

@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
Comment on lines +27 to +28
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.

This seems to be an ABI-breaking change, we can't just do it like that.

Copy link
Contributor Author

@lslusarczyk lslusarczyk Jul 14, 2025

Choose a reason for hiding this comment

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

Thank you for pointing it out. How shall I make this change? I guess there is some way of changing ABI.
I see: sycl/doc/developer/ABIPolicyGuide.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This method is part of an experimental extension https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/experimental/sycl_ext_oneapi_virtual_mem.asciidoc Acording to https://github.com/intel/llvm/blob/sycl/sycl/doc/developer/ABIPolicyGuide.md Features clearly marked as experimental are considered as an exception to this guideline.

I understand although ABI change is possible I should get consensus on API change with virtual_mem extension owners. @steffenlarsen , @aelovikov-intel , @aarongreig - you are code contributors for virtual mem, should I discuss it with you, some of you, some other people too? I'd like to start email thread with interested people about this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think in this case it would be as simple as using two overloads instead of default value for the allocationSize. Was previous behavior the same as = 1 case of the new impl?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. Previous behavior is the same as new one with =1.
Ok. I'm adding an additional overload. Thank you for suggestion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Please check if the signature looks OK. If so I'll update extension documentation.

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

@igchor igchor left a comment

Choose a reason for hiding this comment

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

UR and L0 adapter changes LGTM

@@ -28,6 +28,9 @@ set(UR_BUILD_TESTS "${SYCL_UR_BUILD_TESTS}" CACHE BOOL "" FORCE)
# UR tests require the examples to be built
set(UR_BUILD_EXAMPLES "${SYCL_UR_BUILD_TESTS}" CACHE BOOL "" FORCE)

option(SYCL_UR_FORMAT_CPP_STYLE "Format code style of UR C++ sources" OFF)
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this? Can't we just pass UR_FORMAT_CPP_STYLE when configuring SYCL?

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