brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · e300c80 Raw
115 lines · c
1// --------------------------------------------------2// Check extends before3// --------------------------------------------------4 5// RUN: %libomptarget-compile-generic \6// RUN:   -DEXTENDS=BEFORE7// RUN: %libomptarget-run-generic 2>&1 \8// RUN: | %fcheck-generic9 10// --------------------------------------------------11// Check extends after12// --------------------------------------------------13 14// RUN: %libomptarget-compile-generic \15// RUN:   -DEXTENDS=AFTER16// RUN: %libomptarget-run-generic 2>&1 \17// RUN: | %fcheck-generic18 19// END.20 21#include <stdio.h>22 23#define BEFORE 024#define AFTER 125 26#define SIZE 10027 28#if EXTENDS == BEFORE29#define SMALL_BEG (SIZE - 2)30#define SMALL_END SIZE31#define LARGE_BEG 032#define LARGE_END SIZE33#elif EXTENDS == AFTER34#define SMALL_BEG 035#define SMALL_END 236#define LARGE_BEG 037#define LARGE_END SIZE38#else39#error EXTENDS undefined40#endif41 42#define SMALL                                                                  \43  SMALL_BEG:                                                                   \44  (SMALL_END - SMALL_BEG)45#define LARGE                                                                  \46  LARGE_BEG:                                                                   \47  (LARGE_END - LARGE_BEG)48 49void check_not_present() {50  int arr[SIZE];51 52  for (int i = 0; i < SIZE; ++i)53    arr[i] = 99;54 55  // CHECK-LABEL: checking not present56  fprintf(stderr, "checking not present\n");57 58  // arr[LARGE] isn't (fully) present at the end of the target data region, so59  // the device-to-host transfer should not be performed, or it might fail.60#pragma omp target data map(tofrom : arr[LARGE])61  {62#pragma omp target exit data map(delete : arr[LARGE])63#pragma omp target enter data map(alloc : arr[SMALL])64#pragma omp target map(alloc : arr[SMALL])65    for (int i = SMALL_BEG; i < SMALL_END; ++i)66      arr[i] = 88;67  }68 69  // CHECK-NOT: omptarget70  // CHECK-NOT: error71  for (int i = 0; i < SIZE; ++i) {72    if (arr[i] != 99)73      fprintf(stderr, "error: arr[%d]=%d\n", i, arr[i]);74  }75}76 77void check_is_present() {78  int arr[SIZE];79 80  for (int i = 0; i < SIZE; ++i)81    arr[i] = 99;82 83  // CHECK-LABEL: checking is present84  fprintf(stderr, "checking is present\n");85 86  // arr[SMALL] is (fully) present at the end of the target data region, and the87  // device-to-host transfer should be performed only for it even though more88  // of the array is then present.89#pragma omp target data map(tofrom : arr[SMALL])90  {91#pragma omp target exit data map(delete : arr[SMALL])92#pragma omp target enter data map(alloc : arr[LARGE])93#pragma omp target map(alloc : arr[LARGE])94    for (int i = LARGE_BEG; i < LARGE_END; ++i)95      arr[i] = 88;96  }97 98  // CHECK-NOT: omptarget99  // CHECK-NOT: error100  for (int i = 0; i < SIZE; ++i) {101    if (SMALL_BEG <= i && i < SMALL_END) {102      if (arr[i] != 88)103        fprintf(stderr, "error: arr[%d]=%d\n", i, arr[i]);104    } else if (arr[i] != 99) {105      fprintf(stderr, "error: arr[%d]=%d\n", i, arr[i]);106    }107  }108}109 110int main() {111  check_not_present();112  check_is_present();113  return 0;114}115