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

Workaround for broken [[deprecated]] in PGI compiler #1581

Merged
merged 2 commits into from
Mar 9, 2020

Conversation

pramodk
Copy link
Contributor

@pramodk pramodk commented Mar 7, 2020

  • similar to Intel and NVCC, add workaround for PGI compiler

  • I tested this with:

kumbhar@bbpv1:~/tmp/fmt/build$ pgc++ --version

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

kumbhar@bbpv1:~/tmp/fmt/build$ cmake .. -DCMAKE_BUILD_TYPE=Debug
-- CMake version: 3.15.3
-- Version: 6.1.3
-- Build type: Debug
-- CXX_STANDARD: 11
-- Required features: cxx_variadic_templates
CMake Warning (dev) at CMakeLists.txt:35 (set):
  implicitly converting 'STRINGS' to 'STRING' type.
Call Stack (most recent call first):
  CMakeLists.txt:253 (set_doc)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- FMT_PEDANTIC: OFF
-- Configuring done
-- Generating done
-- Build files have been written to: /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/build
  • Currently two tests are failing:
$ make test

88% tests passed, 2 tests failed out of 17

Total Test time (real) =   0.29 sec

The following tests FAILED:
	  7 - format-test (SEGFAULT)
	  8 - format-impl-test (Failed)
Errors while running CTest


$ ctest -V

...
7: /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/format-test.cc:1111: Failure
7: Value of: format("{:.494}", 4.9406564584124654E-324)
7:   Actual: "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
7: Expected: "4.9406564584124654417656879286822137236505980261432476442558568250067550" "727020875186529983636163599237979656469544571773092665671035593979639877" "479601078187812630071319031140452784581716784898210368871863605699873072" "305000638740915356498438731247339727316961514003171538539807412623856559" "117102665855668676818703956031062493194527159149245532930545654440112748" "012970999954193198940908041656332452475714786901472678015935523861155013" "480352649347201937902681071074917033322268447533357208324319361e-324"
7: Which is: "4.9406564584124654417656879286822137236505980261432476442558568250067550727020875186529983636163599237979656469544571773092665671035593979639877479601078187812630071319031140452784581716784898210368871863605699873072305000638740915356498438731247339727316961514003171538539807412623856559117102665855668676818703956031062493194527159149245532930545654440112748012970999954193198940908041656332452475714786901472678015935523861155013480352649347201937902681071074917033322268447533357208324319361e-324"
7: [  FAILED  ] FormatterTest.Precision (1 ms)

8: [ RUN      ] FormatTest.CountCodePoints
8: /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/format-impl-test.cc:434: Failure
8: Value of: fmt::internal::count_code_points( fmt::basic_string_view<char8_t>(reinterpret_cast<const char8_t*>("ёжик")))
8:   Actual: 1
8: Expected: 4
8: [  FAILED  ] FormatTest.CountCodePoints (0 ms)

I didn't look into details but if there are any suggestions, it will be helpful.

  - similar to Intel and NVCC, add workaround for PGI compiler
pramodk added a commit to BlueBrain/nmodl that referenced this pull request Mar 7, 2020
 - set CMAKE_CXX11_STANDARD_COMPILE_OPTION to remove -A : https://www.pgroup.com/userforum/viewtopic.php?f=4&t=7565&p=27308#p27308
 - use forks of fmt and spdlog because of fmtlib/fmt#1581
Copy link
Contributor

@vitaut vitaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. Mostly looks good but please apply clang-format.

The FormatterTest.Precision failure is likely due to non-IEEE754 floating point. In this case you could try making the failing check conditional on is_iec559:

if (std::numeric_limits<double>::is_iec559) {
  EXPECT_EQ(
      "4.9406564584124654417656879286822137236505980261432476442558568250067550"
      "727020875186529983636163599237979656469544571773092665671035593979639877"
      "479601078187812630071319031140452784581716784898210368871863605699873072"
      "305000638740915356498438731247339727316961514003171538539807412623856559"
      "117102665855668676818703956031062493194527159149245532930545654440112748"
      "012970999954193198940908041656332452475714786901472678015935523861155013"
      "480352649347201937902681071074917033322268447533357208324319361e-324",
      format("{:.494}", 4.9406564584124654E-324));
}

It's hard to say why CountCodePoints is failing. You'll need to provide more information.

@pramodk
Copy link
Contributor Author

