Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
add signal handler for fpe, bus error (#18956)
Browse files Browse the repository at this point in the history
* add handler for fpe, bus error

* fix bug

* fix build

* copy comments
  • Loading branch information
szha committed Aug 20, 2020
1 parent adcd997 commit bbc39fa
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 313 deletions.
45 changes: 1 addition & 44 deletions include/mxnet/c_api_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,52 +22,9 @@
* \file c_api_error.h
* \brief Error handling for C API.
*/
#include <string>
#include <mxnet/runtime/c_runtime_api.h>

#ifndef MXNET_C_API_ERROR_H_
#define MXNET_C_API_ERROR_H_

/*!
* \brief Macros to guard beginning and end section of all functions
* every function starts with API_BEGIN()
* and finishes with API_END() or API_END_HANDLE_ERROR()
* The finally clause contains procedure to cleanup states when an error happens.
*/
#define MX_API_BEGIN() \
try { \
on_enter_api(__FUNCTION__);
#define MX_API_END() \
} \
catch (const std::exception &_except_) { \
on_exit_api(); \
return MXAPIHandleException(_except_); \
} \
on_exit_api(); \
return 0; // NOLINT(*)
#define MX_API_END_HANDLE_ERROR(Finalize) \
} \
catch (const std::exception &_except_) { \
Finalize; \
on_exit_api(); \
return MXAPIHandleException(_except_); \
} \
on_exit_api(); \
return 0; // NOLINT(*)

/*!
* \brief Set the last error message needed by C API
* \param msg The error message to set.
*/
void MXAPISetLastError(const char* msg);
/*!
* \brief handle exception throwed out
* \param e the exception
* \return the return value of API after exception is handled
*/
int MXAPIHandleException(const std::exception &e);

namespace mxnet {
extern void on_enter_api(const char *function);
extern void on_exit_api();
}
#endif // MXNET_C_API_ERROR_H_
47 changes: 47 additions & 0 deletions include/mxnet/runtime/c_runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define MXNET_RUNTIME_C_RUNTIME_API_H_

#include <dlpack/dlpack.h>
#include <string>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -177,4 +178,50 @@ MXNET_DLL int MXNetObjectTypeKey2Index(const char* type_key, unsigned* out_tinde
#ifdef __cplusplus
} // extern "C"
#endif


/*!
* \brief Macros to guard beginning and end section of all functions
* every function starts with API_BEGIN()
* and finishes with API_END() or API_END_HANDLE_ERROR()
* The finally clause contains procedure to cleanup states when an error happens.
*/
#define MX_API_BEGIN() \
try { \
on_enter_api(__FUNCTION__);
#define MX_API_END() \
} \
catch (const std::exception &_except_) { \
on_exit_api(); \
return MXAPIHandleException(_except_); \
} \
on_exit_api(); \
return 0; // NOLINT(*)
#define MX_API_END_HANDLE_ERROR(Finalize) \
} \
catch (const std::exception &_except_) { \
Finalize; \
on_exit_api(); \
return MXAPIHandleException(_except_); \
} \
on_exit_api(); \
return 0; // NOLINT(*)

/*!
* \brief Set the last error message needed by C API
* \param msg The error message to set.
*/
void MXAPISetLastError(const char* msg);
/*!
* \brief handle exception throwed out
* \param e the exception
* \return the return value of API after exception is handled
*/
int MXAPIHandleException(const std::exception &e);

namespace mxnet {
extern void on_enter_api(const char *function);
extern void on_exit_api();
}

#endif // MXNET_RUNTIME_C_RUNTIME_API_H_
4 changes: 4 additions & 0 deletions python/mxnet/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ def __init__(self, msg):
register_error("AttributeError", AttributeError)
register_error("IndexError", IndexError)
register_error("NotImplementedError", NotImplementedError)
register_error("InternalError", InternalError)
register_error("IOError", IOError)
register_error("FloatingPointError", FloatingPointError)
register_error("RuntimeError", RuntimeError)
6 changes: 3 additions & 3 deletions src/c_api/c_api_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

/*!
* Copyright (c) 2015 by Contributors
* \file c_api_error.h
* \brief Error handling for C API.
* \file c_api_common.h
* \brief Common C API utils
*/
#ifndef MXNET_C_API_C_API_COMMON_H_
#define MXNET_C_API_C_API_COMMON_H_
Expand All @@ -29,7 +29,7 @@
#include <dmlc/logging.h>
#include <dmlc/thread_local.h>
#include <mxnet/c_api.h>
#include <mxnet/c_api_error.h>
#include <mxnet/runtime/c_runtime_api.h>
#include <mxnet/base.h>
#include <mxnet/op_attr_types.h>
#include <nnvm/graph.h>
Expand Down
206 changes: 0 additions & 206 deletions src/c_api/c_api_error.cc

This file was deleted.

Loading

0 comments on commit bbc39fa

Please sign in to comment.