public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/108030] New: `std::experimental::simd` not inlined
@ 2022-12-09 11:29 bernhardmgruber at gmail dot com
  2022-12-09 12:15 ` [Bug libstdc++/108030] " mkretz at gcc dot gnu.org
                   ` (22 more replies)
  0 siblings, 23 replies; 24+ messages in thread
From: bernhardmgruber at gmail dot com @ 2022-12-09 11:29 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2023-05-25  7:08 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-09 11:29 [Bug libstdc++/108030] New: `std::experimental::simd` not inlined bernhardmgruber at gmail dot com
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

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).