[arrayfire] 31/75: Add better error messages coming out of unified api
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Feb 29 08:01:12 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch dfsg-clean
in repository arrayfire.
commit fd87af4a91e302efdebc71e43655c1bb16ccbea7
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Mon Feb 15 19:32:09 2016 -0500
Add better error messages coming out of unified api
---
src/api/c/error.cpp | 4 +---
src/api/unified/array.cpp | 1 +
src/api/unified/error.cpp | 31 ++++++++++++++++++++++++++++---
src/api/unified/symbol_manager.cpp | 7 ++++---
src/api/unified/symbol_manager.hpp | 29 +++++++++++++++++++++--------
5 files changed, 55 insertions(+), 17 deletions(-)
diff --git a/src/api/c/error.cpp b/src/api/c/error.cpp
index 4a7d4b2..521ca9b 100644
--- a/src/api/c/error.cpp
+++ b/src/api/c/error.cpp
@@ -53,9 +53,7 @@ const char *af_err_to_string(const af_err err)
case AF_ERR_NO_DBL: return "Double precision not supported for this device";
case AF_ERR_NO_GFX: return "Graphics functionality unavailable. "
"ArrayFire compiled without Graphics support";
- case AF_ERR_LOAD_LIB: return "Failed to load dynamic library. "
- "See http://www.arrayfire.com/docs/unifiedbackend.htm "
- "for instructions to set up environment for Unified backend";
+ case AF_ERR_LOAD_LIB: return "Failed to load dynamic library. ";
case AF_ERR_LOAD_SYM: return "Failed to load symbol";
case AF_ERR_ARR_BKND_MISMATCH: return "There was a mismatch between an array and the current backend";
case AF_ERR_INTERNAL: return "Internal error";
diff --git a/src/api/unified/array.cpp b/src/api/unified/array.cpp
index 59158ca..7d4f948 100644
--- a/src/api/unified/array.cpp
+++ b/src/api/unified/array.cpp
@@ -8,6 +8,7 @@
********************************************************/
#include <af/array.h>
+#include <af/backend.h>
#include "symbol_manager.hpp"
af_err af_create_array(af_array *arr, const void * const data, const unsigned ndims, const dim_t * const dims, const af_dtype type)
diff --git a/src/api/unified/error.cpp b/src/api/unified/error.cpp
index 00b0739..0224876 100644
--- a/src/api/unified/error.cpp
+++ b/src/api/unified/error.cpp
@@ -9,13 +9,38 @@
#include <af/array.h>
#include <af/exception.h>
+#include <af/device.h>
+#include <algorithm>
#include "symbol_manager.hpp"
void af_get_last_error(char **str, dim_t *len)
{
- typedef void(*af_func)(char **, dim_t *);
- af_func func = (af_func)LOAD_SYMBOL();
- return func(str, len);
+ // Set error message from unified backend
+ std::string &global_error_string = get_global_error_string();
+ dim_t slen = std::min(MAX_ERR_SIZE, (int)global_error_string.size());
+
+ // If this is true, the error is coming from the unified backend.
+ if (slen != 0) {
+
+ if (len && slen == 0) {
+ *len = 0;
+ *str = NULL;
+ return;
+ }
+
+ af_alloc_host((void**)str, sizeof(char) * (slen + 1));
+ global_error_string.copy(*str, slen);
+
+ (*str)[slen] = '\0';
+ global_error_string = std::string("");
+
+ if (len) *len = slen;
+ } else {
+ // If false, the error is coming from active backend.
+ typedef void(*af_func)(char **, dim_t *);
+ af_func func = (af_func)LOAD_SYMBOL();
+ func(str, len);
+ }
}
const char *af_err_to_string(const af_err err)
diff --git a/src/api/unified/symbol_manager.cpp b/src/api/unified/symbol_manager.cpp
index 94fef2d..96cec0b 100644
--- a/src/api/unified/symbol_manager.cpp
+++ b/src/api/unified/symbol_manager.cpp
@@ -203,8 +203,9 @@ af_err AFSymbolManager::setBackend(af::Backend bknd)
activeHandle = defaultHandle;
activeBackend = defaultBackend;
return AF_SUCCESS;
- } else
- return AF_ERR_LOAD_LIB;
+ } else {
+ UNIFIED_ERROR_LOAD_LIB();
+ }
}
int idx = bknd >> 1; // Convert 1, 2, 4 -> 0, 1, 2
if(bkndHandles[idx]) {
@@ -212,7 +213,7 @@ af_err AFSymbolManager::setBackend(af::Backend bknd)
activeBackend = bknd;
return AF_SUCCESS;
} else {
- return AF_ERR_LOAD_LIB;
+ UNIFIED_ERROR_LOAD_LIB();
}
}
diff --git a/src/api/unified/symbol_manager.hpp b/src/api/unified/symbol_manager.hpp
index 1530102..658ac74 100644
--- a/src/api/unified/symbol_manager.hpp
+++ b/src/api/unified/symbol_manager.hpp
@@ -12,6 +12,7 @@
#include <string>
#include <stdlib.h>
#include <util.hpp>
+#include <err_common.hpp>
#if defined(OS_WIN)
#include <Windows.h>
@@ -27,6 +28,13 @@ namespace unified
const int NUM_BACKENDS = 3;
const int NUM_ENV_VARS = 2;
+#define UNIFIED_ERROR_LOAD_LIB() \
+ AF_RETURN_ERROR("Failed to load dynamic library. " \
+ "See http://www.arrayfire.com/docs/unifiedbackend.htm " \
+ "for instructions to set up environment for Unified backend.", \
+ AF_ERR_LOAD_LIB)
+
+
class AFSymbolManager {
public:
static AFSymbolManager& getInstance();
@@ -43,8 +51,9 @@ class AFSymbolManager {
template<typename... CalleeArgs>
af_err call(const char* symbolName, CalleeArgs... args) {
- if (!activeHandle)
- return AF_ERR_LOAD_LIB;
+ if (!activeHandle) {
+ UNIFIED_ERROR_LOAD_LIB();
+ }
typedef af_err(*af_func)(CalleeArgs...);
af_func funcHandle;
#if defined(OS_WIN)
@@ -53,7 +62,10 @@ class AFSymbolManager {
funcHandle = (af_func)dlsym(activeHandle, symbolName);
#endif
if (!funcHandle) {
- return AF_ERR_LOAD_SYM;
+ std::string str = "Failed to load symbol: ";
+ str += symbolName;
+ AF_RETURN_ERROR(str.c_str(),
+ AF_ERR_LOAD_SYM);
}
return funcHandle(args...);
@@ -97,11 +109,12 @@ bool checkArrays(af_backend activeBackend, T a, Args... arg)
// Macro to check af_array as inputs. The arguments to this macro should be
// only input af_arrays. Not outputs or other types.
-#define CHECK_ARRAYS(...) do { \
- af_backend backendId = unified::AFSymbolManager::getInstance().getActiveBackend(); \
- if(!unified::checkArrays(backendId, __VA_ARGS__)) \
- return AF_ERR_ARR_BKND_MISMATCH; \
-} while(0)
+#define CHECK_ARRAYS(...) do { \
+ af_backend backendId = unified::AFSymbolManager::getInstance().getActiveBackend(); \
+ if(!unified::checkArrays(backendId, __VA_ARGS__)) \
+ AF_RETURN_ERROR("Input array does not belong to current backend", \
+ AF_ERR_ARR_BKND_MISMATCH); \
+ } while(0)
#if defined(OS_WIN)
#define CALL(...) unified::AFSymbolManager::getInstance().call(__FUNCTION__, __VA_ARGS__)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git
More information about the debian-science-commits
mailing list