Skip to content

Commit 90f2ab4

Browse files
committed
libgomp.c++/target-std__multimap-concurrent.C: Fix USM memory freeing
Fix the unified-shared memory test, libgomp.c++/target-std__multimap-concurrent-usm.C added in commit r16-1010-g83ca283853f195 libgomp: Add testcases for concurrent access to standard C++ containers on offload targets, a number of USM variants This tests includes the actual code of target-std__multimap-concurrent.C. The issue is that multimap.insert allocates memory – which is freed by the destructor. However, if the memory is allocated on a device ('insert'), it also needs to be freed there ('clear') as in general freeing device-allocated memory is not possible on the host. libgomp/ChangeLog: * testsuite/libgomp.c++/target-std__multimap-concurrent.C: Fix memory freeing of device allocated memory with USM.
1 parent 4983e97 commit 90f2ab4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

libgomp/testsuite/libgomp.c++/target-std__multimap-concurrent.C

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <stdlib.h>
55
#include <time.h>
66
#include <map>
7+
#include <omp.h>
78

89
// Make sure that KEY_MAX is less than N to ensure some duplicate keys.
910
#define N 3000
@@ -53,6 +54,16 @@ int main (void)
5354
for (auto it = range.first; it != range.second; ++it)
5455
sum += (long long) it->first * it->second;
5556
}
57+
#ifdef MEM_SHARED
58+
/* Even with USM, memory allocated on the device (with _map.insert)
59+
must be freed on the device. */
60+
if (omp_get_default_device () != omp_initial_device
61+
&& omp_get_default_device () != omp_get_num_devices ())
62+
{
63+
#pragma omp target
64+
_map.clear ();
65+
}
66+
#endif
5667

5768
#ifndef MEM_SHARED
5869
#pragma omp target

0 commit comments

Comments
 (0)