23 const std::vector<std::string> tokens =
25 if (tokens.size() == 2) {
27 if (device_type_lower ==
"cpu") {
29 }
else if (device_type_lower ==
"cuda") {
31 }
else if (device_type_lower ==
"sycl") {
35 "Invalid device string {}. Valid device strings are like "
36 "\"CPU:0\", \"CUDA:1\" or \"SYCL:0\"",
41 "Invalid device string {}. Valid device strings are like "
42 "\"CPU:0\", \"CUDA:1\" or \"SYCL:0\"",
48 const std::vector<std::string> tokens =
50 if (tokens.size() == 2) {
51 return std::stoi(tokens[1]);
54 "Invalid device string {}. Valid device strings are like "
55 "\"CPU:0\", \"CUDA:1\" or \"SYCL:0\"",
61 : device_type_(device_type), device_id_(device_id) {
110 if (device == *
this) {
121 std::vector<Device> devices;
122 devices.insert(devices.end(), cpu_devices.begin(), cpu_devices.end());
123 devices.insert(devices.end(), cuda_devices.begin(), cuda_devices.end());
124 devices.insert(devices.end(), sycl_devices.begin(), sycl_devices.end());
133 std::vector<Device> devices;
static std::vector< Device > GetAvailableSYCLDevices()
Returns a vector of available SYCL device.
Device()=default
Default constructor -> "CPU:0".
static std::vector< Device > GetAvailableCUDADevices()
Returns a vector of available CUDA device.
static std::vector< Device > GetAvailableDevices()
Returns a vector of available devices.
DeviceType
Type for device.
bool operator==(const Device &other) const
static std::vector< Device > GetAvailableCPUDevices()
Returns a vector of available CPU device.
std::string ToString() const
Returns string representation of device, e.g. "CPU:0", "CUDA:0".
bool operator!=(const Device &other) const
static void PrintAvailableDevices()
Print all available devices.
bool operator<(const Device &other) const
bool IsAvailable() const
Returns true if the device is available.
Helper functions for the ml ops.
std::vector< Device > GetAvailableSYCLDevices()
Return a list of available SYCL devices.
static Device::DeviceType StringToDeviceType(const std::string &type_colon_id)
static int StringToDeviceId(const std::string &type_colon_id)
void SplitString(std::vector< std::string > &tokens, const std::string &str, const std::string &delimiters=" ", bool trim_empty_str=true)
std::string ToLower(const std::string &s)
Convert string to the lower case.
Generic file read and write utility for python interface.
std::string to_string(const T &n)