Skip to content

[UR][Offload] Add initial membuffer implementation #18849

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 3 commits into
base: sycl
Choose a base branch
from

Conversation

callumfare
Copy link
Contributor

Add a basic implementation of buffers to the Offload adapter. The design is loosely based on the CUDA and HIP adapters.

For now contexts only support a single device, so the implementation is relatively simple. When multi-device contexts are supported we will need to handle migration of data between devices (or otherwise change this implementation)

@callumfare callumfare requested a review from a team as a code owner June 6, 2025 14:32
#include <OffloadAPI.h>
#include <unordered_map>
#include <ur_api.h>

struct ur_context_handle_t_ : RefCounted {
ur_context_handle_t_(ur_device_handle_t hDevice) : Device{hDevice} {
urDeviceRetain(Device);
// For convenience, store the host device in the context
OffloadHost = Adapter.HostDevice;
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't Adapter globally visible and lives for the lifetime of all adapter handles? Why do we need to keep a copy 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.

Yeah this wasn't necessary, fixed now


// TODO: olMemcpy src should be const
olMemcpy(hQueue->OffloadQueue, DevPtr + offset, hQueue->OffloadDevice,
const_cast<void *>(pSrc), hQueue->Context->OffloadHost, size,
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me a bit uneasy - Could we change olMemcpy to be const void *?

Copy link
Contributor Author

Choose a reason for hiding this comment

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


void *DevPtr = std::get<BufferMem>(hBuffer->Mem).Ptr;

olMemcpy(hQueue->OffloadQueue, pDst, hQueue->Context->OffloadHost,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we not be checking the result of this against OL_SUCCESS?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed now. I wonder if it would be good to have a OL_CHECK(...) macro or similar to hide the logic of checking the error every time.

Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly surprised there isn't one yet. I think it's worth adding, yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool, I can do that in a separate 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.

2 participants