Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Initialisation.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Emmanouil Michalainas, CERN, December 2018
5 *
6 * Copyright (c) 2021, CERN
7 *
8 * Redistribution and use in source and binary forms,
9 * with or without modification, are permitted according to the terms
10 * listed in LICENSE (http://roofit.sourceforge.net/license.txt)
11 */
12
13#include "RooBatchCompute.h"
14
15#include "TEnv.h"
16#include "TSystem.h"
17#include "TError.h"
18
19#include <string>
20#include <exception>
21
22// First initialisation of the pointers. When implementations of the batch compute library
23// are loaded, they will overwrite the pointers.
26
27namespace {
28
29/// Dynamically load a library and throw exception in case of failure
30void loadWithErrorChecking(const std::string &libName)
31{
32 const auto returnValue = gSystem->Load(libName.c_str());
33 if (returnValue == -1 || returnValue == -2) {
34 throw std::runtime_error("RooFit was unable to load its computation library " + libName);
35 }
36}
37
38} // end anonymous namespace
39
40namespace RooBatchCompute {
41
42/// Inspect hardware capabilities, and load the optimal library for RooFit computations.
43void init()
44{
45 // Check if the library was not initialised already
46 static bool isInitialised = false;
47 if (isInitialised)
48 return;
49 isInitialised = true;
50
51 const std::string userChoice = gEnv->GetValue("RooFit.BatchCompute", "auto");
52#ifdef R__RF_ARCHITECTURE_SPECIFIC_LIBS
53#ifdef R__HAS_CUDA
54 if(gSystem->Load("libRooBatchCompute_CUDA") != 0) {
56 }
57#endif // R__HAS_CUDA
58
59 __builtin_cpu_init();
60#if __GNUC__ > 5 || defined(__clang__)
61 bool supported_avx512 = __builtin_cpu_supports("avx512cd") && __builtin_cpu_supports("avx512vl") &&
62 __builtin_cpu_supports("avx512bw") && __builtin_cpu_supports("avx512dq");
63#else
64 bool supported_avx512 = false;
65#endif
66
67 if (userChoice == "auto") {
68 if (supported_avx512)
69 loadWithErrorChecking("libRooBatchCompute_AVX512");
70 else if (__builtin_cpu_supports("avx2"))
71 loadWithErrorChecking("libRooBatchCompute_AVX2");
72 else if (__builtin_cpu_supports("avx"))
73 loadWithErrorChecking("libRooBatchCompute_AVX");
74 else if (__builtin_cpu_supports("sse4.1"))
75 loadWithErrorChecking("libRooBatchCompute_SSE4.1");
76 } else if (userChoice == "avx512")
77 loadWithErrorChecking("libRooBatchCompute_AVX512");
78 else if (userChoice == "avx2")
79 loadWithErrorChecking("libRooBatchCompute_AVX2");
80 else if (userChoice == "avx")
81 loadWithErrorChecking("libRooBatchCompute_AVX");
82 else if (userChoice == "sse")
83 loadWithErrorChecking("libRooBatchCompute_SSE4.1");
84 else if (userChoice != "generic")
85 throw std::invalid_argument(
86 "Supported options for `RooFit.BatchCompute` are `auto`, `avx512`, `avx2`, `avx`, `sse`, `generic`.");
87#endif // R__RF_ARCHITECTURE_SPECIFIC_LIBS
88
89 if (RooBatchCompute::dispatchCPU == nullptr)
90 loadWithErrorChecking("libRooBatchCompute_GENERIC");
91}
92
93} // namespace RooBatchCompute
R__EXTERN TEnv * gEnv
Definition TEnv.h:170
R__EXTERN TSystem * gSystem
Definition TSystem.h:559
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:1855
Namespace for dispatching RooFit computations to various backends.
R__EXTERN RooBatchComputeInterface * dispatchCUDA
R__EXTERN RooBatchComputeInterface * dispatchCPU
This dispatch pointer points to an implementation of the compute library, provided one has been loade...
void init()
Inspect hardware capabilities, and load the optimal library for RooFit computations.