Compiling with C++ stdlib Procedures

Hi there,

I am trying to convert an existing C++ applications to rank documents to use OpenACC. It has already been changed to use OpenCL, however the version used here is based on a CPU ONLY version. I only mention the OpenCL because some headers are still included.

I am running Ubuntu 12.04, and the latest download compiler from the PGI site. The code dicussed can be found at https://gist.github.com/anonymous/bd73b9c6a80a47be60d3

I am compiling using this

pgcpp -acc -ta=radeon -O2 cpu_reference_implementation_acc.cpp read_files.cpp timing.cpp OpenCLUtils.cpp -I/opt/AMDAPP/include -o acc_doc_rank -lpthread

, however the other versions are compiled with "

-std=c++0x

" also. This gives the following error:

pgcpp-Error-Unknown switch:c++0x

I am getting the following error:

PGCC-S-0155-Procedures called in a compute region must have acc routine information: __stl_throw_out_of_range__3stdFPCc (cpu_reference_implementation_acc.cpp: 177)
PGCC-S-0155-Kernel region ignored; see -Minfo messages  (cpu_reference_implementation_acc.cpp)
PGCC/x86 Linux 14.10-0: compilation completed with severe errors
read_files.cpp:
"read_files.cpp", line 95: error: no instance of constructor
          "std::basic_ifstream<_CharT, _Traits>::basic_ifstream [with
          _CharT=char, _Traits=std::char_traits<char>]" matches the argument
          list
            argument types are: (std::string, const int)
      std::ifstream in(file, std::ifstream::binary);
                       ^

"read_files.cpp", line 137: error: name followed by "::" must be a class or
          namespace name
      threadCount = std::thread::hardware_concurrency();
                         ^

2 errors detected in the compilation of "read_files.cpp".

[/code]

Hi jhebus1,

To enable C++11 features, use the “pgc++” instead of “pgcpp” and add the flag “–c++11”.

Note that “pgc++” is compatible with “g++” and will use the GNU STL. Hence, you need to have a “g++” version that supports the C++11 features you’re using.

Hope this helps,
Mat

Hi,

Thanks for that.

Now,

pgc++ -acc -ta=radeon  -I/opt/AMDAPP/include -O2 cpu_reference_implementation_acc.cpp read_files.cpp -o acc_doc_rank

gives the following error

cpu_reference_implementation_acc.cpp:
"/usr/include/c++/4.6/bits/c++0x_warning.h", line 32: catastrophic error: 
          #error directive: This file requires compiler and library support
          for the upcoming ISO C++ standard, C++0x. This support is currently
          experimental, and must be enabled with the -std=c++0x or
          -std=gnu++0x compiler options.
  #error This file requires compiler and library support for the upcoming \
   ^

1 catastrophic error detected in the compilation of "cpu_reference_implementation_acc.cpp".
Compilation terminated.
read_files.cpp:
"/usr/include/c++/4.6/bits/c++0x_warning.h", line 32: catastrophic error: 
          #error directive: This file requires compiler and library support
          for the upcoming ISO C++ standard, C++0x. This support is currently
          experimental, and must be enabled with the -std=c++0x or
          -std=gnu++0x compiler options.
  #error This file requires compiler and library support for the upcoming \
   ^

1 catastrophic error detected in the compilation of "read_files.cpp".
Compilation terminated.

The above compilation line should have read

pgc++ -acc -ta=radeon --c++0x  -I/opt/AMDAPP/include -O2 cpu_reference_implementation_acc.cpp read_files.cpp -o acc_doc_rank

Hi jhebus1,

You’re using GNU version 4.6 which has partial support for C++0X but not C++11. You can try setting the define flag “-D__GXX_EXPERIMENTAL_CXX0X__” on the compilation, but you’ll most likely run into other issues.

