| 59 | namespace tensorrt { |
| 60 | |
| 61 | void* TRTDeviceAllocator::allocate(uint64_t size, uint64_t alignment, |
| 62 | uint32_t flags) noexcept { |
| 63 | if (size == 0) return nullptr; |
| 64 | // WAR for allocator alignment requirement. Certain cuda API calls require GPU |
| 65 | // memory with alignment to cudaDeviceProp::textureAlignment. |
| 66 | // See issue #20856 |
| 67 | alignment = 512; |
| 68 | assert((alignment & (alignment - 1)) == 0); // zero or a power of 2. |
| 69 | uint64_t total_size = size + alignment; |
| 70 | // TODO(aaroey): AllocateRaw takes size_t size as input, so it'll produce |
| 71 | // unexpected result when TRT tries to allocate more bytes than size_t can |
| 72 | // carry. Fix this. |
| 73 | void* mem = allocator_->AllocateRaw(alignment, total_size); |
| 74 | if (!mem) return nullptr; |
| 75 | |
| 76 | void* alloc_mem = mem; |
| 77 | QCHECK(Align(alignment, size, mem, total_size)); |
| 78 | if (mem != alloc_mem) { |
| 79 | QCHECK(mem_map_.insert({mem, alloc_mem}).second); |
| 80 | } |
| 81 | VLOG(2) << "Allocated " << total_size << " bytes memory @" << alloc_mem |
| 82 | << "; aligned to " << size << " bytes @" << mem << " with alignment " |
| 83 | << alignment; |
| 84 | return mem; |
| 85 | } |
| 86 | |
| 87 | TRTDeviceAllocator::TRTDeviceAllocator(Allocator* allocator) |
| 88 | : allocator_(allocator) { |
nothing calls this directly
no test coverage detected