1 #pragma once 2 3 #include <cstring> 4 #include <sstream> 5 #include <string> 6 #include <utility> 7 8 namespace chainerx { 9 10 class Backend; 11 12 class DeviceId { 13 public: 14 DeviceId(const std::string& device_name); // NOLINT DeviceId(std::string backend_name,int index)15 DeviceId(std::string backend_name, int index) : backend_name_{std::move(backend_name)}, index_{index} {} 16 backend_name()17 const std::string& backend_name() const { return backend_name_; } index()18 int index() const { return index_; } 19 20 std::string ToString() const; 21 22 private: 23 std::string backend_name_; 24 int index_; 25 }; 26 27 inline bool operator==(const DeviceId& lhs, const DeviceId& rhs) { 28 return lhs.backend_name() == rhs.backend_name() && lhs.index() == rhs.index(); 29 } 30 31 inline bool operator!=(const DeviceId& lhs, const DeviceId& rhs) { return !(lhs == rhs); } 32 33 std::ostream& operator<<(std::ostream& os, const DeviceId& device_id); 34 35 } // namespace chainerx 36