forked from cms-sw/cmssw
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use only CUDA devices with a supported architecture (#286)
For each available CUDA device, check if its architecture is supported running a simple kernel. This allows to restrict using only the supported devices - at configuration time, in the SwitchProducerCUDA, via the cudaIsEnabled test; - at run time, in the CUDAService and its clients; - when running tests, via exitSansCUDADevices.
- Loading branch information
Showing
11 changed files
with
94 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,7 @@ | ||
#include <algorithm> | ||
#include <array> | ||
#include <cstdlib> | ||
#include <iostream> | ||
|
||
#include <cuda_runtime.h> | ||
#include "HeterogeneousCore/CUDAUtilities/interface/supportedCUDADevices.h" | ||
|
||
int main() { | ||
int devices = 0; | ||
auto status = cudaGetDeviceCount(& devices); | ||
if (status != cudaSuccess) { | ||
return EXIT_FAILURE; | ||
} | ||
|
||
int minimumMajor = 6; // min minor is implicitly 0 | ||
|
||
// This approach (requiring all devices are supported) is rather | ||
// conservative. In principle we could consider just dropping the | ||
// unsupported devices. Currently that would be easiest to achieve | ||
// in CUDAService though. | ||
for (int i = 0; i < devices; ++i) { | ||
cudaDeviceProp properties; | ||
cudaGetDeviceProperties(&properties, i); | ||
|
||
if(properties.major < minimumMajor) { | ||
return EXIT_FAILURE; | ||
} | ||
} | ||
|
||
return EXIT_SUCCESS; | ||
return supportedCUDADevices().empty() ? EXIT_FAILURE : EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
HeterogeneousCore/CUDAUtilities/interface/supportedCUDADevices.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef HeterogeneousCore_CUDAUtilities_interface_supportedCUDADevices_h | ||
#define HeterogeneousCore_CUDAUtilities_interface_supportedCUDADevices_h | ||
|
||
#include <vector> | ||
|
||
std::vector<int> supportedCUDADevices(); | ||
|
||
#endif // HeterogeneousCore_CUDAUtilities_interface_supportedCUDADevices_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
HeterogeneousCore/CUDAUtilities/src/supportedCUDADevices.cu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <vector> | ||
|
||
#include <cuda_runtime.h> | ||
|
||
#include "HeterogeneousCore/CUDAUtilities/interface/cudaCheck.h" | ||
#include "HeterogeneousCore/CUDAUtilities/interface/supportedCUDADevices.h" | ||
|
||
__global__ | ||
void isSupported(bool * result) { | ||
* result = true; | ||
} | ||
|
||
std::vector<int> supportedCUDADevices() { | ||
int devices = 0; | ||
auto status = cudaGetDeviceCount(&devices); | ||
if (status != cudaSuccess or devices == 0) { | ||
return {}; | ||
} | ||
|
||
std::vector<int> supportedDevices; | ||
supportedDevices.reserve(devices); | ||
|
||
for (int i = 0; i < devices; ++i) { | ||
cudaCheck(cudaSetDevice(i)); | ||
bool supported = false; | ||
bool * supported_d; | ||
cudaCheck(cudaMalloc(&supported_d, sizeof(bool))); | ||
cudaCheck(cudaMemset(supported_d, 0x00, sizeof(bool))); | ||
isSupported<<<1,1>>>(supported_d); | ||
// swallow any eventual error from launching the kernel on an unsupported device | ||
cudaGetLastError(); | ||
cudaCheck(cudaDeviceSynchronize()); | ||
cudaCheck(cudaMemcpy(& supported, supported_d, sizeof(bool), cudaMemcpyDeviceToHost)); | ||
cudaCheck(cudaFree(supported_d)); | ||
if (supported) { | ||
supportedDevices.push_back(i); | ||
} | ||
cudaCheck(cudaDeviceReset()); | ||
} | ||
|
||
return supportedDevices; | ||
} |