Files
rocm-systems/hipamd/tests/src/runtimeApi/stream/hipStreamACb_ThrdBehaviour.cpp
T
Lakhan singh Thakur 18f8b15523 [dtest] Enhancing hipStreamAddCallback() api test
-Scenario-1:: This test case is used to verify if the callback function
              called through  hipStreamAddCallback() api completes the
	      execution in order as hipStreamAddCallback() api queued
	      in their respective streams: hipStreamACb_AltEnqueue.cpp
-Scenario-2:: This test case tests if Host thread continues with next
              command after hipStreamAddCallback() api or wait for
	      callback() call to finish. Ideally Host thread should not
              wait for callback to
              finish: hipStreamACb_ThrdBehaviour.cpp
-Scenario-3:: Streams are launched in individual GPUs with different
              kernel Verify that all the kernels queued are executed
	      before the callback is hit: hipStreamACb_MStrm_Mgpu.cpp
-Scenario-4:: Checks the callback execution in the same order it was
              added. Also, it checks if the number of callbacks
	      executed are same as the number of callbacks added:
	      hipStreamACb_order.cpp
-Scenario-5:: This test case checks whether hipStreamSynchronize() is
              taking less time than the time taken by Callback()
	      function launched by hipStreamAddCallback() api :
	      hipStreamACb_StrmSyncTiming.cpp
-Scenario-6:: This test case is used to check if the runtime is ok when
              hipStreamAddCallback() is called back to back multiple
	      calls: hipStreamACb_MultiCalls.cpp
-Scenario-7:: This test case is used to check the behaviour of HIP when
              multiple hipStreaAddCallback() are called over multiple
	      Threads:hipStreamACb_MultiThread.cpp
              (Currently disabled)

SWDEV-238517 for enhancing hip unit tests

Change-Id: I9c7b7df6766c728b2b201df18726b9fbdd434c06
2020-07-07 00:43:32 -04:00

64 lines
2.4 KiB
C++

/*
* Copyright (c) 2020-present 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 WARRANNTY OF ANY KIND, EXPRESS OR
* IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* */
// Testcase Description: This test case tests if Host thread continues with
// next command after hipStreamAddCallback() api or wait for callback() call to
// finish. Ideally Host thread should not wait for callback to finish.
/* HIT_START
* BUILD: %t %s ../../test_common.cpp NVCC_OPTIONS --std=c++11
* TEST: %t
* HIT_END
*/
#include <unistd.h>
#include <stdio.h>
#include "hip/hip_runtime.h"
#include "test_common.h"
#ifdef __HIP_PLATFORM_HCC__
#define HIPRT_CB
#endif
bool Callback_Completed = false;
void HIPRT_CB Callback1(hipStream_t stream, hipError_t status, void* userData) {
sleep(5);
Callback_Completed = true;
}
int main(int argc, char* argv[]) {
hipStream_t mystream;
HIPCHECK(hipStreamCreateWithFlags(&mystream, hipStreamNonBlocking));
HIPCHECK(hipStreamAddCallback(mystream, Callback1, NULL, 0));
sleep(1);
// Callback_Completed is initialized to false. The same is set to true at
// the end of callback and callback sleeps for 5 seconds.
// So, in case Callback_Completed is true here, it means the main thread
// has waited till callback is complete and is a fail case.
if (Callback_Completed == false) {
HIPCHECK(hipStreamDestroy(mystream));
passed();
} else {
HIPCHECK(hipStreamDestroy(mystream));
failed("Unexpected: Host thread is waiting for callback to finish");
}
}