Skip to content

[Core] New TSystem::CompileMacro flag, "h" #14067

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dpiparo
Copy link
Member

@dpiparo dpiparo commented Nov 16, 2023

This Pull request:

Adds a new flag to CompileMacro, "h".

Changes or fixes:

This new functionality allows not to rebuild the macro even if the file is newer than the library based on a hash built for the macro and its name. This helps distributed execution, providing a clean way to augment python analyses with accelerated functions in C++ and compiled when the worker cannot be setup but just individual tasks.

Checklist:

  • [v] tested changes locally
  • [v] updated the docs (if necessary)

When TSystem::CompileMacro is invoked with new option "h", a hash of the
macro name and content is produced and embedded as a symbol in the
library. Then, even if the timestamp of the file is changed, if the hash
is the same, the macro is not recompiled and the interpreter is not accessed.

This fixes memory hoarding of workers of distributed systems when
a. A C macro is used to accelerate some python functions
b. A setup of the worker is not possible (for example only a setup per task is allowed)
@phsft-bot
Copy link

Starting build on ROOT-performance-centos8-multicore/soversion, ROOT-ubuntu2204/nortcxxmod, ROOT-ubuntu2004/python3, mac12arm/cxx20, windows10/default
How to customize builds

@dpiparo dpiparo self-assigned this Nov 16, 2023
@dpiparo dpiparo added this to the 6.32/00 milestone Nov 16, 2023
@ferdymercury
Copy link
Contributor

ferdymercury commented Nov 16, 2023

Thanks Danilo! Now that you are modifying this file, maybe could you also address the two first points of this issue wrt the doxygen documentation? #10395 Thks

@dpiparo
Copy link
Member Author

dpiparo commented Nov 16, 2023

Hi @ferdymercury , thanks for the reminder - it's a good proposal. I propose to let the tests run and add one additional commit when some additional refinement is needed!

@phsft-bot
Copy link

Build failed on windows10/default.
Running on null:C:\build\workspace\root-pullrequests-build
See console output.

Errors:

  • [2023-11-16T16:08:14.169Z] C:\build\workspace\root-pullrequests-build\root\core\base\src\TSystem.cxx(49,10): fatal error C1083: Cannot open include file: 'dlfcn.h': No such file or directory [C:\build\workspace\root-pullrequests-build\build\core\Core.vcxproj]

@phsft-bot
Copy link

Build failed on ROOT-ubuntu2204/nortcxxmod.
Running on root-ubuntu-2204-1.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

@phsft-bot
Copy link

Build failed on ROOT-performance-centos8-multicore/soversion.
Running on olbdw-01.cern.ch:/data/sftnight/workspace/root-pullrequests-build
See console output.

@phsft-bot
Copy link

Build failed on ROOT-ubuntu2004/python3.
Running on root-ubuntu-2004-3.cern.ch:/home/sftnight/build/workspace/root-pullrequests-build
See console output.

Failing tests:

Copy link

Test Results

       3 files         3 suites   11h 15m 27s ⏱️
2 443 tests 2 442 ✔️ 0 💤 1
7 268 runs  7 267 ✔️ 0 💤 1

For more details on these failures, see this check.

Results for commit 41c7b93.

@@ -46,6 +46,7 @@ allows a simple partial implementation for new OS'es.
#include "THashList.h"
#include "ThreadLocalStorage.h"

#include <dlfcn.h>
Copy link
Member

Choose a reason for hiding this comment

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

Is this used?

@Axel-Naumann
Copy link
Member

Axel-Naumann commented Nov 16, 2023

Can this new mode be the default? And we add option h for the old, non hash approach?

const std::string dlsym_jit_name("__ROOT_Internal_CompileMacro_lsym_jit");
std::string dlsym_jit_code = "void *";
dlsym_jit_code +=
dlsym_jit_name + "(const char* hash_symbol_name) {return dlsym(RTLD_DEFAULT, hash_symbol_name);} ";
Copy link
Member

Choose a reason for hiding this comment

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

dlsym is (was?) not portable to Windows. See TROOT.cxx TCling.cxx TProtoClass.cxx and TClass.cxx (where TROOT.cxx seems to be the more recent one. (and yes we could use a factorization of those 4 instances).

@@ -2827,6 +2829,7 @@ int TSystem::CompileMacro(const char *filename, Option_t *opt,
Bool_t withInfo = kTRUE;
Bool_t verbose = kFALSE;
Bool_t internalDebug = kFALSE;
Bool_t compileIfDifferent = kFALSE;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Bool_t compileIfDifferent = kFALSE;
Bool_t compileOnlyIfDifferent = kFALSE;


std::string hash_symbol_name = "__ROOT_Internal_CompileMacro_";
if (compileIfDifferent) {
std::ifstream inputFile(expFileName);
Copy link
Member

Choose a reason for hiding this comment

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

We should check both the source and the optional corresponding header file.

// Add to the dictionary the symbol which will be checked
// to avoid to rebuild, unload and reload the library if requested by the user
// with the "h" option
std::ofstream dictfile(dict, std::ios::app);
Copy link
Member

Choose a reason for hiding this comment

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

On windows, this means reopening a file that was just written, it may induced race condition with the file system locks (or maybe not). An alternative is to produce yet another file and have it included in the dictionary source file by rootcling by using, in the LinkDef.h the #pragma extra_include ... line.

Comment on lines +21 to +22
ROOT_EXPECT_INFO(gSystem->CompileMacro(srcFileName, "h"), "ACLiC",
"The macro has been already built and loaded according to its checksum.");
Copy link
Member

@pcanal pcanal Nov 16, 2023

Choose a reason for hiding this comment

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

We should also test that it is NOT being rebuild upon the timestamp being updated and that it IS being rebuild upon the source (or header files) being changed.


std::ofstream srcFile;
srcFile.open(srcFileName);
srcFile << "int testmacro(){return 42;}";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
srcFile << "int testmacro(){return 42;}";
srcFile << "int testmacro(){return 42;}\n";

@ferdymercury ferdymercury modified the milestones: 6.32/00, 6.32.04 Jun 18, 2024
@pcanal pcanal removed this from the 6.32.04 milestone Feb 18, 2025
@pcanal pcanal added this to the 6.36.00 milestone Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants