SWDEV-397576 Adding protection for HIP calls to understand MI failures

Change-Id: Icd6a2cb3be5520ee57fdd76bfafa06801b7061c0
Este cometimento está contido em:
gobhardw criou e Gopesh Bhardwaj cometeu 2023-05-11 13:02:31 -04:00
1 ascendente 55c6a2d4ad
cometimento 0b401d71c6
5 ficheiros modificados
+116 -116

Não existem ficheiros que correspondam à sua pesquisa

+26 -36
Ver ficheiro
@@ -27,8 +27,7 @@ THE SOFTWARE.
#include <iostream>
#include "hip/hip_runtime.h"
#define HIP_ASSERT(x) (assert((x) == hipSuccess))
#include "utils/test_helper.h"
#define WIDTH 1024
#define HEIGHT 1024
@@ -39,10 +38,8 @@ THE SOFTWARE.
#define THREADS_PER_BLOCK_Y 16
#define THREADS_PER_BLOCK_Z 1
__global__ void vectoradd_float(float *__restrict__ a,
const float *__restrict__ b,
const float *__restrict__ c, int width,
int height) {
__global__ void vectoradd_float(float* __restrict__ a, const float* __restrict__ b,
const float* __restrict__ c, int width, int height) {
int x = hipBlockDim_x * hipBlockIdx_x + hipThreadIdx_x;
int y = hipBlockDim_y * hipBlockIdx_y + hipThreadIdx_y;
@@ -53,16 +50,16 @@ __global__ void vectoradd_float(float *__restrict__ a,
}
int main() {
float *hostA;
float *hostB;
float *hostC;
float* hostA;
float* hostB;
float* hostC;
float *deviceA;
float *deviceB;
float *deviceC;
float* deviceA;
float* deviceB;
float* deviceC;
hipDeviceProp_t devProp;
hipGetDeviceProperties(&devProp, 0);
HIP_RC(hipGetDeviceProperties(&devProp, 0));
std::cout << " System minor " << devProp.minor << std::endl;
std::cout << " System major " << devProp.major << std::endl;
std::cout << " agent prop name " << devProp.name << std::endl;
@@ -72,9 +69,9 @@ int main() {
int i;
int errors;
hostA = reinterpret_cast<float *>(malloc(NUM * sizeof(float)));
hostB = reinterpret_cast<float *>(malloc(NUM * sizeof(float)));
hostC = reinterpret_cast<float *>(malloc(NUM * sizeof(float)));
hostA = reinterpret_cast<float*>(malloc(NUM * sizeof(float)));
hostB = reinterpret_cast<float*>(malloc(NUM * sizeof(float)));
hostC = reinterpret_cast<float*>(malloc(NUM * sizeof(float)));
// initialize the input data
for (i = 0; i < NUM; i++) {
@@ -82,26 +79,19 @@ int main() {
hostC[i] = static_cast<float>(i) * 100.0f;
}
HIP_ASSERT(
hipMalloc(reinterpret_cast<void **>(&deviceA), NUM * sizeof(float)));
HIP_ASSERT(
hipMalloc(reinterpret_cast<void **>(&deviceB), NUM * sizeof(float)));
HIP_ASSERT(
hipMalloc(reinterpret_cast<void **>(&deviceC), NUM * sizeof(float)));
HIP_RC(hipMalloc(reinterpret_cast<void**>(&deviceA), NUM * sizeof(float)));
HIP_RC(hipMalloc(reinterpret_cast<void**>(&deviceB), NUM * sizeof(float)));
HIP_RC(hipMalloc(reinterpret_cast<void**>(&deviceC), NUM * sizeof(float)));
HIP_ASSERT(
hipMemcpy(deviceB, hostB, NUM * sizeof(float), hipMemcpyHostToDevice));
HIP_ASSERT(
hipMemcpy(deviceC, hostC, NUM * sizeof(float), hipMemcpyHostToDevice));
HIP_RC(hipMemcpy(deviceB, hostB, NUM * sizeof(float), hipMemcpyHostToDevice));
HIP_RC(hipMemcpy(deviceC, hostC, NUM * sizeof(float), hipMemcpyHostToDevice));
hipLaunchKernelGGL(
vectoradd_float,
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB,
deviceC, WIDTH, HEIGHT);
HIP_KL(hipLaunchKernelGGL(vectoradd_float,
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT / THREADS_PER_BLOCK_Y),
dim3(THREADS_PER_BLOCK_X, THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB,
deviceC, WIDTH, HEIGHT));
HIP_ASSERT(
hipMemcpy(hostA, deviceA, NUM * sizeof(float), hipMemcpyDeviceToHost));
HIP_RC(hipMemcpy(hostA, deviceA, NUM * sizeof(float), hipMemcpyDeviceToHost));
// verify the results
errors = 0;
@@ -116,9 +106,9 @@ int main() {
printf("PASSED!\n");
}
HIP_ASSERT(hipFree(deviceA));
HIP_ASSERT(hipFree(deviceB));
HIP_ASSERT(hipFree(deviceC));
HIP_RC(hipFree(deviceA));
HIP_RC(hipFree(deviceB));
HIP_RC(hipFree(deviceC));
free(hostA);
free(hostB);