tensorflow/stream_executor/gpu/redzone_allocator.cc
// Check that redzones weren't overwritten on a host.
//
// Slower, but gives a more useful error message.
Check that redzones weren't overwritten on a host.
Slower, but gives a more useful error message.
Check that redzones weren ' t overwritten on a host . Slower but gives a more useful error message .
static port::StatusOr<RedzoneCheckStatus> CheckRedzoneHost(
    DeviceMemoryBase redzone, DeviceMemoryBase user_allocation,
    absl::string_view name, Stream* stream, uint8 redzone_pattern) {
  uint64_t size = redzone.size();
  auto redzone_data = absl::make_unique<uint8[]>(size);
  TF_RETURN_IF_ERROR(stream->ThenMemcpy(redzone_data.get(), redzone, size)
                         .BlockHostUntilDone());
  std::array<uint8, sizeof(uint64_t)> pattern_arr;
  pattern_arr.fill(redzone_pattern);
  uint64_t pattern64;
  std::memcpy(&pattern64, pattern_arr.data(), sizeof(uint64_t));
  int64_t i;
  for (i = 0; i + 7 < size; i += sizeof(uint64_t)) {
    uint64_t rz_value = *reinterpret_cast<uint64_t*>(&redzone_data[i]);
    if (rz_value != pattern64) {
      return RedzoneCheckStatus(name, user_allocation.opaque(), i, pattern64,
                                rz_value);
    }
  }
  for (; i < size; ++i) {
    uint8 rz_value = redzone_data[i];
    if (rz_value != redzone_pattern) {
      return RedzoneCheckStatus(name, user_allocation.opaque(), i,
                                redzone_pattern, rz_value);
    }
  }
  return RedzoneCheckStatus::OK();
}
static port :: StatusOr < RedzoneCheckStatus > CheckRedzoneHost ( DeviceMemoryBase redzone , DeviceMemoryBase user_allocation , absl :: string_view name , Stream * stream , uint8 redzone_pattern ) { uint64_t size = redzone . size ( ) ; auto redzone_data = absl :: make_unique < uint8 [ ] > ( size ) ; TF_RETURN_IF_ERROR ( stream -> ThenMemcpy ( redzone_data . get ( ) , redzone , size ) . BlockHostUntilDone ( ) ) ; std :: array < uint8 , sizeof ( uint64_t ) > pattern_arr ; pattern_arr . fill ( redzone_pattern ) ; uint64_t pattern64 ; std :: memcpy ( & pattern64 , pattern_arr . data ( ) , sizeof ( uint64_t ) ) ; int64_t i ; for ( i = 0 ; i + 7 < size ; i += sizeof ( uint64_t ) ) { uint64_t rz_value = * reinterpret_cast < uint64_t * > ( & redzone_data [ i ] ) ; if ( rz_value != pattern64 ) { return RedzoneCheckStatus ( name , user_allocation . opaque ( ) , i , pattern64 , rz_value ) ; } } for ( ; i < size ; ++ i ) { uint8 rz_value = redzone_data [ i ] ; if ( rz_value != redzone_pattern ) { return RedzoneCheckStatus ( name , user_allocation . opaque ( ) , i , redzone_pattern , rz_value ) ; } } return RedzoneCheckStatus :: OK ( ) ; }
Check that redzones weren't overwritten on a host.
Check that redzones weren ' t overwritten on a host .