Skip to content
Snippets Groups Projects
Commit f6967e9b authored by Christoph Hasse's avatar Christoph Hasse :cartwheel_tone1:
Browse files

replace header hash with hash of header+functor_jitter

parent 1691fac8
No related branches found
No related tags found
1 merge request!2699FunctorFactory, replace CLING backend with native compiler
......@@ -98,6 +98,44 @@ struct FunctorFactory : public extends<Service, Functors::IFactory> {
StatusCode initialize() override {
auto sc = Service::initialize();
// we will fill this buffer with the content of functor_jitter and the
// preprocessed header to then calcuate a hash and write that value into
// m_header_hash which will be used to define a JIT library's filename
std::stringstream buffer;
// first we need to find the "functor_jitter" script on the runtime_path.
// That env var looks like "path1:path2:path3...."
auto const runtime_path = System::getEnv( "PATH" );
auto begin = 0U;
auto end = runtime_path.find( ':' );
auto found_functor_jitter = std::filesystem::path{};
while ( end != std::string::npos ) {
auto path = std::filesystem::path{runtime_path.substr( begin, end - begin )};
path.append( "functor_jitter" );
if ( std::filesystem::is_regular_file( path ) ) {
found_functor_jitter = path;
break;
}
// move new begin to just after the ":"
begin = end + 1;
end = runtime_path.find( ':', begin );
}
// if we didn't find anything and break out of the while loop, we need to
// check the last element
if ( end == std::string::npos ) {
auto path = std::filesystem::path{runtime_path.substr( begin, end - begin )};
path.append( "/functor_jitter" );
if ( std::filesystem::is_regular_file( path ) ) { found_functor_jitter = path; }
}
if ( found_functor_jitter.empty() ) {
error() << "Could not find 'functor_jitter' executable on runtime path!" << endmsg;
return StatusCode::FAILURE;
}
debug() << "Calculating hash of: " << found_functor_jitter << endmsg;
buffer << std::ifstream{found_functor_jitter}.rdbuf();
// runtime environment variable which points to the preprocessed header
auto const path_to_header = System::getEnv( "FUNCTORFACTORY_PREPROCESSED_HEADER" );
if ( path_to_header == "UNKNOWN" ) {
......@@ -106,10 +144,10 @@ struct FunctorFactory : public extends<Service, Functors::IFactory> {
return StatusCode::FAILURE;
}
std::stringstream buffer;
buffer << std::ifstream{path_to_header}.rdbuf();
m_header_hash = Functors::Cache::hashToStr( Functors::Cache::makeHash( buffer.str() ) );
debug() << "FunctorFactory initialized with header hash: " << m_header_hash << endmsg;
m_dependencies_hash = Functors::Cache::hashToStr( Functors::Cache::makeHash( buffer.str() ) );
debug() << "Calculating hash of: " << path_to_header << endmsg;
debug() << "FunctorFactory initialized with dependencies hash: " << m_dependencies_hash << endmsg;
return sc;
}
......@@ -129,7 +167,7 @@ struct FunctorFactory : public extends<Service, Functors::IFactory> {
for ( auto const& entry : m_all ) { full_lib_code += entry.second.second; }
full_lib_code += "}";
auto const file_prefix = "FunctorJitLib_" + m_header_hash + "_" +
auto const file_prefix = "FunctorJitLib_" + m_dependencies_hash + "_" +
Functors::Cache::hashToStr( Functors::Cache::makeHash( full_lib_code ) );
auto const lib_filename = file_prefix + ".so";
auto const lib_full_path = m_jit_lib_dir + lib_filename;
......@@ -245,6 +283,7 @@ private:
Gaudi::Details::Property::ImmediatelyInvokeHandler{true}};
std::string m_header_hash{};
std::string m_dependencies_hash{};
LibHandle m_lib_handle{nullptr, lib_closer};
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment