Skip to content

Commit

Permalink
[RF] Avoid need for R__HAS_CUDA
Browse files Browse the repository at this point in the history
In RooFit, there are checks if ROOT is build with CUDA only in the
`.cxx` implementation files, not in the public headers. We therefore
don't need a `R__HAS_CUDA` in the ROOT configuration.

The `R__HAS_CUDA` flag was only introduced in ROOT 6.26 and it was never
advocated to users, so it should be safe to remove it.
  • Loading branch information
guitargeek committed Oct 24, 2023
1 parent c80403e commit a113110
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 52 deletions.
5 changes: 0 additions & 5 deletions cmake/modules/RootConfiguration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,6 @@ if(CMAKE_USE_PTHREADS_INIT)
else()
set(haspthread undef)
endif()
if(cuda)
set(hascuda define)
else()
set(hascuda undef)
endif()
if(x11)
set(hasxft define)
else()
Expand Down
1 change: 0 additions & 1 deletion config/RConfigure.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#@setresuid@ R__HAS_SETRESUID /**/
#@hasmathmore@ R__HAS_MATHMORE /**/
#@haspthread@ R__HAS_PTHREAD /**/
#@hascuda@ R__HAS_CUDA /**/
#@hasxft@ R__HAS_XFT /**/
#@hascocoa@ R__HAS_COCOA /**/
#@hasvc@ R__HAS_VC /**/
Expand Down
6 changes: 4 additions & 2 deletions roofit/batchcompute/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ ROOT_LINKER_LIBRARY(RooBatchCompute
${CudaDependencies}
)

if(cuda)
target_compile_definitions(RooBatchCompute PUBLIC ROOFIT_CUDA)
endif()

target_include_directories(RooBatchCompute INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/res>)

if(vdt OR builtin_vdt)
Expand Down Expand Up @@ -68,5 +72,3 @@ if (cuda)
ROOT_LINKER_LIBRARY(RooBatchCompute_CUDA src/RooBatchCompute.cu src/ComputeFunctions.cu TYPE SHARED DEPENDENCIES RooBatchCompute)
target_compile_options(RooBatchCompute_CUDA PRIVATE -DRF_ARCH=CUDA -lineinfo --expt-relaxed-constexpr)
endif()

ROOT_INSTALL_HEADERS()
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#include <RConfig.h>

#ifdef R__HAS_CUDA
#ifdef ROOFIT_CUDA
#include <RooFit/Detail/CudaInterface.h>
#endif

Expand Down Expand Up @@ -53,17 +53,15 @@ void init();
/// the RooBatchCompute library.
class Config {
public:
#ifdef R__HAS_CUDA
#ifdef ROOFIT_CUDA
bool useCuda() const { return _cudaStream != nullptr; }
void setCudaStream(RooFit::Detail::CudaInterface::CudaStream *cudaStream) { _cudaStream = cudaStream; }
RooFit::Detail::CudaInterface::CudaStream *cudaStream() const { return _cudaStream; }
#else
bool useCuda() const { return false; }
#endif

private:
#ifdef R__HAS_CUDA
RooFit::Detail::CudaInterface::CudaStream *_cudaStream = nullptr;
#else
bool useCuda() const { return false; }
#endif
};

Expand Down
4 changes: 2 additions & 2 deletions roofit/batchcompute/src/Initialisation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ void init()

const std::string userChoice = gEnv->GetValue("RooFit.BatchCompute", "auto");
#ifdef R__RF_ARCHITECTURE_SPECIFIC_LIBS
#ifdef R__HAS_CUDA
#ifdef ROOFIT_CUDA
if(gSystem->Load("libRooBatchCompute_CUDA") != 0) {
RooBatchCompute::dispatchCUDA = nullptr;
}
#endif // R__HAS_CUDA
#endif // ROOFIT_CUDA

__builtin_cpu_init();
#if __GNUC__ > 5 || defined(__clang__)
Expand Down
9 changes: 7 additions & 2 deletions roofit/roofitcore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -488,15 +488,20 @@ ROOT_STANDARD_LIBRARY_PACKAGE(RooFitCore
${EXTRA_DICT_OPTS}
)

# The following definitions are PUBLIC so they can also be used in ROOT-internal tests

if(roofit_legacy_eval_backend)
target_compile_definitions(RooFitCore PRIVATE ROOFIT_LEGACY_EVAL_BACKEND)
target_compile_definitions(RooFitCore PUBLIC ROOFIT_LEGACY_EVAL_BACKEND)
endif()

if(roofit_multiprocess)
# PUBLIC to it can also be used in tests
target_compile_definitions(RooFitCore PUBLIC ROOFIT_MULTIPROCESS)
endif()

if(cuda)
target_compile_definitions(RooFitCore PUBLIC ROOFIT_CUDA)
endif()

target_include_directories(RooFitCore INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/res>)

