File: numa_library.cpp

package info (click to toggle)
intel-compute-runtime 25.44.36015.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,632 kB
  • sloc: cpp: 931,547; lisp: 2,074; sh: 719; makefile: 162; python: 21
file content (56 lines) | stat: -rw-r--r-- 1,980 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
 * Copyright (C) 2023-2024 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/os_interface/linux/numa_library.h"

#include "shared/source/helpers/debug_helpers.h"

#include <cerrno>
#include <iostream>

namespace NEO {
namespace Linux {

std::unique_ptr<NEO::OsLibrary> NumaLibrary::osLibrary(nullptr);
NumaLibrary::GetMemPolicyPtr NumaLibrary::getMemPolicyFunction(nullptr);
NumaLibrary::NumaAvailablePtr NumaLibrary::numaAvailableFunction(nullptr);
NumaLibrary::NumaMaxNodePtr NumaLibrary::numaMaxNodeFunction(nullptr);
int NumaLibrary::maxNode(-1);
bool NumaLibrary::numaLoaded(false);

bool NumaLibrary::init() {
    osLibrary.reset(NEO::OsLibrary::loadFunc(std::string(numaLibNameStr)));
    numaLoaded = false;
    numaAvailableFunction = nullptr;
    numaMaxNodeFunction = nullptr;
    getMemPolicyFunction = nullptr;
    if (osLibrary) {
        DEBUG_BREAK_IF(!osLibrary->isLoaded());
        numaAvailableFunction = reinterpret_cast<NumaAvailablePtr>(osLibrary->getProcAddress(std::string(procNumaAvailableStr)));
        numaMaxNodeFunction = reinterpret_cast<NumaMaxNodePtr>(osLibrary->getProcAddress(std::string(procNumaMaxNodeStr)));
        getMemPolicyFunction = reinterpret_cast<GetMemPolicyPtr>(osLibrary->getProcAddress(std::string(procGetMemPolicyStr)));
        if (numaAvailableFunction && numaMaxNodeFunction && getMemPolicyFunction) {
            if ((*numaAvailableFunction)() == 0) {
                maxNode = (*numaMaxNodeFunction)();
                numaLoaded = maxNode > 0;
            }
        }
    }
    return numaLoaded;
}

bool NumaLibrary::getMemPolicy(int *mode, std::vector<unsigned long> &nodeMask) {
    if (numaLoaded) {
        // re-initialize vector with size maxNode;
        std::vector<unsigned long>(maxNode + 1, 0).swap(nodeMask);
        return (*getMemPolicyFunction)(mode, nodeMask.data(), maxNode + 1, nullptr, 0) != -1;
    }
    return false;
}

} // namespace Linux
} // namespace NEO