This is an archive of the discontinued LLVM Phabricator instance.

[OPENMP]Remove const firstprivate allocation as a variable in a constant space.
ClosedPublic

Authored by ABataev on Jul 2 2021, 1:47 PM.

Details

Summary

Current implementation is not compatible with asynchronous target
regions, need to remove it.

Diff Detail

Event Timeline

ABataev created this revision.Jul 2 2021, 1:47 PM
ABataev requested review of this revision.Jul 2 2021, 1:47 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 2 2021, 1:47 PM
Herald added a subscriber: sstefan1. · View Herald Transcript
vzakhari accepted this revision.Jul 6 2021, 3:07 PM
vzakhari added a subscriber: vzakhari.

LGTM

This revision is now accepted and ready to land.Jul 6 2021, 3:07 PM
jhuber6 added a subscriber: jhuber6.Jul 8 2021, 9:21 AM

This revision causes a bug with generic regions. Firstprivate constants now aren't mapped properly into an internal parallel region and will just be zero. For example if I run this code I will see different values for the constants inside and outside the parallel region.

#include <complex>
#include <cstdio>

void foo(const std::complex<double> X, std::complex<double> Y) {
#pragma omp target firstprivate(X) map(from:Y)
  {
    printf ("Outside parallel: %f + %fi\n", X.real(), X.imag());
#pragma omp parallel firstprivate(X)
    {
      printf ("Inside parallel: %f + %fi\n", X.real(), X.imag());
      Y = X;
    }
  }
}

int main() {
  std::complex<double> X = {1.0, 1.0};
  std::complex<double> Y;
  foo(X, Y);
}
Outside parallel: 1.000000 + 1.000000i
Inside parallel: 0.000000 + 0.000000i

I'm assuming they aren't being properly copied because they were originally global constants that had visibility everywhere.

This revision causes a bug with generic regions. Firstprivate constants now aren't mapped properly into an internal parallel region and will just be zero. For example if I run this code I will see different values for the constants inside and outside the parallel region.

#include <complex>
#include <cstdio>

void foo(const std::complex<double> X, std::complex<double> Y) {
#pragma omp target firstprivate(X) map(from:Y)
  {
    printf ("Outside parallel: %f + %fi\n", X.real(), X.imag());
#pragma omp parallel firstprivate(X)
    {
      printf ("Inside parallel: %f + %fi\n", X.real(), X.imag());
      Y = X;
    }
  }
}

int main() {
  std::complex<double> X = {1.0, 1.0};
  std::complex<double> Y;
  foo(X, Y);
}
Outside parallel: 1.000000 + 1.000000i
Inside parallel: 0.000000 + 0.000000i

I'm assuming they aren't being properly copied because they were originally global constants that had visibility everywhere.

Hi, thanks for the report. I think I know the reason, I prepared a patch D105647. Could you check if it fixes the issue?