()
| 8 | |
| 9 | |
| 10 | def test1(): |
| 11 | mem = ContiguousMemoryAllocator(1024, torch.half, 'cpu') |
| 12 | mem.print_allocation(resolution=100) |
| 13 | a1 = mem.allocate_tensor(64).mul_(0.0).add_(1.0) |
| 14 | mem.print_allocation(resolution=100) |
| 15 | mem.release_tensor(a1) |
| 16 | mem.print_allocation(resolution=100) |
| 17 | a2 = mem.allocate_tensor(64).mul_(0.0).add_(2.0) |
| 18 | a3 = mem.allocate_tensor(256).mul_(0.0).add_(3.0) |
| 19 | a4 = mem.allocate_tensor(128).mul_(0.0).add_(4.0) |
| 20 | mem.print_allocation(resolution=100) |
| 21 | mem.release_tensor(a3) |
| 22 | mem.print_allocation(resolution=100) |
| 23 | a5 = mem.allocate_tensor(64).mul_(0.0).add_(5.0) |
| 24 | a6 = mem.allocate_tensor(256).mul_(0.0).add_(6.0) |
| 25 | a7 = mem.allocate_tensor(128).mul_(0.0).add_(7.0) |
| 26 | mem.print_allocation(resolution=100) |
| 27 | a8 = mem.allocate_tensor(256).mul_(0.0).add_(8.0) |
| 28 | a9 = mem.allocate_tensor(128).mul_(0.0).add_(9.0) |
| 29 | mem.print_allocation(resolution=100) |
| 30 | mem.release_tensor(a9) |
| 31 | mem.release_tensor(a6) |
| 32 | mem.release_tensor(a2) |
| 33 | mem.release_tensor(a5) |
| 34 | |
| 35 | a10 = mem.allocate_tensor(512).mul_(0.0).add_(10.0) |
| 36 | mem.print_allocation(resolution=100) |
| 37 | #print(f"a4:{a4}") |
| 38 | #print(f"a7:{a7}") |
| 39 | #print(f"a8:{a8}") |
| 40 | #print(f"a10:{a10}") |
| 41 | assert (a4.norm() + a7.norm() + a8.norm() + a10.norm()).item() == 474.50, "Test failed" |
| 42 | |
| 43 | |
| 44 | def test2(): |
no test coverage detected