mirror of
https://github.com/ROCm/composable_kernel.git
synced 2026-03-27 10:37:38 +00:00
* chore(copyright): update copyright header for tile_engine directory * chore(copyright): update copyright header for script directory * chore(copyright): update copyright header for test_data directory * chore(copyright): update copyright header for python directory * chore(copyright): update copyright header for profiler directory * chore(copyright): update copyright header for library directory * chore(copyright): update copyright header for include directory
26 lines
601 B
C++
26 lines
601 B
C++
// Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#ifdef __linux__
|
|
#include <sched.h>
|
|
#endif
|
|
#include <thread>
|
|
namespace ck {
|
|
inline unsigned int get_available_cpu_cores()
|
|
{
|
|
#if defined(__linux__)
|
|
cpu_set_t cpu_set;
|
|
if(sched_getaffinity(0, sizeof(cpu_set_t), &cpu_set) == 0)
|
|
{
|
|
unsigned int cpu_count = CPU_COUNT(&cpu_set);
|
|
if(cpu_count > 0)
|
|
return cpu_count;
|
|
}
|
|
#endif
|
|
// Fallback if sched_getaffinity unavailable or fails
|
|
return std::thread::hardware_concurrency();
|
|
}
|
|
} // namespace ck
|