intel-extension-for-pytorch
745 строк · 27.5 Кб
1import unittest2from common_utils import TestCase3from utils.cpuinfo import construct_numa_config4from intel_extension_for_pytorch.cpu.launch import (5CPUPoolList,6Launcher,7DistributedTrainingLauncher,8)
9import os10from os.path import expanduser11import glob12import subprocess13
14
15class TestLauncher(TestCase):16launch_scripts = [17["python", "-m", "intel_extension_for_pytorch.cpu.launch"],18["ipexrun"],19]20
21def find_lib(self, lib_type):22library_paths = []23if "CONDA_PREFIX" in os.environ:24library_paths.append(f'{os.environ["CONDA_PREFIX"]}/lib/')25elif "VIRTUAL_ENV" in os.environ:26library_paths.append(f'{os.environ["VIRTUAL_ENV"]}/lib/')27
28library_paths += [29f'{expanduser("~")}/.local/lib/',30"/usr/local/lib/",31"/usr/local/lib64/",32"/usr/lib/",33"/usr/lib64/",34]35lib_find = False36for lib_path in library_paths:37library_file = f"{lib_path}/lib{lib_type}.so"38matches = glob.glob(library_file)39if len(matches) > 0:40lib_find = True41break42return lib_find43
44def del_env(self, env_name):45if env_name in os.environ:46del os.environ[env_name]47
48def test_memory_allocator_setup(self):49launcher = Launcher()50
51# tcmalloc52find_tcmalloc = self.find_lib("tcmalloc")53launcher.set_memory_allocator(memory_allocator="tcmalloc")54ld_preload = (55":".join(launcher.ld_preload) if len(launcher.ld_preload) > 0 else ""56)57tcmalloc_enabled = "libtcmalloc.so" in ld_preload58self.assertEqual(find_tcmalloc, tcmalloc_enabled)59
60# jemalloc61find_jemalloc = self.find_lib("jemalloc")62launcher.set_memory_allocator(memory_allocator="jemalloc")63ld_preload = (64":".join(launcher.ld_preload) if len(launcher.ld_preload) > 0 else ""65)66jemalloc_enabled = "libjemalloc.so" in ld_preload67self.assertEqual(find_jemalloc, jemalloc_enabled)68if jemalloc_enabled:69self.assertTrue("MALLOC_CONF" in launcher.environ_set)70self.assertTrue(71launcher.environ_set["MALLOC_CONF"]72== "oversize_threshold:1,background_thread:true,metadata_thp:auto"73)74
75self.del_env("MALLOC_CONF")76launcher.set_memory_allocator(memory_allocator="jemalloc", benchmark=True)77if jemalloc_enabled:78self.assertTrue("MALLOC_CONF" in launcher.environ_set)79self.assertTrue(80launcher.environ_set["MALLOC_CONF"]81== "oversize_threshold:1,background_thread:false,metadata_thp:always,dirty_decay_ms:-1,muzzy_decay_ms:-1"82)83
84def test_mpi_pin_domain_and_ccl_worker_affinity(self):85# HT ON, use_logical_cores ON86nprocs_per_node = 287ccl_worker_count = 488lscpu_txt = construct_numa_config(89nprocs_per_node, 28, enable_ht=True, numa_mode=190)91launcher = DistributedTrainingLauncher(lscpu_txt=lscpu_txt)92
93launcher.cpuinfo.gen_pools_ondemand(94ninstances=nprocs_per_node, use_logical_cores=True95)96pin_domain_affinity = launcher.get_pin_domain_affinity(97launcher.cpuinfo.pools_ondemand, ccl_worker_count98)99expect_pin_domain = "[0xffffff0,0xffffff00000000]"100self.assertEqual(pin_domain_affinity["pin_domain"], expect_pin_domain)101expected_ccl_worker_affinity = "0,1,2,3,28,29,30,31"102self.assertEqual(pin_domain_affinity["affinity"], expected_ccl_worker_affinity)103
104# HT ON, use_logical_cores OFF105nprocs_per_node = 2106ccl_worker_count = 4107lscpu_txt = construct_numa_config(108nprocs_per_node, 28, enable_ht=True, numa_mode=1109)110launcher = DistributedTrainingLauncher(lscpu_txt=lscpu_txt)111
112launcher.cpuinfo.gen_pools_ondemand(113ninstances=nprocs_per_node, use_logical_cores=True114)115pin_domain_affinity = launcher.get_pin_domain_affinity(116launcher.cpuinfo.pools_ondemand,117ccl_worker_count,118logical_cores_for_ccl=True,119)120expect_pin_domain = "[0xfffffff,0xfffffff0000000]"121self.assertEqual(pin_domain_affinity["pin_domain"], expect_pin_domain)122expected_ccl_worker_affinity = "56,57,58,59,84,85,86,87"123self.assertEqual(pin_domain_affinity["affinity"], expected_ccl_worker_affinity)124
125# HT OFF, use_logical_cores ON126nprocs_per_node = 2127ccl_worker_count = 4128lscpu_txt = construct_numa_config(129nprocs_per_node, 28, enable_ht=False, numa_mode=1130)131launcher = DistributedTrainingLauncher(lscpu_txt=lscpu_txt)132
133launcher.cpuinfo.gen_pools_ondemand(134ninstances=nprocs_per_node, use_logical_cores=True135)136pin_domain_affinity = launcher.get_pin_domain_affinity(137launcher.cpuinfo.pools_ondemand,138ccl_worker_count,139logical_cores_for_ccl=True,140)141expect_pin_domain = "[0xffffff0,0xffffff00000000]"142self.assertEqual(pin_domain_affinity["pin_domain"], expect_pin_domain)143expected_ccl_worker_affinity = "0,1,2,3,28,29,30,31"144self.assertEqual(pin_domain_affinity["affinity"], expected_ccl_worker_affinity)145
146# nodes_list147nprocs_per_node = 2148ccl_worker_count = 2149lscpu_txt = construct_numa_config(4, 14, enable_ht=True, numa_mode=1)150launcher = DistributedTrainingLauncher(lscpu_txt=lscpu_txt)151
152launcher.cpuinfo.gen_pools_ondemand(153ninstances=nprocs_per_node, nodes_list=[1, 2], use_logical_cores=True154)155pin_domain_affinity = launcher.get_pin_domain_affinity(156launcher.cpuinfo.pools_ondemand, ccl_worker_count157)158expect_pin_domain = "[0xfff0000,0x3ffc0000000]"159self.assertEqual(pin_domain_affinity["pin_domain"], expect_pin_domain)160expected_ccl_worker_affinity = "14,15,28,29"161self.assertEqual(pin_domain_affinity["affinity"], expected_ccl_worker_affinity)162
163# ncores_per_instance164nprocs_per_node = 2165ccl_worker_count = 4166lscpu_txt = construct_numa_config(167nprocs_per_node, 28, enable_ht=True, numa_mode=1168)169launcher = DistributedTrainingLauncher(lscpu_txt=lscpu_txt)170
171launcher.cpuinfo.gen_pools_ondemand(172ninstances=nprocs_per_node,173ncores_per_instance=(8 + ccl_worker_count) * nprocs_per_node,174use_logical_cores=True,175)176pin_domain_affinity = launcher.get_pin_domain_affinity(177launcher.cpuinfo.pools_ondemand, ccl_worker_count178)179expect_pin_domain = "[0xff0,0xff0000]"180self.assertEqual(pin_domain_affinity["pin_domain"], expect_pin_domain)181expected_ccl_worker_affinity = "0,1,2,3,12,13,14,15"182self.assertEqual(pin_domain_affinity["affinity"], expected_ccl_worker_affinity)183
184# e-cores185nprocs_per_node = 2186ccl_worker_count = 4187lscpu_txt = construct_numa_config(188nprocs_per_node, 28, enable_ht=True, n_e_cores=4, numa_mode=0189)190launcher = DistributedTrainingLauncher(lscpu_txt=lscpu_txt)191
192launcher.cpuinfo.gen_pools_ondemand(193ninstances=nprocs_per_node, use_logical_cores=True194)195pin_domain_affinity = launcher.get_pin_domain_affinity(196launcher.cpuinfo.pools_ondemand,197ccl_worker_count,198logical_cores_for_ccl=True,199)200expect_pin_domain = "[0xfffffff,0xfffffff000000000000000]"201self.assertEqual(pin_domain_affinity["pin_domain"], expect_pin_domain)202expected_ccl_worker_affinity = "28,29,30,31,88,89,90,91"203self.assertEqual(pin_domain_affinity["affinity"], expected_ccl_worker_affinity)204
205def test_launcher_scripts(self):206for launch_script in self.launch_scripts:207cmd = launch_script + ["--help"]208r = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)209self.assertEqual(r.returncode, 0)210
211def verify_affinity(self, pools, ground_truth):212self.assertEqual(len(pools), ground_truth["ninstances"])213self.assertEqual(len(pools[0]), ground_truth["ncores_per_instance"])214self.assertEqual(215len(set([c.cpu for p in pools for c in p])), ground_truth["num_cores_sum"]216)217self.assertEqual(218len(set([c.node for p in pools for c in p])), ground_truth["num_nodes_sum"]219)220for i in range(ground_truth["ninstances"]):221self.assertEqual(222len(set([c.cpu for c in pools[i]])), ground_truth["num_cores"][i]223)224self.assertEqual(225len(set([c.node for c in pools[i]])), ground_truth["num_nodes"][i]226)227pool_txt = pools[i].get_pool_txt()228self.assertEqual(pool_txt["cores"], ground_truth["pools_cores"][i])229self.assertEqual(pool_txt["nodes"], ground_truth["pools_nodes"][i])230
231def test_core_affinity(self):232# mode 0233num_nodes = 2234n_phycores_per_node = 28235lscpu_txt = construct_numa_config(236num_nodes, n_phycores_per_node, enable_ht=True, numa_mode=0237)238cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)239ground_truth = {240"ninstances": 1,241"ncores_per_instance": 112,242"num_cores_sum": 112,243"num_nodes_sum": 2,244"num_cores": [112],245"num_nodes": [2],246"pools_cores": ["0-111"],247"pools_nodes": ["0,1"],248}249self.verify_affinity([cpuinfo.pool_all], ground_truth)250
251cpuinfo.gen_pools_ondemand(ninstances=2)252ground_truth = {253"ninstances": 2,254"ncores_per_instance": 28,255"num_cores_sum": 56,256"num_nodes_sum": 2,257"num_cores": [28, 28],258"num_nodes": [1, 1],259"pools_cores": ["0-27", "56-83"],260"pools_nodes": ["0", "1"],261}262self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)263
264cpuinfo.gen_pools_ondemand(ninstances=4)265ground_truth = {266"ninstances": 4,267"ncores_per_instance": 14,268"num_cores_sum": 56,269"num_nodes_sum": 2,270"num_cores": [14, 14, 14, 14],271"num_nodes": [1, 1, 1, 1],272"pools_cores": ["0-13", "14-27", "56-69", "70-83"],273"pools_nodes": ["0", "0", "1", "1"],274}275self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)276
277cpuinfo.gen_pools_ondemand(ncores_per_instance=28)278ground_truth = {279"ninstances": 2,280"ncores_per_instance": 28,281"num_cores_sum": 56,282"num_nodes_sum": 2,283"num_cores": [28, 28],284"num_nodes": [1, 1],285"pools_cores": ["0-27", "56-83"],286"pools_nodes": ["0", "1"],287}288self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)289
290cpuinfo.gen_pools_ondemand(ncores_per_instance=14)291ground_truth = {292"ninstances": 4,293"ncores_per_instance": 14,294"num_cores_sum": 56,295"num_nodes_sum": 2,296"num_cores": [14, 14, 14, 14],297"num_nodes": [1, 1, 1, 1],298"pools_cores": ["0-13", "14-27", "56-69", "70-83"],299"pools_nodes": ["0", "0", "1", "1"],300}301self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)302
303cores_list_local = []304cores_list_local.extend(list(i for i in range(14, 28)))305cores_list_local.extend(list(i for i in range(42, 56)))306cpuinfo.gen_pools_ondemand(cores_list=cores_list_local)307ground_truth = {308"ninstances": 1,309"ncores_per_instance": 28,310"num_cores_sum": 28,311"num_nodes_sum": 1,312"num_cores": [28],313"num_nodes": [1],314"pools_cores": ["14-27,42-55"],315"pools_nodes": ["0"],316}317self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)318
319num_nodes = 4320n_phycores_per_node = 14321lscpu_txt = construct_numa_config(322num_nodes, n_phycores_per_node, enable_ht=True, numa_mode=0323)324cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)325ground_truth = {326"ninstances": 1,327"ncores_per_instance": 112,328"num_cores_sum": 112,329"num_nodes_sum": 4,330"num_cores": [112],331"num_nodes": [4],332"pools_cores": ["0-111"],333"pools_nodes": ["0,1,2,3"],334}335self.verify_affinity([cpuinfo.pool_all], ground_truth)336
337cpuinfo.gen_pools_ondemand(nodes_list=[1, 2])338ground_truth = {339"ninstances": 1,340"ncores_per_instance": 28,341"num_cores_sum": 28,342"num_nodes_sum": 2,343"num_cores": [28],344"num_nodes": [2],345"pools_cores": ["28-41,56-69"],346"pools_nodes": ["1,2"],347}348self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)349
350num_nodes = 2351n_phycores_per_node = 28352lscpu_txt = construct_numa_config(353num_nodes, n_phycores_per_node, enable_ht=True, n_e_cores=4, numa_mode=0354)355cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)356cpuinfo.gen_pools_ondemand(ninstances=2)357ground_truth = {358"ninstances": 2,359"ncores_per_instance": 28,360"num_cores_sum": 56,361"num_nodes_sum": 2,362"num_cores": [28, 28],363"num_nodes": [1, 1],364"pools_cores": ["0-27", "60-87"],365"pools_nodes": ["0", "1"],366}367self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)368
369# mode 1370num_nodes = 2371n_phycores_per_node = 28372lscpu_txt = construct_numa_config(373num_nodes, n_phycores_per_node, enable_ht=True, numa_mode=1374)375cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)376cpuinfo.gen_pools_ondemand(ninstances=1)377ground_truth = {378"ninstances": 1,379"ncores_per_instance": 56,380"num_cores_sum": 56,381"num_nodes_sum": 2,382"num_cores": [56],383"num_nodes": [2],384"pools_cores": ["0-55"],385"pools_nodes": ["0,1"],386}387self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)388
389cpuinfo.gen_pools_ondemand(ninstances=2)390ground_truth = {391"ninstances": 2,392"ncores_per_instance": 28,393"num_cores_sum": 56,394"num_nodes_sum": 2,395"num_cores": [28, 28],396"num_nodes": [1, 1],397"pools_cores": ["0-27", "28-55"],398"pools_nodes": ["0", "1"],399}400self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)401
402cpuinfo.gen_pools_ondemand(ninstances=4)403ground_truth = {404"ninstances": 4,405"ncores_per_instance": 14,406"num_cores_sum": 56,407"num_nodes_sum": 2,408"num_cores": [14, 14, 14, 14],409"num_nodes": [1, 1, 1, 1],410"pools_cores": ["0-13", "14-27", "28-41", "42-55"],411"pools_nodes": ["0", "0", "1", "1"],412}413self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)414
415cpuinfo.gen_pools_ondemand(ncores_per_instance=28)416ground_truth = {417"ninstances": 2,418"ncores_per_instance": 28,419"num_cores_sum": 56,420"num_nodes_sum": 2,421"num_cores": [28, 28],422"num_nodes": [1, 1],423"pools_cores": ["0-27", "28-55"],424"pools_nodes": ["0", "1"],425}426self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)427
428cpuinfo.gen_pools_ondemand(ncores_per_instance=14)429ground_truth = {430"ninstances": 4,431"ncores_per_instance": 14,432"num_cores_sum": 56,433"num_nodes_sum": 2,434"num_cores": [14, 14, 14, 14],435"num_nodes": [1, 1, 1, 1],436"pools_cores": ["0-13", "14-27", "28-41", "42-55"],437"pools_nodes": ["0", "0", "1", "1"],438}439self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)440
441cores_list_local = []442cores_list_local.extend(list(i for i in range(14, 28)))443cores_list_local.extend(list(i for i in range(42, 56)))444cpuinfo.gen_pools_ondemand(ninstances=2, cores_list=cores_list_local)445ground_truth = {446"ninstances": 2,447"ncores_per_instance": 14,448"num_cores_sum": 28,449"num_nodes_sum": 2,450"num_cores": [14, 14],451"num_nodes": [1, 1],452"pools_cores": ["14-27", "42-55"],453"pools_nodes": ["0", "1"],454}455self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)456
457num_nodes = 4458n_phycores_per_node = 14459lscpu_txt = construct_numa_config(460num_nodes, n_phycores_per_node, enable_ht=True, numa_mode=1461)462cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)463cpuinfo.gen_pools_ondemand(ninstances=2, nodes_list=[1, 2])464ground_truth = {465"ninstances": 2,466"ncores_per_instance": 14,467"num_cores_sum": 28,468"num_nodes_sum": 2,469"num_cores": [14, 14],470"num_nodes": [1, 1],471"pools_cores": ["14-27", "28-41"],472"pools_nodes": ["1", "2"],473}474self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)475
476num_nodes = 2477n_phycores_per_node = 28478lscpu_txt = construct_numa_config(479num_nodes, n_phycores_per_node, enable_ht=True, n_e_cores=4, numa_mode=1480)481cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)482cpuinfo.gen_pools_ondemand(ninstances=2)483ground_truth = {484"ninstances": 2,485"ncores_per_instance": 28,486"num_cores_sum": 56,487"num_nodes_sum": 2,488"num_cores": [28, 28],489"num_nodes": [1, 1],490"pools_cores": ["0-27", "28-55"],491"pools_nodes": ["0", "1"],492}493self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)494
495# mode 2496num_nodes = 2497n_phycores_per_node = 28498lscpu_txt = construct_numa_config(499num_nodes, n_phycores_per_node, enable_ht=True, numa_mode=2500)501cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)502cpuinfo.gen_pools_ondemand(ninstances=2)503ground_truth = {504"ninstances": 2,505"ncores_per_instance": 28,506"num_cores_sum": 56,507"num_nodes_sum": 2,508"num_cores": [28, 28],509"num_nodes": [1, 1],510"pools_cores": [511"0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54",512"56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110",513],514"pools_nodes": ["0", "1"],515}516self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)517
518cpuinfo.gen_pools_ondemand(ninstances=4)519ground_truth = {520"ninstances": 4,521"ncores_per_instance": 14,522"num_cores_sum": 56,523"num_nodes_sum": 2,524"num_cores": [14, 14, 14, 14],525"num_nodes": [1, 1, 1, 1],526"pools_cores": [527"0,2,4,6,8,10,12,14,16,18,20,22,24,26",528"28,30,32,34,36,38,40,42,44,46,48,50,52,54",529"56,58,60,62,64,66,68,70,72,74,76,78,80,82",530"84,86,88,90,92,94,96,98,100,102,104,106,108,110",531],532"pools_nodes": ["0", "0", "1", "1"],533}534self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)535
536cpuinfo.gen_pools_ondemand(ncores_per_instance=28)537ground_truth = {538"ninstances": 2,539"ncores_per_instance": 28,540"num_cores_sum": 56,541"num_nodes_sum": 2,542"num_cores": [28, 28],543"num_nodes": [1, 1],544"pools_cores": [545"0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54",546"56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110",547],548"pools_nodes": ["0", "1"],549}550self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)551
552cpuinfo.gen_pools_ondemand(ncores_per_instance=14)553ground_truth = {554"ninstances": 4,555"ncores_per_instance": 14,556"num_cores_sum": 56,557"num_nodes_sum": 2,558"num_cores": [14, 14, 14, 14],559"num_nodes": [1, 1, 1, 1],560"pools_cores": [561"0,2,4,6,8,10,12,14,16,18,20,22,24,26",562"28,30,32,34,36,38,40,42,44,46,48,50,52,54",563"56,58,60,62,64,66,68,70,72,74,76,78,80,82",564"84,86,88,90,92,94,96,98,100,102,104,106,108,110",565],566"pools_nodes": ["0", "0", "1", "1"],567}568self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)569
570cpuinfo.gen_pools_ondemand(ninstances=3)571ground_truth = {572"ninstances": 3,573"ncores_per_instance": 18,574"num_cores_sum": 54,575"num_nodes_sum": 2,576"num_cores": [18, 18, 18],577"num_nodes": [1, 2, 1],578"pools_cores": [579"0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34",580"36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70",581"72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106",582],583"pools_nodes": ["0", "0,1", "1"],584}585self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)586
587cores_list_local = []588cores_list_local.extend(list(i for i in range(14, 28)))589cores_list_local.extend(list(i for i in range(98, 112)))590cpuinfo.gen_pools_ondemand(ninstances=2, cores_list=cores_list_local)591ground_truth = {592"ninstances": 2,593"ncores_per_instance": 14,594"num_cores_sum": 28,595"num_nodes_sum": 2,596"num_cores": [14, 14],597"num_nodes": [1, 1],598"pools_cores": ["14-27", "98-111"],599"pools_nodes": ["0", "1"],600}601self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)602
603num_nodes = 4604n_phycores_per_node = 14605lscpu_txt = construct_numa_config(606num_nodes, n_phycores_per_node, enable_ht=True, numa_mode=2607)608cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)609cpuinfo.gen_pools_ondemand(nodes_list=[1, 2])610ground_truth = {611"ninstances": 1,612"ncores_per_instance": 28,613"num_cores_sum": 28,614"num_nodes_sum": 2,615"num_cores": [28],616"num_nodes": [2],617"pools_cores": [618"28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82"619],620"pools_nodes": ["1,2"],621}622self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)623
624num_nodes = 2625n_phycores_per_node = 28626lscpu_txt = construct_numa_config(627num_nodes, n_phycores_per_node, enable_ht=True, n_e_cores=4, numa_mode=2628)629cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)630cpuinfo.gen_pools_ondemand(ninstances=2)631ground_truth = {632"ninstances": 2,633"ncores_per_instance": 28,634"num_cores_sum": 56,635"num_nodes_sum": 2,636"num_cores": [28, 28],637"num_nodes": [1, 1],638"pools_cores": [639"0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54",640"60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,100,102,104,106,108,110,112,114",641],642"pools_nodes": ["0", "1"],643}644self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)645
646def test_core_affinity_with_logical_cores(self):647num_nodes = 2648n_phycores_per_node = 28649lscpu_txt = construct_numa_config(650num_nodes, n_phycores_per_node, enable_ht=True, numa_mode=1651)652cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)653cpuinfo.gen_pools_ondemand(ninstances=2, use_logical_cores=True)654ground_truth = {655"ninstances": 2,656"ncores_per_instance": 56,657"num_cores_sum": 112,658"num_nodes_sum": 2,659"num_cores": [56, 56],660"num_nodes": [1, 1],661"pools_cores": ["0-27,56-83", "28-55,84-111"],662"pools_nodes": ["0", "1"],663}664self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)665
666def test_core_affinity_with_skip_cross_node_cores(self):667num_nodes = 2668n_phycores_per_node = 28669lscpu_txt = construct_numa_config(670num_nodes, n_phycores_per_node, enable_ht=True, numa_mode=1671)672cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)673cpuinfo.gen_pools_ondemand(ninstances=3, skip_cross_node_cores=True)674ground_truth = {675"ninstances": 3,676"ncores_per_instance": 14,677"num_cores_sum": 42,678"num_nodes_sum": 2,679"num_cores": [14, 14, 14],680"num_nodes": [1, 1, 1],681"pools_cores": ["0-13", "14-27", "28-41"],682"pools_nodes": ["0", "0", "1"],683}684self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)685
686def test_core_affinity_with_skip_cross_node_cores_and_use_logical_core(self):687num_nodes = 2688n_phycores_per_node = 28689lscpu_txt = construct_numa_config(690num_nodes, n_phycores_per_node, enable_ht=True, numa_mode=1691)692cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)693cpuinfo.gen_pools_ondemand(694ninstances=7, use_logical_cores=True, skip_cross_node_cores=True695)696ground_truth = {697"ninstances": 7,698"ncores_per_instance": 14,699"num_cores_sum": 98,700"num_nodes_sum": 2,701"num_cores": [14, 14, 14, 14, 14, 14, 14],702"num_nodes": [1, 1, 1, 1, 1, 1, 1],703"pools_cores": [704"0-6,56-62",705"7-13,63-69",706"14-20,70-76",707"21-27,77-83",708"28-34,84-90",709"35-41,91-97",710"42-48,98-104",711],712"pools_nodes": ["0", "0", "0", "0", "1", "1", "1"],713}714self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)715
716def test_core_affinity_with_skip_cross_node_cores_and_node_id_use_logical_core(717self,718):719num_nodes = 4720n_phycores_per_node = 14721lscpu_txt = construct_numa_config(722num_nodes, n_phycores_per_node, enable_ht=True, numa_mode=1723)724cpuinfo = CPUPoolList(lscpu_txt=lscpu_txt)725cpuinfo.gen_pools_ondemand(726ninstances=3,727nodes_list=[1, 2],728use_logical_cores=True,729skip_cross_node_cores=True,730)731ground_truth = {732"ninstances": 3,733"ncores_per_instance": 14,734"num_cores_sum": 42,735"num_nodes_sum": 2,736"num_cores": [14, 14, 14],737"num_nodes": [1, 1, 1],738"pools_cores": ["14-20,70-76", "21-27,77-83", "28-34,84-90"],739"pools_nodes": ["1", "1", "2"],740}741self.verify_affinity(cpuinfo.pools_ondemand, ground_truth)742
743
744if __name__ == "__main__":745test = unittest.main()746