-
Notifications
You must be signed in to change notification settings - Fork 15.3k
Reland: [OpenMP] Implement omp_get_uid_from_device() / omp_get_device_from_uid() #168554
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
ro-i
wants to merge
6
commits into
main
Choose a base branch
from
users/ro-i/openmp-device-uid
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.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d070b75
[OpenMP] Implement omp_get_uid_from_device() / omp_get_device_from_uid()
ro-i 31b9b06
fix fortran declarations
ro-i 2480ae5
fix omp_lib.h.var
ro-i b1c5e6e
fix omp_lib.F90.var and add F90 test
ro-i 1c46492
push forgotten test
ro-i bde0665
remove Fortran support for this patch
ro-i 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,13 @@ | |
|
|
||
| extern "C" { | ||
|
|
||
| /// Definitions | ||
| ///{ | ||
|
|
||
| #define omp_invalid_device -2 | ||
|
|
||
| ///} | ||
|
|
||
| /// Type declarations | ||
| ///{ | ||
|
|
||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| // RUN: %libomptarget-compile-run-and-check-generic | ||
|
|
||
| #include <omp.h> | ||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| int test_omp_device_uid(int device_num) { | ||
| const char *device_uid = omp_get_uid_from_device(device_num); | ||
| if (device_uid == NULL) { | ||
| printf("FAIL for device %d: omp_get_uid_from_device returned NULL\n", | ||
| device_num); | ||
| return 0; | ||
| } | ||
|
|
||
| int device_num_from_uid = omp_get_device_from_uid(device_uid); | ||
| if (device_num_from_uid != device_num) { | ||
| printf( | ||
| "FAIL for device %d: omp_get_device_from_uid returned %d (UID: %s)\n", | ||
| device_num, device_num_from_uid, device_uid); | ||
| return 0; | ||
| } | ||
|
|
||
| if (device_num == omp_get_initial_device()) | ||
| return 1; | ||
|
|
||
| int success = 1; | ||
|
|
||
| // Note that the following code may be executed on the host if the host is the | ||
| // device | ||
| #pragma omp target map(tofrom : success) device(device_num) | ||
| { | ||
| int device_num = omp_get_device_num(); | ||
|
|
||
| // omp_get_uid_from_device() in the device runtime is a dummy function | ||
| // returning NULL | ||
| const char *device_uid = omp_get_uid_from_device(device_num); | ||
|
|
||
| // omp_get_device_from_uid() in the device runtime is a dummy function | ||
| // returning omp_invalid_device. | ||
| int device_num_from_uid = omp_get_device_from_uid(device_uid); | ||
|
|
||
| // Depending on whether we're executing on the device or the host, we either | ||
| // got NULL as the device UID or the correct device UID. Consequently, | ||
| // omp_get_device_from_uid() either returned omp_invalid_device or the | ||
| // correct device number (aka omp_get_initial_device()). | ||
| if (device_uid ? device_num_from_uid != device_num | ||
| : device_num_from_uid != omp_invalid_device) { | ||
| printf("FAIL for device %d (target): omp_get_device_from_uid returned %d " | ||
| "(UID: %s)\n", | ||
| device_num, device_num_from_uid, device_uid); | ||
| success = 0; | ||
| } | ||
| } | ||
|
|
||
| return success; | ||
| } | ||
|
|
||
| int main() { | ||
| int num_devices = omp_get_num_devices(); | ||
| int num_failed = 0; | ||
| // (also test initial device aka num_devices) | ||
| for (int i = 0; i < num_devices + 1; i++) { | ||
| if (!test_omp_device_uid(i)) { | ||
| printf("FAIL for device %d\n", i); | ||
| num_failed++; | ||
| } | ||
| } | ||
| if (num_failed) { | ||
| printf("FAIL\n"); | ||
| return 1; | ||
| } | ||
| printf("PASS\n"); | ||
| return 0; | ||
| } | ||
|
|
||
| // CHECK: PASS |
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
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.
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.