File: encode_alu_helper.h

package info (click to toggle)
intel-compute-runtime 25.35.35096.9-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 79,324 kB
  • sloc: cpp: 926,243; lisp: 3,433; sh: 715; makefile: 162; python: 21
file content (81 lines) | stat: -rw-r--r-- 2,713 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
/*
 * Copyright (C) 2022-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#pragma once

#include "shared/source/command_stream/linear_stream.h"
#include "shared/source/helpers/register_offsets.h"
#include "shared/source/helpers/string.h"

#include <array>
#include <tuple>

namespace NEO {
template <typename GfxFamily, size_t aluCount>
class EncodeAluHelper {
  public:
    using MI_MATH_ALU_INST_INLINE = typename GfxFamily::MI_MATH_ALU_INST_INLINE;
    using MI_MATH = typename GfxFamily::MI_MATH;

    using OperandTupleT = std::tuple<AluRegisters, AluRegisters, AluRegisters>;
    using OperandArrayT = std::array<OperandTupleT, aluCount>;

    constexpr EncodeAluHelper() {
        aluOps.miMath.DW0.BitField.InstructionType = MI_MATH::COMMAND_TYPE_MI_COMMAND;
        aluOps.miMath.DW0.BitField.InstructionOpcode = MI_MATH::MI_COMMAND_OPCODE_MI_MATH;
        aluOps.miMath.DW0.BitField.DwordLength = aluCount - 1;
    }

    consteval EncodeAluHelper(OperandArrayT inputParams) : EncodeAluHelper() {
        for (auto &param : inputParams) {
            auto &[opcode, operand1, operand2] = param;
            if (opcode == AluRegisters::opcodeNone) {
                break;
            }
            setNextAlu(opcode, operand1, operand2);
        }
    }

    void setMocs([[maybe_unused]] uint32_t mocs) {
        if constexpr (GfxFamily::isUsingMiMathMocs) {
            aluOps.miMath.DW0.BitField.MemoryObjectControlState = mocs;
        }
    }

    constexpr void setNextAlu(AluRegisters opcode) {
        setNextAlu(opcode, AluRegisters::opcodeNone, AluRegisters::opcodeNone);
    }

    constexpr void setNextAlu(AluRegisters opcode, AluRegisters operand1, AluRegisters operand2) {
        aluOps.aliInst[aluIndex].DW0.BitField.ALUOpcode = static_cast<uint32_t>(opcode);
        aluOps.aliInst[aluIndex].DW0.BitField.Operand1 = static_cast<uint32_t>(operand1);
        aluOps.aliInst[aluIndex].DW0.BitField.Operand2 = static_cast<uint32_t>(operand2);

        aluIndex++;
    }
    void copyToCmdStream(LinearStream &cmdStream) const {
        UNRECOVERABLE_IF(aluIndex != aluCount);

        auto cmds = cmdStream.getSpace(sizeof(AluOps));
        memcpy_s(cmds, sizeof(AluOps), &aluOps, sizeof(AluOps));
    }

    static constexpr size_t getCmdsSize() {
        return (sizeof(MI_MATH) + (aluCount * sizeof(MI_MATH_ALU_INST_INLINE)));
    }

  protected:
    struct alignas(1) AluOps {
        MI_MATH miMath = {};
        MI_MATH_ALU_INST_INLINE aliInst[aluCount];
    } aluOps;

    size_t aluIndex = 0;

    static_assert(sizeof(AluOps) == getCmdsSize(), "This structure is consumed by GPU and must follow specific restrictions for padding and size");
};
} // namespace NEO