* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef FUNCTIONSYSTEM_NUMA_UTILS_H
#define FUNCTIONSYSTEM_NUMA_UTILS_H
#include <vector>
#include <mutex>
#include <atomic>
#ifdef ENABLE_NUMA
#include "common/utils/numa_dl.h"
#endif
#include "common/resource_view/resource_type.h"
namespace functionsystem::utils {
class NUMAUtils {
public:
~NUMAUtils() = default;
static bool IsNUMAAvailable();
static int GetNUMANodeCount();
static int GetNUMANodeCPUCount(int nodeId);
static std::vector<int> GetNUMANodeCPUCounts();
static std::vector<double> GetNUMANodeCPUsFromResourceUnit(const resource_view::ResourceUnit& resourceUnit);
static std::vector<double> GetNUMANodeCPUsFromAllocatable(const resource_view::Resources& allocatable,
const std::string& nodeID);
private:
static std::atomic<bool> numaAvailable_;
static std::atomic<int> maxNode_;
static std::once_flag initFlag_;
static void Initialize();
};
}
#endif