GNU 4.7 was the first to offer partial support of C++11, with 4.8 nearing completion (see: https://gcc.gnu.org/projects/cxx0x.html)

  • Mat

Hi Mat,

Thanks for the reply.

To reiterate, this code compiles fine when either just single threaded, multi-threaded, or using opencl. The following is the normal build for the single threaded:

g++ -W -Wall -g  -Wno-deprecated -Wno-unused-parameter -Wno-deprecated-declarations -Wno-ignored-qualifiers -I/opt/AMDAPP/include -std=c++0x    -c -o cpu_reference_implementation.o cpu_reference_implementation.cpp
g++ -W -Wall -g  -Wno-deprecated -Wno-unused-parameter -Wno-deprecated-declarations -Wno-ignored-qualifiers -I/opt/AMDAPP/include -std=c++0x    -c -o read_files.o read_files.cpp
g++ -W -Wall -g  -Wno-deprecated -Wno-unused-parameter -Wno-deprecated-declarations -Wno-ignored-qualifiers -I/opt/AMDAPP/include -std=c++0x    -c -o OpenCLUtils.o OpenCLUtils.cpp
cc -W -Wall -g  -Wno-deprecated -Wno-unused-parameter -Wno-deprecated-declarations -Wno-ignored-qualifiers -I/opt/AMDAPP/include   -c -o timing.o timing.c
g++ -W -Wall -g  -Wno-deprecated -Wno-unused-parameter -Wno-deprecated-declarations -Wno-ignored-qualifiers -I/opt/AMDAPP/include -std=c++0x  -o cpu_reference_implementation cpu_reference_implementation.o read_files.o OpenCLUtils.o timing.o -lpthread

I have taken the same code and applied the OpenACC pragmas which is giving the errors.

Applying the flag you mentioned:

-D__GXX_EXPERIMENTAL_CXX0X_

get past the previous error but now generates the following error:

PGCC-W-0155-Unsupported size in alignment directive  (cpu_reference_implementation_acc.cpp)
PGCC-W-0155-Unsupported size in alignment directive  (cpu_reference_implementation_acc.cpp)
PGCC-W-0155-Unsupported size in alignment directive  (cpu_reference_implementation_acc.cpp)
PGCC-W-0155-Unsupported size in alignment directive  (cpu_reference_implementation_acc.cpp)
PGCC-W-0155-Unsupported size in alignment directive  (cpu_reference_implementation_acc.cpp)
PGCC-W-0155-Unsupported size in alignment directive  (cpu_reference_implementation_acc.cpp)
PGCC-W-0155-Unsupported size in alignment directive  (cpu_reference_implementation_acc.cpp)
PGCC-W-0155-Unsupported size in alignment directive  (cpu_reference_implementation_acc.cpp)
PGCC-W-0155-Unsupported size in alignment directive  (cpu_reference_implementation_acc.cpp)
PGCC-W-0155-Unsupported size in alignment directive  (cpu_reference_implementation_acc.cpp)
PGCC-W-0155-Unsupported size in alignment directive  (cpu_reference_implementation_acc.cpp)
PGCC-W-0155-Unsupported size in alignment directive  (cpu_reference_implementation_acc.cpp)
PGCC-S-0155-Procedures called in a compute region must have acc routine information: _ZSt20__throw_out_of_rangePKc (cpu_reference_implementation_acc.cpp: 719)
PGCC-S-0155-Kernel region ignored; see -Minfo messages  (cpu_reference_implementation_acc.cpp)
PGCC/x86 Linux 14.10-0: compilation completed with severe errors
read_files.cpp:
"read_files.cpp", line 137: error: name followed by "::" must be a class or
          namespace name
      threadCount = std::thread::hardware_concurrency();
                         ^

1 error detected in the compilation of "read_files.cpp".

Thanks,

Paul

Hi Paul,

OpenACC requires all routines called from device code, have a device equivalent version. The PGI C++ compiler will attempt to auto-generate device routines if the source is visible during compilation (i.e. it’s found in the same source, or is a template). If not visible, the user will need to decorate both the prototype and the definition with the “acc routine” pragma.

In this case, the routine is “std::__throw_out_of_range(const char *)”. My guess is that you’re not calling this routine yourself, but rather it’s hidden down a call chain someplace. So not something you’re likely be able to add a “routine” directive to.

I went and downloaded the project you posted, but it’s missing a few header files so I’m not able to compile it. If you can post the full source or send it to PGI Customer Service (trs@pgroup.com), I’ll try and reproduce the error.

I did see in the “acc_ccp_ref.cpp” that you’re trying to use stl:vector within a compute region. This is known limitation of OpenACC where it doesn’t support complex data structures, especially with a container type like vector where the underlying data could be anything. The OpenACC committee is currently in the process of defining how to work with complex data management, with the preliminary proposal just being published last November. You can find the proposal here: http://www.openacc.org/sites/default/files/TR-14-1.pdf

If you haven’t already, I would suggest listening to Michael Wolfe’s webinar on using OpenACC with C++ (http://www.pgroup.com/media/ieee_openacc_webinar_may2014.mp4). That should get you started with the current state of OpenACC and C++.

Note that our engineers are working hard on improving C++ support. We’re experimenting with using NVIDIA’s Unified Memory feature (http://devblogs.nvidia.com/parallelforall/unified-memory-in-cuda-6/) which will allow us to support complex data structures, including vector, without the need for additions to the OpenACC standard. There’s caveats to UM, but overall it’s looking promising.

In March, I’ll be giving a presentation at NVIDIA’s GTC conference (http://www.gputechconf.com/) on using OpenACC within C++ classes, and folks from Sandia National Labs will present a talk on their experience of using OpenACC and C++.

Best Regards,
Mat

Hi Mat,

Thanks for the informative post.

I have sent an email with all the code. Hope that you can at least confirm your hypothesis.

Paul