Skip to content

Comments

Add hybrid compilation mode to exclude <hwloc.h> from global includes#210

Open
solbjorn wants to merge 1 commit intotzcnt:mainfrom
solbjorn:standalone-hwloc
Open

Add hybrid compilation mode to exclude <hwloc.h> from global includes#210
solbjorn wants to merge 1 commit intotzcnt:mainfrom
solbjorn:standalone-hwloc

Conversation

@solbjorn
Copy link
Contributor

When TMC is used project-wide and header-only, and TMC_USE_HWLOC is defined, <hwloc.h> gets included to every file due to inclusion of .ipp files.

This might be unwanted for several reasons:

  • the entire project and its subprojects need to have the hwloc include folder in their include paths;
  • on Windows, <hwloc.h> unconditionally includes <windows.h>, and including this file globally is a bad practice (it's overbloated, can provoke different symbol conflicts etc.).

Add a hybrid compilation mode, TMC_STANDALONE_COMPILATION_HWLOC. In this mode, one still needs to create an implementation file and define TMC_IMPL there, but only the .ipp files which include <hwloc.h> will be included and compiled there. The rest of TMC will still be header-only, so that most of potential performance gains remains.

This mode only introduce changes when TMC_USE_HWLOC is defined and TMC_WINDOWS_DLL is not. The latter requires a full standalone implementation, while without the former no files include <hwloc.h>, so that it's pointless to make anything non header-only. The default behaviour remains the same as before the change.

This mode might be improved furtherly in future by isolating the functions which use/need <hwloc.h> to separate .ipp files. Big implementation files like ex_cpu.ipp could be then inlined more aggressively.

When TMC is used project-wide and header-only, and TMC_USE_HWLOC is
defined, <hwloc.h> gets included to every file due to inclusion of
.ipp files.

This might be unwanted for several reasons:
a) the entire project and its subprojects need to have the hwloc
   include folder in their include paths;
b) on Windows, <hwloc.h> unconditionally includes <windows.h>,
   and including this file globally is a bad practice (it's
   overbloated, can provoke different symbol conflicts etc.).

Add a hybrid compilation mode, TMC_STANDALONE_COMPILATION_HWLOC.
In this mode, one still needs to create an implementation file
and define TMC_IMPL there, but only the .ipp files which include
<hwloc.h> will be included and compiled there. The rest of TMC
will still be header-only, so that most of potential performance
gains remains.

This mode only introduce changes when TMC_USE_HWLOC is defined and
TMC_WINDOWS_DLL is not. The latter requires a full standalone
implementation, while without the former no files include <hwloc.h>,
so that it's pointless to make anything non-header-only.
The default behaviour remains the same as before the change.

This mode might be improved furtherly in future by isolating
the functions which use/need <hwloc.h> to separate .ipp files.
Big implementation files like ex_cpu.ipp could be then inlined
more aggressively.

Signed-off-by: Alexander Lobakin <alobakin@mailbox.org>
@solbjorn solbjorn changed the title Add hybrid compilation mode to exclude <hwloc.h> from global includes Add hybrid compilation mode to exclude <hwloc.h> from global includes Feb 10, 2026
@tzcnt
Copy link
Owner

tzcnt commented Feb 17, 2026

Sorry for the late reply. I'm still thinking about how to handle the build system overall, given the variety of different requests lately

@solbjorn
Copy link
Contributor Author

Sorry for the late reply. I'm still thinking about how to handle the build system overall, given the variety of different requests lately

Adding TMC to awesome-cpp and awesome-hpp brought its fruits ;) Great to see increasing interest in your library, well deserved.

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