| 412 | } |
| 413 | |
| 414 | string GPUUtil::MemoryDebugString(const Device* device, Tensor* tensor) { |
| 415 | string ret; |
| 416 | CHECK(tensor); |
| 417 | const int64 num_bytes = std::min<int64>( |
| 418 | FLAGS_brain_gpu_util_debug_string_maxlen, tensor->TotalBytes()); |
| 419 | void* ptr = (num_bytes > 0) ? GetBase(tensor) : nullptr; |
| 420 | strings::Appendf(&ret, "%p:", ptr); |
| 421 | if (num_bytes > 0) { |
| 422 | auto* dev_info = device->tensorflow_gpu_device_info(); |
| 423 | if (!dev_info) { |
| 424 | strings::StrAppend( |
| 425 | &ret, PrintMemory(reinterpret_cast<const char*>(ptr), num_bytes)); |
| 426 | } else { |
| 427 | string buf; |
| 428 | buf.resize(num_bytes); |
| 429 | DeviceMemoryBase gpu_ptr(ptr, num_bytes); |
| 430 | auto s = dev_info->stream->parent()->SynchronousMemcpyD2H( |
| 431 | gpu_ptr, num_bytes, gtl::string_as_array(&buf)); |
| 432 | strings::StrAppend(&ret, |
| 433 | PrintMemory(gtl::string_as_array(&buf), num_bytes)); |
| 434 | } |
| 435 | } |
| 436 | return ret; |
| 437 | } |
| 438 | |
| 439 | // TODO(pbar) Checksum is called from places without a valid device context. |
| 440 | uint64 GPUUtil::Checksum(Device* gpu_device, |
nothing calls this directly
no test coverage detected