pramodk commented Mar 8, 2020

The FormatterTest.Precision failure is likely due to non-IEEE754 floating point. In this case you could try making the failing check conditional on is_iec559

Thanks! In the compiler manual I saw flag -Kieee related to conformance of IEEE 754. This fixes FormatterTest.Precision test.

There are now two tests that are failing:

  • ./bin/format-test segfaults for :
TEST(FormatTest, FormatUTF8Precision) {
  using str_type = std::basic_string<char8_t>;
  str_type format(reinterpret_cast<const char8_t*>(u8"{:.4}"));
  str_type str(reinterpret_cast<const char8_t*>(u8"caf\u00e9s"));  // cafés
  auto result = fmt::format(format, str);
  EXPECT_EQ(fmt::internal::count_code_points(result), 4);
  EXPECT_EQ(result.size(), 5);
  EXPECT_EQ(from_u8str(result), from_u8str(str.substr(0, 5)));
}

stack trance is:

(gdb) bt
#0  0x00000000005faa05 in fmt::v6::internal::parse_format_string (format_str=..., handler=0x7fffffff9330)
    at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/include/fmt/format.h:2562
#1  0x000000000060f1db in fmt::v6::vformat_to (out=..., format_str=..., args=..., loc=...)
    at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/include/fmt/format.h:3151
#2  0x00000000005fa904 in fmt::v6::internal::vformat_to (buf=0x7fffffff9480, format_str=..., args=...)
    at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/include/fmt/format.h:3306
#3  0x00000000005fa858 in fmt::v6::internal::vformat (format_str=..., args=...)
    at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/include/fmt/format.h:3424
#4  0x0000000000606340 in fmt::v6::format (format_str=0x7fffffff98d8, args=0x7fffffff98b0)
    at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/include/fmt/core.h:1546
#5  0x000000000047ad60 in FormatTest_FormatUTF8Precision_Test::TestBody ()
    at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/format-test.cc:2568
#6  0x000000000067cf8d in testing::internal::HandleSehExceptionsInMethodIfSupported (object=0x7fffe40008c0, method=...,
    location=0x6d1f2f <.S51215> "the test body") at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/gmock-gtest-all.cc:3447
#7  0x0000000000673653 in testing::internal::HandleExceptionsInMethodIfSupported (object=0x7fffe40008c0, method=...,
    location=0x6d1f2f <.S51215> "the test body") at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/gmock-gtest-all.cc:3483
#8  0x000000000064b152 in testing::Test::Run () at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/gmock-gtest-all.cc:3519
#9  0x000000000064c2c2 in testing::TestInfo () at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/gmock-gtest-all.cc:3690
#10 0x000000000064ccb3 in testing::TestCase () at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/gmock-gtest-all.cc:3807
#11 0x0000000000659147 in testing::internal::UnitTestImpl () at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/gmock-gtest-all.cc:5648
#12 0x000000000067d10d in testing::internal::HandleSehExceptionsInMethodIfSupported (object=0x9bfd70, method=...,
    location=0x6d1e75 <.S52231> "auxiliary test code (environments or event listeners)")
    at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/gmock-gtest-all.cc:3447
#13 0x0000000000675103 in testing::internal::HandleExceptionsInMethodIfSupported (object=0x9bfd70, method=...,
    location=0x6d1e75 <.S52231> "auxiliary test code (environments or event listeners)")
    at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/gmock-gtest-all.cc:3483
#14 0x000000000064d65d in testing::UnitTest () at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/gmock-gtest-all.cc:5268
#15 0x000000000062b931 in RUN_ALL_TESTS () at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/gtest/gtest.h:20062
#16 0x000000000062b963 in main (argc=1, argv=0x7fffffff9eb8) at /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/test-main.cc:37
  • CountCodePoints test:
TEST(FormatTest, CountCodePoints) {
#ifndef __cpp_char8_t
  using fmt::char8_t;
#endif
  EXPECT_EQ(4, fmt::internal::count_code_points(
    fmt::basic_string_view<char8_t>(reinterpret_cast<const char8_t*>("ёжик"))));
}

produces:

8: [ RUN      ] FormatTest.CountCodePoints
8: /gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/test/format-impl-test.cc:434: Failure
8: Value of: fmt::internal::count_code_points( fmt::basic_string_view<char8_t>(reinterpret_cast<const char8_t*>("ёжик")))
8:   Actual: 1
8: Expected: 4

