File: create.inl

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 (178 lines) | stat: -rw-r--r-- 4,686 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 * Copyright (C) 2018-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/ail/ail_configuration.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/string_helpers.h"

#include "opencl/source/cl_device/cl_device.h"
#include "opencl/source/context/context.h"
#include "opencl/source/platform/platform.h"
#include "opencl/source/program/program.h"

namespace NEO {

template <typename T>
T *Program::create(
    Context *pContext,
    const ClDeviceVector &deviceVector,
    const size_t *lengths,
    const unsigned char **binaries,
    cl_int *binaryStatus,
    cl_int &errcodeRet) {
    auto program = new T(pContext, false, deviceVector);

    cl_int retVal = CL_INVALID_PROGRAM;

    for (auto i = 0u; i < deviceVector.size(); i++) {
        auto device = deviceVector[i];
        retVal = program->createProgramFromBinary(binaries[i], lengths[i], *device); // NOLINT(clang-analyzer-core.CallAndMessage)
        if (retVal != CL_SUCCESS) {
            break;
        }
    }
    program->createdFrom = CreatedFrom::binary;

    if (binaryStatus) {
        DEBUG_BREAK_IF(retVal != CL_SUCCESS);
        *binaryStatus = CL_SUCCESS;
    }

    if (retVal != CL_SUCCESS) {
        delete program;
        program = nullptr;
    }

    errcodeRet = retVal;
    return program;
}

template <typename T>
T *Program::create(
    Context *pContext,
    cl_uint count,
    const char **strings,
    const size_t *lengths,
    cl_int &errcodeRet) {
    std::string combinedString;
    size_t combinedStringSize = 0;
    T *program = nullptr;

    auto retVal = StringHelpers::createCombinedString(
        combinedString,
        combinedStringSize,
        count,
        strings,
        lengths);

    if (CL_SUCCESS == retVal) {

        auto ail = pContext->getDevice(0)->getRootDeviceEnvironment().getAILConfigurationHelper();
        if (ail) {
            ail->modifyKernelIfRequired(combinedString);
        }

        program = new T(pContext, false, pContext->getDevices());
        program->sourceCode.swap(combinedString);
        program->createdFrom = CreatedFrom::source;
    }

    errcodeRet = retVal;
    return program;
}

template <typename T>
T *Program::createBuiltInFromSource(
    const char *nullTerminatedString,
    Context *context,
    const ClDeviceVector &deviceVector,
    cl_int *errcodeRet) {
    cl_int retVal = CL_SUCCESS;
    T *program = nullptr;

    if (nullTerminatedString == nullptr) {
        retVal = CL_INVALID_VALUE;
    }

    if (retVal == CL_SUCCESS) {
        program = new T(context, true, deviceVector);
        program->sourceCode = nullTerminatedString;
        program->createdFrom = CreatedFrom::source;
    }

    if (errcodeRet) {
        *errcodeRet = retVal;
    }

    return program;
}

template <typename T>
T *Program::createBuiltInFromGenBinary(
    Context *context,
    const ClDeviceVector &deviceVector,
    const void *binary,
    size_t size,
    cl_int *errcodeRet) {
    cl_int retVal = CL_SUCCESS;
    T *program = nullptr;

    if ((binary == nullptr) || (size == 0)) {
        retVal = CL_INVALID_VALUE;
    }

    if (CL_SUCCESS == retVal) {

        program = new T(context, true, deviceVector);
        for (const auto &device : deviceVector) {
            if (program->buildInfos[device->getRootDeviceIndex()].packedDeviceBinarySize == 0) {
                program->replaceDeviceBinary(std::move(makeCopy(binary, size)), size, device->getRootDeviceIndex());
            }
        }
        program->setBuildStatusSuccess(deviceVector, CL_PROGRAM_BINARY_TYPE_EXECUTABLE);
        program->isCreatedFromBinary = true;
        program->createdFrom = CreatedFrom::binary;
    }

    if (errcodeRet) {
        *errcodeRet = retVal;
    }

    return program;
}

template <typename T>
T *Program::createFromIL(Context *context,
                         const void *il,
                         size_t length,
                         cl_int &errcodeRet) {
    errcodeRet = CL_SUCCESS;

    if ((il == nullptr) || (length == 0)) {
        errcodeRet = CL_INVALID_BINARY;
        return nullptr;
    }

    auto deviceVector = context->getDevices();
    T *program = new T(context, false, deviceVector);
    for (const auto &device : deviceVector) {
        errcodeRet = program->createProgramFromBinary(il, length, *device);
        if (errcodeRet != CL_SUCCESS) {
            break;
        }
    }
    program->createdFrom = CreatedFrom::il;

    if (errcodeRet != CL_SUCCESS) {
        delete program;
        program = nullptr;
    }

    return program;
}
} // namespace NEO