-
Notifications
You must be signed in to change notification settings - Fork 25
New tests usm (first 5 from PR 632) #780
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
10 commits
Select commit
Hold shift + click to select a range
55ba35a
Adding add test_requires_unified_shared_memory_allocatable.F90
739fd64
Adding add test_requires_unified_shared_memory_allocatable_map.F90
3add76b
adding test_requires_unified_shared_memory_malloc_is_device_ptr.c
de613b9
test_requires_unified_shared_memory_malloc.c
f9807ae
test_requires_unified_shared_memory_malloc_map.c
dbca608
Apply suggestions from code review
seyonglee cac3bb8
Update tests/5.0/requires/test_requires_unified_shared_memory_allocat…
seyonglee 60c80cd
Update test_requires_unified_shared_memory_malloc.c
spophale 1ed2b85
Update test_requires_unified_shared_memory_malloc_is_device_ptr.c
spophale d7b4023
Update test_requires_unified_shared_memory_malloc_map.c
spophale 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
76 changes: 76 additions & 0 deletions
76
tests/5.0/requires/test_requires_unified_shared_memory_allocatable.F90
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 @@ | ||
| !===--- test_requires_unified_shared_memory_allocatable.F90 ------------------------------===// | ||
| ! | ||
| ! OpenMP API Version 5.0 Nov 2018 | ||
| ! | ||
| ! This test checks for unified shared memory support of an allocatable array. | ||
| ! | ||
| !===------------------------------------------------------------------------------===// | ||
|
|
||
| #define OMPVV_MODULE_REQUIRES_LINE !$omp requires unified_shared_memory | ||
| #include "ompvv.F90" | ||
|
|
||
| #define N 1024 | ||
|
|
||
| PROGRAM test_requires_unified_shared_memory_allocatable | ||
| USE iso_fortran_env | ||
| USE ompvv_lib | ||
| USE omp_lib | ||
| implicit none | ||
|
|
||
| !$omp requires unified_shared_memory | ||
|
|
||
| OMPVV_TEST_OFFLOADING | ||
| OMPVV_TEST_VERBOSE(unified_shared_memory_allocatable() .NE. 0) | ||
| OMPVV_REPORT_AND_RETURN() | ||
|
|
||
| CONTAINS | ||
| INTEGER FUNCTION unified_shared_memory_allocatable() | ||
| INTEGER:: errors, i | ||
| INTEGER, ALLOCATABLE:: anArray(:) | ||
| INTEGER, ALLOCATABLE:: anArrayCopy(:) | ||
|
|
||
| OMPVV_INFOMSG("Unified shared memory testing - Array on allocatable") | ||
|
|
||
| errors = 0 | ||
|
|
||
| ALLOCATE(anArray(N), anArrayCopy(N)) | ||
|
|
||
| OMPVV_ERROR_IF(.NOT. ALLOCATED(anArray), "Memory was not properly allocated") | ||
| OMPVV_ERROR_IF(.NOT. ALLOCATED(anArrayCopy), "Memory was not properly allocated") | ||
|
|
||
| DO i = 1, N | ||
| anArray(i) = i | ||
| anArrayCopy(i) = 0 | ||
| END DO | ||
|
|
||
| ! Modify in the device | ||
| !$omp target | ||
| DO i = 1, N | ||
| anArray(i) = anArray(i) + 10 | ||
| END DO | ||
| !$omp end target | ||
|
|
||
| ! Modify again on the host | ||
| DO i = 1, N | ||
| anArray(i) = anArray(i) + 10 | ||
| END DO | ||
|
|
||
| ! Get the value the device is seeing | ||
| !$omp target | ||
| DO i = 1, N | ||
| anArrayCopy(i) = anArray(i) | ||
| END DO | ||
| !$omp end target | ||
|
|
||
| DO i = 1, N | ||
| OMPVV_TEST_AND_SET_VERBOSE(errors, anArray(i) .NE. (i + 20)) | ||
| OMPVV_TEST_AND_SET_VERBOSE(errors, anArrayCopy(i) .NE. (i + 20)) | ||
| IF (errors .NE. 0) THEN | ||
| exit | ||
| END IF | ||
| END DO | ||
|
|
||
| DEALLOCATE(anArray, anArrayCopy) | ||
| unified_shared_memory_allocatable = errors | ||
| END FUNCTION unified_shared_memory_allocatable | ||
| END PROGRAM test_requires_unified_shared_memory_allocatable | ||
73 changes: 73 additions & 0 deletions
73
tests/5.0/requires/test_requires_unified_shared_memory_allocatable_map.F90
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 @@ | ||
| !===--- test_requires_unified_shared_memory_allocatable_map.F90 --------------------------===// | ||
| ! | ||
| ! OpenMP API Version 5.0 Nov 2018 | ||
| ! | ||
| ! This test checks for unified shared memory of an array that is allocated | ||
| ! using allocatable and that is accessed from host and device with the same pointer. | ||
| ! | ||
| ! The mapping of a pointer under shared memory should allow for the pointer to | ||
| ! have the same value as in the host. | ||
| ! | ||
| !===------------------------------------------------------------------------------===// | ||
|
|
||
| #define OMPVV_MODULE_REQUIRES_LINE !$omp requires unified_shared_memory | ||
| #include "ompvv.F90" | ||
|
|
||
| #define N 1024 | ||
|
|
||
| PROGRAM test_requires_unified_shared_memory_allocatable_map | ||
| USE iso_fortran_env | ||
| USE ompvv_lib | ||
| USE omp_lib | ||
| implicit none | ||
| LOGICAL:: isOffloading | ||
|
|
||
| !$omp requires unified_shared_memory | ||
|
|
||
| OMPVV_TEST_AND_SET_OFFLOADING(isOffloading) | ||
|
|
||
| OMPVV_WARNING_IF(.NOT. isOffloading, "With no offloading, unified shared memory is guaranteed due to host execution") | ||
|
|
||
| OMPVV_TEST_VERBOSE(unified_shared_memory_allocatable_map() .NE. 0) | ||
|
|
||
| OMPVV_REPORT_AND_RETURN() | ||
|
|
||
| CONTAINS | ||
| INTEGER FUNCTION unified_shared_memory_allocatable_map() | ||
| INTEGER:: errors, i | ||
| INTEGER, ALLOCATABLE:: anArray(:) | ||
| INTEGER:: ERR | ||
|
|
||
| OMPVV_INFOMSG("Unified shared memory testing - Array on allocatable") | ||
|
|
||
| errors = 0 | ||
|
|
||
| ALLOCATE(anArray(N), STAT=ERR) | ||
|
|
||
| IF( ERR /= 0 ) THEN | ||
| OMPVV_ERROR("Memory was not properly allocated") | ||
| OMPVV_RETURN(ERR) | ||
| END IF | ||
|
|
||
| DO i = 1, N | ||
| anArray(i) = i | ||
| END DO | ||
|
|
||
| ! Modify in the device | ||
| !$omp target map(anArray) | ||
| DO i = 1, N | ||
| anArray(i) = anArray(i) + 10 | ||
| END DO | ||
| !$omp end target | ||
|
|
||
| DO i = 1, N | ||
| OMPVV_TEST_AND_SET_VERBOSE(errors, anArray(i) .NE. (i + 10)) | ||
| IF (errors .NE. 0) THEN | ||
| exit | ||
| END IF | ||
| END DO | ||
|
|
||
| DEALLOCATE(anArray) | ||
| unified_shared_memory_allocatable_map = errors | ||
| END FUNCTION unified_shared_memory_allocatable_map | ||
| END PROGRAM test_requires_unified_shared_memory_allocatable_map |
84 changes: 84 additions & 0 deletions
84
tests/5.0/requires/test_requires_unified_shared_memory_malloc.c
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,84 @@ | ||
| //===---test_requires_unified_shared_memory_malloc.c --------------------------===// | ||
| // | ||
| // OpenMP API Version 5.0 Nov 2018 | ||
| // | ||
| // This test checks for unified shared memory of an array that is allocated using | ||
| // malloc on host is accessed from host and device with the same pointer. | ||
| // | ||
| // It uses the default mapping of pointers to access the array. | ||
| // | ||
| ////===----------------------------------------------------------------------===// | ||
| #include <omp.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include "ompvv.h" | ||
|
|
||
| #define N 1024 | ||
|
|
||
| #pragma omp requires unified_shared_memory | ||
|
|
||
| int unified_shared_memory_malloc() { | ||
| OMPVV_INFOMSG("Unified shared memory testing - Malloced Array"); | ||
| int errors = 0; | ||
|
|
||
| int *anArray; | ||
| int *anArrayCopy; | ||
|
|
||
| anArray = (int*)malloc(sizeof(int)*N); | ||
| anArrayCopy = (int*)malloc(sizeof(int)*N); | ||
|
|
||
spophale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if( anArray == NULL ) { | ||
| OMPVV_ERROR("Memory for anArray was not allocated"); | ||
| OMPVV_RETURN(1); | ||
| } | ||
|
|
||
| if( anArrayCopy == NULL ) { | ||
| OMPVV_ERROR("Memory for anArrayCopy was not allocated"); | ||
| OMPVV_RETURN(1); | ||
| } | ||
|
|
||
| for (int i = 0; i < N; i++) { | ||
| anArray[i] = i; | ||
| anArrayCopy[i] = 0; | ||
| } | ||
| // Modify in the device | ||
| #pragma omp target | ||
| { | ||
| for (int i = 0; i < N; i++) { | ||
| anArray[i] += 10; | ||
| } | ||
| } | ||
| // Modify again on the host | ||
| for (int i = 0; i < N; i++) { | ||
| anArray[i] += 10; | ||
| } | ||
|
|
||
| // Get the value the device is seeing | ||
| #pragma omp target | ||
| { | ||
| for (int i = 0; i < N; i++) { | ||
| anArrayCopy[i] = anArray[i]; | ||
| } | ||
| } | ||
|
|
||
| for (int i = 0; i < N; i++) { | ||
| OMPVV_TEST_AND_SET_VERBOSE(errors, anArray[i] != i + 20); | ||
| OMPVV_TEST_AND_SET_VERBOSE(errors, anArrayCopy[i] != i + 20); | ||
| if (errors) break; | ||
| } | ||
|
|
||
| free(anArray); | ||
| free(anArrayCopy); | ||
| return errors; | ||
| } | ||
|
|
||
| int main() { | ||
| int isOffloading; | ||
| OMPVV_TEST_AND_SET_OFFLOADING(isOffloading); | ||
| OMPVV_WARNING_IF(!isOffloading, "With no offloading, unified shared memory is guaranteed due to host execution"); | ||
| int errors = 0; | ||
|
|
||
| OMPVV_TEST_AND_SET_VERBOSE(errors, unified_shared_memory_malloc()); | ||
|
|
||
| OMPVV_REPORT_AND_RETURN(errors); | ||
| } | ||
84 changes: 84 additions & 0 deletions
84
tests/5.0/requires/test_requires_unified_shared_memory_malloc_is_device_ptr.c
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,84 @@ | ||
| //===---test_requires_unified_shared_memory_malloc_is_device_ptr.c -----------===// | ||
| // | ||
| // OpenMP API Version 5.0 Nov 2018 | ||
| // | ||
| // This test Checks for unified shared memory of an array that is allocated using | ||
| // malloc and that is accessed from host and device with the same pointer | ||
| // | ||
| // To guarantee the use of the device pointer, we use the is_device_ptr clause | ||
| // | ||
| ////===----------------------------------------------------------------------===// | ||
| #include <omp.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include "ompvv.h" | ||
|
|
||
| #define N 1024 | ||
|
|
||
| #pragma omp requires unified_shared_memory | ||
|
|
||
| int unified_shared_memory_malloc() { | ||
| OMPVV_INFOMSG("Unified shared memory testing - Array on malloc"); | ||
| int errors = 0; | ||
|
|
||
| int *anArray; | ||
| int *anArrayCopy; | ||
|
|
||
| anArray = (int*)malloc(sizeof(int)*N); | ||
| anArrayCopy = (int*)malloc(sizeof(int)*N); | ||
|
|
||
| if( anArray == NULL ) { | ||
| OMPVV_ERROR("Memory for anArray was not allocated"); | ||
| OMPVV_RETURN(1); | ||
| } | ||
|
|
||
| if( anArrayCopy == NULL ) { | ||
| OMPVV_ERROR("Memory for anArrayCopy was not allocated"); | ||
| OMPVV_RETURN(1); | ||
| } | ||
|
|
||
| for (int i = 0; i < N; i++) { | ||
| anArray[i] = i; | ||
| anArrayCopy[i] = 0; | ||
| } | ||
| // Modify in the device | ||
| #pragma omp target is_device_ptr(anArray) | ||
| { | ||
| for (int i = 0; i < N; i++) { | ||
| anArray[i] += 10; | ||
| } | ||
| } | ||
| // Modify again on the host | ||
| for (int i = 0; i < N; i++) { | ||
| anArray[i] += 10; | ||
| } | ||
|
|
||
| // Get the value the device is seeing | ||
| #pragma omp target is_device_ptr(anArray) | ||
| { | ||
| for (int i = 0; i < N; i++) { | ||
| anArrayCopy[i] = anArray[i]; | ||
| } | ||
| } | ||
|
|
||
| for (int i = 0; i < N; i++) { | ||
| OMPVV_TEST_AND_SET_VERBOSE(errors, anArray[i] != i + 20); | ||
| OMPVV_TEST_AND_SET_VERBOSE(errors, anArrayCopy[i] != i + 20); | ||
| if (errors) break; | ||
| } | ||
|
|
||
| free(anArray); | ||
| free(anArrayCopy); | ||
| return errors; | ||
| } | ||
| int main() { | ||
| int isOffloading; | ||
| OMPVV_TEST_AND_SET_OFFLOADING(isOffloading); | ||
| OMPVV_WARNING_IF(!isOffloading, "With no offloading, unified shared memory is guaranteed due to host execution"); | ||
| int errors = 0; | ||
|
|
||
| OMPVV_TEST_AND_SET_VERBOSE(errors, unified_shared_memory_malloc()); | ||
|
|
||
| OMPVV_REPORT_AND_RETURN(errors); | ||
| } | ||
|
|
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.
Uh oh!
There was an error while loading. Please reload this page.