include/ck/library/utility/thread.hpp Source File# Composable Kernel: include/ck/library/utility/thread.hpp Source File includecklibraryutility thread.hpp Go to the documentation of this file. 1 // SPDX-License-Identifier: MIT 2 // Copyright (c) 2025, Advanced Micro Devices, Inc. All rights reserved. 3 4 #pragma once 5 6 #ifdef __linux__ 7 #include <sched.h> 8 #endif 9 #include <thread> 10 namespace ck { 11 inline unsigned int get_available_cpu_cores() 12 { 13 #if defined(__linux__) 14 cpu_set_t cpu_set; 15 if(sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set) == 0) 16 { 17 unsigned int cpu_count = CPU_COUNT(&cpu_set); 18 if(cpu_count > 0) 19 return cpu_count; 20 } 21 #endif 22 // Fallback if sched_getaffinity unavailable or fails 23 return std::thread::hardware_concurrency(); 24 } 25 } // namespace ck ckDefinition: ck.hpp:269 ck::get_available_cpu_coresunsigned int get_available_cpu_cores()Definition: thread.hpp:11