brintos

brintos / llvm-project-archived public Read only

0
0
Text · 690 B · b587b61 Raw
38 lines · c
1// RUN: %libomptarget-compile-run-and-check-generic2 3// REQUIRES: libc4 5#include <stdio.h>6#include <stdlib.h>7 8#pragma omp declare target to(malloc)9#pragma omp declare target to(free)10 11int main() {12  unsigned h_x;13  unsigned *d_x;14#pragma omp target map(from : d_x)15  {16    d_x = (unsigned *)malloc(sizeof(unsigned));17    *d_x = 1;18  }19 20#pragma omp target is_device_ptr(d_x) map(from : h_x)21  { h_x = *d_x; }22 23#pragma omp target is_device_ptr(d_x)24  { free(d_x); }25 26#pragma omp target teams num_teams(64)27#pragma omp parallel num_threads(32)28  {29    int *ptr = (int *)malloc(sizeof(int));30    *ptr = 42;31    free(ptr);32  }33 34  // CHECK: PASS35  if (h_x == 1)36    fputs("PASS\n", stdout);37}38