Refactor pipe control post sync programming.

Change-Id: I81f4840345494c6d32679e29faaff786677cb4b0
This commit is contained in:
Mrozek, Michal
2018-11-23 10:32:15 +01:00
committed by sys_ocldev
parent d961bd8354
commit 61e7ae9280
7 changed files with 78 additions and 54 deletions

View File

@@ -108,12 +108,7 @@ void GpgpuWalkerHelper<GfxFamily>::dispatchProfilingCommandsStart(
// PIPE_CONTROL for global timestamp
uint64_t TimeStampAddress = reinterpret_cast<uint64_t>(&(hwTimeStamps.GlobalStartTS));
auto pPipeControlCmd = (PIPE_CONTROL *)commandStream->getSpace(sizeof(PIPE_CONTROL));
*pPipeControlCmd = PIPE_CONTROL::sInit();
pPipeControlCmd->setCommandStreamerStallEnable(true);
pPipeControlCmd->setPostSyncOperation(PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_TIMESTAMP);
pPipeControlCmd->setAddress(static_cast<uint32_t>(TimeStampAddress & 0x0000FFFFFFFFULL));
pPipeControlCmd->setAddressHigh(static_cast<uint32_t>(TimeStampAddress >> 32));
PipeControlHelper<GfxFamily>::obtainPipeControlAndProgramPostSyncOperation(commandStream, PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_TIMESTAMP, TimeStampAddress, 0llu);
//MI_STORE_REGISTER_MEM for context local timestamp
TimeStampAddress = reinterpret_cast<uint64_t>(&(hwTimeStamps.ContextStartTS));
@@ -311,14 +306,9 @@ void GpgpuWalkerHelper<GfxFamily>::dispatchPerfCountersCommandsStart(
address = reinterpret_cast<uint64_t>(&(hwPerfCounter.HWPerfCounters.HwPerfReportBegin.Oa));
pReportPerfCount->setMemoryAddress(address);
//Timestamp: Global Start
pPipeControlCmd = (PIPE_CONTROL *)commandStream->getSpace(sizeof(PIPE_CONTROL));
*pPipeControlCmd = PIPE_CONTROL::sInit();
pPipeControlCmd->setCommandStreamerStallEnable(true);
pPipeControlCmd->setPostSyncOperation(PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_TIMESTAMP);
address = reinterpret_cast<uint64_t>(&(hwPerfCounter.HWTimeStamp.GlobalStartTS));
pPipeControlCmd->setAddress(static_cast<uint32_t>(address & ((uint64_t)UINT32_MAX)));
pPipeControlCmd->setAddressHigh(static_cast<uint32_t>(address >> 32));
PipeControlHelper<GfxFamily>::obtainPipeControlAndProgramPostSyncOperation(commandStream, PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_TIMESTAMP, address, 0llu);
GpgpuWalkerHelper<GfxFamily>::dispatchPerfCountersUserCounterCommands(commandQueue, hwPerfCounter, commandStream, true);
@@ -347,13 +337,8 @@ void GpgpuWalkerHelper<GfxFamily>::dispatchPerfCountersCommandsEnd(
GpgpuWalkerHelper<GfxFamily>::dispatchPerfCountersOABufferStateCommands(commandQueue, hwPerfCounter, commandStream);
//Timestamp: Global End
pPipeControlCmd = (PIPE_CONTROL *)commandStream->getSpace(sizeof(PIPE_CONTROL));
*pPipeControlCmd = PIPE_CONTROL::sInit();
pPipeControlCmd->setCommandStreamerStallEnable(true);
pPipeControlCmd->setPostSyncOperation(PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_TIMESTAMP);
address = reinterpret_cast<uint64_t>(&(hwPerfCounter.HWTimeStamp.GlobalEndTS));
pPipeControlCmd->setAddress(static_cast<uint32_t>(address & ((uint64_t)UINT32_MAX)));
pPipeControlCmd->setAddressHigh(static_cast<uint32_t>(address >> 32));
PipeControlHelper<GfxFamily>::obtainPipeControlAndProgramPostSyncOperation(commandStream, PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_TIMESTAMP, address, 0llu);
auto pReportPerfCount = (MI_REPORT_PERF_COUNT *)commandStream->getSpace(sizeof(MI_REPORT_PERF_COUNT));
*pReportPerfCount = MI_REPORT_PERF_COUNT::sInit();

View File

@@ -187,8 +187,8 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
//Some architectures (SKL) requires to have pipe control prior to pipe control with tag write, add it here
addPipeControlWA(commandStreamTask, dispatchFlags.dcFlush);
auto pCmd = addPipeControlCmd(commandStreamTask);
pCmd->setPostSyncOperation(PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA);
auto address = getTagAllocation()->getGpuAddress();
auto pCmd = PipeControlHelper<GfxFamily>::obtainPipeControlAndProgramPostSyncOperation(&commandStreamTask, PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA, address, taskCount + 1);
//Some architectures (BDW) requires to have at least one flush bit set
addDcFlushToPipeControl(pCmd, dispatchFlags.dcFlush);
@@ -204,11 +204,6 @@ CompletionStamp CommandStreamReceiverHw<GfxFamily>::flushTask(
pCmd->setStateCacheInvalidationEnable(true);
}
auto address = getTagAllocation()->getGpuAddress();
pCmd->setAddressHigh(address >> 32);
pCmd->setAddress(address & (0xffffffff));
pCmd->setImmediateData(taskCount + 1);
this->latestSentTaskCount = taskCount + 1;
DBG_LOG(LogTaskCounts, __FUNCTION__, "Line: ", __LINE__, "taskCount", taskCount);
if (DebugManager.flags.AddPatchInfoCommentsForAUBDump.get()) {

View File

@@ -8,6 +8,7 @@
#include "runtime/command_stream/command_stream_receiver_hw.h"
#include "runtime/command_stream/experimental_command_buffer.h"
#include "runtime/command_stream/linear_stream.h"
#include "runtime/helpers/hw_helper.h"
#include "runtime/memory_manager/graphics_allocation.h"
namespace OCLRT {
@@ -75,12 +76,7 @@ void ExperimentalCommandBuffer::addTimeStampPipeControl() {
uint64_t timeStampAddress = timestamps->getGpuAddress() + timestampsOffset;
pCmd = static_cast<PIPE_CONTROL *>(currentStream->getSpace(sizeof(PIPE_CONTROL)));
*pCmd = GfxFamily::cmdInitPipeControl;
pCmd->setCommandStreamerStallEnable(true);
pCmd->setPostSyncOperation(PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_TIMESTAMP);
pCmd->setAddress(static_cast<uint32_t>(timeStampAddress & 0x0000FFFFFFFFULL));
pCmd->setAddressHigh(static_cast<uint32_t>(timeStampAddress >> 32));
PipeControlHelper<GfxFamily>::obtainPipeControlAndProgramPostSyncOperation(currentStream.get(), PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_TIMESTAMP, timeStampAddress, 0llu);
//moving to next chunk
timestampsOffset += sizeof(uint64_t);

View File

@@ -228,25 +228,13 @@ void DeviceQueueHw<GfxFamily>::addExecutionModelCleanUpSection(Kernel *parentKer
addPipeControlCmdWa();
auto pipeControl = slbCS.getSpaceForCmd<PIPE_CONTROL>();
*pipeControl = PIPE_CONTROL::sInit();
pipeControl->setCommandStreamerStallEnable(true);
pipeControl->setPostSyncOperation(PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA);
pipeControl->setAddressHigh(criticalSectionAddress >> 32);
pipeControl->setAddress(criticalSectionAddress & (0xffffffff));
pipeControl->setImmediateData(ExecutionModelCriticalSection::Free);
PipeControlHelper<GfxFamily>::obtainPipeControlAndProgramPostSyncOperation(&slbCS, PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA, criticalSectionAddress, ExecutionModelCriticalSection::Free);
uint64_t tagAddress = (uint64_t)device->getTagAddress();
addPipeControlCmdWa();
auto pipeControl2 = slbCS.getSpaceForCmd<PIPE_CONTROL>();
*pipeControl2 = PIPE_CONTROL::sInit();
pipeControl2->setCommandStreamerStallEnable(true);
pipeControl2->setPostSyncOperation(PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA);
pipeControl2->setAddressHigh(tagAddress >> 32);
pipeControl2->setAddress(tagAddress & (0xffffffff));
pipeControl2->setImmediateData(taskCount);
PipeControlHelper<GfxFamily>::obtainPipeControlAndProgramPostSyncOperation(&slbCS, PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA, tagAddress, taskCount);
addMediaStateClearCmds();

View File

@@ -127,4 +127,26 @@ struct LriHelper {
return lri;
}
};
template <typename GfxFamily>
struct PipeControlHelper {
using PIPE_CONTROL = typename GfxFamily::PIPE_CONTROL;
using POST_SYNC_OPERATION = typename GfxFamily::PIPE_CONTROL::POST_SYNC_OPERATION;
static PIPE_CONTROL *obtainPipeControlAndProgramPostSyncOperation(LinearStream *commandStream,
POST_SYNC_OPERATION operation,
uint64_t gpuAddress,
uint64_t immediateData) {
auto pipeControl = reinterpret_cast<PIPE_CONTROL *>(commandStream->getSpace(sizeof(PIPE_CONTROL)));
*pipeControl = PIPE_CONTROL::sInit();
pipeControl->setCommandStreamerStallEnable(true);
pipeControl->setPostSyncOperation(operation);
pipeControl->setAddress(static_cast<uint32_t>(gpuAddress & 0x0000FFFFFFFFULL));
pipeControl->setAddressHigh(static_cast<uint32_t>(gpuAddress >> 32));
if (operation == POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA) {
pipeControl->setImmediateData(immediateData);
}
return pipeControl;
}
};
} // namespace OCLRT

View File

@@ -400,14 +400,7 @@ typename GfxFamily::MI_ATOMIC *KernelCommandsHelper<GfxFamily>::programMiAtomic(
template <typename GfxFamily>
void KernelCommandsHelper<GfxFamily>::programPipeControlDataWriteWithCsStall(LinearStream &commandStream, uint64_t writeAddress, uint64_t data) {
using PIPE_CONTROL = typename GfxFamily::PIPE_CONTROL;
auto pipeControlCmd = commandStream.getSpaceForCmd<PIPE_CONTROL>();
*pipeControlCmd = PIPE_CONTROL::sInit();
pipeControlCmd->setCommandStreamerStallEnable(true);
pipeControlCmd->setPostSyncOperation(PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA);
pipeControlCmd->setAddress(static_cast<uint32_t>(writeAddress & 0x0000FFFFFFFFULL));
pipeControlCmd->setAddressHigh(static_cast<uint32_t>(writeAddress >> 32));
pipeControlCmd->setImmediateData(data);
PipeControlHelper<GfxFamily>::obtainPipeControlAndProgramPostSyncOperation(&commandStream, PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA, writeAddress, data);
}
template <typename GfxFamily>

View File

@@ -147,6 +147,51 @@ HWTEST_F(LriHelperTests, givenAddressAndOffsetWhenHelperIsUsedThenProgramCmdStre
EXPECT_TRUE(memcmp(lri, &expectedLri, sizeof(MI_LOAD_REGISTER_IMM)) == 0);
}
using PipeControlHelperTests = ::testing::Test;
HWTEST_F(PipeControlHelperTests, givenPostSyncWriteTimestampModeWhenHelperIsUsedThenProperFieldsAreProgrammed) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
std::unique_ptr<uint8_t> buffer(new uint8_t[128]);
LinearStream stream(buffer.get(), 128);
uint64_t address = 0x1234567887654321;
uint64_t immediateData = 0x1234;
auto expectedPipeControl = PIPE_CONTROL::sInit();
expectedPipeControl.setCommandStreamerStallEnable(true);
expectedPipeControl.setPostSyncOperation(PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_TIMESTAMP);
expectedPipeControl.setAddress(static_cast<uint32_t>(address & 0x0000FFFFFFFFULL));
expectedPipeControl.setAddressHigh(static_cast<uint32_t>(address >> 32));
auto pipeControl = PipeControlHelper<FamilyType>::obtainPipeControlAndProgramPostSyncOperation(&stream, PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_TIMESTAMP, address, immediateData);
EXPECT_EQ(sizeof(PIPE_CONTROL), stream.getUsed());
EXPECT_EQ(pipeControl, stream.getCpuBase());
EXPECT_TRUE(memcmp(pipeControl, &expectedPipeControl, sizeof(PIPE_CONTROL)) == 0);
}
HWTEST_F(PipeControlHelperTests, givenPostSyncWriteImmediateDataModeWhenHelperIsUsedThenProperFieldsAreProgrammed) {
using PIPE_CONTROL = typename FamilyType::PIPE_CONTROL;
std::unique_ptr<uint8_t> buffer(new uint8_t[128]);
LinearStream stream(buffer.get(), 128);
uint64_t address = 0x1234567887654321;
uint64_t immediateData = 0x1234;
auto expectedPipeControl = PIPE_CONTROL::sInit();
expectedPipeControl.setCommandStreamerStallEnable(true);
expectedPipeControl.setPostSyncOperation(PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA);
expectedPipeControl.setAddress(static_cast<uint32_t>(address & 0x0000FFFFFFFFULL));
expectedPipeControl.setAddressHigh(static_cast<uint32_t>(address >> 32));
expectedPipeControl.setImmediateData(immediateData);
auto pipeControl = PipeControlHelper<FamilyType>::obtainPipeControlAndProgramPostSyncOperation(&stream, PIPE_CONTROL::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA, address, immediateData);
EXPECT_EQ(sizeof(PIPE_CONTROL), stream.getUsed());
EXPECT_EQ(pipeControl, stream.getCpuBase());
EXPECT_TRUE(memcmp(pipeControl, &expectedPipeControl, sizeof(PIPE_CONTROL)) == 0);
}
TEST(HwInfoTest, givenHwInfoWhenIsCoreThenPlatformTypeIsCore) {
HardwareInfo hwInfo;
hwInfo.capabilityTable.isCore = true;