EXSWHTEC-178 - Implement tests for Graph Event Node APIs #44
Change-Id: Id3f569d94d347af2f5e27513fa01c5a1e8e30fd9
이 커밋은 다음에 포함됨:
@@ -47,33 +47,30 @@ Testcase Scenarios :
|
||||
- Pass event record node as input node.
|
||||
*/
|
||||
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_test_checkers.hh>
|
||||
#include <hip_test_common.hh>
|
||||
#include <hip_test_kernels.hh>
|
||||
|
||||
#define GRID_DIM 64
|
||||
#define BLK_DIM 256
|
||||
#define LEN (GRID_DIM * BLK_DIM)
|
||||
#define DELAY_IN_MS 2000
|
||||
|
||||
/**
|
||||
* Kernel Functions to perform square and introduce delay in device.
|
||||
*/
|
||||
static __global__ void sqr_ker_func(int* a, int* b, int clockrate) {
|
||||
int tx = hipBlockIdx_x*hipBlockDim_x + hipThreadIdx_x;
|
||||
if (tx < LEN) b[tx] = a[tx]*a[tx];
|
||||
uint64_t wait_t = DELAY_IN_MS,
|
||||
start = clock64()/clockrate, cur;
|
||||
do { cur = clock64()/clockrate - start;}while (cur < wait_t);
|
||||
static __global__ void sqr_ker_func(int* a, int* b, size_t N, int clockrate, size_t delayMs) {
|
||||
int tx = hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x;
|
||||
if (tx < N) b[tx] = a[tx] * a[tx];
|
||||
uint64_t wait_t = delayMs, start = clock64() / clockrate, cur;
|
||||
do {
|
||||
cur = clock64() / clockrate - start;
|
||||
} while (cur < wait_t);
|
||||
}
|
||||
|
||||
static __global__ void sqr_ker_func_gfx11(int* a, int* b, int clockrate) {
|
||||
static __global__ void sqr_ker_func_gfx11(int* a, int* b, size_t N, int clockrate, size_t delayMs) {
|
||||
#if HT_AMD
|
||||
int tx = hipBlockIdx_x*hipBlockDim_x + hipThreadIdx_x;
|
||||
if (tx < LEN) b[tx] = a[tx]*a[tx];
|
||||
uint64_t wait_t = DELAY_IN_MS,
|
||||
start = wall_clock64()/clockrate, cur;
|
||||
do { cur = wall_clock64()/clockrate - start;}while (cur < wait_t);
|
||||
int tx = hipBlockIdx_x * hipBlockDim_x + hipThreadIdx_x;
|
||||
if (tx < N) b[tx] = a[tx] * a[tx];
|
||||
uint64_t wait_t = delayMs, start = wall_clock64() / clockrate, cur;
|
||||
do {
|
||||
cur = wall_clock64() / clockrate - start;
|
||||
} while (cur < wait_t);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -81,7 +78,10 @@ static __global__ void sqr_ker_func_gfx11(int* a, int* b, int clockrate) {
|
||||
* Scenario 1: Test to validate setting different events in executable graph.
|
||||
*/
|
||||
TEST_CASE("Unit_hipGraphExecEventWaitNodeSetEvent_SetAndVerifyMemory") {
|
||||
size_t memsize = LEN*sizeof(int);
|
||||
constexpr size_t gridSize = 64;
|
||||
constexpr size_t blockSize = 256;
|
||||
constexpr size_t N = gridSize * blockSize;
|
||||
size_t memsize = N * sizeof(int);
|
||||
hipGraph_t graph1, graph2;
|
||||
HIP_CHECK(hipGraphCreate(&graph1, 0));
|
||||
HIP_CHECK(hipGraphCreate(&graph2, 0));
|
||||
@@ -91,8 +91,7 @@ TEST_CASE("Unit_hipGraphExecEventWaitNodeSetEvent_SetAndVerifyMemory") {
|
||||
HIP_CHECK(hipEventCreate(&event2));
|
||||
// Create nodes with event_start and event1_end
|
||||
hipGraphNode_t event_rec;
|
||||
HIP_CHECK(hipGraphAddEventRecordNode(&event_rec, graph1, nullptr, 0,
|
||||
event1));
|
||||
HIP_CHECK(hipGraphAddEventRecordNode(&event_rec, graph1, nullptr, 0, event1));
|
||||
int *inp_h, *inp_d, *out_h, *out_d;
|
||||
// Allocate host buffers
|
||||
inp_h = reinterpret_cast<int*>(malloc(memsize));
|
||||
@@ -103,7 +102,7 @@ TEST_CASE("Unit_hipGraphExecEventWaitNodeSetEvent_SetAndVerifyMemory") {
|
||||
HIP_CHECK(hipMalloc(&inp_d, memsize));
|
||||
HIP_CHECK(hipMalloc(&out_d, memsize));
|
||||
// Initialize host buffer
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
for (uint32_t i = 0; i < N; i++) {
|
||||
inp_h[i] = i;
|
||||
out_h[i] = 0;
|
||||
}
|
||||
@@ -112,10 +111,12 @@ TEST_CASE("Unit_hipGraphExecEventWaitNodeSetEvent_SetAndVerifyMemory") {
|
||||
// MemcpyH2D -> kernel1 -> event_rec
|
||||
hipGraphNode_t memcpyH2D, kernelnode1;
|
||||
hipKernelNodeParams kernelNodeParams1{};
|
||||
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D, graph1, nullptr, 0, inp_d,
|
||||
inp_h, memsize, hipMemcpyHostToDevice));
|
||||
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D, graph1, nullptr, 0, inp_d, inp_h, memsize,
|
||||
hipMemcpyHostToDevice));
|
||||
// Get device clock rate
|
||||
int clkRate = 0;
|
||||
size_t NElem{N};
|
||||
size_t delayMs{2000};
|
||||
if (IsGfx11()) {
|
||||
HIPCHECK(hipDeviceGetAttribute(&clkRate, hipDeviceAttributeWallClockRate, 0));
|
||||
} else {
|
||||
@@ -123,29 +124,25 @@ TEST_CASE("Unit_hipGraphExecEventWaitNodeSetEvent_SetAndVerifyMemory") {
|
||||
}
|
||||
// kernel1
|
||||
auto sqr_ker_func_used = IsGfx11() ? sqr_ker_func_gfx11 : sqr_ker_func;
|
||||
void* kernelArgs[] = {&inp_d, &out_d, reinterpret_cast<void *>(&clkRate)};
|
||||
kernelNodeParams1.func = reinterpret_cast<void *>(sqr_ker_func_used);
|
||||
kernelNodeParams1.gridDim = dim3(GRID_DIM);
|
||||
kernelNodeParams1.blockDim = dim3(BLK_DIM);
|
||||
void* kernelArgs[] = {&inp_d, &out_d, reinterpret_cast<void*>(&NElem),
|
||||
reinterpret_cast<void*>(&clkRate), reinterpret_cast<void*>(&delayMs)};
|
||||
kernelNodeParams1.func = reinterpret_cast<void*>(sqr_ker_func_used);
|
||||
kernelNodeParams1.gridDim = dim3(gridSize);
|
||||
kernelNodeParams1.blockDim = dim3(blockSize);
|
||||
kernelNodeParams1.sharedMemBytes = 0;
|
||||
kernelNodeParams1.kernelParams = reinterpret_cast<void**>(kernelArgs);
|
||||
kernelNodeParams1.extra = nullptr;
|
||||
HIP_CHECK(hipGraphAddKernelNode(&kernelnode1, graph1, nullptr, 0,
|
||||
&kernelNodeParams1));
|
||||
HIP_CHECK(hipGraphAddKernelNode(&kernelnode1, graph1, nullptr, 0, &kernelNodeParams1));
|
||||
// Create dependencies for graph1
|
||||
HIP_CHECK(hipGraphAddDependencies(graph1, &memcpyH2D,
|
||||
&kernelnode1, 1));
|
||||
HIP_CHECK(hipGraphAddDependencies(graph1, &kernelnode1,
|
||||
&event_rec, 1));
|
||||
HIP_CHECK(hipGraphAddDependencies(graph1, &memcpyH2D, &kernelnode1, 1));
|
||||
HIP_CHECK(hipGraphAddDependencies(graph1, &kernelnode1, &event_rec, 1));
|
||||
// graph2 creation ...........
|
||||
// waitnode(event1) -> MemcpyD2H
|
||||
hipGraphNode_t event_wait_node, memcpyD2H;
|
||||
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H, graph2, nullptr, 0,
|
||||
out_h, out_d, memsize, hipMemcpyDeviceToHost));
|
||||
HIP_CHECK(hipGraphAddEventWaitNode(&event_wait_node, graph2, nullptr, 0,
|
||||
event1));
|
||||
HIP_CHECK(hipGraphAddDependencies(graph2, &event_wait_node,
|
||||
&memcpyD2H, 1));
|
||||
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H, graph2, nullptr, 0, out_h, out_d, memsize,
|
||||
hipMemcpyDeviceToHost));
|
||||
HIP_CHECK(hipGraphAddEventWaitNode(&event_wait_node, graph2, nullptr, 0, event1));
|
||||
HIP_CHECK(hipGraphAddDependencies(graph2, &event_wait_node, &memcpyD2H, 1));
|
||||
// Instantiate graph1 and graph2
|
||||
hipStream_t streamForGraph1, streamForGraph2;
|
||||
hipGraphExec_t graphExec1, graphExec2;
|
||||
@@ -160,8 +157,8 @@ TEST_CASE("Unit_hipGraphExecEventWaitNodeSetEvent_SetAndVerifyMemory") {
|
||||
HIP_CHECK(hipStreamSynchronize(streamForGraph2));
|
||||
// Validate output
|
||||
bool btestPassed = true;
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
if (out_h[i] != (inp_h[i]*inp_h[i])) {
|
||||
for (uint32_t i = 0; i < N; i++) {
|
||||
if (out_h[i] != (inp_h[i] * inp_h[i])) {
|
||||
btestPassed = false;
|
||||
break;
|
||||
}
|
||||
@@ -170,10 +167,8 @@ TEST_CASE("Unit_hipGraphExecEventWaitNodeSetEvent_SetAndVerifyMemory") {
|
||||
// hipGraphExecEventWaitNodeSetEvent() TEST
|
||||
// Change the event at event_wait_node node to event2 and
|
||||
// the event at event_rec node to event2.
|
||||
HIP_CHECK(hipGraphExecEventRecordNodeSetEvent(graphExec1,
|
||||
event_rec, event2));
|
||||
HIP_CHECK(hipGraphExecEventWaitNodeSetEvent(graphExec2,
|
||||
event_wait_node, event2));
|
||||
HIP_CHECK(hipGraphExecEventRecordNodeSetEvent(graphExec1, event_rec, event2));
|
||||
HIP_CHECK(hipGraphExecEventWaitNodeSetEvent(graphExec2, event_wait_node, event2));
|
||||
// Launch graph1 and graph2
|
||||
HIP_CHECK(hipGraphLaunch(graphExec1, streamForGraph1));
|
||||
HIP_CHECK(hipGraphLaunch(graphExec2, streamForGraph2));
|
||||
@@ -181,8 +176,8 @@ TEST_CASE("Unit_hipGraphExecEventWaitNodeSetEvent_SetAndVerifyMemory") {
|
||||
HIP_CHECK(hipStreamSynchronize(streamForGraph2));
|
||||
// Validate output
|
||||
btestPassed = true;
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
if (out_h[i] != (inp_h[i]*inp_h[i])) {
|
||||
for (uint32_t i = 0; i < N; i++) {
|
||||
if (out_h[i] != (inp_h[i] * inp_h[i])) {
|
||||
btestPassed = false;
|
||||
break;
|
||||
}
|
||||
@@ -214,12 +209,10 @@ TEST_CASE("Unit_hipGraphExecEventWaitNodeSetEvent_VerifyEventNotChanged") {
|
||||
HIP_CHECK(hipEventCreate(&event1));
|
||||
HIP_CHECK(hipEventCreate(&event2));
|
||||
hipGraphNode_t eventwait;
|
||||
HIP_CHECK(hipGraphAddEventWaitNode(&eventwait, graph, nullptr, 0,
|
||||
event1));
|
||||
HIP_CHECK(hipGraphAddEventWaitNode(&eventwait, graph, nullptr, 0, event1));
|
||||
hipGraphExec_t graphExec;
|
||||
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
|
||||
HIP_CHECK(hipGraphExecEventWaitNodeSetEvent(graphExec,
|
||||
eventwait, event2));
|
||||
HIP_CHECK(hipGraphExecEventWaitNodeSetEvent(graphExec, eventwait, event2));
|
||||
HIP_CHECK(hipGraphEventWaitNodeGetEvent(eventwait, &event_out));
|
||||
// validate set event and get event are same
|
||||
REQUIRE(event1 == event_out);
|
||||
@@ -240,13 +233,11 @@ TEST_CASE("Unit_hipGraphExecEventWaitNodeSetEvent_Negative") {
|
||||
HIP_CHECK(hipEventCreate(&event1));
|
||||
HIP_CHECK(hipEventCreate(&event2));
|
||||
hipGraphNode_t eventrec, eventwait;
|
||||
HIP_CHECK(hipGraphAddEventRecordNode(&eventrec, graph, nullptr, 0,
|
||||
event1));
|
||||
HIP_CHECK(hipGraphAddEventWaitNode(&eventwait, graph, nullptr, 0,
|
||||
event1));
|
||||
HIP_CHECK(hipGraphAddEventRecordNode(&eventrec, graph, nullptr, 0, event1));
|
||||
HIP_CHECK(hipGraphAddEventWaitNode(&eventwait, graph, nullptr, 0, event1));
|
||||
// Create memset
|
||||
constexpr size_t Nbytes = 1024;
|
||||
char *A_d;
|
||||
char* A_d;
|
||||
hipGraphNode_t memset_A;
|
||||
hipMemsetParams memsetParams{};
|
||||
HIP_CHECK(hipMalloc(&A_d, Nbytes));
|
||||
@@ -262,62 +253,59 @@ TEST_CASE("Unit_hipGraphExecEventWaitNodeSetEvent_Negative") {
|
||||
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
|
||||
|
||||
SECTION("hGraphExec = nullptr") {
|
||||
REQUIRE(hipErrorInvalidValue ==
|
||||
hipGraphExecEventWaitNodeSetEvent(nullptr, eventwait, event2));
|
||||
HIP_CHECK_ERROR(hipGraphExecEventWaitNodeSetEvent(nullptr, eventwait, event2),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("hNode = nullptr") {
|
||||
REQUIRE(hipErrorInvalidValue ==
|
||||
hipGraphExecEventWaitNodeSetEvent(graphExec, nullptr, event2));
|
||||
HIP_CHECK_ERROR(hipGraphExecEventWaitNodeSetEvent(graphExec, nullptr, event2),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("event = nullptr") {
|
||||
REQUIRE(hipErrorInvalidValue ==
|
||||
hipGraphExecEventWaitNodeSetEvent(graphExec, eventwait, nullptr));
|
||||
HIP_CHECK_ERROR(hipGraphExecEventWaitNodeSetEvent(graphExec, eventwait, nullptr),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("hGraphExec is uninitialized") {
|
||||
hipGraphExec_t graphExec1{};
|
||||
REQUIRE(hipErrorInvalidValue ==
|
||||
hipGraphExecEventWaitNodeSetEvent(graphExec1, eventwait, event2));
|
||||
HIP_CHECK_ERROR(hipGraphExecEventWaitNodeSetEvent(graphExec1, eventwait, event2),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("hNode is uninitialized") {
|
||||
hipGraphNode_t dummy{};
|
||||
REQUIRE(hipErrorInvalidValue ==
|
||||
hipGraphExecEventWaitNodeSetEvent(graphExec, dummy, event2));
|
||||
HIP_CHECK_ERROR(hipGraphExecEventWaitNodeSetEvent(graphExec, dummy, event2),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("event is uninitialized") {
|
||||
hipEvent_t event_dummy{};
|
||||
REQUIRE(hipErrorInvalidValue ==
|
||||
hipGraphExecEventWaitNodeSetEvent(graphExec, eventwait,
|
||||
event_dummy));
|
||||
HIP_CHECK_ERROR(hipGraphExecEventWaitNodeSetEvent(graphExec, eventwait, event_dummy),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("event wait node does not exist") {
|
||||
hipGraph_t graph1;
|
||||
HIP_CHECK(hipGraphCreate(&graph1, 0));
|
||||
HIP_CHECK(hipGraphAddMemsetNode(&memset_A, graph1, nullptr, 0,
|
||||
&memsetParams));
|
||||
HIP_CHECK(hipGraphAddMemsetNode(&memset_A, graph1, nullptr, 0, &memsetParams));
|
||||
hipGraphExec_t graphExec1;
|
||||
HIP_CHECK(hipGraphInstantiate(&graphExec1, graph1, nullptr, nullptr, 0));
|
||||
REQUIRE(hipErrorInvalidValue ==
|
||||
hipGraphExecEventWaitNodeSetEvent(graphExec1, eventwait, event2));
|
||||
HIP_CHECK_ERROR(hipGraphExecEventWaitNodeSetEvent(graphExec1, eventwait, event2),
|
||||
hipErrorInvalidValue);
|
||||
HIP_CHECK(hipGraphExecDestroy(graphExec1));
|
||||
HIP_CHECK(hipGraphDestroy(graph1));
|
||||
}
|
||||
|
||||
SECTION("pass memset node as hNode") {
|
||||
HIP_CHECK(hipGraphAddMemsetNode(&memset_A, graph, nullptr, 0,
|
||||
&memsetParams));
|
||||
REQUIRE(hipErrorInvalidValue ==
|
||||
hipGraphExecEventWaitNodeSetEvent(graphExec, memset_A, event2));
|
||||
HIP_CHECK(hipGraphAddMemsetNode(&memset_A, graph, nullptr, 0, &memsetParams));
|
||||
HIP_CHECK_ERROR(hipGraphExecEventWaitNodeSetEvent(graphExec, memset_A, event2),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
SECTION("pass event record node as hNode") {
|
||||
REQUIRE(hipErrorInvalidValue ==
|
||||
hipGraphExecEventWaitNodeSetEvent(graphExec, eventrec, event2));
|
||||
HIP_CHECK_ERROR(hipGraphExecEventWaitNodeSetEvent(graphExec, eventrec, event2),
|
||||
hipErrorInvalidValue);
|
||||
}
|
||||
|
||||
HIP_CHECK(hipFree(A_d));
|
||||
|
||||
새 이슈에서 참조
사용자 차단