llvm-project
65 строк · 1.6 Кб
1// RUN: %libomptarget-compilexx-generic
2// RUN: %libomptarget-run-generic %fcheck-generic
3
4// REQURIES: gpu
5// UNSUPPORTED: nvidiagpu
6// UNSUPPORTED: amdgpu
7
8#include <cstdio>
9
10#include <omp.h>
11
12extern "C" {
13void *llvm_omp_target_lock_mem(void *ptr, size_t size, int device_num);
14void llvm_omp_target_unlock_mem(void *ptr, int device_num);
15}
16
17int main() {
18int n = 100;
19int *unlocked = new int[n];
20
21for (int i = 0; i < n; i++)
22unlocked[i] = i;
23
24int *locked = (int *)llvm_omp_target_lock_mem(unlocked, n * sizeof(int),
25omp_get_default_device());
26if (!locked)
27return 0;
28
29#pragma omp target teams distribute parallel for map(tofrom : unlocked[ : n])
30for (int i = 0; i < n; i++)
31unlocked[i] += 1;
32
33#pragma omp target teams distribute parallel for map(tofrom : unlocked[10 : 10])
34for (int i = 10; i < 20; i++)
35unlocked[i] += 1;
36
37#pragma omp target teams distribute parallel for map(tofrom : locked[ : n])
38for (int i = 0; i < n; i++)
39locked[i] += 1;
40
41#pragma omp target teams distribute parallel for map(tofrom : locked[10 : 10])
42for (int i = 10; i < 20; i++)
43locked[i] += 1;
44
45llvm_omp_target_unlock_mem(unlocked, omp_get_default_device());
46
47int err = 0;
48for (int i = 0; i < n; i++) {
49if (i < 10 || i > 19) {
50if (unlocked[i] != i + 2) {
51printf("Err at %d, got %d, expected %d\n", i, unlocked[i], i + 1);
52err++;
53}
54} else if (unlocked[i] != i + 4) {
55printf("Err at %d, got %d, expected %d\n", i, unlocked[i], i + 2);
56err++;
57}
58}
59
60// CHECK: PASS
61if (err == 0)
62printf("PASS\n");
63
64return err;
65}
66