[Openmp-commits] [PATCH] D102107: [OpenMP] Codegen aggregate for outlined function captures

Pushpinder Singh via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Sep 30 00:27:05 PDT 2021


pdhaliwal added a comment.

I modified the declare_mapper_target to print the contents of array after target region and found the following output:

  2 3 4 5 6 7 8 9 10 11 Sum = 65

Program:

  #include <cstdio>
  #include <cstdlib>
  
  #define NUM 10
  
  int main() {
    int *c= new int[NUM];
    for (int i = 0; i < NUM; i++) {
      c[i] = 1;
    }
  #pragma omp target teams distribute  parallel for map(tofrom: c[0:NUM])
    for (int i = 0; i < NUM; i++) {
      c[i]++;
    }
    int sum = 0;
    for (int i = 0; i < NUM; i++) {
      sum += c[i];
      printf("%d ", c[i]);
    }
    // CHECK: Sum = 2048
    printf("Sum = %d\n", sum);
    return 0;
  }

Different variant of the same program is producing correct output,

  #include <cstdio>
  #include <cstdlib>
  
  #define NUM 10
  
  int main() {
    int *c= new int[NUM];
    for (int i = 0; i < NUM; i++) {
      c[i] = 1;
    }
  
    int *b = new int[NUM];
  #pragma omp target teams distribute  parallel for map(tofrom: c[0:NUM], b[0:NUM])
    for (int i = 0; i < NUM; i++) {
      b[i] = c[i] + 1;
    }
    int sum = 0;
    for (int i = 0; i < NUM; i++) {
      sum += b[i];
      printf("%d ", b[i]);
    }
    // CHECK: Sum = 2048
    printf("Sum = %d\n", sum);
    return 0;
  }

Output (this is the right answer):

  2 2 2 2 2 2 2 2 2 2 Sum = 20

On internal amd-stg-open branch, this patch works fine, so issue is only with the trunk.
I compared the generated IR before and after applying this patch, I didn't see anything suspicious. (but can't be 100% sure).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102107/new/

https://reviews.llvm.org/D102107



More information about the Openmp-commits mailing list