Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 2 additions & 33 deletions Common/CUDA/TIGRE_common.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#if defined(IS_FOR_PYTIGRE)
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include "TIGRE_common.hpp"

#if defined(IS_FOR_PYTIGRE)
void mexPrintf(const char* format, ...) {
PRINT_HERE("");
va_list argpointer;
Expand All @@ -12,40 +11,10 @@ void mexPrintf(const char* format, ...) {
va_end(argpointer);
}
void mexErrMsgIdAndTxt(const char* pcTag, const char* pcMsg) {
/* Record and return. This used to exit(1), which ended the host Python
* process on any CUDA error - no exception, no traceback, nothing the
* caller could catch. Callers now return the errors.hpp codes and the
* Cython layer raises TigreCudaCallError, so an error is something the
* caller can handle rather than the end of the interpreter. */
PRINT_HERE("%s %s\n", pcTag, pcMsg);
tigreSetLastError(pcTag, pcMsg);
exit(1);
}
void mexWarnMsgIdAndTxt(const char* pcTag, const char* pcMsg) {
PRINT_HERE("%s %s\n", pcTag, pcMsg);
}
#endif // IS_FOR_PYTIGRE

/* Detail of the last recorded error, shared by both bindings.
*
* One static buffer suffices: the CUDA entry points are called one at a time
* from the host language, and the binding reads the message immediately after
* a non-zero return. */
static char s_lastError[512] = {0};

void tigreSetLastError(const char* pcTag, const char* pcMsg) {
const char* tag = pcTag ? pcTag : "";
const char* msg = pcMsg ? pcMsg : "";
#if defined(_MSC_VER)
_snprintf_s(s_lastError, sizeof(s_lastError), _TRUNCATE, "%s %s", tag, msg);
#else
snprintf(s_lastError, sizeof(s_lastError), "%s %s", tag, msg);
#endif
}

const char* tigreGetLastError(void) {
return s_lastError;
}

void tigreClearLastError(void) {
s_lastError[0] = '\0';
}
23 changes: 0 additions & 23 deletions Common/CUDA/TIGRE_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,4 @@ void mexWarnMsgIdAndTxt(const char* pcTag, const char* pcMsg);
#include "mex.h"
#include "tmwtypes.h"
#endif // IS_TIGRE_FOR_PYTHON

/* Last error recorded by cudaCheckErrors(), so a binding can report WHAT
* failed rather than only that something did.
*
* Under IS_FOR_PYTIGRE, mexErrMsgIdAndTxt() used to exit(1): any CUDA error
* terminated the host Python process - no exception, no traceback, nothing the
* caller could catch, and the interpreter gone along with any unsaved work. A
* library must not end its host process. Under MATLAB the same call longjmps
* out of the middle of a CUDA function, running no cleanup, so every error
* leaked every device buffer, page-locked allocation, stream and texture held
* at that moment for the rest of the session.
*
* The CUDA entry points now return the codes from errors.hpp instead and clean
* up on the way out (see tigre_cleanup.hpp). Each binding reports at its own
* boundary: MATLAB raises a MATLAB error, and the Cython layer raises a
* TigreCudaCallError - the mechanism its error_list was always indexed against.
*
* Declared for both bindings so the CUDA sources stay binding-agnostic.
*/
void tigreSetLastError(const char* pcTag, const char* pcMsg);
const char* tigreGetLastError(void);
void tigreClearLastError(void);

#endif // _COMMON_HPP_20201017_
101 changes: 0 additions & 101 deletions Common/CUDA/tigre_cleanup.hpp

This file was deleted.

Loading
Loading