1# Owner(s): ["module: unknown"] 2 3from torch.testing._internal.common_utils import TestCase, run_tests 4import os 5import subprocess 6import sys 7 8class TestMKLDNNVerbose(TestCase): 9 def test_verbose_on(self): 10 num = 0 11 loc = os.path.dirname(os.path.abspath(__file__)) 12 with subprocess.Popen(f'{sys.executable} -u {loc}/mkldnn_verbose.py --verbose-level=1', shell=True, 13 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as p: 14 for line in p.stdout.readlines(): 15 line = str(line, 'utf-8').strip() 16 if line.startswith("onednn_verbose"): 17 num = num + 1 18 elif line == 'Failed to set MKLDNN into verbose mode. Please consider to disable this verbose scope.': 19 return 20 self.assertTrue(num > 0, 'oneDNN verbose messages not found.') 21 22 def test_verbose_off(self): 23 num = 0 24 loc = os.path.dirname(os.path.abspath(__file__)) 25 with subprocess.Popen(f'{sys.executable} -u {loc}/mkldnn_verbose.py --verbose-level=0', shell=True, 26 stdout=subprocess.PIPE, stderr=subprocess.STDOUT) as p: 27 for line in p.stdout.readlines(): 28 line = str(line, 'utf-8').strip() 29 if line.startswith("onednn_verbose"): 30 num = num + 1 31 self.assertEqual(num, 0, 'unexpected oneDNN verbose messages found.') 32 33if __name__ == '__main__': 34 run_tests() 35