File: offline_linker.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 (84 lines) | stat: -rw-r--r-- 2,446 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Copyright (C) 2022-2023 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

#include "shared/source/helpers/hw_info.h"
#include "shared/source/utilities/arrayref.h"

#include "ocl_igc_interface/code_type.h"

#include <cstddef>
#include <memory>
#include <string>
#include <utility>
#include <vector>

class OclocArgHelper;

namespace NEO {

class OsLibrary;
class OclocIgcFacade;

class OfflineLinker {
  protected:
    enum class OperationMode {
        skipExecution = 0,
        showHelp = 1,
        linkFiles = 2,
    };

    struct InputFileContent {
        InputFileContent(std::unique_ptr<char[]> bytes, size_t size, IGC::CodeType::CodeType_t codeType)
            : bytes{std::move(bytes)}, size{size}, codeType{codeType} {}

        std::unique_ptr<char[]> bytes{};
        size_t size{};
        IGC::CodeType::CodeType_t codeType{};
    };

  public:
    static std::unique_ptr<OfflineLinker> create(size_t argsCount, const std::vector<std::string> &args, int &errorCode, OclocArgHelper *argHelper);
    MOCKABLE_VIRTUAL ~OfflineLinker();

    int execute();
    std::string getBuildLog() const;

  protected:
    explicit OfflineLinker(OclocArgHelper *argHelper, std::unique_ptr<OclocIgcFacade> igcFacade);
    int initialize(size_t argsCount, const std::vector<std::string> &args);
    int parseCommand(size_t argsCount, const std::vector<std::string> &args);
    IGC::CodeType::CodeType_t parseOutputFormat(const std::string &outputFormatName);
    int verifyLinkerCommand();
    int loadInputFilesContent();
    IGC::CodeType::CodeType_t detectCodeType(char *bytes, size_t size) const;
    int initHardwareInfo();
    int link();
    int showHelp();
    std::vector<uint8_t> createSingleInputFile() const;
    std::pair<int, std::vector<uint8_t>> translateToOutputFormat(const std::vector<uint8_t> &elfInput);
    void tryToStoreBuildLog(const char *buildLogRaw, size_t size);

    MOCKABLE_VIRTUAL ArrayRef<const HardwareInfo *> getHardwareInfoTable() const;

    OclocArgHelper *argHelper{};
    OperationMode operationMode{};

    std::vector<std::string> inputFilenames{};
    std::vector<InputFileContent> inputFilesContent{};
    std::string outputFilename{};
    IGC::CodeType::CodeType_t outputFormat{};
    std::string options{};
    std::string internalOptions{};

    std::unique_ptr<OclocIgcFacade> igcFacade;
    HardwareInfo hwInfo{};
    std::string buildLog{};
};

} // namespace NEO