File: label.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 (71 lines) | stat: -rw-r--r-- 2,332 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
/*
 * Copyright (C) 2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "level_zero/experimental/source/mutable_cmdlist/label.h"

#include "shared/source/command_container/command_encoder.h"
#include "shared/source/command_stream/linear_stream.h"
#include "shared/source/helpers/aligned_memory.h"
#include "shared/source/helpers/ptr_math.h"
#include "shared/source/memory_manager/graphics_allocation.h"

#include "level_zero/core/source/cmdlist/cmdlist.h"
#include "level_zero/core/source/mutable_cmdlist/mutable_cmdlist.h"

namespace L0 {
namespace MCL {

Label::Label(ze_command_list_handle_t hCmdList, const InterfaceLabelDescriptor *desc) {
    this->hCmdList = hCmdList;
    this->name = desc->name == nullptr ? "" : std::string(desc->name);
    this->alignment = desc->alignment;
    this->gpuAddress = undefined<GpuAddress>;
}

Label *Label::create(ze_command_list_handle_t hCmdList, const InterfaceLabelDescriptor *desc) {
    return new Label(hCmdList, desc);
}

ze_result_t Label::setLabel(ze_command_list_handle_t hCmdList) {
    if (this->hCmdList != hCmdList) {
        return ZE_RESULT_ERROR_INVALID_ARGUMENT;
    }

    if (isSet()) {
        return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
    }

    auto cmdList = MutableCommandList::fromHandle(hCmdList);
    auto cs = cmdList->getBase()->getCmdContainer().getCommandStream();

    GpuAddress labelAddress = cs->getGraphicsAllocation()->getGpuAddress() + cs->getUsed();
    if (this->alignment) {
        const GpuAddress alignedAddress = alignUp<GpuAddress>(labelAddress, this->alignment);
        if (auto padding = alignedAddress - labelAddress) {
            if (padding % 4 != 0U) {
                return ZE_RESULT_ERROR_UNSUPPORTED_ALIGNMENT;
            }
            auto numNoops = padding >> 2;
            for (size_t i = 0; i < numNoops; i++) {
                cmdList->getBase()->appendMINoop();
            }
        }
        labelAddress = alignedAddress;
    }
    this->gpuAddress = labelAddress;

    cmdList->appendSetPredicate(NEO::MiPredicateType::disable);
    auto csCpuBase = cs->getCpuBase();
    for (const auto offset : getUsages()) {
        memcpy_s(ptrOffset(csCpuBase, offset), sizeof(GpuAddress), &labelAddress, sizeof(GpuAddress));
    }

    return ZE_RESULT_SUCCESS;
}

} // namespace MCL
} // namespace L0