CPU affinity setting of pipeline process when using config_threadpool

@popojames , to set different cpu affinity to different runtime(module), user need to create different thread and call the config function within these different thread like what I mentioned in “Can tvm…” post, following is a example(included a example for Kspecify support in PR #9802).

you can set the break point in ‘t*.start()’ and using "taskset -cpa " to check the affinity changes.

import threading
import time
from tvm._ffi import get_global_func
config_threadpool = get_global_func('runtime.config_threadpool')

def test(name, affinity_type, cpu_list = []):
    print(f"Thread {name} start , type is {type} cpu_list is {cpu_list}")
    if affinity_type == -1:
        config_threadpool(-1, 4)
    elif affinity_type == 1:
        config_threadpool(1, 4)
    else:
        config_threadpool(-2, 4, cpu_list)

    time.sleep(200)
    print(f"Thread {name}: exit")

t1 = threading.Thread(target=test, args=(1, 1))
t2 = threading.Thread(target=test, args=(2, -1))
cpus1 = ['2','3','4','5']
cpus2 = ['6','7','8','9']
t3 = threading.Thread(target=test, args=(3, -2, cpus1))
t4 = threading.Thread(target=test, args=(3, -2, cpus2))
t1.start()
t2.start()
t3.start()
t4.start()
1 Like