Skip to content

Commit

Permalink
Merge pull request #891 from CHIP-SPV/error-maps
Browse files Browse the repository at this point in the history
Expand the use of error maps
  • Loading branch information
pvelesko authored Aug 16, 2024
2 parents 08d4916 + af3314b commit fc6d412
Show file tree
Hide file tree
Showing 8 changed files with 1,198 additions and 412 deletions.
2 changes: 1 addition & 1 deletion src/CHIPBackend.hh
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public:
std::shared_ptr<chipstar::Event> CpuCallbackComplete;
std::shared_ptr<chipstar::Event> GpuAck;

hipError_t Status;
hipError_t CallbackStatus;
void *CallbackArgs;
hipStreamCallback_t CallbackF;

Expand Down
21 changes: 3 additions & 18 deletions src/CHIPException.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,10 @@ public:
throw CHIPError(msg, errtype); \
} while (0)

#define CHIPERR_CHECK_LOG_AND_THROW(status, success, errtype, ...) \
#define CHIPERR_LOG_AND_ABORT(msg) \
do { \
if (status != success) { \
std::string error_msg = std::string(resultToString(status)); \
std::string custom_msg = std::string(__VA_ARGS__); \
std::string msg_ = error_msg + " " + custom_msg; \
CHIPERR_LOG_AND_THROW(msg_, errtype); \
} \
} while (0)

#define CHIPERR_CHECK_LOG_AND_ABORT(status, success, errtype, ...) \
do { \
if (status != success) { \
std::string error_msg = std::string(resultToString(status)); \
std::string custom_msg = std::string(__VA_ARGS__); \
std::string msg_ = error_msg + " " + custom_msg; \
std::cout << msg_ << std::endl; \
std::abort(); \
} \
logError("{} in {}:{}:{}\n", msg, __FILE__, __LINE__, __func__); \
std::abort(); \
} while (0)

#define CHIP_TRY try {
Expand Down
373 changes: 168 additions & 205 deletions src/backend/Level0/CHIPBackendLevel0.cc

Large diffs are not rendered by default.

54 changes: 25 additions & 29 deletions src/backend/Level0/CHIPBackendLevel0.hh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
#include "../../CHIPBackend.hh"
#include "ze_api.h"
#include "../src/common.hh"
#include "zeHipErrorConversion.hh"

std::string resultToString(ze_result_t Status);
static thread_local ze_result_t zeStatus; // instantiated in CHIPBackendLevel0.cc

std::string resultToString(ze_result_t zeStatus);

// fw declares
class CHIPBackendLevel0;
Expand Down Expand Up @@ -206,45 +209,38 @@ class FencedCmdList {
public:
FencedCmdList(ze_device_handle_t &DevLz, ze_context_handle_t &CtxLz,
ze_command_list_desc_t &Desc) {
auto Status = zeCommandListCreate(CtxLz, DevLz, &Desc, &ZeCmdList_);
CHIPERR_CHECK_LOG_AND_ABORT(Status, ZE_RESULT_SUCCESS,
"Failed to create command list");
zeStatus = zeCommandListCreate(CtxLz, DevLz, &Desc, &ZeCmdList_);
CHIPERR_CHECK_LOG_AND_ABORT("Failed to create command list");
}

bool reset() {
auto Status = zeCommandListReset(ZeCmdList_);
CHIPERR_CHECK_LOG_AND_ABORT(Status, ZE_RESULT_SUCCESS,
"Failed to reset command list");
zeStatus = zeCommandListReset(ZeCmdList_);
CHIPERR_CHECK_LOG_AND_ABORT("Failed to reset command list");
return true;
}

void execute(ze_command_queue_handle_t &CmdQLz) {
auto Status = zeFenceCreate(CmdQLz, &ZeFenceDesc_, &ZeFence_);
CHIPERR_CHECK_LOG_AND_ABORT(Status, ZE_RESULT_SUCCESS,
"Failed to create fence");
Status = zeCommandListClose(ZeCmdList_);
CHIPERR_CHECK_LOG_AND_ABORT(Status, ZE_RESULT_SUCCESS,
"Failed to close command list");

Status =
zeStatus = zeFenceCreate(CmdQLz, &ZeFenceDesc_, &ZeFence_);
CHIPERR_CHECK_LOG_AND_ABORT("Failed to create fence");
zeStatus = zeCommandListClose(ZeCmdList_);
CHIPERR_CHECK_LOG_AND_ABORT("Failed to close command list");

zeStatus =
zeCommandQueueExecuteCommandLists(CmdQLz, 1, &ZeCmdList_, ZeFence_);
CHIPERR_CHECK_LOG_AND_ABORT(Status, ZE_RESULT_SUCCESS,
"Failed to execute command list");
CHIPERR_CHECK_LOG_AND_ABORT("Failed to execute command list");
}

bool isFinished() {
auto Status = zeFenceQueryStatus(ZeFence_);
return Status == ZE_RESULT_SUCCESS;
zeStatus = zeFenceQueryStatus(ZeFence_);
return zeStatus == ZE_RESULT_SUCCESS;
}

~FencedCmdList() {
auto Status = zeCommandListDestroy(ZeCmdList_);
CHIPERR_CHECK_LOG_AND_ABORT(Status, ZE_RESULT_SUCCESS,
"Failed to destroy command list");
zeStatus = zeCommandListDestroy(ZeCmdList_);
CHIPERR_CHECK_LOG_AND_ABORT("Failed to destroy command list");

Status = zeFenceDestroy(ZeFence_);
CHIPERR_CHECK_LOG_AND_ABORT(Status, ZE_RESULT_SUCCESS,
"Failed to destroy fence");
zeStatus = zeFenceDestroy(ZeFence_);
CHIPERR_CHECK_LOG_AND_ABORT("Failed to destroy fence");
}

ze_command_list_handle_t &getCmdList() { return ZeCmdList_; }
Expand Down Expand Up @@ -520,17 +516,17 @@ public:
// The application must not call this function from
// simultaneous threads with the same image handle.
// Done via destructor should not be called from multiple threads
ze_result_t Status = zeImageDestroy(Handle);
CHIPERR_CHECK_LOG_AND_THROW(Status, ZE_RESULT_SUCCESS, hipErrorTbd);
zeStatus = zeImageDestroy(Handle);
CHIPERR_CHECK_LOG_AND_THROW(hipErrorTbd);
}

// Destroy the LZ sampler object
static void destroySampler(ze_sampler_handle_t Handle) {
// The application must not call this function
// from simultaneous threads with the same sampler handle.
// Done via destructor should not be called from multiple threads
ze_result_t Status = zeSamplerDestroy(Handle);
CHIPERR_CHECK_LOG_AND_THROW(Status, ZE_RESULT_SUCCESS, hipErrorTbd);
zeStatus = zeSamplerDestroy(Handle);
CHIPERR_CHECK_LOG_AND_THROW(hipErrorTbd);
}
};

Expand Down
Loading

0 comments on commit fc6d412

Please sign in to comment.