Files
clang-p2996/openmp/libomptarget/test/api/omp_device_managed_memory.c
Joseph Huber 5216a9bfb0 [Libmoptarget] Enable the shared allocator for AMDGPU
Currently, the AMDGPU plugin did not support the `TARGET_ALLOC_SHARED`
allocation kind. We used the fine-grained memory allocator for the
"host" alloc when this is most likely not what is intended. Fine-grained
memory can be accessed by all agents, so it should be considered shared.
This patch removes the use of fine-grained memory for the host
allocator. A later patch will add support for this via the
`hsa_amd_memory_lock` method.

Reviewed By: kevinsala

Differential Revision: https://reviews.llvm.org/D143771
2023-02-20 08:44:08 -06:00

30 lines
695 B
C

// RUN: %libomptarget-compile-run-and-check-generic
#include <omp.h>
#include <stdio.h>
void *llvm_omp_target_alloc_shared(size_t, int);
void llvm_omp_target_free_shared(void *, int);
int main() {
const int N = 64;
const int device = omp_get_default_device();
int *shared_ptr = llvm_omp_target_alloc_shared(N * sizeof(int), device);
#pragma omp target teams distribute parallel for device(device) \
is_device_ptr(shared_ptr)
for (int i = 0; i < N; ++i) {
shared_ptr[i] = 1;
}
int sum = 0;
for (int i = 0; i < N; ++i)
sum += shared_ptr[i];
llvm_omp_target_free_shared(shared_ptr, device);
// CHECK: PASS
if (sum == N)
printf("PASS\n");
}