[arrayfire] 30/75: Fixing af_get_last_error for unified backend
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 11aa9339fc60a8888b76e140ce933e773386fab1
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date: Sun Feb 14 21:47:48 2016 -0500
Fixing af_get_last_error for unified backend
The way it was implemented, it was getting the last error
generated from unified backend. This change gets the last error
generated from a particular backend instead.
---
src/api/c/err_common.cpp | 61 ++++------------------------
src/api/c/err_common.hpp | 4 ++
src/api/c/error.cpp | 65 ++++++++++++++++++++++++++++++
src/api/c/index.cpp | 68 ++++++++++++++++++++++++++++++++
src/api/c/util.cpp | 81 --------------------------------------
src/api/unified/CMakeLists.txt | 13 +++---
src/api/unified/error.cpp | 26 ++++++++++++
src/api/unified/index.cpp | 34 ++++++++++++++++
src/api/unified/symbol_manager.hpp | 8 ++++
src/api/unified/util.cpp | 5 ---
10 files changed, 218 insertions(+), 147 deletions(-)
diff --git a/src/api/c/err_common.cpp b/src/api/c/err_common.cpp
index 495967a..e95ece6 100644
--- a/src/api/c/err_common.cpp
+++ b/src/api/c/err_common.cpp
@@ -150,9 +150,6 @@ int DimensionError::getArgIndex() const
return argIndex;
}
-static const int MAX_ERR_SIZE = 1024;
-static std::string global_err_string;
-
void
print_error(const string &msg)
{
@@ -161,57 +158,7 @@ print_error(const string &msg)
if(perr != "0")
fprintf(stderr, "%s\n", msg.c_str());
}
- global_err_string = msg;
-}
-
-void af_get_last_error(char **str, dim_t *len)
-{
- dim_t slen = std::min(MAX_ERR_SIZE, (int)global_err_string.size());
-
- if (len && slen == 0) {
- *len = 0;
- *str = NULL;
- return;
- }
-
- af_alloc_host((void**)str, sizeof(char) * (slen + 1));
- global_err_string.copy(*str, slen);
-
- (*str)[slen] = '\0';
- global_err_string = std::string("");
-
- if(len) *len = slen;
-}
-
-const char *af_err_to_string(const af_err err)
-{
- switch (err) {
- case AF_SUCCESS: return "Success";
- case AF_ERR_NO_MEM: return "Device out of memory";
- case AF_ERR_DRIVER: return "Driver not available or incompatible";
- case AF_ERR_RUNTIME: return "Runtime error ";
- case AF_ERR_INVALID_ARRAY: return "Invalid array";
- case AF_ERR_ARG: return "Invalid input argument";
- case AF_ERR_SIZE: return "Invalid input size";
- case AF_ERR_TYPE: return "Function does not support this data type";
- case AF_ERR_DIFF_TYPE: return "Input types are not the same";
- case AF_ERR_BATCH: return "Invalid batch configuration";
- case AF_ERR_NOT_SUPPORTED: return "Function not supported";
- case AF_ERR_NOT_CONFIGURED: return "Function not configured to build";
- case AF_ERR_NONFREE: return "Function unavailable. "
- "ArrayFire compiled without Non-Free algorithms support";
- 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_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";
- case AF_ERR_UNKNOWN:
- default: return "Unknown error";
- }
+ get_global_error_string() = msg;
}
af_err processException()
@@ -271,3 +218,9 @@ af_err processException()
return err;
}
+
+std::string& get_global_error_string()
+{
+ static std::string global_error_string = std::string("");
+ return global_error_string;
+}
diff --git a/src/api/c/err_common.hpp b/src/api/c/err_common.hpp
index c8eb90a..60ef642 100644
--- a/src/api/c/err_common.hpp
+++ b/src/api/c/err_common.hpp
@@ -203,3 +203,7 @@ void print_error(const std::string &msg);
__AF_FILENAME__, __LINE__, \
"\n", __err); \
} while(0)
+
+
+static const int MAX_ERR_SIZE = 1024;
+std::string& get_global_error_string();
diff --git a/src/api/c/error.cpp b/src/api/c/error.cpp
new file mode 100644
index 0000000..4a7d4b2
--- /dev/null
+++ b/src/api/c/error.cpp
@@ -0,0 +1,65 @@
+/*******************************************************
+ * Copyright (c) 2014, ArrayFire
+ * All rights reserved.
+ *
+ * This file is distributed under 3-clause BSD license.
+ * The complete license agreement can be obtained at:
+ * http://arrayfire.com/licenses/BSD-3-Clause
+ ********************************************************/
+
+#include <af/exception.h>
+#include <af/device.h>
+#include <err_common.hpp>
+#include <string>
+#include <algorithm>
+
+void af_get_last_error(char **str, dim_t *len)
+{
+ std::string &global_error_string = get_global_error_string();
+ dim_t slen = std::min(MAX_ERR_SIZE, (int)global_error_string.size());
+
+ 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;
+}
+
+const char *af_err_to_string(const af_err err)
+{
+ switch (err) {
+ case AF_SUCCESS: return "Success";
+ case AF_ERR_NO_MEM: return "Device out of memory";
+ case AF_ERR_DRIVER: return "Driver not available or incompatible";
+ case AF_ERR_RUNTIME: return "Runtime error ";
+ case AF_ERR_INVALID_ARRAY: return "Invalid array";
+ case AF_ERR_ARG: return "Invalid input argument";
+ case AF_ERR_SIZE: return "Invalid input size";
+ case AF_ERR_TYPE: return "Function does not support this data type";
+ case AF_ERR_DIFF_TYPE: return "Input types are not the same";
+ case AF_ERR_BATCH: return "Invalid batch configuration";
+ case AF_ERR_NOT_SUPPORTED: return "Function not supported";
+ case AF_ERR_NOT_CONFIGURED: return "Function not configured to build";
+ case AF_ERR_NONFREE: return "Function unavailable. "
+ "ArrayFire compiled without Non-Free algorithms support";
+ 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_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";
+ case AF_ERR_UNKNOWN:
+ default: return "Unknown error";
+ }
+}
diff --git a/src/api/c/index.cpp b/src/api/c/index.cpp
index f5a214f..4a20ca2 100644
--- a/src/api/c/index.cpp
+++ b/src/api/c/index.cpp
@@ -230,3 +230,71 @@ af_err af_index_gen(af_array *out, const af_array in, const dim_t ndims, const a
return AF_SUCCESS;
}
+
+af_seq af_make_seq(double begin, double end, double step)
+{
+ af_seq seq = {begin, end, step};
+ return seq;
+}
+
+af_err af_create_indexers(af_index_t** indexers)
+{
+ try {
+ af_index_t* out = new af_index_t[4];
+ std::swap(*indexers, out);
+ }
+ CATCHALL;
+ return AF_SUCCESS;
+}
+
+af_err af_set_array_indexer(af_index_t* indexer, const af_array idx, const dim_t dim)
+{
+ try {
+ ARG_ASSERT(0, (indexer!=NULL));
+ ARG_ASSERT(1, (idx!=NULL));
+ ARG_ASSERT(2, (dim>=0 && dim<=3));
+ indexer[dim].idx.arr = idx;
+ indexer[dim].isBatch = false;
+ indexer[dim].isSeq = false;
+ }
+ CATCHALL
+ return AF_SUCCESS;
+}
+
+af_err af_set_seq_indexer(af_index_t* indexer, const af_seq* idx, const dim_t dim, const bool is_batch)
+{
+ try {
+ ARG_ASSERT(0, (indexer!=NULL));
+ ARG_ASSERT(1, (idx!=NULL));
+ ARG_ASSERT(2, (dim>=0 && dim<=3));
+ indexer[dim].idx.seq = *idx;
+ indexer[dim].isBatch = is_batch;
+ indexer[dim].isSeq = true;
+ }
+ CATCHALL
+ return AF_SUCCESS;
+}
+
+af_err af_set_seq_param_indexer(af_index_t* indexer,
+ const double begin, const double end, const double step,
+ const dim_t dim, const bool is_batch)
+{
+ try {
+ ARG_ASSERT(0, (indexer!=NULL));
+ ARG_ASSERT(4, (dim>=0 && dim<=3));
+ indexer[dim].idx.seq = af_make_seq(begin, end, step);
+ indexer[dim].isBatch = is_batch;
+ indexer[dim].isSeq = true;
+ }
+ CATCHALL
+ return AF_SUCCESS;
+}
+
+af_err af_release_indexers(af_index_t* indexers)
+{
+ try {
+ delete[] indexers;
+ }
+ CATCHALL;
+ return AF_SUCCESS;
+}
diff --git a/src/api/c/util.cpp b/src/api/c/util.cpp
deleted file mode 100644
index 9b16fe9..0000000
--- a/src/api/c/util.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/*******************************************************
- * Copyright (c) 2014, ArrayFire
- * All rights reserved.
- *
- * This file is distributed under 3-clause BSD license.
- * The complete license agreement can be obtained at:
- * http://arrayfire.com/licenses/BSD-3-Clause
- ********************************************************/
-
-#include <af/index.h>
-// The following should be included using double quotes
-// to enable it's use in unified wrapper
-#include "err_common.hpp"
-
-af_seq af_make_seq(double begin, double end, double step)
-{
- af_seq seq = {begin, end, step};
- return seq;
-}
-
-af_err af_create_indexers(af_index_t** indexers)
-{
- try {
- af_index_t* out = new af_index_t[4];
- std::swap(*indexers, out);
- }
- CATCHALL;
- return AF_SUCCESS;
-}
-
-af_err af_set_array_indexer(af_index_t* indexer, const af_array idx, const dim_t dim)
-{
- try {
- ARG_ASSERT(0, (indexer!=NULL));
- ARG_ASSERT(1, (idx!=NULL));
- ARG_ASSERT(2, (dim>=0 && dim<=3));
- indexer[dim].idx.arr = idx;
- indexer[dim].isBatch = false;
- indexer[dim].isSeq = false;
- }
- CATCHALL
- return AF_SUCCESS;
-}
-
-af_err af_set_seq_indexer(af_index_t* indexer, const af_seq* idx, const dim_t dim, const bool is_batch)
-{
- try {
- ARG_ASSERT(0, (indexer!=NULL));
- ARG_ASSERT(1, (idx!=NULL));
- ARG_ASSERT(2, (dim>=0 && dim<=3));
- indexer[dim].idx.seq = *idx;
- indexer[dim].isBatch = is_batch;
- indexer[dim].isSeq = true;
- }
- CATCHALL
- return AF_SUCCESS;
-}
-
-af_err af_set_seq_param_indexer(af_index_t* indexer,
- const double begin, const double end, const double step,
- const dim_t dim, const bool is_batch)
-{
- try {
- ARG_ASSERT(0, (indexer!=NULL));
- ARG_ASSERT(4, (dim>=0 && dim<=3));
- indexer[dim].idx.seq = af_make_seq(begin, end, step);
- indexer[dim].isBatch = is_batch;
- indexer[dim].isSeq = true;
- }
- CATCHALL
- return AF_SUCCESS;
-}
-
-af_err af_release_indexers(af_index_t* indexers)
-{
- try {
- delete[] indexers;
- }
- CATCHALL;
- return AF_SUCCESS;
-}
diff --git a/src/api/unified/CMakeLists.txt b/src/api/unified/CMakeLists.txt
index 6ed95d0..c44e43b 100644
--- a/src/api/unified/CMakeLists.txt
+++ b/src/api/unified/CMakeLists.txt
@@ -15,13 +15,12 @@ FILE(GLOB cpp_sources
SOURCE_GROUP(api\\cpp\\Sources FILES ${cpp_sources})
FILE(GLOB common_sources
- "../c/util.cpp"
- "../c/err_common.cpp"
- "../c/type_util.cpp"
- "../c/version.cpp"
- "../../backend/dim4.cpp"
- "../../backend/util.cpp"
- )
+ "../c/version.cpp"
+ "../c/err_common.cpp"
+ "../c/type_util.cpp"
+ "../../backend/dim4.cpp"
+ "../../backend/util.cpp"
+ )
SOURCE_GROUP(common FILES ${common_sources})
diff --git a/src/api/unified/error.cpp b/src/api/unified/error.cpp
new file mode 100644
index 0000000..00b0739
--- /dev/null
+++ b/src/api/unified/error.cpp
@@ -0,0 +1,26 @@
+/*******************************************************
+ * Copyright (c) 2015, ArrayFire
+ * All rights reserved.
+ *
+ * This file is distributed under 3-clause BSD license.
+ * The complete license agreement can be obtained at:
+ * http://arrayfire.com/licenses/BSD-3-Clause
+ ********************************************************/
+
+#include <af/array.h>
+#include <af/exception.h>
+#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);
+}
+
+const char *af_err_to_string(const af_err err)
+{
+ typedef char *(*af_func)(af_err);
+ af_func func = (af_func)LOAD_SYMBOL();
+ return func(err);
+}
diff --git a/src/api/unified/index.cpp b/src/api/unified/index.cpp
index 0927dd8..4df5926 100644
--- a/src/api/unified/index.cpp
+++ b/src/api/unified/index.cpp
@@ -52,3 +52,37 @@ af_err af_assign_gen( af_array *out,
CHECK_ARRAYS(lhs, rhs);
return CALL(out, lhs, ndims, indices, rhs);
}
+
+af_seq af_make_seq(double begin, double end, double step)
+{
+ af_seq seq = {begin, end, step};
+ return seq;
+}
+
+af_err af_create_indexers(af_index_t** indexers)
+{
+ return CALL(indexers);
+}
+
+af_err af_set_array_indexer(af_index_t* indexer, const af_array idx, const dim_t dim)
+{
+ CHECK_ARRAYS(idx);
+ return CALL(indexer, idx, dim);
+}
+
+af_err af_set_seq_indexer(af_index_t* indexer, const af_seq* idx, const dim_t dim, const bool is_batch)
+{
+ return CALL(indexer, idx, dim, is_batch);
+}
+
+af_err af_set_seq_param_indexer(af_index_t* indexer,
+ const double begin, const double end, const double step,
+ const dim_t dim, const bool is_batch)
+{
+ return CALL(indexer, begin, end, step, dim, is_batch);
+}
+
+af_err af_release_indexers(af_index_t* indexers)
+{
+ return CALL(indexers);
+}
diff --git a/src/api/unified/symbol_manager.hpp b/src/api/unified/symbol_manager.hpp
index 048d184..1530102 100644
--- a/src/api/unified/symbol_manager.hpp
+++ b/src/api/unified/symbol_manager.hpp
@@ -59,6 +59,8 @@ class AFSymbolManager {
return funcHandle(args...);
}
+ LibHandle getHandle() { return activeHandle; }
+
protected:
AFSymbolManager();
@@ -108,3 +110,9 @@ bool checkArrays(af_backend activeBackend, T a, Args... arg)
#define CALL(...) unified::AFSymbolManager::getInstance().call(__func__, __VA_ARGS__)
#define CALL_NO_PARAMS() unified::AFSymbolManager::getInstance().call(__func__)
#endif
+
+#if defined(OS_WIN)
+#define LOAD_SYMBOL() GetProcAddress(unified::AFSymbolManager::getInstance().getHandle(), __FUNCTION__)
+#else
+#define LOAD_SYMBOL() dlsym(unified::AFSymbolManager::getInstance().getHandle(), __func__)
+#endif
diff --git a/src/api/unified/util.cpp b/src/api/unified/util.cpp
index 155c4f8..178ac87 100644
--- a/src/api/unified/util.cpp
+++ b/src/api/unified/util.cpp
@@ -56,8 +56,3 @@ af_err af_example_function(af_array* out, const af_array in, const af_someenum_t
CHECK_ARRAYS(in);
return CALL(out, in, param);
}
-
-af_err af_get_version(int *major, int *minor, int *patch)
-{
- return CALL(major, minor, patch);
-}
--
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