Skip to content

Commit

Permalink
Disable GPU methods if no device available (#1213)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvilpas authored and chriseclectic committed Apr 14, 2021
1 parent 89b5a1b commit 1d95e90
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/controllers/aer_controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,12 @@ void Controller::set_config(const json_t &config) {
throw std::runtime_error(
"Simulation device \"GPU\" is not supported on this system");
#else
int nDev;
if (cudaGetDeviceCount(&nDev) != cudaSuccess) {
cudaGetLastError();
throw std::runtime_error("No CUDA device available!");
}

sim_device_ = Device::GPU;
#endif
}
Expand Down
14 changes: 14 additions & 0 deletions src/controllers/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,20 @@ class Controller {
//-------------------------------------------------------------------------

void Controller::set_config(const json_t &config) {
#ifdef AER_THRUST_CUDA
{
std::string method;
if (JSON::get_value(method, "method", config)) {
if(method.find("gpu") != std::string::npos){
int nDev;
if (cudaGetDeviceCount(&nDev) != cudaSuccess) {
cudaGetLastError();
throw std::runtime_error("No CUDA device available!");
}
}
}
}
#endif

// Load validation threshold
JSON::get_value(validation_threshold_, "validation_threshold", config);
Expand Down

0 comments on commit 1d95e90

Please sign in to comment.