1 | // RUN: %libomptarget-compile-run-and-check-generic |
---|---|
2 | |
3 | #include <omp.h> |
4 | #include <stdio.h> |
5 | #include <assert.h> |
6 | |
7 | int main() { |
8 | const int N = 64; |
9 | |
10 | int *device_ptr = |
11 | omp_alloc(N * sizeof(int), llvm_omp_target_device_mem_alloc); |
12 | |
13 | #pragma omp target teams distribute parallel for is_device_ptr(device_ptr) |
14 | for (int i = 0; i < N; ++i) { |
15 | device_ptr[i] = 1; |
16 | } |
17 | |
18 | int sum = 0; |
19 | #pragma omp target parallel for reduction(+ : sum) is_device_ptr(device_ptr) |
20 | for (int i = 0; i < N; ++i) |
21 | sum += device_ptr[i]; |
22 | |
23 | // CHECK: PASS |
24 | if (sum == N) |
25 | printf(format: "PASS\n"); |
26 | |
27 | omp_free(device_ptr, llvm_omp_target_device_mem_alloc); |
28 | |
29 | // Make sure this interface works. |
30 | void *ptr = omp_alloc(0, llvm_omp_target_device_mem_alloc); |
31 | assert(!ptr && "Ptr not (nullptr)"); |
32 | omp_free(ptr, llvm_omp_target_device_mem_alloc); |
33 | } |
34 |