Skip to content

Reference collector receives NULL name for __itt_task_begin after first in PyTorch #178

@nchaimov

Description

@nchaimov

I'm trying to write a tool which will use the __itt_task_begin and __itt_task_end calls emitted by the ITT instrumentation built into PyTorch. To that end, I was experimenting with the reference collector found in this repository, but am finding that it does not work correctly with PyTorch, even though VTune does.

Specifically, with the reference collector, I find that the first call to __itt_task_begin gets logged correctly. However, the second and all subsequent calls yields an Incorrect function call warning, which is due to the __itt_string_handle *name argument being NULL.

The simplest example which demonstrates the problem manually annotates two tasks:

import torch

torch.profiler.itt.range_push("Hello")
torch.profiler.itt.range_push("World")
torch.profiler.itt.range_pop()
torch.profiler.itt.range_pop()

If I run this example with Intel VTune 2023.1.0, the output correctly includes both tasks:

$ vtune -collect hotspots python pytorch_itt_manual.py

[...]
Top Tasks
Task Type  Task Time  Task Count  Average Task Time
---------  ---------  ----------  -----------------
Hello         0.000s           1             0.000s
World         0.000s           1             0.000s

However, if I use the reference collector, only the first task is correctly logged. The second one is invalid, because the name argument is NULL.

$ INTEL_LIBITTNOTIFY_LOG_DIR=$PWD INTEL_LIBITTNOTIFY64=$HOME/ittapi/src/ittnotify_refcol/libittrefcol.so  python pytorch_itt_manual.py
$ cat libittnotify_refcol_202555124144.log
[INFO] __itt_task_begin(...) - functions args: domain=PyTorch handle=Hello
[WARN] __itt_task_begin(...) - Incorrect function call
[INFO] __itt_task_end(...) - functions args: domain=PyTorch
[INFO] __itt_task_end(...) - functions args: domain=PyTorch

The second call to __itt_task_begin doesn't work, nor will any subsequent calls if there are more than two.

My assumption is that the problem is with the reference collector rather than PyTorch, since this works correctly with VTune, although I am not certain of this.

Does anyone have any advice about how I can get the reference collector to get the name handles for all __itt_task_begin annotations emitted by PyTorch?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions