Skip to content

Adding --print_statistics and API for querying HAL memory usage. - #6868

Merged
benvanik merged 6 commits into
mainfrom
benvanik-hal-alloc-stats
Aug 25, 2021
Merged

benvanik merged 6 commits into
mainfrom
benvanik-hal-alloc-stats

Conversation

@benvanik

@benvanik benvanik commented Aug 25, 2021 •

Copy link
Copy Markdown
Collaborator

IREE_STATISTICS_ENABLE=1 can now be configured to add APIs
for querying/printing HAL memory statistics. Future changes will
use this macro for other parts of the system (task system dispatch
statistics, etc).

Each HAL backend gets the ability to track statistics as it pleases.
This is useful for allocators that can adjust allocation sizes or are
performing suballocating from larger block pools, etc.

The default heap allocator is the only one populating the stats today.
Future extensions would be to track things like imported/mapped memory
or reach into VMA in Vulkan to query its sizing statistics.

CUDA/ROCM are currently reporting our logical allocations but there
may be driver APIs that could give us better numbers.

Adding --print_statistics to iree-run-module prints:

[[ iree_hal_allocator_t memory statistics ]]
  HOST_LOCAL:            0b peak /            0b allocated /            0b freed /            0b live
DEVICE_LOCAL:    106340864b peak /    106340864b allocated /    106340864b freed /            0b live

Fixes #6845.

@benvanik benvanik added the hal/api IREE's public C hardware abstraction layer API label Aug 25, 2021
@google-cla google-cla Bot added the cla: yes label Aug 25, 2021
@benvanik
benvanik requested review from ScottTodd and hcindyl August 25, 2021 21:09
@benvanik benvanik changed the title Adding --print_memory_statistics and API for querying HAL memory usage. Adding --print_statistics and API for querying HAL memory usage. Aug 25, 2021
Used to guard code that performs programmatic statistics tracking.
Independent from debug/release and tracing so that fully optimized builds
can still track stats if they choose (useful in bare-metal/etc).
Comment thread iree/base/config.h Resolved
Each HAL backend gets the ability to track statistics as it pleases.
This is useful for allocators that can adjust allocation sizes or are
performing suballocating from larger block pools, etc.

The default heap allocator is the only one populating the stats today.
Future extensions would be to track things like imported/mapped memory
or reach into VMA in Vulkan to query its statistics.

Adding --print_statistics to iree-run-module prints:
```
[[ iree_hal_allocator_t memory statistics ]]
  HOST_LOCAL:            0b peak /            0b allocated /            0b freed /            0b live
DEVICE_LOCAL:    106340864b peak /    106340864b allocated /    106340864b freed /            0b live
```

Fixes #6845.
This uses the VMA device memory reporting functions to give us an
accurate size of actual device memory consumed (vs what we think we
allocate):
```
[[ iree_hal_allocator_t memory statistics ]]
  HOST_LOCAL:      8388608b peak /      8388608b allocated /            0b freed /      8388608b live
DEVICE_LOCAL:      3506176b peak /      3506176b allocated /            0b freed /      3506176b live
```
This reports the amount of memory we ask for but not what CUDA may be
allocating under the covers:
```
[[ iree_hal_allocator_t memory statistics ]]
  HOST_LOCAL:           32b peak /           32b allocated /           32b freed /            0b live
DEVICE_LOCAL:           16b peak /           16b allocated /           16b freed /            0b live
```
@benvanik
benvanik force-pushed the benvanik-hal-alloc-stats branch from ece6bcc to 15aa194 Compare August 25, 2021 22:30
@benvanik
benvanik requested a review from hcindyl August 25, 2021 22:30
@benvanik
benvanik marked this pull request as ready for review August 25, 2021 22:36
Comment on lines -78 to +141
create_info.pDeviceMemoryCallbacks = NULL;
create_info.pDeviceMemoryCallbacks = &device_memory_callbacks;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome that there's a place to insert callbacks already :D

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's pretty apparent from its API that VMA is heavily used by people doing real stuff - lots of good inspiration in there!

@benvanik
benvanik enabled auto-merge August 25, 2021 22:37
@benvanik
benvanik merged commit 7158a83 into main Aug 25, 2021
@benvanik
benvanik deleted the benvanik-hal-alloc-stats branch August 25, 2021 23:20
@hanhanW hanhanW mentioned this pull request Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hal/api IREE's public C hardware abstraction layer API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an iree_hal_allocator_t shim that reports memory usage information during execution.

3 participants