-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Add tgt_target_kernel_async and helper #212862
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
Draft
ZuseZ4
wants to merge
1
commit into
llvm:main
Choose a base branch
from
ZuseZ4:async-offload-kernel-launch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−1
Draft
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -75,6 +75,125 @@ bool checkDevice(int64_t &DeviceID, ident_t *Loc) { | |
| return false; | ||
| } | ||
|
|
||
| struct __tgt_async_info_handle { | ||
| int64_t DeviceId; | ||
| AsyncInfoTy AsyncInfo; | ||
|
|
||
| __tgt_async_info_handle(int64_t DeviceId, DeviceTy &Device) | ||
| : DeviceId(DeviceId), AsyncInfo(Device) {} | ||
| }; | ||
|
|
||
| EXTERN __tgt_async_info_handle * | ||
| __tgt_async_info_create(int64_t DeviceId) { | ||
| assert(PM && "Runtime not initialized"); | ||
|
|
||
| if (checkDevice(DeviceId, nullptr)) | ||
| return nullptr; | ||
|
|
||
| auto DeviceOrErr = PM->getDevice(DeviceId); | ||
| if (!DeviceOrErr) | ||
| return nullptr; | ||
|
|
||
| return new __tgt_async_info_handle(DeviceId, *DeviceOrErr); | ||
| } | ||
|
|
||
| EXTERN int __tgt_async_info_synchronize( | ||
| __tgt_async_info_handle *Handle) { | ||
| if (!Handle) | ||
| return OFFLOAD_SUCCESS; | ||
|
|
||
| return Handle->AsyncInfo.synchronize(); | ||
| } | ||
|
|
||
| EXTERN void __tgt_async_info_destroy( | ||
| __tgt_async_info_handle *Handle) { | ||
| if (!Handle) | ||
| return; | ||
|
|
||
| Handle->AsyncInfo.synchronize(); | ||
| delete Handle; | ||
|
Member
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. Handle = nullptr? |
||
| } | ||
|
|
||
| template <typename TargetAsyncInfoTy> | ||
| static inline int | ||
| targetKernel(ident_t *Loc, int64_t DeviceId, int32_t NumTeams, | ||
| int32_t ThreadLimit, void *HostPtr, KernelArgsTy *KernelArgs, | ||
| AsyncInfoTy *ExternalAsyncInfo = nullptr) { | ||
| assert(PM && "Runtime not initialized"); | ||
| static_assert(std::is_convertible_v<TargetAsyncInfoTy &, AsyncInfoTy &>, | ||
| "Target AsyncInfoTy must be convertible to AsyncInfoTy."); | ||
|
|
||
| if (checkDevice(DeviceId, Loc)) | ||
| return OMP_TGT_FAIL; | ||
|
|
||
| if (KernelArgs->Version > OMP_KERNEL_ARG_VERSION) | ||
| FATAL_MESSAGE(DeviceId, "Unsupported kernel argument version %u", | ||
| KernelArgs->Version); | ||
|
|
||
| KernelArgs = upgradeKernelArgs(KernelArgs, NumTeams, ThreadLimit); | ||
|
|
||
| auto DeviceOrErr = PM->getDevice(DeviceId); | ||
| if (!DeviceOrErr) | ||
| FATAL_MESSAGE(DeviceId, "%s", | ||
| toString(DeviceOrErr.takeError()).c_str()); | ||
|
|
||
| std::optional<TargetAsyncInfoTy> OwnedAsyncInfo; | ||
|
|
||
| if (!ExternalAsyncInfo) { | ||
| OwnedAsyncInfo.emplace(*DeviceOrErr); | ||
| ExternalAsyncInfo = &*OwnedAsyncInfo; | ||
| } | ||
|
|
||
| AsyncInfoTy &AsyncInfo = *ExternalAsyncInfo; | ||
|
|
||
| OMPT_IF_BUILT(InterfaceRAII TargetRAII( | ||
| RegionInterface.getCallbacks<ompt_target>(), DeviceId, | ||
| /*CodePtr=*/HostPtr)); | ||
|
|
||
| int Rc = target(Loc, *DeviceOrErr, HostPtr, *KernelArgs, AsyncInfo); | ||
|
|
||
| if (!OwnedAsyncInfo) { | ||
| handleTargetOutcome(Rc == OFFLOAD_SUCCESS, Loc); | ||
| return Rc; | ||
| } | ||
|
|
||
| { | ||
| TIMESCOPE_WITH_DETAILS_AND_IDENT("Runtime: synchronize", "", Loc); | ||
| if (Rc == OFFLOAD_SUCCESS) | ||
| Rc = AsyncInfo.synchronize(); | ||
| } | ||
|
|
||
| handleTargetOutcome(Rc == OFFLOAD_SUCCESS, Loc); | ||
| return Rc; | ||
| } | ||
|
Member
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. This function looks copied, can we reuse the original instead? |
||
|
|
||
| EXTERN int __tgt_target_kernel_async( | ||
| ident_t *Loc, int64_t DeviceId, int32_t NumTeams, int32_t ThreadLimit, | ||
| void *HostPtr, KernelArgsTy *KernelArgs, | ||
| __tgt_async_info_handle *Handle) { | ||
| OMPT_IF_BUILT(ReturnAddressSetterRAII RA(__builtin_return_address(0))); | ||
|
|
||
| if (!Handle || !KernelArgs) { | ||
| handleTargetOutcome(false, Loc); | ||
| return OMP_TGT_FAIL; | ||
| } | ||
|
|
||
| int64_t ResolvedDeviceId = DeviceId; | ||
|
|
||
| if (checkDevice(ResolvedDeviceId, Loc)) | ||
| return OMP_TGT_FAIL; | ||
|
|
||
| if (ResolvedDeviceId != Handle->DeviceId) { | ||
| handleTargetOutcome(false, Loc); | ||
| return OMP_TGT_FAIL; | ||
| } | ||
|
|
||
| return targetKernel<AsyncInfoTy>( | ||
| Loc, ResolvedDeviceId, NumTeams, ThreadLimit, HostPtr, KernelArgs, | ||
| &Handle->AsyncInfo); | ||
| } | ||
|
|
||
|
|
||
| //////////////////////////////////////////////////////////////////////////////// | ||
| /// adds requires flags | ||
| EXTERN void __tgt_register_requires(int64_t Flags) { | ||
|
|
||
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.
An AsyncInfoTy has the device ID and you probably don't need another type to wrap it at all.