File tree Expand file tree Collapse file tree 6 files changed +69
-3
lines changed Expand file tree Collapse file tree 6 files changed +69
-3
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,11 @@ void free(void *Ptr);
39
39
40
40
} // namespace ompx
41
41
42
+ extern " C" {
43
+ [[gnu::weak]] void *malloc (size_t Size);
44
+ [[gnu::weak]] void free (void *Ptr);
45
+ }
46
+
42
47
#pragma omp end declare target
43
48
44
49
#endif
Original file line number Diff line number Diff line change @@ -188,7 +188,7 @@ typedef enum omp_allocator_handle_t {
188
188
omp_cgroup_mem_alloc = 6 ,
189
189
omp_pteam_mem_alloc = 7 ,
190
190
omp_thread_mem_alloc = 8 ,
191
- KMP_ALLOCATOR_MAX_HANDLE = ~(0U )
191
+ KMP_ALLOCATOR_MAX_HANDLE = ~(0LU )
192
192
} omp_allocator_handle_t ;
193
193
194
194
#define __PRAGMA (STR ) _Pragma (#STR)
Original file line number Diff line number Diff line change 9
9
//
10
10
// ===----------------------------------------------------------------------===//
11
11
12
+ #include " Allocator.h"
12
13
#include " Configuration.h"
13
14
#include " Types.h"
14
15
@@ -128,6 +129,33 @@ double omp_get_wtime(void) { return ompx::impl::getWTime(); }
128
129
void *__llvm_omp_indirect_call_lookup (void *HstPtr) {
129
130
return ompx::impl::indirectCallLookup (HstPtr);
130
131
}
132
+
133
+ void *omp_alloc (size_t size, omp_allocator_handle_t allocator) {
134
+ switch (allocator) {
135
+ case omp_default_mem_alloc:
136
+ case omp_large_cap_mem_alloc:
137
+ case omp_const_mem_alloc:
138
+ case omp_high_bw_mem_alloc:
139
+ case omp_low_lat_mem_alloc:
140
+ return malloc (size);
141
+ default :
142
+ return nullptr ;
143
+ }
144
+ }
145
+
146
+ void omp_free (void *ptr, omp_allocator_handle_t allocator) {
147
+ switch (allocator) {
148
+ case omp_default_mem_alloc:
149
+ case omp_large_cap_mem_alloc:
150
+ case omp_const_mem_alloc:
151
+ case omp_high_bw_mem_alloc:
152
+ case omp_low_lat_mem_alloc:
153
+ free (ptr);
154
+ case omp_null_allocator:
155
+ default :
156
+ return ;
157
+ }
158
+ }
131
159
}
132
160
133
161
// /}
Original file line number Diff line number Diff line change @@ -53,12 +53,12 @@ namespace {
53
53
extern " C" {
54
54
#ifdef __AMDGPU__
55
55
56
- [[gnu::weak]] void *malloc (uint64_t Size) { return allocator::alloc (Size); }
56
+ [[gnu::weak]] void *malloc (size_t Size) { return allocator::alloc (Size); }
57
57
[[gnu::weak]] void free (void *Ptr) { allocator::free (Ptr); }
58
58
59
59
#else
60
60
61
- [[gnu::weak, gnu::leaf]] void *malloc (uint64_t Size);
61
+ [[gnu::weak, gnu::leaf]] void *malloc (size_t Size);
62
62
[[gnu::weak, gnu::leaf]] void free (void *Ptr);
63
63
64
64
#endif
Original file line number Diff line number Diff line change
1
+ // RUN: %libomptarget-compile-run-and-check-generic
2
+
3
+ #include <assert.h>
4
+ #include <omp.h>
5
+ #include <stdio.h>
6
+
7
+ int main () {
8
+ #pragma omp target teams num_teams(4)
9
+ #pragma omp parallel
10
+ {
11
+ int * ptr = (int * )omp_alloc (sizeof (int ), omp_default_mem_alloc );
12
+ assert (ptr && "Ptr is (null)!" );
13
+ * ptr = 1 ;
14
+ assert (* ptr == 1 && "Ptr is not 1" );
15
+ omp_free (ptr , omp_default_mem_alloc );
16
+ }
17
+
18
+ #pragma omp target
19
+ {
20
+ assert (!omp_alloc (sizeof (int ), omp_null_allocator ) && "Ptr is not (null)!" );
21
+ }
22
+
23
+ // CHECK: PASS
24
+ printf ("PASS\n" );
25
+ }
Original file line number Diff line number Diff line change @@ -1496,6 +1496,14 @@ clause. Examples for both are given below.
1496
1496
$ clang++ -fopenmp --offload-arch=gfx90a -O3 shared.c
1497
1497
$ env ./shared
1498
1498
1499
+ .. _libomptarget_device_allocator :
1500
+
1501
+ Device Allocation
1502
+ ^^^^^^^^^^^^^^^^^
1503
+
1504
+ The device runtime supports basic runtime allocation via the ``omp_alloc ``
1505
+ function. Currently, this allocates global memory for all default traits. Access
1506
+ modifiers are currently not supported and return a null pointer.
1499
1507
1500
1508
.. _libomptarget_device_debugging :
1501
1509
You can’t perform that action at this time.
0 commit comments