forked from Xilinx/XRT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VITIS-11112 HIP Binding: Memory Management. (Xilinx#7983)
* Initial implementation of some HIP memory APIs. (Xilinx#11) Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * Add hipMemset(). (Xilinx#12) Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * minor fix to hipHostMalloc() (Xilinx#13) Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * Fix the typo. (Xilinx#14) Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * fix some issues from code review. Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * fix minor error in error.cpp. Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * remove new operation from memory_database::GetInstance(). Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * Fix some issues from code review. Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * change class name error_state to error. Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * remove some duplicate code. Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * fix some issues. Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * fix some issues. Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * fix more issues. Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> * fix more issues. Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com> --------- Signed-off-by: Chiming Zhang <Chiming.Zhang@amd.com>
- Loading branch information
1 parent
f23d53e
commit 6ed717d
Showing
8 changed files
with
1,083 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// Copyright (C) 2024 Advanced Micro Device, Inc. All rights reserved. | ||
|
||
#include "core/common/error.h" | ||
#include "hip/config.h" | ||
#include "hip/hip_runtime_api.h" | ||
#include "hip/core/device.h" | ||
#include "hip/core/error.h" | ||
#include <string> | ||
|
||
namespace xrt::core::hip | ||
{ | ||
static hipError_t | ||
hip_peek_last_error() | ||
{ | ||
return error::instance().peek_last_error(); | ||
} | ||
|
||
static hipError_t | ||
hip_get_last_error() | ||
{ | ||
hipError_t last_error = error::instance().peek_last_error(); | ||
error::instance().reset_last_error(); | ||
return last_error; | ||
} | ||
|
||
} // xrt::core::hip | ||
|
||
// Return hip error as text string form. | ||
hipError_t | ||
hipDrvGetErrorName(hipError_t hipError, | ||
const char **errorName) | ||
{ | ||
try { | ||
*errorName = xrt::core::hip::error::get_error_name(hipError); | ||
return hipSuccess; | ||
} catch (const std::exception &ex) { | ||
xrt_core::send_exception_message(ex.what()); | ||
} | ||
return hipErrorInvalidValue; | ||
} | ||
|
||
// Return handy text string message to explain the error which occurred. | ||
hipError_t | ||
hipDrvGetErrorString(hipError_t hipError, | ||
const char **errorString) | ||
{ | ||
try { | ||
// TODO: return more detailed error string instead of error name | ||
*errorString = xrt::core::hip::error::get_error_name(hipError); | ||
return hipSuccess; | ||
} catch (const std::exception &ex) { | ||
xrt_core::send_exception_message(ex.what()); | ||
} | ||
return hipErrorInvalidValue; | ||
} | ||
|
||
// Return handy text string message to explain the error which occurred. | ||
const char * | ||
hipGetErrorString(hipError_t hipError) | ||
{ | ||
const char *error_string = nullptr; | ||
try { | ||
// TODO: return more detailed error string instead of error name | ||
error_string = xrt::core::hip::error::get_error_name(hipError); | ||
} catch (const std::exception &ex) { | ||
xrt_core::send_exception_message(ex.what()); | ||
} | ||
return error_string; | ||
} | ||
|
||
// Return hip error as text string form. | ||
const char * | ||
hipGetErrorName(hipError_t hipError) | ||
{ | ||
const char *error_name = nullptr; | ||
try { | ||
error_name = xrt::core::hip::error::get_error_name(hipError); | ||
} catch (const std::exception &ex) { | ||
xrt_core::send_exception_message(ex.what()); | ||
} | ||
return error_name; | ||
} | ||
|
||
template<typename F> hipError_t | ||
handle_hip_error_error(F && f) | ||
{ | ||
hipError_t last_error = hipSuccess; | ||
try { | ||
return f(); | ||
} catch (const std::exception &ex) { | ||
xrt_core::send_exception_message(ex.what()); | ||
} | ||
return last_error; | ||
} | ||
|
||
// return last error returned by any HIP API call and resets the stored error code | ||
hipError_t | ||
hipExtGetLastError() | ||
{ | ||
return hipGetLastError(); | ||
} | ||
|
||
// return last error returned by any HIP API call and resets the stored error code | ||
hipError_t | ||
hipGetLastError(void) | ||
{ | ||
return handle_hip_error_error([&] { return xrt::core::hip::hip_get_last_error(); }); | ||
} | ||
|
||
// Return last error returned by any HIP runtime API call. | ||
hipError_t hipPeekAtLastError() | ||
{ | ||
return handle_hip_error_error([&] { return xrt::core::hip::hip_peek_last_error(); }); | ||
} | ||
|
||
//hipError_t handle_hip_error([&] { xrt::core::hip::hipMemCpy(dst, src, sizeBytes, kind); }); |
Oops, something went wrong.