Skip to content

Commit

Permalink
Resurrect GPU autodetection.
Browse files Browse the repository at this point in the history
Fixes issue #1632.

Pull request #1633.
  • Loading branch information
ihavnoid authored and gcp committed Jul 18, 2018
1 parent 8e9ca8e commit aaf5392
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 2 additions & 4 deletions src/OpenCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,7 @@ std::vector<size_t> OpenCL::get_sgemm_tuners(void) {
return tuners;
}

void OpenCL::initialize(const int channels, const std::vector<int> & gpus,
bool silent) {
void OpenCL::initialize(const int channels, int gpu, bool silent) {
std::vector<cl::Platform> platforms;
try {
cl::Platform::get(&platforms);
Expand Down Expand Up @@ -1022,8 +1021,7 @@ void OpenCL::initialize(const int channels, const std::vector<int> & gpus,
myprintf("Device score: %d\n", this_score);
}

bool preferred =
std::find(cbegin(gpus), cend(gpus), id) != cend(gpus);
bool preferred = (gpu == id);

if ((this_score > best_score) || preferred) {
best_version = opencl_version;
Expand Down
3 changes: 1 addition & 2 deletions src/OpenCL.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ class OpenCL {
friend class OpenCL_Network;
friend class Tuner;
public:
void initialize(const int channels, const std::vector<int> & gpus,
bool silent = false);
void initialize(const int channels, int gpu, bool silent = false);
void ensure_context_initialized(OpenCLContext & opencl_context);
std::string get_device_name();

Expand Down
7 changes: 5 additions & 2 deletions src/OpenCLScheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@
void OpenCLScheduler::initialize(const int channels) {
// multi-gpu?
auto gpus = cfg_gpus;

// an empty GPU list from the command line represents autodetect.
// put a minus one GPU index here.
if (gpus.empty()) {
gpus = {0};
gpus = {-1};
}

auto silent{false};
Expand All @@ -42,7 +45,7 @@ void OpenCLScheduler::initialize(const int channels) {
for (auto gpu : gpus) {
auto opencl = std::make_unique<OpenCL>();
auto net = std::make_unique<OpenCL_Network>(*opencl);
opencl->initialize(channels, {gpu}, silent);
opencl->initialize(channels, gpu, silent);
m_opencl.push_back(std::move(opencl));
m_networks.push_back(std::move(net));

Expand Down

0 comments on commit aaf5392

Please sign in to comment.