[arrayfire] 177/284: Add OpenCL-CPU fallback for inverse
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:31 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/experimental
in repository arrayfire.
commit 4e2d46cec61b0226f3e1cbe558b58aa21c4f4cc5
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date: Fri Jan 8 15:26:08 2016 -0500
Add OpenCL-CPU fallback for inverse
---
src/backend/opencl/cpu/cpu_inverse.cpp | 77 ++++++++++++++++++++++++++++++++++
src/backend/opencl/cpu/cpu_inverse.hpp | 19 +++++++++
src/backend/opencl/inverse.cpp | 6 +++
3 files changed, 102 insertions(+)
diff --git a/src/backend/opencl/cpu/cpu_inverse.cpp b/src/backend/opencl/cpu/cpu_inverse.cpp
new file mode 100644
index 0000000..f1418b2
--- /dev/null
+++ b/src/backend/opencl/cpu/cpu_inverse.cpp
@@ -0,0 +1,77 @@
+/*******************************************************
+ * 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 <cpu/cpu_lapack_helper.hpp>
+#include <cpu/cpu_inverse.hpp>
+#include <err_common.hpp>
+#include <copy.hpp>
+#include <cpu/cpu_lu.hpp>
+
+namespace opencl
+{
+namespace cpu
+{
+
+template<typename T>
+using getri_func_def = int (*)(ORDER_TYPE, int,
+ T *, int,
+ const int *);
+
+#define INV_FUNC_DEF( FUNC ) \
+template<typename T> FUNC##_func_def<T> FUNC##_func();
+
+#define INV_FUNC( FUNC, TYPE, PREFIX ) \
+template<> FUNC##_func_def<TYPE> FUNC##_func<TYPE>() \
+{ return & LAPACK_NAME(PREFIX##FUNC); }
+
+INV_FUNC_DEF( getri )
+INV_FUNC(getri , float , s)
+INV_FUNC(getri , double , d)
+INV_FUNC(getri , cfloat , c)
+INV_FUNC(getri , cdouble, z)
+
+template<typename T>
+Array<T> inverse(const Array<T> &in)
+{
+ int M = in.dims()[0];
+ //int N = in.dims()[1];
+
+ // This condition is already handled in opencl/inverse.cpp
+ //if (M != N) {
+ //Array<T> I = identity<T>(in.dims());
+ //return solve(in, I);
+ //}
+
+ Array<T> A = copyArray<T>(in);
+
+ Array<int> pivot = cpu::lu_inplace<T>(A, false);
+
+ T *aPtr = getMappedPtr<T>(A.get());
+ int *pPtr = getMappedPtr<int>(pivot.get());
+
+ getri_func<T>()(AF_LAPACK_COL_MAJOR, M,
+ aPtr, A.strides()[1],
+ pPtr);
+
+ unmapPtr(A.get(), aPtr);
+ unmapPtr(pivot.get(), pPtr);
+
+ return A;
+}
+
+#define INSTANTIATE(T) \
+ template Array<T> inverse<T> (const Array<T> &in);
+
+INSTANTIATE(float)
+INSTANTIATE(cfloat)
+INSTANTIATE(double)
+INSTANTIATE(cdouble)
+
+}
+}
diff --git a/src/backend/opencl/cpu/cpu_inverse.hpp b/src/backend/opencl/cpu/cpu_inverse.hpp
new file mode 100644
index 0000000..38581a1
--- /dev/null
+++ b/src/backend/opencl/cpu/cpu_inverse.hpp
@@ -0,0 +1,19 @@
+/*******************************************************
+ * 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 <Array.hpp>
+
+namespace opencl
+{
+namespace cpu
+{
+ template<typename T>
+ Array<T> inverse(const Array<T> &in);
+}
+}
diff --git a/src/backend/opencl/inverse.cpp b/src/backend/opencl/inverse.cpp
index eb8348e..df95554 100644
--- a/src/backend/opencl/inverse.cpp
+++ b/src/backend/opencl/inverse.cpp
@@ -12,6 +12,8 @@
#include <identity.hpp>
#if defined(WITH_OPENCL_LINEAR_ALGEBRA)
+#include <platform.hpp>
+#include <cpu/cpu_inverse.hpp>
namespace opencl
{
@@ -19,6 +21,10 @@ namespace opencl
template<typename T>
Array<T> inverse(const Array<T> &in)
{
+ if(OpenCLCPUOffload()) {
+ if (in.dims()[0] == in.dims()[1])
+ return cpu::inverse(in);
+ }
Array<T> I = identity<T>(in.dims());
return solve<T>(in, I);
}
--
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