[arrayfire] 07/408: FEAT Add CPU backend for unwrap function
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Mon Sep 21 19:11:02 UTC 2015
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/sid
in repository arrayfire.
commit b0e4992e8ed8bef7c930d561fcca96f7de69dcb0
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date: Wed Jun 17 14:56:34 2015 -0400
FEAT Add CPU backend for unwrap function
* Empty functions for CUDA and OpenCL
---
include/af/image.h | 4 ++
src/api/c/unwrap.cpp | 60 +++++++++++++++++++++++++++
src/api/cpp/unwrap.cpp | 23 +++++++++++
src/backend/cpu/unwrap.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++
src/backend/cpu/unwrap.hpp | 18 ++++++++
src/backend/cuda/unwrap.cu | 52 +++++++++++++++++++++++
src/backend/cuda/unwrap.hpp | 18 ++++++++
src/backend/opencl/unwrap.cpp | 52 +++++++++++++++++++++++
src/backend/opencl/unwrap.hpp | 18 ++++++++
9 files changed, 340 insertions(+)
diff --git a/include/af/image.h b/include/af/image.h
index 67f5fc3..f5751a6 100644
--- a/include/af/image.h
+++ b/include/af/image.h
@@ -461,6 +461,8 @@ AFAPI array rgb2hsv(const array& in);
*/
AFAPI array colorSpace(const array& image, const CSpace to, const CSpace from);
+AFAPI array unwrap(const array& in, const dim_t wx, const dim_t wy, const dim_t sx, const dim_t sy);
+
}
#endif
@@ -903,6 +905,8 @@ extern "C" {
*/
AFAPI af_err af_color_space(af_array *out, const af_array image, const af_cspace_t to, const af_cspace_t from);
+ AFAPI af_err af_unwrap(af_array *out, const af_array in, const dim_t wx, const dim_t wy, const dim_t sx, const dim_t sy);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/api/c/unwrap.cpp b/src/api/c/unwrap.cpp
new file mode 100644
index 0000000..6ef8d49
--- /dev/null
+++ b/src/api/c/unwrap.cpp
@@ -0,0 +1,60 @@
+/*******************************************************
+ * 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/image.h>
+#include <af/defines.h>
+#include <err_common.hpp>
+#include <handle.hpp>
+#include <backend.hpp>
+#include <ArrayInfo.hpp>
+#include <unwrap.hpp>
+
+using af::dim4;
+using namespace detail;
+
+template<typename T>
+static inline af_array unwrap(const af_array in, const dim_t wx, const dim_t wy,
+ const dim_t sx, const dim_t sy)
+{
+ return getHandle(unwrap<T>(getArray<T>(in), wx, wy, sx, sy));
+}
+
+af_err af_unwrap(af_array *out, const af_array in,
+ const dim_t wx, const dim_t wy, const dim_t sx, const dim_t sy)
+{
+ try {
+ ArrayInfo info = getInfo(in);
+ af_dtype type = info.getType();
+ af::dim4 idims = info.dims();
+
+ DIM_ASSERT(1, idims[0] >= wx && idims[1] >= wy);
+ ARG_ASSERT(4, sx > 0);
+ ARG_ASSERT(5, sy > 0);
+
+ af_array output;
+
+ switch(type) {
+ case f32: output = unwrap<float >(in, wx, wy, sx, sy); break;
+ case f64: output = unwrap<double >(in, wx, wy, sx, sy); break;
+ case c32: output = unwrap<cfloat >(in, wx, wy, sx, sy); break;
+ case c64: output = unwrap<cdouble>(in, wx, wy, sx, sy); break;
+ case s32: output = unwrap<int >(in, wx, wy, sx, sy); break;
+ case u32: output = unwrap<uint >(in, wx, wy, sx, sy); break;
+ case s64: output = unwrap<intl >(in, wx, wy, sx, sy); break;
+ case u64: output = unwrap<uintl >(in, wx, wy, sx, sy); break;
+ case u8: output = unwrap<uchar >(in, wx, wy, sx, sy); break;
+ case b8: output = unwrap<char >(in, wx, wy, sx, sy); break;
+ default: TYPE_ERROR(1, type);
+ }
+ std::swap(*out,output);
+ }
+ CATCHALL;
+
+ return AF_SUCCESS;
+}
diff --git a/src/api/cpp/unwrap.cpp b/src/api/cpp/unwrap.cpp
new file mode 100644
index 0000000..b10dbeb
--- /dev/null
+++ b/src/api/cpp/unwrap.cpp
@@ -0,0 +1,23 @@
+/*******************************************************
+ * 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/array.h>
+#include <af/image.h>
+#include "error.hpp"
+
+namespace af
+{
+ array unwrap(const array& in, const dim_t wx, const dim_t wy, const dim_t sx, const dim_t sy)
+ {
+ af_array out = 0;
+ AF_THROW(af_unwrap(&out, in.get(), wx, wy, sx, sy));
+ return array(out);
+ }
+}
+
diff --git a/src/backend/cpu/unwrap.cpp b/src/backend/cpu/unwrap.cpp
new file mode 100644
index 0000000..691cf08
--- /dev/null
+++ b/src/backend/cpu/unwrap.cpp
@@ -0,0 +1,95 @@
+/*******************************************************
+ * 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>
+#include <unwrap.hpp>
+#include <stdexcept>
+#include <err_cpu.hpp>
+
+namespace cpu
+{
+ template<typename T>
+ void unwrap_(T *outPtr, const T *inPtr, const af::dim4 &odims, const af::dim4 &idims,
+ const af::dim4 &ostrides, const af::dim4 &istrides,
+ const dim_t wx, const dim_t wy, const dim_t sx, const dim_t sy)
+ {
+ dim_t nx = (idims[0] - wx) / sx + 1;
+ dim_t ny = (idims[1] - wy) / sy + 1;
+
+ for(dim_t w = 0; w < odims[3]; w++) {
+ for(dim_t z = 0; z < odims[2]; z++) {
+ dim_t cOut = w * ostrides[3] + z * ostrides[2];
+ dim_t cIn = w * istrides[3] + z * istrides[2];
+ for(dim_t col = 0; col < odims[1]; col++) {
+ // Calculate input window index
+ dim_t winy = (col / ny);
+ dim_t winx = (col % ny);
+
+ dim_t startx = winx * sx;
+ dim_t starty = winy * sy;
+
+ T* optr = outPtr + cOut + col * ostrides[1];
+ const T* iptr = inPtr + cIn + starty * istrides[1] + startx;
+
+ for(dim_t y = 0; y < wy; y++) {
+ for(dim_t x = 0; x < wx; x++) {
+ dim_t oloc = (y * wy + x) * ostrides[0];
+ dim_t iloc = (y * istrides[1] + x * istrides[0]);
+ optr[oloc] = iptr[iloc];
+ }
+ }
+ }
+ }
+ }
+ }
+
+ template<typename T>
+ Array<T> unwrap(const Array<T> &in, const dim_t wx, const dim_t wy,
+ const dim_t sx, const dim_t sy)
+ {
+ af::dim4 idims = in.dims();
+
+ dim_t nx = (idims[0] - wx) / sx + 1;
+ dim_t ny = (idims[1] - wy) / sy + 1;
+
+ af::dim4 odims(wx * wy, nx * ny, idims[2], idims[3]);
+
+ // Create output placeholder
+ Array<T> outArray = createEmptyArray<T>(odims);
+
+ // Get pointers to raw data
+ const T *inPtr = in.get();
+ T *outPtr = outArray.get();
+
+ af::dim4 ostrides = outArray.strides();
+ af::dim4 istrides = in.strides();
+
+ unwrap_(outPtr, inPtr, odims, idims, ostrides, istrides, wx, wy, sx, sy);
+
+ return outArray;
+ }
+
+
+#define INSTANTIATE(T) \
+ template Array<T> unwrap<T> (const Array<T> &in, const dim_t wx, const dim_t wy, \
+ const dim_t sx, const dim_t sy);
+
+
+ INSTANTIATE(float)
+ INSTANTIATE(double)
+ INSTANTIATE(cfloat)
+ INSTANTIATE(cdouble)
+ INSTANTIATE(int)
+ INSTANTIATE(uint)
+ INSTANTIATE(intl)
+ INSTANTIATE(uintl)
+ INSTANTIATE(uchar)
+ INSTANTIATE(char)
+}
+
diff --git a/src/backend/cpu/unwrap.hpp b/src/backend/cpu/unwrap.hpp
new file mode 100644
index 0000000..c492813
--- /dev/null
+++ b/src/backend/cpu/unwrap.hpp
@@ -0,0 +1,18 @@
+/*******************************************************
+ * 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 cpu
+{
+ template<typename T>
+ Array<T> unwrap(const Array<T> &in, const dim_t wx, const dim_t wy,
+ const dim_t sx, const dim_t sy);
+}
+
diff --git a/src/backend/cuda/unwrap.cu b/src/backend/cuda/unwrap.cu
new file mode 100644
index 0000000..d44ffd8
--- /dev/null
+++ b/src/backend/cuda/unwrap.cu
@@ -0,0 +1,52 @@
+/*******************************************************
+ * 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>
+#include <unwrap.hpp>
+//#include <kernel/unwrap.hpp>
+#include <stdexcept>
+#include <err_cuda.hpp>
+
+namespace cuda
+{
+ template<typename T>
+ Array<T> unwrap(const Array<T> &in, const dim_t wx, const dim_t wy,
+ const dim_t sx, const dim_t sy)
+ {
+ af::dim4 idims = in.dims();
+
+ dim_t nx = (idims[0] - wx) / sx + 1;
+ dim_t ny = (idims[1] - wy) / sy + 1;
+
+ af::dim4 odims(wx * wy, nx * ny, idims[2], idims[3]);
+
+ // Create output placeholder
+ Array<T> outArray = createEmptyArray<T>(odims);
+
+ return outArray;
+ }
+
+
+#define INSTANTIATE(T) \
+ template Array<T> unwrap<T> (const Array<T> &in, const dim_t wx, const dim_t wy, \
+ const dim_t sx, const dim_t sy);
+
+
+ INSTANTIATE(float)
+ INSTANTIATE(double)
+ INSTANTIATE(cfloat)
+ INSTANTIATE(cdouble)
+ INSTANTIATE(int)
+ INSTANTIATE(uint)
+ INSTANTIATE(intl)
+ INSTANTIATE(uintl)
+ INSTANTIATE(uchar)
+ INSTANTIATE(char)
+}
+
diff --git a/src/backend/cuda/unwrap.hpp b/src/backend/cuda/unwrap.hpp
new file mode 100644
index 0000000..ad71a12
--- /dev/null
+++ b/src/backend/cuda/unwrap.hpp
@@ -0,0 +1,18 @@
+/*******************************************************
+ * 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 cuda
+{
+ template<typename T>
+ Array<T> unwrap(const Array<T> &in, const dim_t wx, const dim_t wy,
+ const dim_t sx, const dim_t sy);
+}
+
diff --git a/src/backend/opencl/unwrap.cpp b/src/backend/opencl/unwrap.cpp
new file mode 100644
index 0000000..7403bb4
--- /dev/null
+++ b/src/backend/opencl/unwrap.cpp
@@ -0,0 +1,52 @@
+/*******************************************************
+ * 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>
+#include <unwrap.hpp>
+//#include <kernel/unwrap.hpp>
+#include <stdexcept>
+#include <err_opencl.hpp>
+
+namespace opencl
+{
+ template<typename T>
+ Array<T> unwrap(const Array<T> &in, const dim_t wx, const dim_t wy,
+ const dim_t sx, const dim_t sy)
+ {
+ af::dim4 idims = in.dims();
+
+ dim_t nx = (idims[0] - wx) / sx + 1;
+ dim_t ny = (idims[1] - wy) / sy + 1;
+
+ af::dim4 odims(wx * wy, nx * ny, idims[2], idims[3]);
+
+ // Create output placeholder
+ Array<T> outArray = createEmptyArray<T>(odims);
+
+ return outArray;
+ }
+
+
+#define INSTANTIATE(T) \
+ template Array<T> unwrap<T> (const Array<T> &in, const dim_t wx, const dim_t wy, \
+ const dim_t sx, const dim_t sy);
+
+
+ INSTANTIATE(float)
+ INSTANTIATE(double)
+ INSTANTIATE(cfloat)
+ INSTANTIATE(cdouble)
+ INSTANTIATE(int)
+ INSTANTIATE(uint)
+ INSTANTIATE(intl)
+ INSTANTIATE(uintl)
+ INSTANTIATE(uchar)
+ INSTANTIATE(char)
+}
+
diff --git a/src/backend/opencl/unwrap.hpp b/src/backend/opencl/unwrap.hpp
new file mode 100644
index 0000000..290f28f
--- /dev/null
+++ b/src/backend/opencl/unwrap.hpp
@@ -0,0 +1,18 @@
+/*******************************************************
+ * 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
+{
+ template<typename T>
+ Array<T> unwrap(const Array<T> &in, const dim_t wx, const dim_t wy,
+ const dim_t sx, const dim_t sy);
+}
+
--
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