Commit b01aac38 authored by Adam Osewski's avatar Adam Osewski
Browse files

Make hip_check_error report file and line accurately.

parent 03d348cc
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved. // Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
#pragma once #pragma once
#include <sstream> #include <sstream>
#include <hip/hip_runtime.h> #include <hip/hip_runtime.h>
// To be removed, which really does not tell the location of failed HIP functional call #define HIP_CHECK_ERROR(retval_or_funcall) \
inline void hip_check_error(hipError_t x) do \
{ { \
if(x != hipSuccess) hipError_t _tmpVal = retval_or_funcall; \
{ if(_tmpVal != hipSuccess) \
std::ostringstream ss; { \
ss << "HIP runtime error: " << hipGetErrorString(x) << ". " std::ostringstream ostr; \
<< "hip_check_error.hpp" ostr << "HIP Function Failed (" \
<< ": " << __LINE__ << "in function: " << __func__; << "file: " << __FILE__ << ":" << __LINE__ << " func: " << __func__ << ") " \
throw std::runtime_error(ss.str()); << hipGetErrorString(_tmpVal); \
} throw std::runtime_error(ostr.str()); \
} } \
#define HIP_CHECK_ERROR(retval_or_funcall) \
do \
{ \
hipError_t _tmpVal = retval_or_funcall; \
if(_tmpVal != hipSuccess) \
{ \
std::ostringstream ostr; \
ostr << "HIP Function Failed (" \
<< "hip_check_error.hpp" \
<< "," << __LINE__ << ") " << hipGetErrorString(_tmpVal); \
throw std::runtime_error(ostr.str()); \
} \
} while(0) } while(0)
#define hip_check_error(retval) HIP_CHECK_ERROR(retval)
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// Copyright (c) 2018-2023, Advanced Micro Devices, Inc. All rights reserved. // Copyright (c) 2018-2024, Advanced Micro Devices, Inc. All rights reserved.
#include "ck/host_utility/hip_check_error.hpp" #include <stdexcept>
#include <iostream>
#include "ck/host_utility/hip_check_error.hpp"
#include "ck/library/utility/device_memory.hpp" #include "ck/library/utility/device_memory.hpp"
DeviceMem::DeviceMem(std::size_t mem_size) : mMemSize(mem_size) DeviceMem::DeviceMem(std::size_t mem_size) : mMemSize(mem_size)
...@@ -71,6 +73,13 @@ DeviceMem::~DeviceMem() ...@@ -71,6 +73,13 @@ DeviceMem::~DeviceMem()
{ {
if(mpDeviceBuf) if(mpDeviceBuf)
{ {
hip_check_error(hipFree(mpDeviceBuf)); try
{
hip_check_error(hipFree(mpDeviceBuf));
}
catch(std::runtime_error& re)
{
std::cerr << re.what() << std::endl;
}
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment