Skip to content

Conversation

@mateuszpn
Copy link
Contributor

@mateuszpn mateuszpn commented Oct 28, 2025

This PR implements zero-copy buffers for integrated GPUs.

Signed-off-by: Mateusz P. Nowak <mateusz.p.nowak@intel.com>
Signed-off-by: Mateusz P. Nowak <mateusz.p.nowak@intel.com>
@mateuszpn mateuszpn changed the title [UR][L0v2 adapter] Fix SYCL buffer map implementation [UR][L0v2 adapter] Fix buffers for integrated gpu Nov 4, 2025
@mateuszpn mateuszpn marked this pull request as ready for review November 4, 2025 15:34
@mateuszpn mateuszpn requested review from a team as code owners November 4, 2025 15:34
@mateuszpn mateuszpn requested a review from vinser52 November 4, 2025 15:34
"opencl": ("cpu", "gpu", "fpga"),
"cuda": "gpu",
"level_zero": "gpu",
"level_zero": ("gpu", "0", "1"),
Copy link
Contributor

Choose a reason for hiding this comment

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed for local tests, but may be useful in CI, too, depending on hw config. Allows to point out which gpu should be used for tests (eg. integrated/discrete). Example:
llvm-lit --param "sycl_devices=level_zero_v2:1" - the tests are run on device level_zero:1 with v2 adapter

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After closer look, as some tests appeared as unsupported, additional one-line fix was necessary.
So, if any of reviewers thinks the change does not belong to this PR, I am also OK with that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should be changing the default config. CI and other dev systems where this is used may have a different configuration where :0 and :1 mean e.g., different dGPUs. Or there may not be a second GPU at all.

void *rawPtr;
UR_CALL_THROWS(hContext->getDefaultUSMPool()->allocate(
hContext, nullptr, nullptr, UR_USM_TYPE_HOST, size, &rawPtr));
if (hostPtr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

when can hostPtr be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just checking the argument. Can we be sure it will never be null?

auto ret =
getMemoryAttrs(hContext->getZeHandle(), hostPtr, nullptr, &memProps);

if (ret == UR_RESULT_SUCCESS && memProps.type != ZE_MEMORY_TYPE_UNKNOWN) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why check against ZE_MEMORY_TYPE_UNKNOWN and not something specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I understand specification right, mem type can be known to be USM (host, device or shared) or unknown. The condition checks if mem type is USM.

wait_list_view & /*waitListView*/) {
// TODO: if writeBackPtr is set, we should copy the data back
/* nop */
// No-op: integrated buffers use zero-copy, no synchronization needed
Copy link
Contributor

@pbalcer pbalcer Nov 5, 2025

Choose a reason for hiding this comment

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

what if we go in this path when creating the buffer:
"// Import failed - allocate backing buffer and set up copy-back"
?

If "import failed" is a possible scenario, we should have a test. If it's not, that code path should be removed.

Comment on lines -116 to -119
// TODO: if writeBackPtr is set, we should map to that pointer
// because that's what SYCL expects, SYCL will attempt to call free
// on the resulting pointer leading to double free with the current
// implementation. Investigate the SYCL implementation.
Copy link
Contributor

Choose a reason for hiding this comment

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

was this comment false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, the comment was not false as long as map/unmap functions missed full handling of copy-back path. Last commit addresses the issue.

Signed-off-by: Mateusz P. Nowak <mateusz.p.nowak@intel.com>
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.

2 participants