diff --git a/runtime/hsa-runtime/core/util/flag.h b/runtime/hsa-runtime/core/util/flag.h index 5ce47a4393..86621b7f24 100644 --- a/runtime/hsa-runtime/core/util/flag.h +++ b/runtime/hsa-runtime/core/util/flag.h @@ -159,6 +159,11 @@ class Flag { var = os::GetEnvVar("HSA_SVM_PROFILE"); svm_profile_ = var; + + // Temporary environment variable to disable CPU affinity override + // Will either rename to HSA_OVERRIDE_CPU_AFFINITY later or remove completely. + var = os::GetEnvVar("HSA_OVERRIDE_CPU_AFFINITY_DEBUG"); + override_cpu_affinity_ = (var == "0") ? false : true; } void parse_masks(uint32_t maxGpu, uint32_t maxCU) { @@ -212,6 +217,8 @@ class Flag { bool check_sramecc_validity() const { return check_sramecc_validity_; } + bool override_cpu_affinity() const { return override_cpu_affinity_; } + XNACK_REQUEST xnack() const { return xnack_; } bool debug() const { return debug_; } @@ -252,6 +259,7 @@ class Flag { bool cu_mask_skip_init_; bool coop_cu_count_; bool discover_copy_agents_; + bool override_cpu_affinity_; SDMA_OVERRIDE enable_sdma_; diff --git a/runtime/hsa-runtime/core/util/lnx/os_linux.cpp b/runtime/hsa-runtime/core/util/lnx/os_linux.cpp index 14cbdea69e..87b676413f 100644 --- a/runtime/hsa-runtime/core/util/lnx/os_linux.cpp +++ b/runtime/hsa-runtime/core/util/lnx/os_linux.cpp @@ -59,6 +59,7 @@ #include #include #include +#include "core/inc/runtime.h" namespace rocr { namespace os { @@ -99,16 +100,18 @@ class os_thread { assert(err == 0 && "pthread_attr_setstacksize failed."); } - int cores = get_nprocs_conf(); - cpu_set_t* cpuset = CPU_ALLOC(cores); - for(int i=0; iflag().override_cpu_affinity()) { + int cores = get_nprocs_conf(); + cpu_set_t* cpuset = CPU_ALLOC(cores); + for (int i = 0; i < cores; i++) { + CPU_SET(i, cpuset); + } + int err = pthread_attr_setaffinity_np(&attrib, CPU_ALLOC_SIZE(cores), cpuset); + assert(err == 0 && "pthread_attr_setaffinity_np failed."); + CPU_FREE(cpuset); } - int err = pthread_attr_setaffinity_np(&attrib, CPU_ALLOC_SIZE(cores), cpuset); - assert(err == 0 && "pthread_attr_setaffinity_np failed."); - CPU_FREE(cpuset); - err = pthread_create(&thread, &attrib, ThreadTrampoline, args.get()); + int err = pthread_create(&thread, &attrib, ThreadTrampoline, args.get()); // Probably a stack size error since system limits can be different from PTHREAD_STACK_MIN // Attempt to grow the stack within reason.