File: external_functions.h

package info (click to toggle)
intel-compute-runtime 25.48.36300.8-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 80,652 kB
  • sloc: cpp: 939,022; lisp: 2,090; sh: 722; makefile: 162; python: 21
file content (79 lines) | stat: -rw-r--r-- 2,791 bytes parent folder | download
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (C) 2022-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

#include <cstdint>
#include <string>
#include <unordered_map>
#include <vector>

namespace NEO {
struct KernelDescriptor;

enum ExternalFunctionResolveError : uint32_t {
    RESOLVE_SUCCESS = 0,
    ERROR_EXTERNAL_FUNCTION_INFO_MISSING,
    ERROR_KERNEL_DESCRIPTOR_MISSING,
    ERROR_LOOP_DETECTED
};

struct ExternalFunctionInfo {
    std::string functionName = "";
    uint8_t barrierCount = 0U;
    uint16_t numGrfRequired = 0U;
    uint8_t simdSize = 0U;
    bool hasRTCalls = false;
    bool hasPrintfCalls = false;
    bool hasIndirectCalls = false;
    bool requireAssertBuffer = false;
    bool requireSyncBuffer = false;
};

struct ExternalFunctionUsageKernel {
    std::string usedFuncName;
    std::string kernelName;
    bool optional = false;
};

struct ExternalFunctionUsageExtFunc {
    std::string usedFuncName;
    std::string callerFuncName;
    bool optional = false;
};

using ExternalFunctionInfosT = std::vector<ExternalFunctionInfo *>;
using KernelDependenciesT = std::vector<const ExternalFunctionUsageKernel *>;
using FunctionDependenciesT = std::vector<const ExternalFunctionUsageExtFunc *>;
using KernelDescriptorMapT = std::unordered_map<std::string, KernelDescriptor *>;
using FuncNameToIdMapT = std::unordered_map<std::string, size_t>;
using DependenciesT = std::vector<std::vector<size_t>>;
using CalledByT = std::vector<std::vector<size_t>>;

class DependencyResolver {
  public:
    DependencyResolver(const std::vector<std::vector<size_t>> &graph) : graph(graph) {}
    std::vector<size_t> resolveDependencies();

  protected:
    void resolveDependency(size_t nodeId, const std::vector<size_t> &edges);
    std::vector<size_t> seen;
    std::vector<size_t> resolved;
    const std::vector<std::vector<size_t>> &graph;
};

uint32_t resolveExternalDependencies(const ExternalFunctionInfosT &externalFunctionInfos, const KernelDependenciesT &kernelDependencies,
                                     const FunctionDependenciesT &funcDependencies, const KernelDescriptorMapT &nameToKernelDescriptor);

uint32_t getExtFuncDependencies(const FuncNameToIdMapT &funcNameToId, const FunctionDependenciesT &funcDependencies, size_t numExternalFuncs,
                                DependenciesT &outDependencies, CalledByT &outCalledBy);

uint32_t resolveExtFuncDependencies(const ExternalFunctionInfosT &externalFunctionInfos, const FuncNameToIdMapT &funcNameToId, const FunctionDependenciesT &funcDependencies);

uint32_t resolveKernelDependencies(const ExternalFunctionInfosT &externalFunctionInfos, const FuncNameToIdMapT &funcNameToId, const KernelDependenciesT &kernelDependencies, const KernelDescriptorMapT &nameToKernelDescriptor);

} // namespace NEO