Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NVidia nvc++ compiler with O2 optimization leads to unknown token error during parsing #205

Closed
franzpoeschel opened this issue Nov 25, 2022 · 1 comment

Comments

@franzpoeschel
Copy link

franzpoeschel commented Nov 25, 2022

I don't know if this is a compiler issue or an issue with the toml11 library, but with optimization level -O2 in nvc++, the toml11 will often fail parsing strings due to unknown tokens appearing. By putting printf statements in the toml11 source code, I found out that the unknown token appears to be a linefeed.

To reproduce:
I installed the NVidia compilers into an Ubuntu 20.04, using the following two packages:

  1. https://developer.download.nvidia.com/hpc-sdk/21.5/nvhpc-2021_21.5_amd64.deb
  2. https://developer.download.nvidia.com/hpc-sdk/21.5/nvhpc-21-5_21.5_amd64.deb

If not yet installed, the environment-modules OS package is needed to activate the compiler environment thereafter via:

> source /etc/profile.d/modules.sh 
> module load /opt/nvidia/hpc_sdk/modulefiles/nvhpc/21.5 
> which nvc++
/opt/nvidia/hpc_sdk/Linux_x86_64/21.5/compilers/bin/nvc++
> nvc++ --version

nvc++ 21.5-0 LLVM 64-bit target on x86-64 Linux -tp skylake 
NVIDIA Compilers and Tools
Copyright (c) 2021, NVIDIA CORPORATION.  All rights reserved.

I checked out toml11 at the v3.7.1 tag (the issue can also be reproduced on the latest master, 22db720 commit) and compiled the following test program:

#include <toml.hpp>

int main()
{
    constexpr char const *raw = R"(
left = "val"
right = "val"
    )";
    constexpr std::ios::openmode openmode = std::ios_base::in;
    std::istringstream istream(raw, openmode);
    toml::value tomlVal = toml::parse(istream);
}

Compilation and invocation:

> nvc++  -I"$HOME/git-repos/toml11" -O2 --c++17 -o main main.cpp
> ./main 
terminate called after throwing an instance of 'toml::syntax_error'
  what():  [error] toml::parse_value: unknown token appeared
 --> unknown file
   |
 2 | left = "val"
   |        ^--- unknown
Aborted (core dumped)
> nvc++  -I"$HOME/git-repos/toml11" -O1 --c++17 -o main main.cpp
> ./main

The second invocation, compiled with -O1 finishes cleanly.

@franzpoeschel
Copy link
Author

franzpoeschel commented Mar 28, 2023

I have tried this again with the recent NVidia developer kit (see installation instructions below). The issue seems to be fixed.

$ curl https://developer.download.nvidia.com/hpc-sdk/ubuntu/DEB-GPG-KEY-NVIDIA-HPC-SDK | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg
$ echo 'deb [signed-by=/usr/share/keyrings/nvidia-hpcsdk-archive-keyring.gpg] https://developer.download.nvidia.com/hpc-sdk/ubuntu/amd64 /' | sudo tee /etc/apt/sources.list.d/nvhpc.list
$ sudo apt-get update -y
$ sudo apt-get install -y nvhpc-23-1

Issue only comes up on NVHPC 2021 with optimization O2 or O3:

> for i in ./main_*; do echo "$i"; "$i"; done
./main_2021_O0
./main_2021_O2
terminate called after throwing an instance of 'toml::syntax_error'
  what():  [error] toml::parse_value: unknown token appeared
 --> unknown file
   |
 2 | left = "val"
   |        ^--- unknown
Aborted (core dumped)
./main_2023_O0
./main_2023_O2
./main_2023_O3

franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue Apr 11, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue Apr 11, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue Apr 12, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue Apr 14, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue May 8, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue May 8, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue May 9, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue May 10, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue May 10, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue May 23, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue May 24, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue May 24, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue Jun 27, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue Jul 7, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue Jul 7, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue Jul 10, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue Jul 24, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue Aug 4, 2023
franzpoeschel added a commit to franzpoeschel/openPMD-api that referenced this issue Aug 10, 2023
ax3l added a commit to openPMD/openPMD-api that referenced this issue Aug 17, 2023
* TOML backend

* Add documentation for TOML

* Fixes for long double and long integer types

* Only run TOML tests if TOML is available

TOML is not shown as available on NVIDIA compilers

* Deactivate long double entirely for JSON/TOML

* CI fix: unused variable

* Hide/deactivate/warn Toml backend on nvcc compilers

ToruNiina/toml11#205

* Usage notes for JSON / TOML

* Update comment in test/python/unittest/API/APITest.py

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>

* Update documentation text

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>

---------

Co-authored-by: Axel Huebl <axel.huebl@plasma.ninja>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant