| 88 | } |
| 89 | |
| 90 | string ShapedBuffer::ToString() const { |
| 91 | string s = absl::StrCat( |
| 92 | "ShapedBuffer(", platform_->Name(), ":", device_ordinal(), |
| 93 | "), on-host shape=" + ShapeUtil::HumanStringWithLayout(on_host_shape()), |
| 94 | ", on-device shape=" + |
| 95 | ShapeUtil::HumanStringWithLayout(on_device_shape()), |
| 96 | ":\n"); |
| 97 | ShapeUtil::ForEachSubshape( |
| 98 | on_device_shape(), |
| 99 | [this, &s](const Shape& subshape, const ShapeIndex& index) { |
| 100 | string shape_str; |
| 101 | if (subshape.IsTuple()) { |
| 102 | shape_str = "tuple"; |
| 103 | } else { |
| 104 | shape_str = ShapeUtil::HumanStringWithLayout(subshape); |
| 105 | } |
| 106 | const se::DeviceMemoryBase& memory = buffer(index); |
| 107 | absl::StrAppendFormat(&s, " %s%p (%d bytes) : %s\n", |
| 108 | string(index.size() * 2, ' '), memory.opaque(), |
| 109 | memory.size(), shape_str); |
| 110 | }); |
| 111 | return s; |
| 112 | } |
| 113 | |
| 114 | std::ostream& operator<<(std::ostream& out, const ShapedBuffer& buffer) { |
| 115 | out << buffer.ToString(); |
no test coverage detected