public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bernhardmgruber at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/108030] New: `std::experimental::simd` not inlined
Date: Fri, 09 Dec 2022 11:29:17 +0000	[thread overview]
Message-ID: <bug-108030-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108030

            Bug ID: 108030
           Summary: `std::experimental::simd` not inlined
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bernhardmgruber at gmail dot com
  Target Milestone: ---

Created attachment 54052
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54052&action=edit
Diff we applied to a local copy of the <experimental/simd>headers.

We tried to explicitely vectorize a C++ function using
`std::experimental::simd` in our particle-in-cell simulation
[picongpu](https://github.com/ComputationalRadiationPhysics/picongpu). The
function is already called from a long call tree of functions marked
`__attribute__((always_inline))`. Profiling the code shows that several
constructs of `std::experimental::simd` where not inlined, leading to
catastrophic performance (several times slower than scalar code).

We compiled, among other flags, with:
```
-g
-march=native
-mtune=native
-fopenmp
-O3
-DNDEBUG
-pthread
-std=c++17
```

We mostly used multiplication/addition as well as the broadcast and generator
constructors of SIMD types. We saw several calls to `_S_multiplies` (IIRC) and
`_S_generate`/`_S_generator` that were not inlined, depending on whether we
used `std::experimental::native_simd` or `std::experimental::fixed_size_simd`.

Upon inspection of the `<experimental/bits/simd_*>` headers, we saw that
several functions are not annotated with `_GLIBCXX_SIMD_INTRINSIC` or other
ways to force inlining. We think this is a missed optimization opportunity.

We tried `-finline-limit=1000000` without success.

We thus applied `_GLIBCXX_SIMD_INTRINSIC` and `__attribute__((always_inline))`
to functions from the SIMD headers that showed up in the profiler (perf) until
all calls were inlined.

Please apply further attributes to SIMD intrinsics to force their inlining.
Mind, that this also affects lambda expressions.

I have attached a diff which our changes to the SIMD headers, but we also bulk
replaced several declaration specifiers, so we may have added more
force-inlines than potentially necessary.

             reply	other threads:[~2022-12-09 11:29 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-09 11:29 bernhardmgruber at gmail dot com [this message]
2022-12-09 12:15 ` [Bug libstdc++/108030] " mkretz at gcc dot gnu.org
2022-12-09 12:15 ` mkretz at gcc dot gnu.org
2022-12-09 14:13 ` jakub at gcc dot gnu.org
2022-12-09 14:51 ` mkretz at gcc dot gnu.org
2022-12-09 14:55 ` jakub at gcc dot gnu.org
2023-02-16 14:58 ` cvs-commit at gcc dot gnu.org
2023-02-19 14:39 ` mkretz at gcc dot gnu.org
2023-02-19 15:21 ` bernhardmgruber at gmail dot com
2023-02-23 14:03 ` cvs-commit at gcc dot gnu.org
2023-02-23 14:04 ` cvs-commit at gcc dot gnu.org
2023-02-23 16:31 ` cvs-commit at gcc dot gnu.org
2023-02-23 19:46 ` cvs-commit at gcc dot gnu.org
2023-02-24 18:40 ` cvs-commit at gcc dot gnu.org
2023-02-24 18:54 ` mkretz at gcc dot gnu.org
2023-04-26  6:57 ` rguenth at gcc dot gnu.org
2023-04-30  9:06 ` mkretz at gcc dot gnu.org
2023-05-23 10:02 ` cvs-commit at gcc dot gnu.org
2023-05-23 10:02 ` cvs-commit at gcc dot gnu.org
2023-05-23 10:02 ` cvs-commit at gcc dot gnu.org
2023-05-25  7:04 ` cvs-commit at gcc dot gnu.org
2023-05-25  7:04 ` cvs-commit at gcc dot gnu.org
2023-05-25  7:04 ` cvs-commit at gcc dot gnu.org
2023-05-25  7:08 ` mkretz at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-108030-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).