Skip to content

Commit

Permalink
Print the NVIDIA and CUDA driver and library versions
Browse files Browse the repository at this point in the history
  • Loading branch information
fwyzard committed Sep 2, 2021
1 parent 9b047a5 commit c31541a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions HeterogeneousCore/CUDAServices/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<use name="FWCore/Utilities"/>
<use name="HeterogeneousCore/CUDAUtilities"/>
<use name="cuda"/>
<use name="cuda-nvml"/>
<export>
<lib name="1"/>
</export>
Expand Down
41 changes: 36 additions & 5 deletions HeterogeneousCore/CUDAServices/src/CUDAService.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
#include <limits>

#include <cuda.h>
#include <cuda_runtime.h>
#include <nvml.h>

#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ParameterSetDescription.h"
#include "FWCore/Utilities/interface/ReusableObjectHolder.h"
#include "HeterogeneousCore/CUDAServices/interface/CUDAService.h"
#include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
#include "HeterogeneousCore/CUDAUtilities/interface/EventCache.h"
#include "HeterogeneousCore/CUDAUtilities/interface/StreamCache.h"
#include "HeterogeneousCore/CUDAUtilities/interface/cachingAllocators.h"
#include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h"
#include "HeterogeneousCore/CUDAUtilities/interface/currentDevice.h"
#include "HeterogeneousCore/CUDAUtilities/interface/device_unique_ptr.h"
#include "HeterogeneousCore/CUDAUtilities/interface/host_unique_ptr.h"
#include "HeterogeneousCore/CUDAUtilities/interface/currentDevice.h"
#include "HeterogeneousCore/CUDAUtilities/interface/cachingAllocators.h"
#include "HeterogeneousCore/CUDAUtilities/interface/nvmlCheck.h"

void setCudaLimit(cudaLimit limit, const char* name, size_t request) {
// read the current device
Expand Down Expand Up @@ -83,6 +86,10 @@ constexpr unsigned int getCudaCoresPerSM(unsigned int major, unsigned int minor)
}
}

std::string decodeVersion(int version) {
return std::to_string(version / 1000) + '.' + std::to_string(version % 1000 / 10);
}

namespace {
template <template <typename> typename UniquePtr, typename Allocate>
void preallocate(Allocate allocate, const std::vector<unsigned int>& bufferSizes) {
Expand Down Expand Up @@ -132,10 +139,34 @@ CUDAService::CUDAService(edm::ParameterSet const& config) : verbose_(config.getU
return;
}
computeCapabilities_.reserve(numberOfDevices_);

// NVIDIA system driver version, e.g. 470.57.02
char systemDriverVersion[NVML_SYSTEM_DRIVER_VERSION_BUFFER_SIZE];
nvmlCheck(nvmlInitWithFlags(NVML_INIT_FLAG_NO_GPUS | NVML_INIT_FLAG_NO_ATTACH));
nvmlCheck(nvmlSystemGetDriverVersion(systemDriverVersion, sizeof(systemDriverVersion)));
nvmlCheck(nvmlShutdown());

// CUDA driver version, e.g. 11.4
// the full version, like 11.4.1 or 11.4.100, is not reported
int driverVersion = 0;
cudaCheck(cudaDriverGetVersion(&driverVersion));

// CUDA runtime version, e.g. 11.4
// the full version, like 11.4.1 or 11.4.108, is not reported
int runtimeVersion = 0;
cudaCheck(cudaRuntimeGetVersion(&runtimeVersion));

edm::LogInfo log("CUDAService");
log << "CUDA runtime successfully initialised, found " << numberOfDevices_ << " compute devices.\n";
if (verbose_) {
log << '\n';
log << "NVIDIA driver: " << systemDriverVersion << '\n';
log << "CUDA driver API: " << decodeVersion(driverVersion) << " (compiled with " << decodeVersion(CUDA_VERSION)
<< ")\n";
log << "CUDA runtime API: " << decodeVersion(runtimeVersion) << " (compiled with " << decodeVersion(CUDART_VERSION)
<< ")\n";
log << "CUDA runtime successfully initialised, found " << numberOfDevices_ << " compute devices.\n\n";
} else {
log << "CUDA runtime version " << decodeVersion(runtimeVersion) << ", driver version "
<< decodeVersion(driverVersion) << ", NVIDIA driver version " << systemDriverVersion << '\n';
}

auto const& limits = config.getUntrackedParameter<edm::ParameterSet>("limits");
Expand Down

0 comments on commit c31541a

Please sign in to comment.