Skip to content

Commit e13a8db

Browse files
authored
Merge pull request #780 from SOLLVE/new_tests_usm
New tests usm (first 5 from PR 632)
2 parents 413a193 + d7b4023 commit e13a8db

5 files changed

Lines changed: 404 additions & 0 deletions
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
!===--- test_requires_unified_shared_memory_allocatable.F90 ------------------------------===//
2+
!
3+
! OpenMP API Version 5.0 Nov 2018
4+
!
5+
! This test checks for unified shared memory support of an allocatable array.
6+
!
7+
!===------------------------------------------------------------------------------===//
8+
9+
#define OMPVV_MODULE_REQUIRES_LINE !$omp requires unified_shared_memory
10+
#include "ompvv.F90"
11+
12+
#define N 1024
13+
14+
PROGRAM test_requires_unified_shared_memory_allocatable
15+
USE iso_fortran_env
16+
USE ompvv_lib
17+
USE omp_lib
18+
implicit none
19+
20+
!$omp requires unified_shared_memory
21+
22+
OMPVV_TEST_OFFLOADING
23+
OMPVV_TEST_VERBOSE(unified_shared_memory_allocatable() .NE. 0)
24+
OMPVV_REPORT_AND_RETURN()
25+
26+
CONTAINS
27+
INTEGER FUNCTION unified_shared_memory_allocatable()
28+
INTEGER:: errors, i
29+
INTEGER, ALLOCATABLE:: anArray(:)
30+
INTEGER, ALLOCATABLE:: anArrayCopy(:)
31+
32+
OMPVV_INFOMSG("Unified shared memory testing - Array on allocatable")
33+
34+
errors = 0
35+
36+
ALLOCATE(anArray(N), anArrayCopy(N))
37+
38+
OMPVV_ERROR_IF(.NOT. ALLOCATED(anArray), "Memory was not properly allocated")
39+
OMPVV_ERROR_IF(.NOT. ALLOCATED(anArrayCopy), "Memory was not properly allocated")
40+
41+
DO i = 1, N
42+
anArray(i) = i
43+
anArrayCopy(i) = 0
44+
END DO
45+
46+
! Modify in the device
47+
!$omp target
48+
DO i = 1, N
49+
anArray(i) = anArray(i) + 10
50+
END DO
51+
!$omp end target
52+
53+
! Modify again on the host
54+
DO i = 1, N
55+
anArray(i) = anArray(i) + 10
56+
END DO
57+
58+
! Get the value the device is seeing
59+
!$omp target
60+
DO i = 1, N
61+
anArrayCopy(i) = anArray(i)
62+
END DO
63+
!$omp end target
64+
65+
DO i = 1, N
66+
OMPVV_TEST_AND_SET_VERBOSE(errors, anArray(i) .NE. (i + 20))
67+
OMPVV_TEST_AND_SET_VERBOSE(errors, anArrayCopy(i) .NE. (i + 20))
68+
IF (errors .NE. 0) THEN
69+
exit
70+
END IF
71+
END DO
72+
73+
DEALLOCATE(anArray, anArrayCopy)
74+
unified_shared_memory_allocatable = errors
75+
END FUNCTION unified_shared_memory_allocatable
76+
END PROGRAM test_requires_unified_shared_memory_allocatable
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
!===--- test_requires_unified_shared_memory_allocatable_map.F90 --------------------------===//
2+
!
3+
! OpenMP API Version 5.0 Nov 2018
4+
!
5+
! This test checks for unified shared memory of an array that is allocated
6+
! using allocatable and that is accessed from host and device with the same pointer.
7+
!
8+
! The mapping of a pointer under shared memory should allow for the pointer to
9+
! have the same value as in the host.
10+
!
11+
!===------------------------------------------------------------------------------===//
12+
13+
#define OMPVV_MODULE_REQUIRES_LINE !$omp requires unified_shared_memory
14+
#include "ompvv.F90"
15+
16+
#define N 1024
17+
18+
PROGRAM test_requires_unified_shared_memory_allocatable_map
19+
USE iso_fortran_env
20+
USE ompvv_lib
21+
USE omp_lib
22+
implicit none
23+
LOGICAL:: isOffloading
24+
25+
!$omp requires unified_shared_memory
26+
27+
OMPVV_TEST_AND_SET_OFFLOADING(isOffloading)
28+
29+
OMPVV_WARNING_IF(.NOT. isOffloading, "With no offloading, unified shared memory is guaranteed due to host execution")
30+
31+
OMPVV_TEST_VERBOSE(unified_shared_memory_allocatable_map() .NE. 0)
32+
33+
OMPVV_REPORT_AND_RETURN()
34+
35+
CONTAINS
36+
INTEGER FUNCTION unified_shared_memory_allocatable_map()
37+
INTEGER:: errors, i
38+
INTEGER, ALLOCATABLE:: anArray(:)
39+
INTEGER:: ERR
40+
41+
OMPVV_INFOMSG("Unified shared memory testing - Array on allocatable")
42+
43+
errors = 0
44+
45+
ALLOCATE(anArray(N), STAT=ERR)
46+
47+
IF( ERR /= 0 ) THEN
48+
OMPVV_ERROR("Memory was not properly allocated")
49+
OMPVV_RETURN(ERR)
50+
END IF
51+
52+
DO i = 1, N
53+
anArray(i) = i
54+
END DO
55+
56+
! Modify in the device
57+
!$omp target map(anArray)
58+
DO i = 1, N
59+
anArray(i) = anArray(i) + 10
60+
END DO
61+
!$omp end target
62+
63+
DO i = 1, N
64+
OMPVV_TEST_AND_SET_VERBOSE(errors, anArray(i) .NE. (i + 10))
65+
IF (errors .NE. 0) THEN
66+
exit
67+
END IF
68+
END DO
69+
70+
DEALLOCATE(anArray)
71+
unified_shared_memory_allocatable_map = errors
72+
END FUNCTION unified_shared_memory_allocatable_map
73+
END PROGRAM test_requires_unified_shared_memory_allocatable_map
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//===---test_requires_unified_shared_memory_malloc.c --------------------------===//
2+
//
3+
// OpenMP API Version 5.0 Nov 2018
4+
//
5+
// This test checks for unified shared memory of an array that is allocated using
6+
// malloc on host is accessed from host and device with the same pointer.
7+
//
8+
// It uses the default mapping of pointers to access the array.
9+
//
10+
////===----------------------------------------------------------------------===//
11+
#include <omp.h>
12+
#include <stdio.h>
13+
#include <stdlib.h>
14+
#include "ompvv.h"
15+
16+
#define N 1024
17+
18+
#pragma omp requires unified_shared_memory
19+
20+
int unified_shared_memory_malloc() {
21+
OMPVV_INFOMSG("Unified shared memory testing - Malloced Array");
22+
int errors = 0;
23+
24+
int *anArray;
25+
int *anArrayCopy;
26+
27+
anArray = (int*)malloc(sizeof(int)*N);
28+
anArrayCopy = (int*)malloc(sizeof(int)*N);
29+
30+
if( anArray == NULL ) {
31+
OMPVV_ERROR("Memory for anArray was not allocated");
32+
OMPVV_RETURN(1);
33+
}
34+
35+
if( anArrayCopy == NULL ) {
36+
OMPVV_ERROR("Memory for anArrayCopy was not allocated");
37+
OMPVV_RETURN(1);
38+
}
39+
40+
for (int i = 0; i < N; i++) {
41+
anArray[i] = i;
42+
anArrayCopy[i] = 0;
43+
}
44+
// Modify in the device
45+
#pragma omp target
46+
{
47+
for (int i = 0; i < N; i++) {
48+
anArray[i] += 10;
49+
}
50+
}
51+
// Modify again on the host
52+
for (int i = 0; i < N; i++) {
53+
anArray[i] += 10;
54+
}
55+
56+
// Get the value the device is seeing
57+
#pragma omp target
58+
{
59+
for (int i = 0; i < N; i++) {
60+
anArrayCopy[i] = anArray[i];
61+
}
62+
}
63+
64+
for (int i = 0; i < N; i++) {
65+
OMPVV_TEST_AND_SET_VERBOSE(errors, anArray[i] != i + 20);
66+
OMPVV_TEST_AND_SET_VERBOSE(errors, anArrayCopy[i] != i + 20);
67+
if (errors) break;
68+
}
69+
70+
free(anArray);
71+
free(anArrayCopy);
72+
return errors;
73+
}
74+
75+
int main() {
76+
int isOffloading;
77+
OMPVV_TEST_AND_SET_OFFLOADING(isOffloading);
78+
OMPVV_WARNING_IF(!isOffloading, "With no offloading, unified shared memory is guaranteed due to host execution");
79+
int errors = 0;
80+
81+
OMPVV_TEST_AND_SET_VERBOSE(errors, unified_shared_memory_malloc());
82+
83+
OMPVV_REPORT_AND_RETURN(errors);
84+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//===---test_requires_unified_shared_memory_malloc_is_device_ptr.c -----------===//
2+
//
3+
// OpenMP API Version 5.0 Nov 2018
4+
//
5+
// This test Checks for unified shared memory of an array that is allocated using
6+
// malloc and that is accessed from host and device with the same pointer
7+
//
8+
// To guarantee the use of the device pointer, we use the is_device_ptr clause
9+
//
10+
////===----------------------------------------------------------------------===//
11+
#include <omp.h>
12+
#include <stdio.h>
13+
#include <stdlib.h>
14+
#include "ompvv.h"
15+
16+
#define N 1024
17+
18+
#pragma omp requires unified_shared_memory
19+
20+
int unified_shared_memory_malloc() {
21+
OMPVV_INFOMSG("Unified shared memory testing - Array on malloc");
22+
int errors = 0;
23+
24+
int *anArray;
25+
int *anArrayCopy;
26+
27+
anArray = (int*)malloc(sizeof(int)*N);
28+
anArrayCopy = (int*)malloc(sizeof(int)*N);
29+
30+
if( anArray == NULL ) {
31+
OMPVV_ERROR("Memory for anArray was not allocated");
32+
OMPVV_RETURN(1);
33+
}
34+
35+
if( anArrayCopy == NULL ) {
36+
OMPVV_ERROR("Memory for anArrayCopy was not allocated");
37+
OMPVV_RETURN(1);
38+
}
39+
40+
for (int i = 0; i < N; i++) {
41+
anArray[i] = i;
42+
anArrayCopy[i] = 0;
43+
}
44+
// Modify in the device
45+
#pragma omp target is_device_ptr(anArray)
46+
{
47+
for (int i = 0; i < N; i++) {
48+
anArray[i] += 10;
49+
}
50+
}
51+
// Modify again on the host
52+
for (int i = 0; i < N; i++) {
53+
anArray[i] += 10;
54+
}
55+
56+
// Get the value the device is seeing
57+
#pragma omp target is_device_ptr(anArray)
58+
{
59+
for (int i = 0; i < N; i++) {
60+
anArrayCopy[i] = anArray[i];
61+
}
62+
}
63+
64+
for (int i = 0; i < N; i++) {
65+
OMPVV_TEST_AND_SET_VERBOSE(errors, anArray[i] != i + 20);
66+
OMPVV_TEST_AND_SET_VERBOSE(errors, anArrayCopy[i] != i + 20);
67+
if (errors) break;
68+
}
69+
70+
free(anArray);
71+
free(anArrayCopy);
72+
return errors;
73+
}
74+
int main() {
75+
int isOffloading;
76+
OMPVV_TEST_AND_SET_OFFLOADING(isOffloading);
77+
OMPVV_WARNING_IF(!isOffloading, "With no offloading, unified shared memory is guaranteed due to host execution");
78+
int errors = 0;
79+
80+
OMPVV_TEST_AND_SET_VERBOSE(errors, unified_shared_memory_malloc());
81+
82+
OMPVV_REPORT_AND_RETURN(errors);
83+
}
84+

0 commit comments

Comments
 (0)