Files
clang-p2996/openmp/libomptarget/test/api/omp_host_pinned_memory.c
Joseph Huber 5d560b6966 [Libomptarget] Implement the host memory allocator with fine grained memory
This patch should enable the "Host" allocation using fine-grained
memory. As far as I understand, this is HSA managed memory that is
availible to the host, but can be accessed by the device as well.
The original patch that introduced these extensions just stipulated that
it's "non-migratable" memory, which is most likely true because it's
managed by the host but accessible by the device. This should work
sufficiently well for what we expect the "host" allocation to do.

Depends on D143771

Reviewed By: kevinsala

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

34 lines
807 B
C

// RUN: %libomptarget-compile-run-and-check-generic
#include <omp.h>
#include <stdio.h>
// Allocate pinned memory on the host
void *llvm_omp_target_alloc_host(size_t, int);
void llvm_omp_target_free_host(void *, int);
int main() {
const int N = 64;
const int device = omp_get_default_device();
const int host = omp_get_initial_device();
int *hst_ptr = llvm_omp_target_alloc_host(N * sizeof(int), device);
for (int i = 0; i < N; ++i)
hst_ptr[i] = 2;
#pragma omp target teams distribute parallel for device(device) \
map(tofrom : hst_ptr[0 : N])
for (int i = 0; i < N; ++i)
hst_ptr[i] -= 1;
int sum = 0;
for (int i = 0; i < N; ++i)
sum += hst_ptr[i];
llvm_omp_target_free_host(hst_ptr, device);
// CHECK: PASS
if (sum == N)
printf("PASS\n");
}