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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/*
* Copyright (C) 2019-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/utilities/metrics_library.h"
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/source/os_interface/os_inc_base.h"
namespace NEO {
///////////////////////////////////////////////////////
// FUNCTION: MetricsLibrary::MetricsLibrary
///////////////////////////////////////////////////////
MetricsLibrary::MetricsLibrary() {
api = std::make_unique<MetricsLibraryInterface>();
osLibrary.reset(OsLibrary::loadFunc({Os::metricsLibraryDllName}));
}
//////////////////////////////////////////////////////
// FUNCTION: MetricsLibrary::open
//////////////////////////////////////////////////////
bool MetricsLibrary::open() {
UNRECOVERABLE_IF(osLibrary.get() == nullptr);
if (osLibrary->isLoaded()) {
api->contextCreate = reinterpret_cast<ContextCreateFunction_1_0>(osLibrary->getProcAddress(METRICS_LIBRARY_CONTEXT_CREATE_1_0));
api->contextDelete = reinterpret_cast<ContextDeleteFunction_1_0>(osLibrary->getProcAddress(METRICS_LIBRARY_CONTEXT_DELETE_1_0));
} else {
api->contextCreate = nullptr;
api->contextDelete = nullptr;
}
if (!api->contextCreate) {
return false;
}
if (!api->contextDelete) {
return false;
}
return true;
}
//////////////////////////////////////////////////////
// MetricsLibrary::createContext
//////////////////////////////////////////////////////
bool MetricsLibrary::contextCreate(
const ClientType_1_0 &clientType,
ClientOptionsSubDeviceData_1_0 &subDevice,
ClientOptionsSubDeviceIndexData_1_0 &subDeviceIndex,
ClientOptionsSubDeviceCountData_1_0 &subDeviceCount,
ClientData_1_0 &clientData,
ContextCreateData_1_0 &createData,
ContextHandle_1_0 &handle) {
MetricsLibraryApi::ClientOptionsData_1_0 clientOptions[4] = {};
clientOptions[0].Type = MetricsLibraryApi::ClientOptionsType::Compute;
clientOptions[0].Compute.Asynchronous = true;
clientOptions[1].Type = MetricsLibraryApi::ClientOptionsType::SubDevice;
clientOptions[1].SubDevice = subDevice;
clientOptions[2].Type = MetricsLibraryApi::ClientOptionsType::SubDeviceIndex;
clientOptions[2].SubDeviceIndex = subDeviceIndex;
clientOptions[3].Type = MetricsLibraryApi::ClientOptionsType::SubDeviceCount;
clientOptions[3].SubDeviceCount = subDeviceCount;
clientData.ClientOptionsCount = 4;
clientData.ClientOptions = clientOptions;
createData.Api = &api->functions;
createData.ClientCallbacks = &api->callbacks;
createData.ClientData = &clientData;
return api->contextCreate(
clientType,
&createData,
&handle) == StatusCode::Success;
}
//////////////////////////////////////////////////////
// MetricsLibrary::contextDelete
//////////////////////////////////////////////////////
bool MetricsLibrary::contextDelete(
const ContextHandle_1_0 &handle) {
return api->contextDelete(handle) == StatusCode::Success;
}
//////////////////////////////////////////////////////
// MetricsLibrary::hwCountersCreate
//////////////////////////////////////////////////////
bool MetricsLibrary::hwCountersCreate(
const ContextHandle_1_0 &context,
const uint32_t slots,
const ConfigurationHandle_1_0 user,
QueryHandle_1_0 &query) {
QueryCreateData_1_0 data = {};
data.HandleContext = context;
data.Type = ObjectType::QueryHwCounters;
data.Slots = slots;
return api->functions.QueryCreate(
&data,
&query) == StatusCode::Success;
}
//////////////////////////////////////////////////////
// MetricsLibrary::hwCountersDelete
//////////////////////////////////////////////////////
bool MetricsLibrary::hwCountersDelete(
const QueryHandle_1_0 &query) {
return api->functions.QueryDelete(query) == StatusCode::Success;
}
//////////////////////////////////////////////////////
// MetricsLibrary::hwCountersGetReport
//////////////////////////////////////////////////////
bool MetricsLibrary::hwCountersGetReport(
const QueryHandle_1_0 &handle,
const uint32_t slot,
const uint32_t slotsCount,
const uint32_t dataSize,
void *data) {
GetReportData_1_0 report = {};
report.Type = ObjectType::QueryHwCounters;
report.Query.Handle = handle;
report.Query.Slot = slot;
report.Query.SlotsCount = slotsCount;
report.Query.Data = data;
report.Query.DataSize = dataSize;
return api->functions.GetData(&report) == StatusCode::Success;
}
//////////////////////////////////////////////////////
// MetricsLibrary::hwCountersGetApiReportSize
//////////////////////////////////////////////////////
uint32_t MetricsLibrary::hwCountersGetApiReportSize() {
ValueType type = ValueType::Uint32;
TypedValue_1_0 value = {};
return api->functions.GetParameter(ParameterType::QueryHwCountersReportApiSize, &type, &value) == StatusCode::Success
? value.ValueUInt32
: 0;
}
//////////////////////////////////////////////////////
// MetricsLibrary::hwCountersGetGpuReportSize
//////////////////////////////////////////////////////
uint32_t MetricsLibrary::hwCountersGetGpuReportSize() {
ValueType type = ValueType::Uint32;
TypedValue_1_0 value = {};
return api->functions.GetParameter(ParameterType::QueryHwCountersReportGpuSize, &type, &value) == StatusCode::Success
? value.ValueUInt32
: 0;
}
//////////////////////////////////////////////////////
// MetricsLibrary::commandBufferGet
//////////////////////////////////////////////////////
bool MetricsLibrary::commandBufferGet(
CommandBufferData_1_0 &data) {
return api->functions.CommandBufferGet(
&data) == StatusCode::Success;
}
//////////////////////////////////////////////////////
// MetricsLibrary::commandBufferGetSize
//////////////////////////////////////////////////////
bool MetricsLibrary::commandBufferGetSize(
const CommandBufferData_1_0 &commandBufferData,
CommandBufferSize_1_0 &commandBufferSize) {
return api->functions.CommandBufferGetSize(
&commandBufferData,
&commandBufferSize) == StatusCode::Success;
}
//////////////////////////////////////////////////////
// MetricsLibrary::oaConfigurationCreate
//////////////////////////////////////////////////////
bool MetricsLibrary::oaConfigurationCreate(
const ContextHandle_1_0 &context,
ConfigurationHandle_1_0 &handle) {
ConfigurationCreateData_1_0 data = {};
data.HandleContext = context;
data.Type = ObjectType::ConfigurationHwCountersOa;
return api->functions.ConfigurationCreate(
&data,
&handle) == StatusCode::Success;
}
//////////////////////////////////////////////////////
// MetricsLibrary::oaConfigurationDelete
//////////////////////////////////////////////////////
bool MetricsLibrary::oaConfigurationDelete(
const ConfigurationHandle_1_0 &handle) {
return api->functions.ConfigurationDelete(handle) == StatusCode::Success;
}
} // namespace NEO
|