-
Notifications
You must be signed in to change notification settings - Fork 5
Use only CUDA devices supported by the SCRAM toolfile #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d5a53f0
c75202c
68089fb
fff1f68
0a40bb1
f502337
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h" | ||
| #include "FWCore/Utilities/interface/Exception.h" | ||
| #include "HeterogeneousCore/CUDAServices/interface/CUDAService.h" | ||
| #include "HeterogeneousCore/CUDAUtilities/interface/supportedCUDADevices.h" | ||
|
|
||
| namespace { | ||
| CUDAService makeCUDAService(edm::ParameterSet ps, edm::ActivityRegistry& ar) { | ||
|
|
@@ -29,13 +30,10 @@ TEST_CASE("Tests of CUDAService", "[CUDAService]") { | |
|
|
||
| // Test setup: check if a simple CUDA runtime API call fails: | ||
| // if so, skip the test with the CUDAService enabled | ||
| int deviceCount = 0; | ||
| auto ret = cudaGetDeviceCount( &deviceCount ); | ||
| int deviceCount = supportedCUDADevices().size(); | ||
|
|
||
| if( ret != cudaSuccess ) { | ||
| WARN("Unable to query the CUDA capable devices from the CUDA runtime API: (" | ||
| << ret << ") " << cudaGetErrorString( ret ) | ||
| << ". Running only tests not requiring devices."); | ||
| if (deviceCount == 0) { | ||
| WARN("No supported CUDA devices available. Running only tests not requiring devices."); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be changed to use
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Yes, if we do not build for any of the available devices, we should skip those tests as well. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about using the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not very familiar with how the test harness works, but if I understand the intent, you wanted to run part of the tests even if there are no available devices: SECTION("Enabled only if there are CUDA capable GPUs") {
auto cs = makeCUDAService(ps, ar);
if(deviceCount <= 0) {
REQUIRE(cs.enabled() == false);
WARN("CUDAService is disabled as there are no CUDA GPU devices");
}
else {
REQUIRE(cs.enabled() == true);
INFO("CUDAService is enabled");
}
}If we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, so I was not able read my own code. |
||
| } | ||
|
|
||
| SECTION("CUDAService enabled") { | ||
|
|
@@ -58,6 +56,7 @@ TEST_CASE("Tests of CUDAService", "[CUDAService]") { | |
| } | ||
|
|
||
| auto cs = makeCUDAService(ps, ar); | ||
| cudaError_t ret; | ||
|
|
||
| SECTION("CUDA Queries") { | ||
| int driverVersion = 0, runtimeVersion = 0; | ||
|
|
||
| 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 |
| 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; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.