File: cache_flush.inl

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 (61 lines) | stat: -rw-r--r-- 2,843 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
/*
 * Copyright (C) 2021-2025 Intel Corporation
 *
 * SPDX-License-Identifier: MIT
 *
 */

#include "shared/source/command_stream/linear_stream.h"
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/helpers/hw_info.h"
#include "shared/source/helpers/l3_range.h"

#include <span>

namespace NEO {

template <typename GfxFamily>
inline void flushGpuCache(LinearStream *commandStream, const std::span<L3Range> &ranges, uint64_t postSyncAddress, const RootDeviceEnvironment &rootDeviceEnvironment) {
    using L3_FLUSH_EVICTION_POLICY = typename GfxFamily::L3_FLUSH_ADDRESS_RANGE::L3_FLUSH_EVICTION_POLICY;
    auto templ = GfxFamily::cmdInitL3ControlWithPostSync;
    templ.getBase().setHdcPipelineFlush(true);

    auto hwInfo = *rootDeviceEnvironment.getHardwareInfo();
    auto &productHelper = rootDeviceEnvironment.getHelper<ProductHelper>();
    auto isA0Stepping = GfxCoreHelper::isWorkaroundRequired(REVISION_A0, REVISION_B, hwInfo, productHelper);

    for (auto it = ranges.begin(), end = ranges.end(); it != end; ++it) {
        if ((it + 1 == end) && (postSyncAddress != 0)) {
            auto l3Control = commandStream->getSpaceForCmd<typename GfxFamily::L3_CONTROL>();
            auto cmd = GfxFamily::cmdInitL3ControlWithPostSync;

            cmd.getBase().setHdcPipelineFlush(templ.getBase().getHdcPipelineFlush());
            cmd.getL3FlushAddressRange().setL3FlushEvictionPolicy(L3_FLUSH_EVICTION_POLICY::L3_FLUSH_EVICTION_POLICY_FLUSH_L3_WITH_EVICTION, isA0Stepping);
            cmd.getL3FlushAddressRange().setAddress(it->getMaskedAddress(), isA0Stepping);
            cmd.getL3FlushAddressRange().setAddressMask(it->getMask(), isA0Stepping);

            cmd.getBase().setPostSyncOperation(GfxFamily::L3_CONTROL_BASE::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA);
            cmd.getPostSyncData().setAddress(postSyncAddress);
            cmd.getPostSyncData().setImmediateData(0);
            *l3Control = cmd;
        } else {
            auto l3Control = commandStream->getSpaceForCmd<typename GfxFamily::L3_CONTROL>();
            templ.getL3FlushAddressRange().setAddress(it->getMaskedAddress(), isA0Stepping);
            templ.getL3FlushAddressRange().setAddressMask(it->getMask(), isA0Stepping);
            templ.getL3FlushAddressRange().setL3FlushEvictionPolicy(L3_FLUSH_EVICTION_POLICY::L3_FLUSH_EVICTION_POLICY_FLUSH_L3_WITH_EVICTION, isA0Stepping);
            *l3Control = templ;
        }
    }
}

template <typename GfxFamily>
inline size_t getSizeNeededToFlushGpuCache(const std::span<L3Range> &ranges, bool usePostSync) {
    size_t size = ranges.size() * sizeof(typename GfxFamily::L3_CONTROL);
    if (usePostSync) {
        UNRECOVERABLE_IF(ranges.size() == 0);
    }

    return size;
}
} // namespace NEO