So seems something related to UTF-8 with PGI? I don't find any relevant info though.

@pramodk
Copy link
Contributor Author

pramodk commented Mar 8, 2020

Mostly looks good but please apply clang-format.

Done

@vitaut vitaut merged commit 5bb8856 into fmtlib:master Mar 9, 2020
pramodk added a commit to BlueBrain/nmodl that referenced this pull request Mar 11, 2020
 - Add newline at the end of files to avoid PGI warnings
 - Fix PGI internal assertion
          external/nmodl/src/codegen/codegen_c_visitor.cpp", line 3969:
          internal error: assertion failed at: "../src/lower_init.c", line
          7946
              auto statement = ShadowUseStatement{lhs, "+=", rhs};
 - Fixes for PGI build:
      set CMAKE_CXX11_STANDARD_COMPILE_OPTION to remove -A : https://www.pgroup.com/userforum/viewtopic.php?f=4&t=7565&p=27308#p27308
 - Use fork of spdlog because of fmtlib/fmt#1581
 - Add necessary compiler flags by default
pramodk added a commit to BlueBrain/nmodl that referenced this pull request Mar 11, 2020
- Add newline at the end of files to avoid PGI warnings
- Fix PGI internal assertion
     external/nmodl/src/codegen/codegen_c_visitor.cpp", line 3969:
     internal error: assertion failed at: "../src/lower_init.c", line 7946
     auto statement = ShadowUseStatement{lhs, "+=", rhs};
- Fixes for PGI build:
     set CMAKE_CXX11_STANDARD_COMPILE_OPTION to remove https://www.pgroup.com/userforum/viewtopic.php?f=4&t=7565&p=27308#p27308
 - Use fork of spdlog because of fmtlib/fmt#1581
 - Add necessary compiler flags by default

See #271, it was merged into wrong branch.

Fixes #262
@vitaut
Copy link
Contributor

vitaut commented Mar 14, 2020

So seems something related to UTF-8 with PGI?

Looks like it.

What does the following program print when compiled with PGI and run?

#include <fmt/format.h>

int main() {
  auto s = fmt::basic_string_view<char8_t>(
      reinterpret_cast<const char8_t*>("ёжик"));
  for (auto c: s) {
    fmt::print("\\x{:02x}", static_cast<unsigned>(c));
  }
}

@pramodk
Copy link
Contributor Author

pramodk commented Mar 15, 2020

What does the following program print when compiled with PGI and run?

sure!

First I was getting this:

"/gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/include/fmt/format.h", line 3502:
          error: a literal operator template must have a template parameter
          list equivalent to "<char ...>"
  FMT_CONSTEXPR internal::udl_formatter<Char, CHARS...> operator""_format() {
                                                        ^
"../test.cpp", line 8: error: identifier "char8_t" is undefined
    auto s = fmt::basic_string_view<char8_t>(
                                    ^
"../test.cpp", line 9: error: identifier "char8_t" is undefined
        reinterpret_cast<const char8_t*>("ёжик"));

Then I added using fmt::char8_; and then got:

"/gpfs/bbp.cscs.ch/home/kumbhar/tmp/fmt/include/fmt/format.h", line 3502:
          error: a literal operator template must have a template parameter
          list equivalent to "<char ...>"
  FMT_CONSTEXPR internal::udl_formatter<Char, CHARS...> operator""_format() {

Then I set FMT_USE_UDL_TEMPLATE 0 and then managed to compiled the code. The output from your program is:

$ ./test
\xffffffd1\xffffffd0

By the way, PGI compile is free to download in case you want to test locally.

Let me know if I should test anything else.

@vitaut
Copy link
Contributor

vitaut commented Mar 15, 2020

PGI butchered the string literal. The correct output should be: \xd1\x91\xd0\xb6\xd0\xb8\xd0\xba (https://godbolt.org/z/eKg2sM). Unfortunately I don't know how to work around this (other than just conditionally disable the tests). Suggestions/PRs are welcome.

teajay-fr pushed a commit to teajay-fr/fmt that referenced this pull request Mar 18, 2020
* Workaround broken [[deprecated]] in PGI compiler
  - similar to Intel and NVCC, add workaround for PGI compiler
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

Successfully merging this pull request may close these issues.

2 participants