Skip to content

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

Closed

Description

@hcindyl

Is there a flag or an existing feature to identify the required hal_buffer size in the IREE codegen flow? It would help us quickly understand the memory usage situation and catch issues like #6826 in codegen time.

Activity

  1. added
    help wanted
    codegen
    on Aug 24, 2021
  2. benvanik commented on Aug 24, 2021

    @benvanik
    Collaborator

    This isn't generally possible in the compiler as any flow control or dynamic shapes or state will prevent it from working - including those induced during lowering: even if the source model doesn't have dynamic behavior we may introduce it for efficiency/code-size reasons. It also assumes that we can reliably perform such analysis: today we overaggressively inline all functions but we really shouldn't be in which case generalized interprocedural lifetime analysis is required and that's... hard. It's like asking clang to spit out how much memory your C code will use at runtime - possible if you never call malloc and never make indirect calls and never stack alloc etc etc - not something you can rely on except in the simple cases where you don't need to rely on it :)

    Tracy does an excellent job showing usage when profiling a model and shows the most important numbers (peak and locality). To catch regressions we should be tracking memory consumption in our benchmarks/tests - this is quite easy to shim in to the HAL and have it print out on exit (total allocation count/bytes allocated/peak usage/etc). Then running your model with your actual input data (including dynamically shaped/stateful inputs) will work.

    (nothing codegen related here, so changing to the above)

  3. changed the title [-]Report hal buffer usage in `iree-translate` or `iree-opt`[/-] [+]Add an `iree_hal_allocator_t` shim that reports memory usage information during execution.[/+] on Aug 24, 2021
  4. added
    hal/api
    enhancement ➕
    and removed
    codegen
    on Aug 24, 2021
  5. hcindyl commented on Aug 24, 2021

    @hcindyl
    ContributorAuthor

    Makes sense. Thanks for the explanation.

  6. self-assigned this
    on Aug 24, 2021
  7. benvanik commented on Aug 24, 2021

    @benvanik
    Collaborator

    I'll see if I can whip a shim up to at least give coarse statistics soon!

  8. hcindyl commented on Aug 24, 2021

    @hcindyl
    ContributorAuthor

    That would be greatly helpful! Thanks for the support!

  9. added 2 commits that reference this issue on Aug 25, 2021
    6c45b16
    8dc07e6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement ➕hal/apihelp wanted

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions