88import subprocess
99
1010class TestLauncher (TestCase ):
11- def del_env (self , env_name ):
12-
13- if env_name in os .environ :
14- del os .environ [env_name ]
15-
1611 def find_lib (self , lib_type ):
1712 library_paths = []
1813 if "CONDA_PREFIX" in os .environ :
@@ -31,28 +26,21 @@ def find_lib(self, lib_type):
3126 break
3227 return lib_find
3328
34- def test_iomp_memory_allocator_setup (self ):
29+ def test_memory_allocator_setup (self ):
3530 launcher = Launcher ()
36- self .del_env ("OMP_NUM_THREADS" )
37- self .del_env ("LD_PRELOAD" )
38- self .del_env ("KMP_AFFINITY" )
39- self .del_env ("KMP_BLOCKTIME" )
40- launcher .set_multi_thread_and_allocator (10 , disable_iomp = False , enable_tcmalloc = True )
41- find_iomp5 = self .find_lib ("iomp5" )
31+
32+ # tcmalloc
33+ launcher .set_memory_allocator (enable_tcmalloc = True )
4234 find_tcmalloc = self .find_lib ("tcmalloc" )
4335 ld_preload_in_os = "LD_PRELOAD" in os .environ
44- iomp5_enabled = "libiomp5.so" in os .environ ["LD_PRELOAD" ] if ld_preload_in_os else False
4536 tcmalloc_enabled = "libtcmalloc.so" in os .environ ["LD_PRELOAD" ] if ld_preload_in_os else False
46- self .assertEqual (find_iomp5 , iomp5_enabled )
4737 self .assertEqual (find_tcmalloc , tcmalloc_enabled )
48- launcher .set_multi_thread_and_allocator (10 , disable_iomp = False , enable_tcmalloc = False , enable_jemalloc = True )
38+
39+ # jemalloc
40+ launcher .set_memory_allocator (enable_tcmalloc = False , enable_jemalloc = True )
4941 find_jemalloc = self .find_lib ("jemalloc" )
5042 jemalloc_enabled = "libjemalloc.so" in os .environ ["LD_PRELOAD" ] if ld_preload_in_os else False
5143 self .assertEqual (find_jemalloc , jemalloc_enabled )
52- kmp_affinity_enabled = "KMP_AFFINITY" in os .environ and os .environ ["KMP_AFFINITY" ] == "granularity=fine,compact,1,0"
53- block_time_enabled = "KMP_BLOCKTIME" in os .environ and os .environ ["KMP_BLOCKTIME" ] == "1"
54- self .assertEqual (kmp_affinity_enabled , True )
55- self .assertEqual (block_time_enabled , True )
5644 if jemalloc_enabled :
5745 self .assertEqual (jemalloc_enabled , "MALLOC_CONF" in os .environ )
5846
@@ -77,7 +65,7 @@ def test_numactl_core_affinity(self):
7765
7866 if numactl_available :
7967 expected_core_affinity = "numactl -C {}-{}" .format (str (0 ), str (num_physical_cores - 1 ))
80- cmd = ["python" , "-m" , "intel_extension_for_pytorch.cpu.launch" , "--no_python" , "hostname " ]
68+ cmd = ["python" , "-m" , "intel_extension_for_pytorch.cpu.launch" , "--no_python" , "ls " ]
8169 r = subprocess .run (cmd , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
8270 assert r .returncode == 0
8371 assert expected_core_affinity in str (r .stdout , "utf-8" )
@@ -87,7 +75,7 @@ def test_taskset_core_affinity(self):
8775 num_physical_cores = cpuinfo .physical_core_nums ()
8876
8977 expected_core_affinity = "taskset -c {}-{}" .format (str (0 ), str (num_physical_cores - 1 ))
90- cmd = ["python" , "-m" , "intel_extension_for_pytorch.cpu.launch" , "--disable_numactl" , "--no_python" , "hostname " ]
78+ cmd = ["python" , "-m" , "intel_extension_for_pytorch.cpu.launch" , "--disable_numactl" , "--no_python" , "ls " ]
9179 r = subprocess .run (cmd , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
9280 assert r .returncode == 0
9381 assert expected_core_affinity in str (r .stdout , "utf-8" )
@@ -101,7 +89,7 @@ def test_core_affinity_with_skip_cross_node_cores(self):
10189 # ncore_per_instance that guarantees cross-node cores binding without --skip_cross_node_cores
10290 ncore_per_instance = num_cores_per_node - 1
10391
104- cmd = "python -m intel_extension_for_pytorch.cpu.launch --ncore_per_instance {} --skip_cross_node_cores --no_python hostname " .format (ncore_per_instance )
92+ cmd = "python -m intel_extension_for_pytorch.cpu.launch --ncore_per_instance {} --skip_cross_node_cores --no_python ls " .format (ncore_per_instance )
10593 r = subprocess .run (cmd .split (), stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
10694 assert r .returncode == 0
10795
@@ -120,7 +108,7 @@ def test_core_affinity_with_skip_cross_node_cores_and_use_logical_core(self):
120108 # ncore_per_instance that guarantees cross-node cores binding without --skip_cross_node_cores
121109 ncore_per_instance = num_cores_per_node - 1
122110
123- cmd = "python -m intel_extension_for_pytorch.cpu.launch --ncore_per_instance {} --use_logical_core --skip_cross_node_cores --no_python hostname " .format (ncore_per_instance )
111+ cmd = "python -m intel_extension_for_pytorch.cpu.launch --ncore_per_instance {} --use_logical_core --skip_cross_node_cores --no_python ls " .format (ncore_per_instance )
124112 r = subprocess .run (cmd .split (), stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
125113 assert r .returncode == 0
126114
@@ -142,7 +130,7 @@ def test_core_affinity_with_skip_cross_node_cores_and_node_id_use_logical_core(s
142130 # ncore_per_instance that guarantees cross-node cores binding without --skip_cross_node_cores
143131 ncore_per_instance = num_cores_per_node - 1
144132
145- cmd = "python -m intel_extension_for_pytorch.cpu.launch --ncore_per_instance {} --node_id 0 --use_logical_core --skip_cross_node_cores --no_python hostname " .format (ncore_per_instance )
133+ cmd = "python -m intel_extension_for_pytorch.cpu.launch --ncore_per_instance {} --node_id 0 --use_logical_core --skip_cross_node_cores --no_python ls " .format (ncore_per_instance )
146134 r = subprocess .run (cmd .split (), stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
147135 assert r .returncode == 0
148136
@@ -166,7 +154,7 @@ def test_skip_cross_node_cores_with_too_many_ncore_per_instance(self):
166154
167155 expected_msg = "Please make sure --ncore_per_instance < core(s) per socket"
168156
169- cmd = "python -m intel_extension_for_pytorch.cpu.launch --ncore_per_instance {} --skip_cross_node_cores --no_python hostname " .format (ncore_per_instance )
157+ cmd = "python -m intel_extension_for_pytorch.cpu.launch --ncore_per_instance {} --skip_cross_node_cores --no_python ls " .format (ncore_per_instance )
170158 r = subprocess .run (cmd .split (), stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
171159 assert r .returncode != 0
172160 assert expected_msg in str (r .stdout , "utf-8" )
@@ -182,7 +170,7 @@ def test_skip_cross_node_cores_with_divisible_ncore_per_instance(self):
182170
183171 expected_msg = "--skip_cross_node_cores is set, but there are no cross-node cores"
184172
185- cmd = "python -m intel_extension_for_pytorch.cpu.launch --ncore_per_instance {} --skip_cross_node_cores --no_python hostname " .format (ncore_per_instance )
173+ cmd = "python -m intel_extension_for_pytorch.cpu.launch --ncore_per_instance {} --skip_cross_node_cores --no_python ls " .format (ncore_per_instance )
186174 r = subprocess .run (cmd .split (), stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
187175 assert r .returncode == 0
188176 assert expected_msg in str (r .stdout , "utf-8" )
0 commit comments