forked from PolusAI/nyxus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
POL5598 SLURM-friendliness for CLI (PolusAI#248)
- Loading branch information
Showing
10 changed files
with
299 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#include "cli_gpu_options.h" | ||
#include "helpers/helpers.h" | ||
|
||
#ifdef USE_GPU | ||
namespace NyxusGpu | ||
{ | ||
bool get_best_device( | ||
// in | ||
const std::vector<int>& devIds, | ||
// out | ||
int& best_id, | ||
std::string& lastCuErmsg); | ||
} | ||
#endif | ||
|
||
bool GpuOptions::empty() | ||
{ | ||
return raw_use_gpu.empty(); | ||
} | ||
|
||
void GpuOptions::set_using_gpu(bool use) | ||
{ | ||
using_gpu_ = use; | ||
} | ||
|
||
bool GpuOptions::get_using_gpu() | ||
{ | ||
return using_gpu_; | ||
} | ||
|
||
bool GpuOptions::set_single_device_id(int id) | ||
{ | ||
if (get_using_gpu()) | ||
{ | ||
this->best_device_id_ = id; | ||
return true; | ||
} | ||
else | ||
return false; | ||
} | ||
|
||
int GpuOptions::get_single_device_id() | ||
{ | ||
return best_device_id_; | ||
} | ||
|
||
bool GpuOptions::parse_input (std::string & ermsg) | ||
{ | ||
#ifdef USE_GPU | ||
|
||
auto u = Nyxus::toupper (this->raw_use_gpu); | ||
if (u.length() == 0) | ||
{ | ||
set_using_gpu (false); | ||
} | ||
else | ||
{ | ||
auto t = Nyxus::toupper("true"), | ||
f = Nyxus::toupper("false"); | ||
if (u != t && u != f) | ||
{ | ||
ermsg = "valid values are " + t + " or " + f; | ||
return false; | ||
} | ||
set_using_gpu (u == t); | ||
|
||
// process user's GPU device choice | ||
if (get_using_gpu()) | ||
{ | ||
std::vector<int> devIds; | ||
|
||
if (! this->raw_requested_device_ids.empty()) | ||
{ | ||
// user input -> vector of IDs | ||
std::vector<std::string> S; | ||
Nyxus::parse_delimited_string (this->raw_requested_device_ids, ",", S); | ||
// examine those IDs | ||
for (const auto& s : S) | ||
{ | ||
if (!s.empty()) | ||
{ | ||
// string -> int | ||
int id; | ||
if (sscanf (s.c_str(), "%d", &id) != 1 || id < 0) | ||
{ | ||
ermsg = s + ": expecting a non-negative integer"; | ||
return false; | ||
} | ||
devIds.push_back (id); | ||
} | ||
} | ||
} | ||
else | ||
devIds.push_back (0); // user did not requested a specific ID, so default it to 0 | ||
|
||
// given a set of suggested devices, choose the least memory-busy one | ||
int best_id = -1; | ||
std::string lastCuErmsg; | ||
if (! NyxusGpu::get_best_device(devIds, best_id, lastCuErmsg)) | ||
{ | ||
ermsg = "cannot use any of GPU devices in " + Nyxus::virguler<int> (devIds) + " due to " + lastCuErmsg; | ||
return false; | ||
} | ||
|
||
// we found at least one workable | ||
this->best_device_id_ = best_id; | ||
} | ||
} | ||
|
||
return true; | ||
|
||
#else | ||
|
||
ermsg = "To have GPU options available, use a Nyxus version with GPU support enabled"; | ||
set_using_gpu (false); | ||
return false; | ||
|
||
#endif | ||
} |
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,30 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
class GpuOptions | ||
{ | ||
public: | ||
// parses "raw_use_gpu" and "raw_requested_device_ids" | ||
bool parse_input (std::string & ermsg); | ||
|
||
// true if the parameters have never been specified via "raw_*" | ||
bool empty(); | ||
|
||
// accessor of the "using" status | ||
void set_using_gpu(bool use); | ||
bool get_using_gpu(); | ||
|
||
// accessor of active device ID | ||
bool set_single_device_id(int id); | ||
int get_single_device_id(); | ||
|
||
// exposed to command line processor | ||
std::string raw_use_gpu; | ||
std::string raw_requested_device_ids; | ||
|
||
private: | ||
bool using_gpu_ = false; | ||
int best_device_id_ = -1; | ||
}; |
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
Oops, something went wrong.