2018-07-23 14:45:44 -04:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "KFDBaseComponentTest.hpp"
|
|
|
|
|
#include "KFDTestUtil.hpp"
|
|
|
|
|
|
|
|
|
|
void KFDBaseComponentTest::SetUpTestCase() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KFDBaseComponentTest::TearDownTestCase() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KFDBaseComponentTest::SetUp() {
|
|
|
|
|
ROUTINE_START
|
|
|
|
|
|
|
|
|
|
ASSERT_SUCCESS(hsaKmtOpenKFD());
|
|
|
|
|
EXPECT_SUCCESS(hsaKmtGetVersion(&m_VersionInfo));
|
|
|
|
|
memset( &m_SystemProperties, 0, sizeof(m_SystemProperties) );
|
2018-08-01 14:18:40 -04:00
|
|
|
memset(m_RenderNodes, 0, sizeof(m_RenderNodes));
|
2018-07-23 14:45:44 -04:00
|
|
|
|
2018-08-14 09:52:31 -04:00
|
|
|
/** In order to be correctly testing the KFD interfaces and ensure
|
2018-07-23 14:45:44 -04:00
|
|
|
* that the KFD acknowledges relevant node parameters
|
2018-08-14 09:52:31 -04:00
|
|
|
* for the rest of the tests and used for more specific topology tests,
|
2018-07-23 14:45:44 -04:00
|
|
|
* call to GetSystemProperties for a system snapshot of the topology here
|
|
|
|
|
*/
|
|
|
|
|
ASSERT_SUCCESS(hsaKmtAcquireSystemProperties(&m_SystemProperties));
|
|
|
|
|
ASSERT_GT(m_SystemProperties.NumNodes, HSAuint32(0)) << "HSA has no nodes.";
|
|
|
|
|
|
|
|
|
|
m_NodeInfo.Init(m_SystemProperties.NumNodes);
|
|
|
|
|
|
|
|
|
|
// setting memory flags with default values , can be modified according to needs
|
|
|
|
|
m_MemoryFlags.ui32.NonPaged = 0; // Paged
|
|
|
|
|
m_MemoryFlags.ui32.CachePolicy = HSA_CACHING_NONCACHED; // Non cached
|
|
|
|
|
m_MemoryFlags.ui32.ReadOnly = 0; // Read/Write
|
|
|
|
|
m_MemoryFlags.ui32.PageSize = HSA_PAGE_SIZE_4KB; // 4KB page
|
2018-08-14 09:52:31 -04:00
|
|
|
m_MemoryFlags.ui32.HostAccess = 1; // Host accessible
|
|
|
|
|
m_MemoryFlags.ui32.NoSubstitute = 0; // Fall back to node 0 if needed
|
2018-07-23 14:45:44 -04:00
|
|
|
m_MemoryFlags.ui32.GDSMemory = 0;
|
|
|
|
|
m_MemoryFlags.ui32.Scratch = 0;
|
|
|
|
|
|
|
|
|
|
const HsaNodeProperties *nodeProperties = m_NodeInfo.HsaDefaultGPUNodeProperties();
|
|
|
|
|
ASSERT_NOTNULL(nodeProperties) << "failed to get HSA default GPU Node properties";
|
|
|
|
|
|
|
|
|
|
g_TestGPUFamilyId = FamilyIdFromNode(nodeProperties);
|
|
|
|
|
|
2019-01-09 19:20:32 -05:00
|
|
|
GetSdmaInfo(nodeProperties, &m_numSdmaEngines, &m_numSdmaQueuesPerEngine);
|
|
|
|
|
|
2018-07-23 14:45:44 -04:00
|
|
|
m_FamilyId = g_TestGPUFamilyId;
|
|
|
|
|
|
|
|
|
|
ROUTINE_END
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KFDBaseComponentTest::TearDown() {
|
|
|
|
|
ROUTINE_START
|
|
|
|
|
|
2018-08-01 14:18:40 -04:00
|
|
|
for (int i = 0; i < MAX_RENDER_NODES; i++) {
|
|
|
|
|
if (m_RenderNodes[i].fd <= 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
amdgpu_device_deinitialize(m_RenderNodes[i].device_handle);
|
|
|
|
|
drmClose(m_RenderNodes[i].fd);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-20 09:54:26 -04:00
|
|
|
EXPECT_SUCCESS(hsaKmtReleaseSystemProperties());
|
|
|
|
|
EXPECT_SUCCESS(hsaKmtCloseKFD());
|
2018-07-23 14:45:44 -04:00
|
|
|
|
|
|
|
|
ROUTINE_END
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HSAuint64 KFDBaseComponentTest::GetSysMemSize() {
|
|
|
|
|
const HsaNodeProperties *nodeProps;
|
|
|
|
|
HsaMemoryProperties cpuMemoryProps;
|
|
|
|
|
HSAuint64 systemMemSize = 0;
|
|
|
|
|
|
|
|
|
|
/* Find System Memory size */
|
|
|
|
|
for (unsigned node = 0; node < m_SystemProperties.NumNodes; node++) {
|
|
|
|
|
nodeProps = m_NodeInfo.GetNodeProperties(node);
|
|
|
|
|
if (nodeProps != NULL && nodeProps->NumCPUCores > 0 && nodeProps->NumMemoryBanks > 0) {
|
2018-08-14 09:52:31 -04:00
|
|
|
/* For NUMA nodes, memory is distributed among different nodes.
|
2018-07-23 14:45:44 -04:00
|
|
|
* Compute total system memory size. KFD driver also computes
|
|
|
|
|
* the system memory (si_meminfo) similarly
|
|
|
|
|
*/
|
|
|
|
|
EXPECT_SUCCESS(hsaKmtGetNodeMemoryProperties(node, 1, &cpuMemoryProps));
|
|
|
|
|
systemMemSize += cpuMemoryProps.SizeInBytes;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return systemMemSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HSAuint64 KFDBaseComponentTest::GetVramSize(int defaultGPUNode) {
|
|
|
|
|
const HsaNodeProperties *nodeProps;
|
|
|
|
|
|
|
|
|
|
/* Find framebuffer size */
|
|
|
|
|
nodeProps = m_NodeInfo.GetNodeProperties(defaultGPUNode);
|
|
|
|
|
EXPECT_NE((const HsaNodeProperties *)NULL, nodeProps);
|
|
|
|
|
HSAuint32 numBanks = nodeProps->NumMemoryBanks;
|
|
|
|
|
HsaMemoryProperties memoryProps[numBanks];
|
|
|
|
|
EXPECT_SUCCESS(hsaKmtGetNodeMemoryProperties(defaultGPUNode, numBanks, memoryProps));
|
|
|
|
|
unsigned bank;
|
|
|
|
|
for (bank = 0; bank < numBanks; bank++) {
|
|
|
|
|
if (memoryProps[bank].HeapType == HSA_HEAPTYPE_FRAME_BUFFER_PRIVATE
|
|
|
|
|
|| memoryProps[bank].HeapType == HSA_HEAPTYPE_FRAME_BUFFER_PUBLIC)
|
|
|
|
|
return memoryProps[bank].SizeInBytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2018-08-01 14:18:40 -04:00
|
|
|
|
|
|
|
|
int KFDBaseComponentTest::FindDRMRenderNode(int gpuNode) {
|
2018-09-21 11:53:23 -04:00
|
|
|
HsaNodeProperties *nodeProperties;
|
|
|
|
|
_HSAKMT_STATUS status;
|
2018-08-01 14:18:40 -04:00
|
|
|
|
2018-09-21 11:53:23 -04:00
|
|
|
nodeProperties = new HsaNodeProperties();
|
2018-08-01 14:18:40 -04:00
|
|
|
|
2018-09-21 11:53:23 -04:00
|
|
|
status = hsaKmtGetNodeProperties(gpuNode, nodeProperties);
|
|
|
|
|
EXPECT_SUCCESS(status) << "Node index: " << gpuNode << "hsaKmtGetNodeProperties returned status " << status;
|
2018-08-01 14:18:40 -04:00
|
|
|
|
2018-09-21 11:53:23 -04:00
|
|
|
if (status != HSAKMT_STATUS_SUCCESS) {
|
|
|
|
|
delete nodeProperties;
|
2018-08-01 14:18:40 -04:00
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-21 11:53:23 -04:00
|
|
|
int minor = nodeProperties->DrmRenderMinor;
|
2018-08-01 14:18:40 -04:00
|
|
|
if (minor < 128) {
|
|
|
|
|
LOG() << "Failed to get minor number " << minor << std::endl;
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int index = minor - 128;
|
|
|
|
|
|
|
|
|
|
if (m_RenderNodes[index].fd == 0) {
|
|
|
|
|
m_RenderNodes[index].fd = drmOpenRender(minor);
|
|
|
|
|
|
|
|
|
|
if (m_RenderNodes[index].fd < 0) {
|
|
|
|
|
LOG() << "Failed to open render node" << std::endl;
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (amdgpu_device_initialize(m_RenderNodes[index].fd,
|
|
|
|
|
&m_RenderNodes[index].major_version,
|
|
|
|
|
&m_RenderNodes[index].minor_version,
|
|
|
|
|
&m_RenderNodes[index].device_handle) != 0) {
|
|
|
|
|
drmClose(m_RenderNodes[index].fd);
|
|
|
|
|
m_RenderNodes[index].fd = 0;
|
|
|
|
|
LOG() << "Failed to initialize amdgpu device" << std::endl;
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return index;
|
|
|
|
|
}
|