Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
CUDAHelpers.cxx
Go to the documentation of this file.
1/*
2 * Project: RooFit
3 * Authors:
4 * Jonas Rembser, CERN 2022
5 *
6 * Copyright (c) 2022, 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 "RooFit/CUDAHelpers.h"
14
15#include <RooBatchCompute.h>
16
17/// Measure the time for transfering data from host to device and vice-versa.
18std::pair<std::chrono::microseconds, std::chrono::microseconds> RooFit::CUDAHelpers::memcpyBenchmark(std::size_t nBytes)
19{
20 using namespace std::chrono;
21
22 std::pair<std::chrono::microseconds, std::chrono::microseconds> ret;
23 auto hostArr = static_cast<double *>(RooBatchCompute::dispatchCUDA->cudaMallocHost(nBytes));
24 auto deviArr = static_cast<double *>(RooBatchCompute::dispatchCUDA->cudaMalloc(nBytes));
25 for (int i = 0; i < 5; i++) {
26 auto start = steady_clock::now();
27 RooBatchCompute::dispatchCUDA->memcpyToCUDA(deviArr, hostArr, nBytes);
28 ret.first += duration_cast<microseconds>(steady_clock::now() - start);
29 start = steady_clock::now();
30 RooBatchCompute::dispatchCUDA->memcpyToCPU(hostArr, deviArr, nBytes);
31 ret.second += duration_cast<microseconds>(steady_clock::now() - start);
32 }
35 ret.first /= 5;
36 ret.second /= 5;
37 return ret;
38}
virtual void memcpyToCPU(void *, const void *, size_t, cudaStream_t *=nullptr)
virtual void memcpyToCUDA(void *, const void *, size_t, cudaStream_t *=nullptr)
R__EXTERN RooBatchComputeInterface * dispatchCUDA
std::pair< std::chrono::microseconds, std::chrono::microseconds > memcpyBenchmark(std::size_t nBytes)
Measure the time for transfering data from host to device and vice-versa.