Skip to content

Commit

Permalink
VITIS-11112 HIP Binding: Memory Management. (Xilinx#7983)
Browse files Browse the repository at this point in the history
* 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
zhangchiming authored Mar 25, 2024
1 parent f23d53e commit 6ed717d
Show file tree
Hide file tree
Showing 8 changed files with 1,083 additions and 96 deletions.
1 change: 1 addition & 0 deletions src/runtime_src/hip/api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_library(hip_api_library_objects OBJECT
hip_stream.cpp
hip_memory.cpp
hip_event.cpp
hip_error.cpp
)

target_include_directories(hip_api_library_objects
Expand Down
117 changes: 117 additions & 0 deletions src/runtime_src/hip/api/hip_error.cpp
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); });
Loading

0 comments on commit 6ed717d

Please sign in to comment.