Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Initialisation.cxx
Go to the documentation of this file.
1#include "RooBatchCompute.h"
2
3#include "TEnv.h"
4#include "TSystem.h"
5
6#include <iostream>
7#include <string>
8#include <exception>
9
10
11// First initialisation of the pointer. When implementations of the batch compute library are loaded,
12// they will overwrite the pointer.
14
15namespace {
16
17////////////////////////////////////////////////////////////////////////////////////////////////////////////////
18/// Dynamically load a library and throw exception in case of failure
19void loadWithErrorChecking(const std::string& libName)
20{
21 const auto returnValue = gSystem->Load(libName.c_str());
22 if (returnValue == -1 || returnValue == -2) {
23 throw std::runtime_error("RooFit was unable to load its computation library " + libName);
24 } else if (returnValue == 1) {
25 // Library should not have been loaded before we tried to do it.
26 throw std::logic_error("RooFit computation library " + libName + " was loaded before RooFit initialisation began.");
27 }
28}
29
30
31////////////////////////////////////////////////////////////////////////////////////////////////////////////////
32/// Inspect hardware capabilities, and load the optimal library for RooFit computations.
33void loadComputeLibrary() {
34
35#ifdef R__RF_ARCHITECTURE_SPECIFIC_LIBS
36
37 // Check if user has requested a specific library architecture in .rootrc
38 const std::string userChoice = gEnv->GetValue("RooFit.ComputationLibraryArch","auto");
39 if (userChoice!="auto" && userChoice!="avx512" && userChoice!="avx2" && userChoice!="avx" && userChoice!="sse4.1" && userChoice!="generic")
40 throw std::invalid_argument("Supported options for `RooFit.ComputationLibraryArch` are `auto`, `avx512`, `avx2`, `avx`, `sse4.1`, `generic`.");
41
42 __builtin_cpu_init();
43#if __GNUC__ > 5 || defined(__clang__)
44 if (__builtin_cpu_supports("avx512cd") && __builtin_cpu_supports("avx512vl") && __builtin_cpu_supports("avx512bw") && __builtin_cpu_supports("avx512dq")
45 && (userChoice=="avx512" || userChoice=="auto") ) {
46 loadWithErrorChecking("libRooBatchCompute_AVX512");
47 return;
48 } else
49#endif
50 if (__builtin_cpu_supports("avx2") && (userChoice=="avx2" || userChoice=="auto")) {
51 loadWithErrorChecking("libRooBatchCompute_AVX2");
52 return;
53 } else if (__builtin_cpu_supports("avx") && (userChoice=="avx" || userChoice=="auto")) {
54 loadWithErrorChecking("libRooBatchCompute_AVX");
55 return;
56 } else if (__builtin_cpu_supports("sse4.1") && (userChoice=="sse4.1" || userChoice=="auto")) {
57 loadWithErrorChecking("libRooBatchCompute_SSE4.1");
58 return;
59 }
60
61#endif //R__RF_ARCHITECTURE_SPECIFIC_LIBS
62
63 if (gDebug>0) {
64 std::cout << "In " << __func__ << "(), " << __FILE__ << ":" << __LINE__ << ": Vector instruction sets not supported, using generic implementation." << std::endl;
65 }
66 loadWithErrorChecking("libRooBatchCompute_GENERIC");
67
68}
69
70} //end anonymous namespace
71
72////////////////////////////////////////////////////////////////////////////////////////////////////////////////
73/// A RAII that performs RooFit's static initialisation.
74static struct RooBatchComputeInitialiser {
75 RooBatchComputeInitialiser() {
76 loadComputeLibrary();
77 }
79
R__EXTERN TEnv * gEnv
Definition TEnv.h:171
Int_t gDebug
Definition TROOT.cxx:590
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
static struct RooBatchComputeInitialiser __RooBatchComputeInitialiser
The interface which should be implemented to provide optimised computation functions for implementati...
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
Definition TEnv.cxx:491
virtual int Load(const char *module, const char *entry="", Bool_t system=kFALSE)
Load a shared library.
Definition TSystem.cxx:1853
R__EXTERN RooBatchComputeInterface * dispatch
This dispatch pointer points to an implementation of the compute library, provided one has been loade...