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

Commit

Permalink
add handler for fpe, bus error
Browse files Browse the repository at this point in the history
  • Loading branch information
szha committed Aug 18, 2020
1 parent be12c8d commit b046b8d
Show file tree
Hide file tree
Showing 8 changed files with 419 additions and 329 deletions.
73 changes: 0 additions & 73 deletions include/mxnet/c_api_error.h

This file was deleted.

46 changes: 46 additions & 0 deletions include/mxnet/runtime/c_runtime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@
#define MXNET_RUNTIME_C_RUNTIME_API_H_

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

#ifdef __cplusplus
extern "C" {
#endif
#include <mxnet/c_api.h>
#include <stdint.h>
#include <stddef.h>
#include <setjmp.h>


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

#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);
/*!
* \brief set jump point for signal handler for this thread by calling sigsetjmp
* \return the return value of sigsetjmp
*/
int* MXAPIGetSigJmpEnv();

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 b046b8d

Please sign in to comment.