-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL][USM] Enable per-context USM behavior. Use PI interfaces and avoid directly calling CL inside SYCL RT. #517
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
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b00e08a
Rewrite USM to go through PI instead of straight to CL
jbrodman 21b59c1
Fix findplatforms issue due to CL weirdness for return types. Add mu…
jbrodman e545d17
Update PI interface use and fix spurious includes
jbrodman 5bc1a07
Requested edits.
jbrodman 6b01e99
Missed a style change.
jbrodman 7bb8c11
Style edits. Pointers chanted to references. Tests consolidated.
jbrodman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
//==-------------- usm_dispatch.hpp - SYCL USM Dispatch --------*- C++ -*---==// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
// ===--------------------------------------------------------------------=== // | ||
#pragma once | ||
|
||
#include <CL/sycl/detail/clusm.hpp> | ||
|
||
#include <memory> | ||
|
||
namespace cl { | ||
namespace sycl { | ||
namespace detail { | ||
namespace usm { | ||
|
||
class USMDispatcher { | ||
public: | ||
USMDispatcher(cl_platform_id Platform); | ||
|
||
void *hostMemAlloc(pi_context Context, cl_mem_properties_intel *Properties, | ||
size_t Size, pi_uint32 Alignment, pi_result *ErrcodeRet); | ||
void *deviceMemAlloc(pi_context Context, pi_device Device, | ||
cl_mem_properties_intel *Properties, size_t Size, | ||
pi_uint32 Alignment, pi_result *ErrcodeRet); | ||
void *sharedMemAlloc(pi_context Context, pi_device Device, | ||
cl_mem_properties_intel *Properties, size_t Size, | ||
pi_uint32 Alignment, pi_result *ErrcodeRet); | ||
pi_result memFree(pi_context Context, void *Ptr); | ||
pi_result setKernelArgMemPointer(pi_kernel Kernel, pi_uint32 ArgIndex, | ||
const void *ArgValue); | ||
void setKernelIndirectAccess(pi_kernel Kernel, pi_queue Queue); | ||
pi_result enqueueMemset(pi_queue Queue, void *Ptr, pi_int32 Value, | ||
size_t Count, pi_uint32 NumEventsInWaitList, | ||
const pi_event *EventWaitList, pi_event *Event); | ||
pi_result enqueueMemcpy(pi_queue Queue, pi_bool Blocking, void *DestPtr, | ||
const void *SrcPtr, size_t Size, | ||
pi_uint32 NumEventsInWaitList, | ||
const pi_event *EventWaitList, pi_event *Event); | ||
pi_result enqueueMigrateMem(pi_queue Queue, const void *Ptr, size_t Size, | ||
cl_mem_migration_flags Flags, | ||
pi_uint32 NumEventsInWaitList, | ||
const pi_event *EventWaitList, pi_event *Event); | ||
pi_result enqueueMemAdvise(pi_queue Queue, void *Ptr, size_t Size, | ||
cl_mem_advice_intel Advice, | ||
pi_uint32 NumEventsInWaitList, | ||
const pi_event *EventWaitList, pi_event *Event); | ||
pi_result getMemAllocInfo(pi_context Context, const void *Ptr, | ||
cl_mem_info_intel ParamName, size_t ParamValueSize, | ||
void *ParamValue, size_t *ParamValueSizeRet); | ||
|
||
private: | ||
bool mEmulated = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably instead of having this var you can check if mEmulator is nullptr or not. |
||
std::unique_ptr<CLUSM> mEmulator; | ||
|
||
clHostMemAllocINTEL_fn pfn_clHostMemAllocINTEL = nullptr; | ||
clDeviceMemAllocINTEL_fn pfn_clDeviceMemAllocINTEL = nullptr; | ||
clSharedMemAllocINTEL_fn pfn_clSharedMemAllocINTEL = nullptr; | ||
clMemFreeINTEL_fn pfn_clMemFreeINTEL = nullptr; | ||
clGetMemAllocInfoINTEL_fn pfn_clGetMemAllocInfoINTEL = nullptr; | ||
clSetKernelArgMemPointerINTEL_fn pfn_clSetKernelArgMemPointerINTEL = nullptr; | ||
clEnqueueMemsetINTEL_fn pfn_clEnqueueMemsetINTEL = nullptr; | ||
clEnqueueMemcpyINTEL_fn pfn_clEnqueueMemcpyINTEL = nullptr; | ||
clEnqueueMigrateMemINTEL_fn pfn_clEnqueueMigrateMemINTEL = nullptr; | ||
clEnqueueMemAdviseINTEL_fn pfn_clEnqueueMemAdviseINTEL = nullptr; | ||
}; | ||
|
||
} // namespace usm | ||
} // namespace detail | ||
} // namespace sycl | ||
} // namespace cl |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you going to move these functions to pi.hpp/pi.cpp ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I think it's better to keep them here as we need some state (the CLUSM object). In some sense the Dispatcher is separate piece of PI. It's easy to wire new backends up here.