| 52 | } |
| 53 | |
| 54 | TEST(GPUBFCAllocatorTest, NoDups) { |
| 55 | PlatformGpuId platform_gpu_id(0); |
| 56 | GPUMemAllocator* sub_allocator = new GPUMemAllocator( |
| 57 | GpuIdUtil::ExecutorForPlatformGpuId(platform_gpu_id).ValueOrDie(), |
| 58 | platform_gpu_id, false /*use_unified_memory*/, {}, {}); |
| 59 | GPUBFCAllocator a(sub_allocator, 1 << 30, "GPU_0_bfc"); |
| 60 | CheckStats(&a, 0, 0, 0, 0); |
| 61 | |
| 62 | // Allocate a lot of raw pointers |
| 63 | std::vector<void*> ptrs; |
| 64 | for (int s = 1; s < 1024; s++) { |
| 65 | void* raw = a.AllocateRaw(1, s); |
| 66 | ptrs.push_back(raw); |
| 67 | } |
| 68 | CheckStats(&a, 1023, 654336, 654336, 1024); |
| 69 | |
| 70 | std::sort(ptrs.begin(), ptrs.end()); |
| 71 | |
| 72 | // Make sure none of them are equal, and that none of them overlap. |
| 73 | for (size_t i = 1; i < ptrs.size(); i++) { |
| 74 | ASSERT_NE(ptrs[i], ptrs[i - 1]); // No dups |
| 75 | size_t req_size = a.RequestedSize(ptrs[i - 1]); |
| 76 | ASSERT_GT(req_size, 0); |
| 77 | ASSERT_GE(static_cast<char*>(ptrs[i]) - static_cast<char*>(ptrs[i - 1]), |
| 78 | req_size); |
| 79 | } |
| 80 | |
| 81 | for (size_t i = 0; i < ptrs.size(); i++) { |
| 82 | a.DeallocateRaw(ptrs[i]); |
| 83 | } |
| 84 | CheckStats(&a, 1023, 0, 654336, 1024); |
| 85 | } |
| 86 | |
| 87 | TEST(GPUBFCAllocatorTest, AllocationsAndDeallocations) { |
| 88 | PlatformGpuId platform_gpu_id(0); |
nothing calls this directly
no test coverage detected