TensorFlow源码分析(5):TensorFlow的设备类型

本文深入分析TensorFlow的设备类型,探讨DeviceType类如何通过字符串表示设备,如CPU、GPU、SYCL和Eigen的对应关系。尽管列出四种类型,实际上主要为CPU和GPU,SYCL用于异构框架,GPU则涉及CUDA编程。TensorFlow的设备类型不仅标识硬件,也指定了计算方式。
摘要由CSDN通过智能技术生成

文章(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*
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值