SWDEV-240806 - Added API hipLaunchHostFunc and updated graph test for host graph node (#2512)

Change-Id: Idf759064946e503a2b3cc2a38f1a7cb049012688
Tá an tiomantas seo le fáil i:
ROCm CI Service Account
2022-02-24 18:56:56 +05:30
tiomanta ag GitHub
tuismitheoir e21231649d
tiomantas d305e34173
D'athraigh 2 comhad le 45 breiseanna agus 3 scriosta
+32 -3
Féach ar an gComhad
@@ -105,6 +105,25 @@ bool hipWithoutGraphs(float* inputVec_h, float* inputVec_d, double* outputVec_d,
return true;
}
typedef struct callBackData {
const char* fn_name;
double* data;
} callBackData_t;
double result_gpu = 0.0;
void myHostNodeCallback(void* data) {
static int iter = 0;
iter++;
// Check status of GPU after stream operations are done
callBackData_t* tmp = (callBackData_t*)(data);
// checkCudaErrors(tmp->status);
double* result = (double*)(tmp->data);
char* function = (char*)(tmp->fn_name);
if (iter == GRAPH_LAUNCH_ITERATIONS)
printf("[%s] Host callback final reduced sum = %lf\n", function, *result);
result_gpu = *result;
*result = 0.0; // reset the result
}
bool hipGraphsUsingStreamCapture(float* inputVec_h, float* inputVec_d, double* outputVec_d,
double* result_d, size_t inputSize, size_t numOfBlocks) {
hipStream_t stream1, stream2, stream3, streamForGraph;
@@ -237,6 +256,16 @@ bool hipGraphsManual(float* inputVec_h, float* inputVec_d, double* outputVec_d,
nodeDependencies.clear();
nodeDependencies.push_back(memcpyNode);
hipGraphNode_t hostNode;
hipHostNodeParams hostParams = {0};
hostParams.fn = myHostNodeCallback;
callBackData_t hostFnData;
hostFnData.data = &result_h;
hostFnData.fn_name = "hipGraphsManual";
hostParams.userData = &hostFnData;
HIPCHECK(hipGraphAddHostNode(&hostNode, graph, nodeDependencies.data(), nodeDependencies.size(),
&hostParams));
hipGraphExec_t graphExec;
hipGraphNode_t* nodes = NULL;
size_t numNodes = 0;
@@ -266,8 +295,8 @@ bool hipGraphsManual(float* inputVec_h, float* inputVec_d, double* outputVec_d,
for (int i = 0; i < inputSize; i++) {
result_h_cpu += inputVec_h[i];
}
if (result_h_cpu != result_h) {
printf("Final reduced sum = %lf %lf\n", result_h_cpu, result_h);
if (result_h_cpu != result_gpu) {
printf("Final reduced sum = %lf %lf\n", result_h_cpu, result_gpu);
return false;
}
return true;
@@ -304,4 +333,4 @@ int main(int argc, char** argv) {
failed("Failed during hipGraph with capture\n");
}
passed();
}
}