CHIP-SPV / chipStar

chipStar is a tool for compiling and running HIP/CUDA on SPIR-V via OpenCL or Level Zero APIs.
Other
227 stars 34 forks source link

Adding runtime error conversion for Level0 backend #886

Closed jjennychen closed 4 months ago

jjennychen commented 4 months ago

The zeHipErrorConversion.hh header file was created to support ze_result_t to hipError_t runtime error conversion. The header file provides the following components:

(1) A type alias that defines ze_hip_error_map_t type as an unordered_map that maps ze_result_t to hipError_t

(2) A macro, CHIPERR_CHECK_LOG_AND_THROW_TABLE, that does exactly what CHIPERR_CHECK_LOG_AND_THROW does, but instead of taking a specific errtype to throw, CHIPERR_CHECK_LOG_AND_THROW_TABLE takes a map of type ze_hip_error_map_t and use it to convert ze_result_t to corresponding hipError_t. Either the default map (DEFAULT_ZE_HIP_ERROR_MAP) or a custom map can be used. An example to create a custom map:

ze_hip_error_map_t myMap = {
    {SOME_ZE_RESULT_T, SOME_HIPERROR_T},
    {SOME_ZE_RESULT_T, SOME_HIPERROR_T}
};

(3) Functions used by the CHIPERR_CHECK_LOG_AND_THROW_TABLE macro to conduct actual conversions

Notes Only one mapping is added to the default map for now, but this is expected to be expanded as we discover more appropriate conversions.