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

Class AllocatorAttributes

tensorflow/core/framework/allocator.h:304–338  ·  view source on GitHub ↗

A tensorflow Op may need access to different kinds of memory that are not simply a function of the device to which the Op has been assigned. For example, an Op executing on a GPU may still need to allocate CPU RAM for some purpose. Internal to the tensorflow runtime we may choose to allocate CPU ram from special regions that have been prepared for higher performance in some use contexts, e.g. do

Source from the content-addressed store, hash-verified

302// attr.set_on_host(true);
303// Allocator* a = allocator(attr);
304struct AllocatorAttributes {
305 void set_on_host(bool v) { value |= (static_cast<int>(v)); }
306 bool on_host() const { return value & 0x1; }
307 void set_nic_compatible(bool v) { value |= (static_cast<int>(v) << 1); }
308 bool nic_compatible() const { return value & (0x1 << 1); }
309 void set_gpu_compatible(bool v) { value |= (static_cast<int>(v) << 2); }
310 bool gpu_compatible() const { return value & (0x1 << 2); }
311 void Merge(AllocatorAttributes other) {
312 value |= other.value;
313 if (scope_id != other.scope_id) {
314 CHECK(scope_id == 0 || other.scope_id == 0)
315 << "At least one scope_id should be zero to merge "
316 "AllocatorAttributes but found this.scope_id="
317 << scope_id << " and other.scope_id=" << other.scope_id;
318 scope_id = scope_id == 0 ? other.scope_id : scope_id;
319 }
320 }
321 // Returns true if the fields set in *this is a subset of or equal to
322 // those set in other.
323 bool IsEqualOrLessRestrictiveThan(const AllocatorAttributes& other) const {
324 return (value | other.value) == other.value;
325 }
326
327 // NOTE: The upper 8 bits of the value are reserved for
328 // device-specific uses. Implementors of a device can interpret these
329 // upper 8 bits in device-specific ways, and ops implemented for those
330 // devices are responsible for setting those 8 bits appropriately.
331 uint32 value = 0;
332 // EXPERIMENTAL: If this is greater than zero, then allocation is delegated to
333 // a named special-purpose allocator on the same device.
334 int32 scope_id = 0;
335
336 // Returns a human readable representation of this.
337 string DebugString() const;
338};
339
340// Returns a trivial implementation of Allocator, which is a process singleton.
341// Access through this function is only intended for use by restricted parts

Callers 15

InitStarClientTagFunction · 0.85
InitStarServerTagFunction · 0.85
ClearMethod · 0.85
ResetMethod · 0.85
ResetMethod · 0.85
ComputeMethod · 0.85
CreateKernelMethod · 0.85
CompileMethod · 0.85
allocate_tempMethod · 0.85
allocate_persistentMethod · 0.85

Calls

no outgoing calls

Tested by 15

CreateOpMethod · 0.68
TESTFunction · 0.68
GetKernelFunction · 0.68
InitTensorMethod · 0.68
DoGatherMethod · 0.68
GetKernelFunction · 0.68
InitTensorMethod · 0.68
DoReduceMethod · 0.68
GetKernelMethod · 0.68
InitTensorMethod · 0.68
DoBroadcastMethod · 0.68
TEST_FFunction · 0.68