unit_tests/profiling/profiling_tests.cpp
HWCMDTEST_F(IGFX_GEN8_CORE, ProfilingTests, GIVENCommandQueueBlockedWithProfilingWHENWalkerIsDispatchedTHENMiStoreRegisterMemIsPresentInCS) {
    typedef typename FamilyType::MI_STORE_REGISTER_MEM MI_STORE_REGISTER_MEM;
    typedef typename FamilyType::GPGPU_WALKER GPGPU_WALKER;

    MockKernel kernel(program.get(), kernelInfo, *pDevice);
    ASSERT_EQ(CL_SUCCESS, kernel.initialize());

    size_t globalOffsets[3] = {0, 0, 0};
    size_t workItems[3] = {1, 1, 1};
    uint32_t dimensions = 1;
    cl_event event;
    cl_event ue = new UserEvent();

    static_cast<CommandQueueHw<FamilyType> *>(pCmdQ)->enqueueKernel(
        &kernel,
        dimensions,
        globalOffsets,
        workItems,
        nullptr,
        1,   // one user event to block queue
        &ue, // user event not signaled
        &event);

    // parseCommands<FamilyType>(*pCmdQ);
    ASSERT_NE(nullptr, pCmdQ->virtualEvent);
    ASSERT_NE(nullptr, pCmdQ->virtualEvent->peekCommand());
    NEO::LinearStream *eventCommandStream = pCmdQ->virtualEvent->peekCommand()->getCommandStream();
    ASSERT_NE(nullptr, eventCommandStream);
    parseCommands<FamilyType>(*eventCommandStream);

    // Find GPGPU_WALKER
    auto itorGPGPUWalkerCmd = find<GPGPU_WALKER *>(cmdList.begin(), cmdList.end());
    GenCmdList::reverse_iterator rItorGPGPUWalkerCmd(itorGPGPUWalkerCmd);
    ASSERT_NE(cmdList.end(), itorGPGPUWalkerCmd);

    // Check MI_STORE_REGISTER_MEMs
    auto itorBeforeMI = reverse_find<MI_STORE_REGISTER_MEM *>(rItorGPGPUWalkerCmd, cmdList.rbegin());
    ASSERT_NE(cmdList.rbegin(), itorBeforeMI);
    auto pBeforeMI = genCmdCast<MI_STORE_REGISTER_MEM *>(*itorBeforeMI);
    pBeforeMI = genCmdCast<MI_STORE_REGISTER_MEM *>(*itorBeforeMI);
    ASSERT_NE(nullptr, pBeforeMI);
    EXPECT_EQ(GP_THREAD_TIME_REG_ADDRESS_OFFSET_LOW, pBeforeMI->getRegisterAddress());

    auto itorAfterMI = find<MI_STORE_REGISTER_MEM *>(itorGPGPUWalkerCmd, cmdList.end());
    ASSERT_NE(cmdList.end(), itorAfterMI);
    auto pAfterMI = genCmdCast<MI_STORE_REGISTER_MEM *>(*itorAfterMI);
    ASSERT_NE(nullptr, pAfterMI);
    EXPECT_EQ(GP_THREAD_TIME_REG_ADDRESS_OFFSET_LOW, pAfterMI->getRegisterAddress());
    ++itorAfterMI;
    EXPECT_EQ(itorAfterMI, cmdList.end());
    clReleaseEvent(event);
    ((UserEvent *)ue)->release();
    pCmdQ->isQueueBlocked();
}
/*
#   One additional MI_STORE_REGISTER_MEM is expected before and after GPGPU_WALKER.
#   If queue is blocked commands should be added to event
*/
One additional MI_STORE_REGISTER_MEM is expected before and after GPGPU_WALKER.
If queue is blocked commands should be added to event
One additional MI_STORE_REGISTER_MEM is expected before and after GPGPU_WALKER . If queue is blocked commands should be added to event
HWCMDTEST_F(IGFX_GEN8_CORE, ProfilingTests, GIVENCommandQueueBlockedWithProfilingWHENWalkerIsDispatchedTHENMiStoreRegisterMemIsPresentInCS) {
    typedef typename FamilyType::MI_STORE_REGISTER_MEM MI_STORE_REGISTER_MEM;
    typedef typename FamilyType::GPGPU_WALKER GPGPU_WALKER;
    MockKernel kernel(program.get(), kernelInfo, *pDevice);
    ASSERT_EQ(CL_SUCCESS, kernel.initialize());
    size_t globalOffsets[3] = {0, 0, 0};
    size_t workItems[3] = {1, 1, 1};
    uint32_t dimensions = 1;
    cl_event event;
    cl_event ue = new UserEvent();
    static_cast<CommandQueueHw<FamilyType> *>(pCmdQ)->enqueueKernel(
        &kernel,
        dimensions,
        globalOffsets,
        workItems,
        nullptr,
        1,   
        &ue, 
        &event);
    ASSERT_NE(nullptr, pCmdQ->virtualEvent);
    ASSERT_NE(nullptr, pCmdQ->virtualEvent->peekCommand());
    NEO::LinearStream *eventCommandStream = pCmdQ->virtualEvent->peekCommand()->getCommandStream();
    ASSERT_NE(nullptr, eventCommandStream);
    parseCommands<FamilyType>(*eventCommandStream);
    auto itorGPGPUWalkerCmd = find<GPGPU_WALKER *>(cmdList.begin(), cmdList.end());
    GenCmdList::reverse_iterator rItorGPGPUWalkerCmd(itorGPGPUWalkerCmd);
    ASSERT_NE(cmdList.end(), itorGPGPUWalkerCmd);
    auto itorBeforeMI = reverse_find<MI_STORE_REGISTER_MEM *>(rItorGPGPUWalkerCmd, cmdList.rbegin());
    ASSERT_NE(cmdList.rbegin(), itorBeforeMI);
    auto pBeforeMI = genCmdCast<MI_STORE_REGISTER_MEM *>(*itorBeforeMI);
    pBeforeMI = genCmdCast<MI_STORE_REGISTER_MEM *>(*itorBeforeMI);
    ASSERT_NE(nullptr, pBeforeMI);
    EXPECT_EQ(GP_THREAD_TIME_REG_ADDRESS_OFFSET_LOW, pBeforeMI->getRegisterAddress());
    auto itorAfterMI = find<MI_STORE_REGISTER_MEM *>(itorGPGPUWalkerCmd, cmdList.end());
    ASSERT_NE(cmdList.end(), itorAfterMI);
    auto pAfterMI = genCmdCast<MI_STORE_REGISTER_MEM *>(*itorAfterMI);
    ASSERT_NE(nullptr, pAfterMI);
    EXPECT_EQ(GP_THREAD_TIME_REG_ADDRESS_OFFSET_LOW, pAfterMI->getRegisterAddress());
    ++itorAfterMI;
    EXPECT_EQ(itorAfterMI, cmdList.end());
    clReleaseEvent(event);
    ((UserEvent *)ue)->release();
    pCmdQ->isQueueBlocked();
}
HWCMDTEST_F ( IGFX_GEN8_CORE , ProfilingTests , GIVENCommandQueueBlockedWithProfilingWHENWalkerIsDispatchedTHENMiStoreRegisterMemIsPresentInCS ) { typedef typename FamilyType :: MI_STORE_REGISTER_MEM MI_STORE_REGISTER_MEM ; typedef typename FamilyType :: GPGPU_WALKER GPGPU_WALKER ; MockKernel kernel ( program . get ( ) , kernelInfo , * pDevice ) ; ASSERT_EQ ( CL_SUCCESS , kernel . initialize ( ) ) ; size_t globalOffsets [ 3 ] = { 0 , 0 , 0 } ; size_t workItems [ 3 ] = { 1 , 1 , 1 } ; uint32_t dimensions = 1 ; cl_event event ; cl_event ue = new UserEvent ( ) ; static_cast < CommandQueueHw < FamilyType > * > ( pCmdQ ) -> enqueueKernel ( & kernel , dimensions , globalOffsets , workItems , nullptr , 1 , & ue , & event ) ; ASSERT_NE ( nullptr , pCmdQ -> virtualEvent ) ; ASSERT_NE ( nullptr , pCmdQ -> virtualEvent -> peekCommand ( ) ) ; NEO :: LinearStream * eventCommandStream = pCmdQ -> virtualEvent -> peekCommand ( ) -> getCommandStream ( ) ; ASSERT_NE ( nullptr , eventCommandStream ) ; parseCommands < FamilyType > ( * eventCommandStream ) ; auto itorGPGPUWalkerCmd = find < GPGPU_WALKER * > ( cmdList . begin ( ) , cmdList . end ( ) ) ; GenCmdList :: reverse_iterator rItorGPGPUWalkerCmd ( itorGPGPUWalkerCmd ) ; ASSERT_NE ( cmdList . end ( ) , itorGPGPUWalkerCmd ) ; auto itorBeforeMI = reverse_find < MI_STORE_REGISTER_MEM * > ( rItorGPGPUWalkerCmd , cmdList . rbegin ( ) ) ; ASSERT_NE ( cmdList . rbegin ( ) , itorBeforeMI ) ; auto pBeforeMI = genCmdCast < MI_STORE_REGISTER_MEM * > ( * itorBeforeMI ) ; pBeforeMI = genCmdCast < MI_STORE_REGISTER_MEM * > ( * itorBeforeMI ) ; ASSERT_NE ( nullptr , pBeforeMI ) ; EXPECT_EQ ( GP_THREAD_TIME_REG_ADDRESS_OFFSET_LOW , pBeforeMI -> getRegisterAddress ( ) ) ; auto itorAfterMI = find < MI_STORE_REGISTER_MEM * > ( itorGPGPUWalkerCmd , cmdList . end ( ) ) ; ASSERT_NE ( cmdList . end ( ) , itorAfterMI ) ; auto pAfterMI = genCmdCast < MI_STORE_REGISTER_MEM * > ( * itorAfterMI ) ; ASSERT_NE ( nullptr , pAfterMI ) ; EXPECT_EQ ( GP_THREAD_TIME_REG_ADDRESS_OFFSET_LOW , pAfterMI -> getRegisterAddress ( ) ) ; ++ itorAfterMI ; EXPECT_EQ ( itorAfterMI , cmdList . end ( ) ) ; clReleaseEvent ( event ) ; ( ( UserEvent * ) ue ) -> release ( ) ; pCmdQ -> isQueueBlocked ( ) ; }
One additional MI_STORE_REGISTER_MEM is expected before and after GPGPU_WALKER.
One additional MI_STORE_REGISTER_MEM is expected before and after GPGPU_WALKER .
// one user event to block queue // user event not signaled // parseCommands<FamilyType>(*pCmdQ); // Find GPGPU_WALKER // Check MI_STORE_REGISTER_MEMs