Create a wrapper for drm_i915_query_topology_info

Related-To: NEO-6852
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2022-05-19 14:06:33 +00:00
committed by Compute-Runtime-Automation
parent d9858bf206
commit 3be31b821b
8 changed files with 64 additions and 41 deletions

View File

@@ -255,15 +255,15 @@ int drmQueryItem(drm_i915_query *query) {
auto queryItemArg = reinterpret_cast<NEO::QueryItem *>(query->items_ptr); auto queryItemArg = reinterpret_cast<NEO::QueryItem *>(query->items_ptr);
if (queryItemArg->length == 0) { if (queryItemArg->length == 0) {
if (queryItemArg->queryId == DRM_I915_QUERY_TOPOLOGY_INFO) { if (queryItemArg->queryId == DRM_I915_QUERY_TOPOLOGY_INFO) {
queryItemArg->length = sizeof(drm_i915_query_topology_info) + 1; queryItemArg->length = sizeof(NEO::QueryTopologyInfo) + 1;
return 0; return 0;
} }
} else { } else {
if (queryItemArg->queryId == DRM_I915_QUERY_TOPOLOGY_INFO) { if (queryItemArg->queryId == DRM_I915_QUERY_TOPOLOGY_INFO) {
auto topologyArg = reinterpret_cast<drm_i915_query_topology_info *>(queryItemArg->dataPtr); auto topologyArg = reinterpret_cast<NEO::QueryTopologyInfo *>(queryItemArg->dataPtr);
topologyArg->max_slices = 1; topologyArg->maxSlices = 1;
topologyArg->max_subslices = 1; topologyArg->maxSubslices = 1;
topologyArg->max_eus_per_subslice = 3; topologyArg->maxEusPerSubslice = 3;
topologyArg->data[0] = 0xFF; topologyArg->data[0] = 0xFF;
return failOnEuTotal || failOnSubsliceTotal; return failOnEuTotal || failOnSubsliceTotal;
} }

View File

@@ -754,7 +754,7 @@ void Drm::setNewResourceBoundToVM(uint32_t vmHandleId) {
} }
} }
bool Drm::translateTopologyInfo(const drm_i915_query_topology_info *queryTopologyInfo, QueryTopologyData &data, TopologyMapping &mapping) { bool Drm::translateTopologyInfo(const QueryTopologyInfo *queryTopologyInfo, QueryTopologyData &data, TopologyMapping &mapping) {
int sliceCount = 0; int sliceCount = 0;
int subSliceCount = 0; int subSliceCount = 0;
int euCount = 0; int euCount = 0;
@@ -763,7 +763,7 @@ bool Drm::translateTopologyInfo(const drm_i915_query_topology_info *queryTopolog
std::vector<int> sliceIndices; std::vector<int> sliceIndices;
sliceIndices.reserve(maxSliceCount); sliceIndices.reserve(maxSliceCount);
for (int x = 0; x < queryTopologyInfo->max_slices; x++) { for (int x = 0; x < queryTopologyInfo->maxSlices; x++) {
bool isSliceEnable = (queryTopologyInfo->data[x / 8] >> (x % 8)) & 1; bool isSliceEnable = (queryTopologyInfo->data[x / 8] >> (x % 8)) & 1;
if (!isSliceEnable) { if (!isSliceEnable) {
continue; continue;
@@ -772,10 +772,10 @@ bool Drm::translateTopologyInfo(const drm_i915_query_topology_info *queryTopolog
sliceCount++; sliceCount++;
std::vector<int> subSliceIndices; std::vector<int> subSliceIndices;
subSliceIndices.reserve(queryTopologyInfo->max_subslices); subSliceIndices.reserve(queryTopologyInfo->maxSubslices);
for (int y = 0; y < queryTopologyInfo->max_subslices; y++) { for (int y = 0; y < queryTopologyInfo->maxSubslices; y++) {
size_t yOffset = (queryTopologyInfo->subslice_offset + x * queryTopologyInfo->subslice_stride + y / 8); size_t yOffset = (queryTopologyInfo->subsliceOffset + x * queryTopologyInfo->subsliceStride + y / 8);
bool isSubSliceEnabled = (queryTopologyInfo->data[yOffset] >> (y % 8)) & 1; bool isSubSliceEnabled = (queryTopologyInfo->data[yOffset] >> (y % 8)) & 1;
if (!isSubSliceEnabled) { if (!isSubSliceEnabled) {
continue; continue;
@@ -783,8 +783,8 @@ bool Drm::translateTopologyInfo(const drm_i915_query_topology_info *queryTopolog
subSliceCount++; subSliceCount++;
subSliceIndices.push_back(y); subSliceIndices.push_back(y);
for (int z = 0; z < queryTopologyInfo->max_eus_per_subslice; z++) { for (int z = 0; z < queryTopologyInfo->maxEusPerSubslice; z++) {
size_t zOffset = (queryTopologyInfo->eu_offset + (x * queryTopologyInfo->max_subslices + y) * queryTopologyInfo->eu_stride + z / 8); size_t zOffset = (queryTopologyInfo->euOffset + (x * queryTopologyInfo->maxSubslices + y) * queryTopologyInfo->euStride + z / 8);
bool isEUEnabled = (queryTopologyInfo->data[zOffset] >> (z % 8)) & 1; bool isEUEnabled = (queryTopologyInfo->data[zOffset] >> (z % 8)) & 1;
if (!isEUEnabled) { if (!isEUEnabled) {
continue; continue;
@@ -1164,7 +1164,7 @@ bool Drm::queryTopology(const HardwareInfo &hwInfo, QueryTopologyData &topologyD
success = false; success = false;
break; break;
} }
auto data = reinterpret_cast<drm_i915_query_topology_info *>(dataQuery.data()); auto data = reinterpret_cast<QueryTopologyInfo *>(dataQuery.data());
QueryTopologyData tileTopologyData = {}; QueryTopologyData tileTopologyData = {};
TopologyMapping mapping; TopologyMapping mapping;
@@ -1180,7 +1180,7 @@ bool Drm::queryTopology(const HardwareInfo &hwInfo, QueryTopologyData &topologyD
topologyData.maxSliceCount = std::max(topologyData.maxSliceCount, tileTopologyData.maxSliceCount); topologyData.maxSliceCount = std::max(topologyData.maxSliceCount, tileTopologyData.maxSliceCount);
topologyData.maxSubSliceCount = std::max(topologyData.maxSubSliceCount, tileTopologyData.maxSubSliceCount); topologyData.maxSubSliceCount = std::max(topologyData.maxSubSliceCount, tileTopologyData.maxSubSliceCount);
topologyData.maxEuCount = std::max(topologyData.maxEuCount, static_cast<int>(data->max_eus_per_subslice)); topologyData.maxEuCount = std::max(topologyData.maxEuCount, static_cast<int>(data->maxEusPerSubslice));
this->topologyMap[i] = mapping; this->topologyMap[i] = mapping;
} }
@@ -1199,11 +1199,11 @@ bool Drm::queryTopology(const HardwareInfo &hwInfo, QueryTopologyData &topologyD
if (dataQuery.empty()) { if (dataQuery.empty()) {
return false; return false;
} }
auto data = reinterpret_cast<drm_i915_query_topology_info *>(dataQuery.data()); auto data = reinterpret_cast<QueryTopologyInfo *>(dataQuery.data());
TopologyMapping mapping; TopologyMapping mapping;
auto retVal = translateTopologyInfo(data, topologyData, mapping); auto retVal = translateTopologyInfo(data, topologyData, mapping);
topologyData.maxEuCount = data->max_eus_per_subslice; topologyData.maxEuCount = data->maxEusPerSubslice;
this->topologyMap.clear(); this->topologyMap.clear();
this->topologyMap[0] = mapping; this->topologyMap[0] = mapping;

View File

@@ -257,7 +257,7 @@ class Drm : public DriverModel {
Drm(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment); Drm(std::unique_ptr<HwDeviceIdDrm> &&hwDeviceIdIn, RootDeviceEnvironment &rootDeviceEnvironment);
int getQueueSliceCount(GemContextParamSseu *sseu); int getQueueSliceCount(GemContextParamSseu *sseu);
bool translateTopologyInfo(const drm_i915_query_topology_info *queryTopologyInfo, QueryTopologyData &data, TopologyMapping &mapping); bool translateTopologyInfo(const QueryTopologyInfo *queryTopologyInfo, QueryTopologyData &data, TopologyMapping &mapping);
std::string generateUUID(); std::string generateUUID();
std::string generateElfUUID(const void *data); std::string generateElfUUID(const void *data);
std::string getSysFsPciPath(); std::string getSysFsPciPath();

View File

@@ -63,4 +63,15 @@ static_assert(offsetof(GemContextParamSseu, subsliceMask) == offsetof(drm_i915_g
static_assert(offsetof(GemContextParamSseu, minEusPerSubslice) == offsetof(drm_i915_gem_context_param_sseu, min_eus_per_subslice)); static_assert(offsetof(GemContextParamSseu, minEusPerSubslice) == offsetof(drm_i915_gem_context_param_sseu, min_eus_per_subslice));
static_assert(offsetof(GemContextParamSseu, maxEusPerSubslice) == offsetof(drm_i915_gem_context_param_sseu, max_eus_per_subslice)); static_assert(offsetof(GemContextParamSseu, maxEusPerSubslice) == offsetof(drm_i915_gem_context_param_sseu, max_eus_per_subslice));
static_assert(sizeof(QueryTopologyInfo) == sizeof(drm_i915_query_topology_info));
static_assert(offsetof(QueryTopologyInfo, flags) == offsetof(drm_i915_query_topology_info, flags));
static_assert(offsetof(QueryTopologyInfo, maxSlices) == offsetof(drm_i915_query_topology_info, max_slices));
static_assert(offsetof(QueryTopologyInfo, maxSubslices) == offsetof(drm_i915_query_topology_info, max_subslices));
static_assert(offsetof(QueryTopologyInfo, maxEusPerSubslice) == offsetof(drm_i915_query_topology_info, max_eus_per_subslice));
static_assert(offsetof(QueryTopologyInfo, subsliceOffset) == offsetof(drm_i915_query_topology_info, subslice_offset));
static_assert(offsetof(QueryTopologyInfo, subsliceStride) == offsetof(drm_i915_query_topology_info, subslice_stride));
static_assert(offsetof(QueryTopologyInfo, euOffset) == offsetof(drm_i915_query_topology_info, eu_offset));
static_assert(offsetof(QueryTopologyInfo, euStride) == offsetof(drm_i915_query_topology_info, eu_stride));
static_assert(offsetof(QueryTopologyInfo, data) == offsetof(drm_i915_query_topology_info, data));
} // namespace NEO } // namespace NEO

View File

@@ -71,4 +71,16 @@ struct GemContextParamSseu {
uint16_t maxEusPerSubslice; uint16_t maxEusPerSubslice;
}; };
struct QueryTopologyInfo {
uint16_t flags;
uint16_t maxSlices;
uint16_t maxSubslices;
uint16_t maxEusPerSubslice;
uint16_t subsliceOffset;
uint16_t subsliceStride;
uint16_t euOffset;
uint16_t euStride;
uint8_t data[];
};
} // namespace NEO } // namespace NEO

View File

@@ -248,18 +248,18 @@ int DrmMock::ioctl(unsigned long request, void *arg) {
if (queryItemArg->length == 0) { if (queryItemArg->length == 0) {
if (queryItemArg->queryId == DRM_I915_QUERY_TOPOLOGY_INFO) { if (queryItemArg->queryId == DRM_I915_QUERY_TOPOLOGY_INFO) {
queryItemArg->length = static_cast<int32_t>(sizeof(drm_i915_query_topology_info) + dataSize); queryItemArg->length = static_cast<int32_t>(sizeof(QueryTopologyInfo) + dataSize);
return 0; return 0;
} }
} else { } else {
if (queryItemArg->queryId == DRM_I915_QUERY_TOPOLOGY_INFO) { if (queryItemArg->queryId == DRM_I915_QUERY_TOPOLOGY_INFO) {
auto topologyArg = reinterpret_cast<drm_i915_query_topology_info *>(queryItemArg->dataPtr); auto topologyArg = reinterpret_cast<QueryTopologyInfo *>(queryItemArg->dataPtr);
if (this->failRetTopology) { if (this->failRetTopology) {
return -1; return -1;
} }
topologyArg->max_slices = this->storedSVal; topologyArg->maxSlices = this->storedSVal;
topologyArg->max_subslices = this->storedSVal ? (this->storedSSVal / this->storedSVal) : 0; topologyArg->maxSubslices = this->storedSVal ? (this->storedSSVal / this->storedSVal) : 0;
topologyArg->max_eus_per_subslice = this->storedSSVal ? (this->storedEUVal / this->storedSSVal) : 0; topologyArg->maxEusPerSubslice = this->storedSSVal ? (this->storedEUVal / this->storedSSVal) : 0;
if (this->disableSomeTopology) { if (this->disableSomeTopology) {
memset(topologyArg->data, 0xCA, dataSize); memset(topologyArg->data, 0xCA, dataSize);

View File

@@ -364,21 +364,21 @@ bool DrmMockPrelimContext::handlePrelimQueryItem(void *arg) {
static_cast<uint16_t>(std::ceil(maxSlices / 8.0)); static_cast<uint16_t>(std::ceil(maxSlices / 8.0));
if (queryItem->length == 0) { if (queryItem->length == 0) {
queryItem->length = static_cast<int32_t>(sizeof(drm_i915_query_topology_info) + dataSize); queryItem->length = static_cast<int32_t>(sizeof(QueryTopologyInfo) + dataSize);
break; break;
} else { } else {
auto topologyArg = reinterpret_cast<drm_i915_query_topology_info *>(queryItem->dataPtr); auto topologyArg = reinterpret_cast<QueryTopologyInfo *>(queryItem->dataPtr);
if (failRetTopology) { if (failRetTopology) {
return false; return false;
} }
topologyArg->max_slices = maxSlices; topologyArg->maxSlices = maxSlices;
topologyArg->max_subslices = maxSubslices; topologyArg->maxSubslices = maxSubslices;
topologyArg->max_eus_per_subslice = maxEuPerSubslice; topologyArg->maxEusPerSubslice = maxEuPerSubslice;
topologyArg->subslice_stride = static_cast<uint16_t>(std::ceil(maxSubslices / 8.0)); topologyArg->subsliceStride = static_cast<uint16_t>(std::ceil(maxSubslices / 8.0));
topologyArg->eu_stride = static_cast<uint16_t>(std::ceil(maxEuPerSubslice / 8.0)); topologyArg->euStride = static_cast<uint16_t>(std::ceil(maxEuPerSubslice / 8.0));
topologyArg->subslice_offset = static_cast<uint16_t>(std::ceil(maxSlices / 8.0)); topologyArg->subsliceOffset = static_cast<uint16_t>(std::ceil(maxSlices / 8.0));
topologyArg->eu_offset = static_cast<uint16_t>(std::ceil(maxSubslices / 8.0)) * maxSlices; topologyArg->euOffset = static_cast<uint16_t>(std::ceil(maxSubslices / 8.0)) * maxSlices;
int threadData = (threadsPerEu == 8) ? 0xff : 0x7f; int threadData = (threadsPerEu == 8) ? 0xff : 0x7f;
@@ -390,9 +390,9 @@ bool DrmMockPrelimContext::handlePrelimQueryItem(void *arg) {
} }
} }
DEBUG_BREAK_IF(ptrDiff(data, topologyArg->data) != topologyArg->subslice_offset); DEBUG_BREAK_IF(ptrDiff(data, topologyArg->data) != topologyArg->subsliceOffset);
data = ptrOffset(topologyArg->data, topologyArg->subslice_offset); data = ptrOffset(topologyArg->data, topologyArg->subsliceOffset);
for (uint32_t sliceId = 0; sliceId < maxSlices; sliceId++) { for (uint32_t sliceId = 0; sliceId < maxSlices; sliceId++) {
for (uint32_t i = 0; i < maxSubslices; i++) { for (uint32_t i = 0; i < maxSubslices; i++) {
data[0] |= 1 << (i % 8); data[0] |= 1 << (i % 8);
@@ -403,9 +403,9 @@ bool DrmMockPrelimContext::handlePrelimQueryItem(void *arg) {
} }
} }
DEBUG_BREAK_IF(ptrDiff(data, topologyArg->data) != topologyArg->eu_offset); DEBUG_BREAK_IF(ptrDiff(data, topologyArg->data) != topologyArg->euOffset);
auto size = dataSize - topologyArg->eu_offset; auto size = dataSize - topologyArg->euOffset;
memset(ptrOffset(topologyArg->data, topologyArg->eu_offset), threadData, size); memset(ptrOffset(topologyArg->data, topologyArg->euOffset), threadData, size);
} }
} break; } break;

View File

@@ -51,9 +51,9 @@ struct QueryTopologyTests : ::testing::Test {
auto dataSize = static_cast<size_t>(std::ceil(realEuCount / 8.0)); auto dataSize = static_cast<size_t>(std::ceil(realEuCount / 8.0));
if (queryItem->length == 0) { if (queryItem->length == 0) {
queryItem->length = static_cast<int32_t>(sizeof(drm_i915_query_topology_info) + dataSize); queryItem->length = static_cast<int32_t>(sizeof(QueryTopologyInfo) + dataSize);
} else { } else {
auto topologyArg = reinterpret_cast<drm_i915_query_topology_info *>(queryItem->dataPtr); auto topologyArg = reinterpret_cast<QueryTopologyInfo *>(queryItem->dataPtr);
uint16_t finalSVal = queryComputeSlicesSCount; uint16_t finalSVal = queryComputeSlicesSCount;
uint16_t finalSSVal = queryComputeSlicesSSCount; uint16_t finalSSVal = queryComputeSlicesSSCount;
@@ -65,9 +65,9 @@ struct QueryTopologyTests : ::testing::Test {
finalEUVal /= 2; finalEUVal /= 2;
} }
topologyArg->max_slices = finalSVal; topologyArg->maxSlices = finalSVal;
topologyArg->max_subslices = (finalSSVal / finalSVal); topologyArg->maxSubslices = (finalSSVal / finalSVal);
topologyArg->max_eus_per_subslice = (finalEUVal / finalSSVal); topologyArg->maxEusPerSubslice = (finalEUVal / finalSSVal);
memset(topologyArg->data, 0xFF, dataSize); memset(topologyArg->data, 0xFF, dataSize);
} }