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

Function GetAllocator

tensorflow/compiler/jit/kernels/xla_ops.cc:183–199  ·  view source on GitHub ↗

Return allocator from platform info if non-null, or populate and return a pointer to the allocator adapter with allocator from context. This is necessary because for XLA devices the underlying TF allocator returns dummy tensors.

Source from the content-addressed store, hash-verified

181// This is necessary because for XLA devices the underlying TF allocator returns
182// dummy tensors.
183static std::shared_ptr<se::DeviceMemoryAllocator> GetAllocator(
184 OpKernelContext* ctx, const XlaPlatformInfo& platform_info) {
185 if (platform_info.custom_allocator()) {
186 return platform_info.custom_allocator();
187 }
188 auto *alloc = ctx->device()->GetAllocator({});
189 auto dc = ctx->op_device_context();
190 if (!dc) {
191 // Stream is not set for the host platform.
192 se::Platform* platform =
193 se::MultiPlatformManager::PlatformWithId(platform_info.platform_id())
194 .ValueOrDie();
195 return std::make_shared<se::TfAllocatorAdapter>(alloc, platform);
196 } else {
197 return std::make_shared<se::TfAllocatorAdapter>(alloc, dc->stream());
198 }
199}
200
201} // namespace
202

Callers 2

CompileToLocalExecutableFunction · 0.70
ComputeMethod · 0.70

Calls 6

custom_allocatorMethod · 0.80
platform_idMethod · 0.80
GetAllocatorMethod · 0.45
deviceMethod · 0.45
op_device_contextMethod · 0.45
streamMethod · 0.45

Tested by

no test coverage detected