Fix test errors
Check the HIP API calls status, and abort if != success. Change-Id: Ifc38d8f28092ffdce1674a05a7886f7c0c97a885
This commit is contained in:
zatwierdzone przez
Laurent Morichetti
rodzic
1680d2c70e
commit
4c6f249cc1
@@ -22,10 +22,19 @@
|
||||
|
||||
#include "roctx.h"
|
||||
|
||||
#define HIP_CALL(call) \
|
||||
do { \
|
||||
hipError_t err = call; \
|
||||
if (err != hipSuccess) { \
|
||||
fprintf(stderr, "%s\n", hipGetErrorString(err)); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
__global__ void kernel() {}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
hipSetDevice(0);
|
||||
HIP_CALL(hipSetDevice(0));
|
||||
|
||||
// Not in a roctx range.
|
||||
kernel<<<1, 1>>>();
|
||||
@@ -59,6 +68,6 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
if (roctxRangePop() != 0) return -1;
|
||||
|
||||
hipDeviceSynchronize();
|
||||
HIP_CALL(hipDeviceSynchronize());
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,14 @@
|
||||
// roctx header file
|
||||
#include <roctx.h>
|
||||
|
||||
#define HIP_CALL(call) \
|
||||
do { \
|
||||
hipError_t err = call; \
|
||||
if (err != hipSuccess) { \
|
||||
fprintf(stderr, "%s\n", hipGetErrorString(err)); \
|
||||
abort(); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define WIDTH 1024
|
||||
|
||||
@@ -65,7 +73,7 @@ int main() {
|
||||
float* gpuTransposeMatrix;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
HIP_CALL(hipGetDeviceProperties(&devProp, 0));
|
||||
|
||||
std::cerr << "Device name " << devProp.name << std::endl;
|
||||
|
||||
@@ -82,15 +90,15 @@ int main() {
|
||||
}
|
||||
|
||||
// allocate the memory on the device side
|
||||
hipMalloc((void**)&gpuMatrix, NUM * sizeof(float));
|
||||
hipMalloc((void**)&gpuTransposeMatrix, NUM * sizeof(float));
|
||||
HIP_CALL(hipMalloc((void**)&gpuMatrix, NUM * sizeof(float)));
|
||||
HIP_CALL(hipMalloc((void**)&gpuTransposeMatrix, NUM * sizeof(float)));
|
||||
|
||||
uint32_t iterations = 100;
|
||||
while (iterations-- > 0) {
|
||||
std::cerr << "## Iteration (" << iterations << ") #################" << std::endl;
|
||||
|
||||
// Memory transfer from host to device
|
||||
hipMemcpy(gpuMatrix, Matrix, NUM * sizeof(float), hipMemcpyHostToDevice);
|
||||
HIP_CALL(hipMemcpy(gpuMatrix, Matrix, NUM * sizeof(float), hipMemcpyHostToDevice));
|
||||
|
||||
roctracer_mark("before HIP LaunchKernel");
|
||||
roctxMark("before hipLaunchKernel");
|
||||
@@ -106,7 +114,8 @@ int main() {
|
||||
// Memory transfer from device to host
|
||||
roctxRangePush("hipMemcpy");
|
||||
|
||||
hipMemcpy(TransposeMatrix, gpuTransposeMatrix, NUM * sizeof(float), hipMemcpyDeviceToHost);
|
||||
HIP_CALL(
|
||||
hipMemcpy(TransposeMatrix, gpuTransposeMatrix, NUM * sizeof(float), hipMemcpyDeviceToHost));
|
||||
|
||||
roctxRangePop(); // for "hipMemcpy"
|
||||
roctxRangePop(); // for "hipLaunchKernel"
|
||||
@@ -131,8 +140,8 @@ int main() {
|
||||
}
|
||||
|
||||
// free the resources on device side
|
||||
hipFree(gpuMatrix);
|
||||
hipFree(gpuTransposeMatrix);
|
||||
HIP_CALL(hipFree(gpuMatrix));
|
||||
HIP_CALL(hipFree(gpuTransposeMatrix));
|
||||
|
||||
// free the resources on host side
|
||||
free(Matrix);
|
||||
|
||||
Reference in New Issue
Block a user