# CUDACachingAllocator rounding pattern

**URL:** <https://dev-discuss.pytorch.org/t/cudacachingallocator-rounding-pattern/1307>\
**Category:** Uncategorized\
**Created:** [June 3, 2023, 8:39pm UTC](https://dev-discuss.pytorch.org/t/cudacachingallocator-rounding-pattern/1307 "2023-06-03T20:39:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![david-macleod](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/david-macleod/32/1165_2.png) [@david-macleod](https://dev-discuss.pytorch.org/u/david-macleod)\
**Post date:** [June 3, 2023, 8:39pm UTC](https://dev-discuss.pytorch.org/t/cudacachingallocator-rounding-pattern/1307/1 "2023-06-03T20:39:08Z")

</div>

According to [get\_allocation\_size](https://github.com/pytorch/pytorch/blob/main/c10/cuda/CUDACachingAllocator.cpp#L2523) there are three tiers of size, which affect how much we round up the request size when calling cudamalloc.

The [comments](https://github.com/pytorch/pytorch/blob/main/c10/cuda/CUDACachingAllocator.cpp#LL58C1-L59C75) suggest that the reason for rounding to 20 mb for 1 \<= size \< 10 is to help reduce fragmentation (makes sense), but then for size \>= 10 mb we fall back to a different pattern such that a request for 11 mb results in a smaller cudamalloc assignment than 9 mb (see plot below)

I was just curious what the reason for this was

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/pytorch1/original/2X/0/04faeed1ce841679b6de5e60dcbe73a379ddf28e.png)
