pgc++ -c -acc failed to compile with -O2

Hi,

I was writing a very simple class template so that we can use Fortran syntax (1-based index, column-first) to access the elements of 2D arrays in acc routines.

The problem and a workaround have been included in the comment of the following code sample.

Thanks,
stw

/*
$ pgc++ --version

pgc++ 19.4-0 LLVM 64-bit target on x86-64 Linux -tp penryn
PGI Compilers and Tools
Copyright (c) 2019, NVIDIA CORPORATION.  All rights reserved.

This will fail:

$ pgc++ -c -acc eg.cc -O2
nvvmCompileProgram error: 9.
Error: /tmp/pgaccgvQdsHV92JUn.gpu (85, 31): parse '%li99' defined with type 'i64'
PGCC-S-0155-Compiler failed to translate accelerator region (see -Minfo messages): Device compiler exited with error status code (eg.cc: 1)
PGCC/x86-64 Linux 19.4-0: compilation completed with severe errors

These won't fail:

$ pgc++ -c -acc eg.cc -O1
$ pgc++ -c -acc eg.cc -O2 -DWORKAROUND
$ pgc++ -c -acc eg.cc -O1 -DWORKAROUND
*/

template <class T, int FRow>
class FMat_2DImpl {
private:
  T (*data_)[FRow];

public:
  #pragma acc routine seq
  FMat_2DImpl(T (*arr)[FRow]) : data_(arr) {}

  #pragma acc routine seq
  const T &operator()(int ifrow1, int ifcol1) const {
    return data_[ifcol1 - 1][ifrow1 - 1];
  }
};

template <class T, int FRow>
class FMat_1DImpl {
private:
  T *data_;

public:
  #pragma acc routine seq
  FMat_1DImpl(T (*arr)[FRow]) : data_((T *)arr) {}

  #pragma acc routine seq
  const T &operator()(int ifrow1, int ifcol1) const {
    return data_[(ifcol1 - 1) * FRow + (ifrow1 - 1)];
  }
};

#pragma acc routine seq
void assign(float w, float *output) { output[0] = w; }

#pragma acc routine seq
void func(float *output) {
  float x[3][3];

#ifndef WORKAROUND
  FMat_2DImpl<float, 3> fx(x);
#else
  FMat_1DImpl<float, 3> fx(x);
#endif

  float w = fx(1, 1) + fx(2, 1) + fx(3, 1);
  assign(w, output);
}

Thanks stw!

I was able to recreate the error here and it looks like a problem with the device LLVM code generation. I’ve added a problem report (TPR#27214) and sent it to engineering for further investigation.

Another workaround is to disable LLVM by either using the flag “-ta=tesla:nollvm” or “-Mnollvm”.

Thanks again,
Mat

TPR #27214 should be fixed with release 19.7