MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / PrepareChunk

Function PrepareChunk

tensorflow/core/common_runtime/pool_allocator.cc:72–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70static const int kPoolAlignment = sizeof(ChunkPrefix);
71
72void* PrepareChunk(void* chunk, size_t alignment, size_t num_bytes) {
73 ChunkPrefix* cp = reinterpret_cast<ChunkPrefix*>(chunk);
74 cp->num_bytes = num_bytes;
75 cp->chunk_ptr = chunk;
76 void* user_ptr = reinterpret_cast<void*>(cp + 1);
77 if (alignment > kPoolAlignment) {
78 // Move user_ptr forward to the first satisfying offset, and write
79 // chunk_ptr just before it.
80 size_t aligned_ptr = reinterpret_cast<size_t>(user_ptr) + alignment;
81 user_ptr = reinterpret_cast<void*>(aligned_ptr & ~(alignment - 1));
82 (reinterpret_cast<ChunkPrefix*>(user_ptr) - 1)->chunk_ptr = chunk;
83 }
84 // Safety check that user_ptr is always past the ChunkPrefix.
85 CHECK_GE(user_ptr, reinterpret_cast<ChunkPrefix*>(chunk) + 1);
86 return user_ptr;
87}
88
89ChunkPrefix* FindPrefix(void* user_ptr) {
90 ChunkPrefix* cp = reinterpret_cast<ChunkPrefix*>(user_ptr) - 1;

Callers 1

AllocateRawMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected