File: ocloc_fcl_facade.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 (151 lines) | stat: -rw-r--r-- 5,646 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
 * Copyright (C) 2022-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/offline_compiler/source/ocloc_fcl_facade.h"

#include "shared/offline_compiler/source/ocloc_api.h"
#include "shared/offline_compiler/source/ocloc_arg_helper.h"
#include "shared/source/compiler_interface/igc_platform_helper.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/os_interface/os_inc_base.h"
#include "shared/source/os_interface/os_library.h"

#include "ocl_igc_interface/igc_ocl_device_ctx.h"
#include "ocl_igc_interface/platform_helper.h"

namespace NEO {

CIF::CIFMain *createMainNoSanitize(CIF::CreateCIFMainFunc_t createFunc);

OclocFclFacade::OclocFclFacade(OclocArgHelper *argHelper)
    : argHelper{argHelper} {
}

OclocFclFacade::~OclocFclFacade() = default;

int OclocFclFacade::initialize(const HardwareInfo &hwInfo) {
    if (initialized) {
        return OCLOC_SUCCESS;
    }
    fclLib = loadFclLibrary();
    if (!fclLib) {
        argHelper->printf("Error! Loading of FCL library has failed! Filename: %s\n", Os::frontEndDllName);
        return OCLOC_OUT_OF_HOST_MEMORY;
    }

    const auto fclCreateMainFunction = loadCreateFclMainFunction();
    if (!fclCreateMainFunction) {
        argHelper->printf("Error! Cannot load required functions from FCL library.\n");
        return OCLOC_OUT_OF_HOST_MEMORY;
    }

    fclMain = createFclMain(fclCreateMainFunction);
    if (!fclMain) {
        argHelper->printf("Error! Cannot create FCL main component!\n");
        return OCLOC_OUT_OF_HOST_MEMORY;
    }

    if (!isFclInterfaceCompatible()) {
        const auto incompatibleInterface{getIncompatibleInterface()};
        argHelper->printf("Error! Incompatible interface in FCL: %s\n", incompatibleInterface.c_str());

        DEBUG_BREAK_IF(true);
        return OCLOC_OUT_OF_HOST_MEMORY;
    }

    fclDeviceCtx = createFclDeviceContext();
    if (!fclDeviceCtx) {
        argHelper->printf("Error! Cannot create FCL device context!\n");
        return OCLOC_OUT_OF_HOST_MEMORY;
    }

    fclDeviceCtx->SetOclApiVersion(ocl30ApiVersion);

    if (shouldPopulateFclInterface()) {
        const auto platform = getPlatformHandle();
        if (!platform) {
            argHelper->printf("Error! FCL device context has not been properly created!\n");
            return OCLOC_OUT_OF_HOST_MEMORY;
        }

        populateFclInterface(*platform, hwInfo);
    }

    initialized = true;
    return OCLOC_SUCCESS;
}

std::unique_ptr<OsLibrary> OclocFclFacade::loadFclLibrary() const {
    return std::unique_ptr<OsLibrary>{OsLibrary::loadFunc({Os::frontEndDllName})};
}

CIF::CreateCIFMainFunc_t OclocFclFacade::loadCreateFclMainFunction() const {
    return reinterpret_cast<CIF::CreateCIFMainFunc_t>(fclLib->getProcAddress(CIF::CreateCIFMainFuncName));
}

CIF::RAII::UPtr_t<CIF::CIFMain> OclocFclFacade::createFclMain(CIF::CreateCIFMainFunc_t createMainFunction) const {
    return CIF::RAII::UPtr(createMainNoSanitize(createMainFunction));
}

bool OclocFclFacade::isFclInterfaceCompatible() const {
    return fclMain->IsCompatible<IGC::FclOclDeviceCtx>();
}

std::string OclocFclFacade::getIncompatibleInterface() const {
    return CIF::InterfaceIdCoder::Dec(fclMain->FindIncompatible<IGC::FclOclDeviceCtx>());
}

CIF::RAII::UPtr_t<IGC::FclOclDeviceCtxTagOCL> OclocFclFacade::createFclDeviceContext() const {
    return fclMain->CreateInterface<IGC::FclOclDeviceCtxTagOCL>();
}

bool OclocFclFacade::shouldPopulateFclInterface() const {
    return fclDeviceCtx->GetUnderlyingVersion() > 4U;
}

CIF::RAII::UPtr_t<IGC::PlatformTagOCL> OclocFclFacade::getPlatformHandle() const {
    return fclDeviceCtx->GetPlatformHandle();
}

void OclocFclFacade::populateFclInterface(IGC::PlatformTagOCL &handle, const HardwareInfo &hwInfo) {
    populateIgcPlatform(handle, hwInfo);
}

IGC::CodeType::CodeType_t OclocFclFacade::getPreferredIntermediateRepresentation() const {
    return fclDeviceCtx->GetPreferredIntermediateRepresentation();
}

CIF::RAII::UPtr_t<CIF::Builtins::BufferLatest> OclocFclFacade::createConstBuffer(const void *data, size_t size) {
    return CIF::Builtins::CreateConstBuffer(fclMain.get(), data, size);
}

CIF::RAII::UPtr_t<IGC::OclTranslationOutputTagOCL> OclocFclFacade::translate(IGC::CodeType::CodeType_t inType, IGC::CodeType::CodeType_t outType, CIF::Builtins::BufferLatest *error,
                                                                             CIF::Builtins::BufferSimple *src,
                                                                             CIF::Builtins::BufferSimple *options,
                                                                             CIF::Builtins::BufferSimple *internalOptions,
                                                                             CIF::Builtins::BufferSimple *tracingOptions,
                                                                             uint32_t tracingOptionsCount) {

    auto fclTranslationCtx = this->createTranslationContext(inType, outType, error);

    if ((nullptr != error->GetMemory<char>()) || (nullptr == fclTranslationCtx)) {
        return nullptr;
    }

    return fclTranslationCtx->Translate(src, options, internalOptions, nullptr, 0);
}

CIF::RAII::UPtr_t<IGC::FclOclTranslationCtxTagOCL> OclocFclFacade::createTranslationContext(IGC::CodeType::CodeType_t inType, IGC::CodeType::CodeType_t outType, CIF::Builtins::BufferLatest *error) {
    return fclDeviceCtx->CreateTranslationCtx(inType, outType, error);
}

bool OclocFclFacade::isInitialized() const {
    return initialized;
}

} // namespace NEO