# For recent clang, this can facilitate auto-vectorisation.
Expand Down
4 changes: 0 additions & 4 deletions roofit/roofitcore/inc/RooFit/Evaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,9 @@ class Evaluator {
private:
void processVariable(NodeInfo &nodeInfo);
void setClientsDirty(NodeInfo &nodeInfo);
#ifdef R__HAS_CUDA
std::span<const double> getValHeterogeneous();
void markGPUNodes();
void assignToGPU(NodeInfo &info);
#endif
void computeCPUNode(const RooAbsArg *node, NodeInfo &info);
void setOperMode(RooAbsArg *arg, RooAbsArg::OperMode opMode);
void syncDataTokens();
Expand All @@ -66,9 +64,7 @@ class Evaluator {
int _nEvaluations = 0;
bool _needToUpdateOutputSizes = false;
RooFit::Detail::DataMap _dataMapCPU;
#ifdef R__HAS_CUDA
RooFit::Detail::DataMap _dataMapCUDA;
#endif
std::vector<NodeInfo> _nodes; // the ordered computation graph
std::stack<std::unique_ptr<ChangeOperModeRAII>> _changeOperModeRAIIs;
};
Expand Down
14 changes: 7 additions & 7 deletions roofit/roofitcore/src/Buffers.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <queue>
#include <map>

#ifdef R__HAS_CUDA
#ifdef ROOFIT_CUDA
namespace CudaInterface = RooFit::Detail::CudaInterface;
using CudaInterface::CudaStream;
#endif
Expand Down Expand Up @@ -68,7 +68,7 @@ class CPUBufferContainer {
std::vector<double> _vec;
};

#ifdef R__HAS_CUDA
#ifdef ROOFIT_CUDA
class GPUBufferContainer {
public:
GPUBufferContainer(std::size_t size) : _arr(size) {}
Expand Down Expand Up @@ -140,7 +140,7 @@ class PinnedBufferContainer {
CudaStream *_cudaStream = nullptr;
mutable LastAccessType _lastAccess = LastAccessType::CPU_READ;
};
#endif // R__HAS_CUDA
#endif // ROOFIT_CUDA

template <class Container>
class BufferImpl : public AbsBuffer {
Expand Down Expand Up @@ -175,15 +175,15 @@ class BufferImpl : public AbsBuffer {

using ScalarBuffer = BufferImpl<ScalarBufferContainer>;
using CPUBuffer = BufferImpl<CPUBufferContainer>;
#ifdef R__HAS_CUDA
#ifdef ROOFIT_CUDA
using GPUBuffer = BufferImpl<GPUBufferContainer>;
using PinnedBuffer = BufferImpl<PinnedBufferContainer>;
#endif

struct BufferQueuesMaps {
ScalarBuffer::QueuesMap scalarBufferQueuesMap;
CPUBuffer::QueuesMap cpuBufferQueuesMap;
#ifdef R__HAS_CUDA
#ifdef ROOFIT_CUDA
GPUBuffer::QueuesMap gpuBufferQueuesMap;
PinnedBuffer::QueuesMap pinnedBufferQueuesMap;
#endif
Expand All @@ -204,7 +204,7 @@ std::unique_ptr<AbsBuffer> BufferManager::makeCpuBuffer(std::size_t size)
{
return std::make_unique<CPUBuffer>(size, _queuesMaps->cpuBufferQueuesMap);
}
#ifdef R__HAS_CUDA
#ifdef ROOFIT_CUDA
std::unique_ptr<AbsBuffer> BufferManager::makeGpuBuffer(std::size_t size)
{
return std::make_unique<GPUBuffer>(size, _queuesMaps->gpuBufferQueuesMap);
Expand All @@ -215,7 +215,7 @@ std::unique_ptr<AbsBuffer> BufferManager::makePinnedBuffer(std::size_t size, Cud
out->vec().setCudaStream(stream);
return out;
}
#endif // R__HAS_CUDA
#endif // ROOFIT_CUDA

} // end namespace Detail
} // end namespace RooFit
4 changes: 2 additions & 2 deletions roofit/roofitcore/src/RooFit/Detail/Buffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include <RConfig.h>

#ifdef R__HAS_CUDA
#ifdef ROOFIT_CUDA
#include <RooFit/Detail/CudaInterface.h>
#endif

Expand Down Expand Up @@ -48,7 +48,7 @@ class BufferManager {

std::unique_ptr<AbsBuffer> makeScalarBuffer();
std::unique_ptr<AbsBuffer> makeCpuBuffer(std::size_t size);
#ifdef R__HAS_CUDA
#ifdef ROOFIT_CUDA
std::unique_ptr<AbsBuffer> makeGpuBuffer(std::size_t size);
std::unique_ptr<AbsBuffer>
makePinnedBuffer(std::size_t size, RooFit::Detail::CudaInterface::CudaStream *stream = nullptr);
Expand Down
Loading

0 comments on commit a113110

Please sign in to comment.