Repository: pytorch/benchmark
Issue: Intel Advisor causes benchmarks to deadlock
Root cause: Resource Mishandling

Hello,

Intel Advisor causes benchmarks to deadlock. I wanted to use it to make Roofline plots.
Please advise if there's any workaround we could use.

Thanks!

<details>
 advisor --collect=survey --project-dir=/external/advisor_logs pytest test_bench.py --ignore_machine_config --cpu_only -k resnet50_prequantized -v --benchmark-verbose --full-trace
Intel(R) Advisor Command Line Tool
Copyright (C) 2009-2021 Intel Corporation. All rights reserved.
advisor: Collection started. To stop the collection, either press CTRL-C or enter from another console window: advisor -r /external/advisor_logs/e000/hs002 -command stop.
^CTraceback (most recent call last):
  File "/usr/local/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/usr/local/bin/pytest", line 8, in <module>
    sys.exit(console_main())
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 185, in console_main
    code = main()
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 143, in main
    config = _prepareconfig(args, plugins)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 318, in _prepareconfig
    config = pluginmanager.hook.pytest_cmdline_parse(
  File "/usr/local/lib/python3.8/dist-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/usr/local/lib/python3.8/dist-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python3.8/dist-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/usr/local/lib/python3.8/dist-packages/pluggy/callers.py", line 203, in _multicall
    gen.send(outcome)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/helpconfig.py", line 100, in pytest_cmdline_parse
    config: Config = outcome.get_result()
  File "/usr/local/lib/python3.8/dist-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.8/dist-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 1003, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 1283, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 1191, in _preparse
    self.hook.pytest_load_initial_conftests(
  File "/usr/local/lib/python3.8/dist-packages/pluggy/hooks.py", line 286, in __call__
    return self._hookexec(self, self.get_hookimpls(), kwargs)
  File "/usr/local/lib/python3.8/dist-packages/pluggy/manager.py", line 93, in _hookexec
    return self._inner_hookexec(hook, methods, kwargs)
  File "/usr/local/lib/python3.8/dist-packages/pluggy/manager.py", line 84, in <lambda>
    self._inner_hookexec = lambda hook, methods, kwargs: hook.multicall(
  File "/usr/local/lib/python3.8/dist-packages/pluggy/callers.py", line 208, in _multicall
    return outcome.get_result()
  File "/usr/local/lib/python3.8/dist-packages/pluggy/callers.py", line 80, in get_result
    raise ex[1].with_traceback(ex[2])
  File "/usr/local/lib/python3.8/dist-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 1070, in pytest_load_initial_conftests
    self.pluginmanager._set_initial_conftests(early_config.known_args_namespace)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 500, in _set_initial_conftests
    self._try_load_conftest(anchor, namespace.importmode)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 508, in _try_load_conftest
    self._getconftestmodules(anchor, importmode)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 536, in _getconftestmodules
    mod = self._importconftest(conftestpath, importmode)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/config/__init__.py", line 570, in _importconftest
    mod = import_path(conftestpath, mode=importmode)
  File "/usr/local/lib/python3.8/dist-packages/_pytest/pathlib.py", line 524, in import_path
    importlib.import_module(module_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "/usr/local/lib/python3.8/dist-packages/_pytest/assertion/rewrite.py", line 170, in exec_module
    exec(co, module.__dict__)
  File "/external/benchmark/conftest.py", line 4, in <module>
    from torchbenchmark.util.machine_config import get_machine_config, check_machine_configured
  File "/external/benchmark/torchbenchmark/util/machine_config.py", line 6, in <module>
    import cpuinfo
  File "/usr/local/lib/python3.8/dist-packages/cpuinfo/__init__.py", line 7, in <module>
    from cpuinfo.cpuinfo import *
  File "/usr/local/lib/python3.8/dist-packages/cpuinfo/cpuinfo.py", line 170, in <module>
    class DataSource(object):
  File "/usr/local/lib/python3.8/dist-packages/cpuinfo/cpuinfo.py", line 171, in DataSource
    bits = platform.architecture()[0]
  File "/usr/lib/python3.8/platform.py", line 692, in architecture
    fileout = _syscmd_file(executable, '')
  File "/usr/lib/python3.8/platform.py", line 641, in _syscmd_file
    output = subprocess.check_output(['file', '-b', target],
  File "/usr/lib/python3.8/subprocess.py", line 415, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/usr/lib/python3.8/subprocess.py", line 493, in run
    with Popen(*popenargs, **kwargs) as process:
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1660, in _execute_child
    part = os.read(errpipe_read, 50000)
KeyboardInterrupt
^C^C^C^C^C^C^C^C^C^C^C^C^C^CKilled
</details>



The deadlock is because of OpenBLAS threads used by numpy.
Building without numpy resolves the deadlock issue, but Intel Advisor is unable to attach itself to `test_bench.py`, so the tests can be run manually instead, as they would then offer better data anyway.