Explicitly cast printed integer types to the primitive type so as to not implicitly rely on whether int64 is long or long long.

PiperOrigin-RevId: 316793291
Change-Id: I6eb74c5d7987fd7ece10e8eef26397e6dd58cf33
This commit is contained in:
A. Unique TensorFlower 2020-06-16 17:49:15 -07:00 committed by TensorFlower Gardener
parent afb849aa36
commit 2bab28aecc
6 changed files with 56 additions and 35 deletions

View File

@ -2822,7 +2822,7 @@ class StatefulOutputRequiredOp : public OpKernel {
void Compute(OpKernelContext* ctx) override { void Compute(OpKernelContext* ctx) override {
// The op counts the number of outputs required in the current subgraph, // The op counts the number of outputs required in the current subgraph,
// and emits that number on each of its required outputs. // and emits that number on each of its required outputs.
Tensor count_outputs_required_t(0LL); Tensor count_outputs_required_t(int64{0});
int64& count_outputs_required = count_outputs_required_t.scalar<int64>()(); int64& count_outputs_required = count_outputs_required_t.scalar<int64>()();
for (int i = 0; i < num_outputs(); ++i) { for (int i = 0; i < num_outputs(); ++i) {
if (ctx->output_required(i)) ++count_outputs_required; if (ctx->output_required(i)) ++count_outputs_required;

View File

@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
==============================================================================*/ ==============================================================================*/
#include <cinttypes>
#include <string> #include <string>
#include "tensorflow/core/platform/env.h" #include "tensorflow/core/platform/env.h"
@ -70,17 +71,18 @@ void PrintChunk(const MemChunk& mc, const uint64 ac_offset, bool freed_at,
// A size class corresponding approximately to log base 100. // A size class corresponding approximately to log base 100.
int size_class = floor(0.5 * log10(static_cast<double>(mc.size()))); int size_class = floor(0.5 * log10(static_cast<double>(mc.size())));
*cumulative_bytes += mc.size(); *cumulative_bytes += mc.size();
printf(" %c %d %p bin=%d bytes=%llu %3.1f%%", mc.in_use() ? 'U' : 'F', printf(" %c %d %p bin=%d bytes=%" PRIu64 " %3.1f%%", mc.in_use() ? 'U' : 'F',
size_class, reinterpret_cast<const void*>(mc.address()), mc.bin(), size_class, reinterpret_cast<const void*>(mc.address()), mc.bin(),
mc.size(), static_cast<uint64_t>(mc.size()),
100 * (*cumulative_bytes / static_cast<float>(total_bytes))); 100 * (*cumulative_bytes / static_cast<float>(total_bytes)));
if (freed_at) { if (freed_at) {
printf(" freed_at=%llu", mc.freed_at_count()); printf(" freed_at=%" PRIu64, static_cast<uint64_t>(mc.freed_at_count()));
} }
if (ac_offset > 0) { if (ac_offset > 0) {
printf(" age=%llu", ac_offset - mc.action_count()); printf(" age=%" PRIu64,
static_cast<uint64_t>(ac_offset - mc.action_count()));
} else { } else {
printf(" ac=%llu", mc.action_count()); printf(" ac=%" PRIu64, static_cast<uint64_t>(mc.action_count()));
} }
// step_ids are random, so save space by showing only low 16 bits. // step_ids are random, so save space by showing only low 16 bits.
printf(" step=%x op=%s\n", static_cast<uint>(0xFFFF & mc.step_id()), printf(" step=%x op=%s\n", static_cast<uint>(0xFFFF & mc.step_id()),
@ -90,18 +92,24 @@ void PrintChunk(const MemChunk& mc, const uint64 ac_offset, bool freed_at,
void PrintSummary(const MemoryDump& md) { void PrintSummary(const MemoryDump& md) {
printf("MemoryMap for allocator %s\n", md.allocator_name().c_str()); printf("MemoryMap for allocator %s\n", md.allocator_name().c_str());
for (auto& it : md.bin_summary()) { for (auto& it : md.bin_summary()) {
printf( printf(" Bin %2d total bytes=%10" PRId64 " \tin use=%10" PRId64
" Bin %2d total bytes=%10lld \tin use=%10lld \ttotal_chunks=%6lld " " \ttotal_chunks=%6" PRId64
"\tin_use=%6lld\n", " "
it.bin(), it.total_bytes_in_bin(), it.total_bytes_in_use(), "\tin_use=%6" PRId64 "\n",
it.total_chunks_in_bin(), it.total_chunks_in_use()); it.bin(), static_cast<int64_t>(it.total_bytes_in_bin()),
static_cast<int64_t>(it.total_bytes_in_use()),
static_cast<int64_t>(it.total_chunks_in_bin()),
static_cast<int64_t>(it.total_chunks_in_use()));
} }
printf( printf("Total num_allocs: %" PRId64 ", bytes_in_use: %" PRId64
"Total num_allocs: %lld, bytes_in_use: %lld, peak_bytes_in_use: %lld,\n" ", peak_bytes_in_use: %" PRId64
"largest_alloc_size: %lld, fragmentation: %f\n", ",\n"
md.stats().num_allocs(), md.stats().bytes_in_use(), "largest_alloc_size: %" PRId64 ", fragmentation: %f\n",
md.stats().peak_bytes_in_use(), md.stats().largest_alloc_size(), static_cast<int64_t>(md.stats().num_allocs()),
md.stats().fragmentation_metric()); static_cast<int64_t>(md.stats().bytes_in_use()),
static_cast<int64_t>(md.stats().peak_bytes_in_use()),
static_cast<int64_t>(md.stats().largest_alloc_size()),
md.stats().fragmentation_metric());
} }
void PrintSortedChunks( void PrintSortedChunks(
@ -125,10 +133,10 @@ void PrintSortedChunks(
for (int i = 0; i < chunks.size(); ++i) { for (int i = 0; i < chunks.size(); ++i) {
const MemChunk* c = chunks[i]; const MemChunk* c = chunks[i];
if (by_addr && i > 0 && last_end != c->address()) { if (by_addr && i > 0 && last_end != c->address()) {
printf(" empty range from %p to %p (%lld)\n", printf(" empty range from %p to %p (%" PRId64 ")\n",
reinterpret_cast<const void*>(last_end), reinterpret_cast<const void*>(last_end),
reinterpret_cast<const void*>(c->address()), reinterpret_cast<const void*>(c->address()),
(c->address() - last_end)); static_cast<int64_t>(c->address() - last_end));
} }
PrintChunk(*c, max_action_count, freed_at, total_bytes, &cumulative_bytes); PrintChunk(*c, max_action_count, freed_at, total_bytes, &cumulative_bytes);
last_end = c->address() + c->size(); last_end = c->address() + c->size();
@ -182,8 +190,8 @@ void PrintChunksByOpName(const MemoryDump& md, const string& op_name,
total_bytes += it.size(); total_bytes += it.size();
} }
} }
printf("\t%d matching Chunks of total size %llu bytes:\n", printf("\t%d matching Chunks of total size %" PRIu64 " bytes:\n",
filtered.chunk_size(), total_bytes); filtered.chunk_size(), static_cast<uint64_t>(total_bytes));
PrintSortedChunks( PrintSortedChunks(
filtered, filtered,
[](const MemChunk* a, const MemChunk* b) { [](const MemChunk* a, const MemChunk* b) {
@ -205,10 +213,13 @@ void PrintSizeHistory(const MemoryDump& md, bool by_age) {
} }
for (auto& it : md.snap_shot()) { for (auto& it : md.snap_shot()) {
if (by_age) { if (by_age) {
printf("\tage=%llu, size=%lld\n", max_action_count - it.action_count(), printf("\tage=%" PRIu64 ", size=%" PRId64 "\n",
it.size()); static_cast<uint64_t>(max_action_count - it.action_count()),
static_cast<int64_t>(it.size()));
} else { } else {
printf("\tac=%llu, size=%lld\n", it.action_count(), it.size()); printf("\tac=%" PRIu64 ", size=%" PRId64 "\n",
static_cast<uint64_t>(it.action_count()),
static_cast<int64_t>(it.size()));
} }
} }
} }

View File

@ -159,7 +159,8 @@ Status SaveDatasetOp::WriteMetadataFile(Env* env, const std::string& path,
uint64 num_elements, bool finalized) { uint64 num_elements, bool finalized) {
SnapshotMetadataRecord metadata; SnapshotMetadataRecord metadata;
metadata.set_creation_timestamp(EnvTime::NowMicros()); metadata.set_creation_timestamp(EnvTime::NowMicros());
metadata.set_run_id(strings::Printf("%llu", run_id)); metadata.set_run_id(
strings::Printf("%llu", static_cast<unsigned long long>(run_id)));
metadata.set_version(kFileFormatVersion); metadata.set_version(kFileFormatVersion);
for (const auto& output_dtype : output_dtypes) { for (const auto& output_dtype : output_dtypes) {
metadata.add_dtype(output_dtype); metadata.add_dtype(output_dtype);

View File

@ -302,9 +302,11 @@ class MapAndBatchDatasetOp::Dataset : public DatasetBase {
} }
auto result = dataset()->traceme_metadata_; auto result = dataset()->traceme_metadata_;
result.push_back(std::make_pair( result.push_back(std::make_pair(
"max_batch_results", strings::Printf("%lld", max_batch_results))); "max_batch_results",
result.push_back( strings::Printf("%lld", static_cast<long long>(max_batch_results))));
std::make_pair("parallelism", strings::Printf("%lld", parallelism))); result.push_back(std::make_pair(
"parallelism",
strings::Printf("%lld", static_cast<long long>(parallelism))));
return result; return result;
} }

View File

@ -50,11 +50,14 @@ namespace snapshot_util {
CustomReader::kSnappyReaderOutputBufferSizeBytes; CustomReader::kSnappyReaderOutputBufferSizeBytes;
std::string HashDirectory(const std::string& path, uint64 hash) { std::string HashDirectory(const std::string& path, uint64 hash) {
return io::JoinPath(path, strings::Printf("%llu", hash)); return io::JoinPath(
path, strings::Printf("%llu", static_cast<unsigned long long>(hash)));
} }
std::string RunDirectory(const std::string& hash_directory, uint64 run_id) { std::string RunDirectory(const std::string& hash_directory, uint64 run_id) {
return RunDirectory(hash_directory, strings::Printf("%llu", run_id)); return RunDirectory(
hash_directory,
strings::Printf("%llu", static_cast<unsigned long long>(run_id)));
} }
std::string RunDirectory(const std::string& hash_directory, std::string RunDirectory(const std::string& hash_directory,
@ -63,13 +66,17 @@ std::string RunDirectory(const std::string& hash_directory,
} }
std::string ShardDirectory(const std::string& run_directory, int64 shard_id) { std::string ShardDirectory(const std::string& run_directory, int64 shard_id) {
return io::JoinPath(run_directory, strings::Printf("%08llu%s", shard_id, return io::JoinPath(
kShardDirectorySuffix)); run_directory,
strings::Printf("%08llu%s", static_cast<unsigned long long>(shard_id),
kShardDirectorySuffix));
} }
std::string GetCheckpointFileName(const std::string& shard_directory, std::string GetCheckpointFileName(const std::string& shard_directory,
uint64 checkpoint_id) { uint64 checkpoint_id) {
return io::JoinPath(shard_directory, return io::JoinPath(
strings::Printf("%08llu.snapshot", checkpoint_id)); shard_directory,
strings::Printf("%08llu.snapshot",
static_cast<unsigned long long>(checkpoint_id)));
} }
Status Writer::Create(Env* env, const std::string& filename, Status Writer::Create(Env* env, const std::string& filename,

View File

@ -486,7 +486,7 @@ class CuptiTraceCollectorImpl : public CuptiTraceCollector {
// Times 2 because HBM is DDR memory; it gets two data bits per each // Times 2 because HBM is DDR memory; it gets two data bits per each
// data lane. // data lane.
auto memory_bandwidth = auto memory_bandwidth =
2ULL * (*mem_clock_khz) * 1000 * (*mem_bus_width_bits) / 8; uint64{2} * (*mem_clock_khz) * 1000 * (*mem_bus_width_bits) / 8;
device_plane->AddStatValue( device_plane->AddStatValue(
*device_plane->GetOrCreateStatMetadata( *device_plane->GetOrCreateStatMetadata(
GetStatTypeStr(StatType::kDevCapMemoryBandwidth)), GetStatTypeStr(StatType::kDevCapMemoryBandwidth)),