文章(4)简要介绍了OpContextConstruction对象的成员变量。从本文开始,对这些成员变量进行详细分析。首先需要分析的是设备类型和设备这两个对象。
TensorFlow关于设备类型的定义非常简单。它定义在tensorflow/core/framework/types.h中。
class DeviceType {
public:
DeviceType(const char* type) // NOLINT(runtime/explicit)
: type_(type) {}
explicit DeviceType(StringPiece type) : type_(type.data(), type.size()) {}
const char* type() const { return type_.c_str(); }
const string& type_string() const { return type_; }
bool operator<(const DeviceType& other) const;
bool operator==(const DeviceType& other) const;
bool operator!=(const DeviceType& other) const { return !(*this == other); }
private:
string type_;
};
DeviceType类本质上维护了一个字符串。换言之,TensorFlow用一个字符串表示设备类型。目前,TensorFlow支持的设备类型有下面几类,参见tensorflow/core/framework/types.h。
TF_EXPORT extern const char*