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
inline void hip_check_error(hipError_t x)
{
if(x != hipSuccess)
{
std::ostringstream ss;
ss << "HIP runtime error: " << hipGetErrorString(x) << ". "
<< "hip_check_error.hpp"
<< ": " << __LINE__ << "in function: " << __func__;
throw std::runtime_error(ss.str());
}
}
#define HIP_CHECK_ERROR(retval_or_funcall) \ #define HIP_CHECK_ERROR(retval_or_funcall) \
do \ do \
{ \ { \
...@@ -27,8 +14,10 @@ inline void hip_check_error(hipError_t x) ...@@ -27,8 +14,10 @@ inline void hip_check_error(hipError_t x)
{ \ { \
std::ostringstream ostr; \ std::ostringstream ostr; \
ostr << "HIP Function Failed (" \ ostr << "HIP Function Failed (" \
<< "hip_check_error.hpp" \ << "file: " << __FILE__ << ":" << __LINE__ << " func: " << __func__ << ") " \
<< "," << __LINE__ << ") " << hipGetErrorString(_tmpVal); \ << hipGetErrorString(_tmpVal); \
throw std::runtime_error(ostr.str()); \ 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)
...@@ -70,7 +72,14 @@ void DeviceMem::SetZero() const ...@@ -70,7 +72,14 @@ void DeviceMem::SetZero() const
DeviceMem::~DeviceMem() DeviceMem::~DeviceMem()
{ {
if(mpDeviceBuf) if(mpDeviceBuf)
{
try
{ {
hip_check_error(hipFree(mpDeviceBuf)); 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