[arrayfire] 07/284: Async CPU diff1 and diff2
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:13 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 c399e751cf7c824e0df575cf266ea7bb13645905
Author: Umar Arshad <umar at arrayfire.com>
Date: Mon Aug 10 23:25:04 2015 -0400
Async CPU diff1 and diff2
---
src/backend/cpu/diff.cpp | 91 ++++++++++++++++++++++++++----------------------
1 file changed, 50 insertions(+), 41 deletions(-)
diff --git a/src/backend/cpu/diff.cpp b/src/backend/cpu/diff.cpp
index 907c111..08c1a66 100644
--- a/src/backend/cpu/diff.cpp
+++ b/src/backend/cpu/diff.cpp
@@ -11,6 +11,8 @@
#include <diff.hpp>
#include <stdexcept>
#include <err_cpu.hpp>
+#include <platform.hpp>
+#include <async_queue.hpp>
namespace cpu
{
@@ -36,28 +38,31 @@ namespace cpu
dims[dim]--;
// Create output placeholder
- Array<T> outArray = createValueArray(dims, (T)0);
-
- // Get pointers to raw data
- const T *inPtr = in.get();
- T *outPtr = outArray.get();
-
- // TODO: Improve this
- for(dim_t l = 0; l < dims[3]; l++) {
- for(dim_t k = 0; k < dims[2]; k++) {
- for(dim_t j = 0; j < dims[1]; j++) {
- for(dim_t i = 0; i < dims[0]; i++) {
- // Operation: out[index] = in[index + 1 * dim_size] - in[index]
- int idx = getIdx(in.strides(), in.offsets(), i, j, k, l);
- int jdx = getIdx(in.strides(), in.offsets(),
- i + is_dim0, j + is_dim1,
- k + is_dim2, l + is_dim3);
- int odx = getIdx(outArray.strides(), outArray.offsets(), i, j, k, l);
- outPtr[odx] = inPtr[jdx] - inPtr[idx];
+ Array<T> outArray = createEmptyArray<T>(dims);
+
+ auto func = [=] (Array<T> outArray, Array<T> in) {
+ // Get pointers to raw data
+ const T *inPtr = in.get();
+ T *outPtr = outArray.get();
+
+ // TODO: Improve this
+ for(dim_t l = 0; l < dims[3]; l++) {
+ for(dim_t k = 0; k < dims[2]; k++) {
+ for(dim_t j = 0; j < dims[1]; j++) {
+ for(dim_t i = 0; i < dims[0]; i++) {
+ // Operation: out[index] = in[index + 1 * dim_size] - in[index]
+ int idx = getIdx(in.strides(), in.offsets(), i, j, k, l);
+ int jdx = getIdx(in.strides(), in.offsets(),
+ i + is_dim0, j + is_dim1,
+ k + is_dim2, l + is_dim3);
+ int odx = getIdx(outArray.strides(), outArray.offsets(), i, j, k, l);
+ outPtr[odx] = inPtr[jdx] - inPtr[idx];
+ }
}
}
}
- }
+ };
+ getQueue().enqueue(func, outArray, in);
return outArray;
}
@@ -76,31 +81,35 @@ namespace cpu
dims[dim] -= 2;
// Create output placeholder
- Array<T> outArray = createValueArray(dims, (T)0);
-
- // Get pointers to raw data
- const T *inPtr = in.get();
- T *outPtr = outArray.get();
-
- // TODO: Improve this
- for(dim_t l = 0; l < dims[3]; l++) {
- for(dim_t k = 0; k < dims[2]; k++) {
- for(dim_t j = 0; j < dims[1]; j++) {
- for(dim_t i = 0; i < dims[0]; i++) {
- // Operation: out[index] = in[index + 1 * dim_size] - in[index]
- int idx = getIdx(in.strides(), in.offsets(), i, j, k, l);
- int jdx = getIdx(in.strides(), in.offsets(),
- i + is_dim0, j + is_dim1,
- k + is_dim2, l + is_dim3);
- int kdx = getIdx(in.strides(), in.offsets(),
- i + 2 * is_dim0, j + 2 * is_dim1,
- k + 2 * is_dim2, l + 2 * is_dim3);
- int odx = getIdx(outArray.strides(), outArray.offsets(), i, j, k, l);
- outPtr[odx] = inPtr[kdx] + inPtr[idx] - inPtr[jdx] - inPtr[jdx];
+ Array<T> outArray = createEmptyArray<T>(dims);
+
+ auto func = [=] (Array<T> outArray, Array<T> in) {
+ // Get pointers to raw data
+ const T *inPtr = in.get();
+ T *outPtr = outArray.get();
+
+ // TODO: Improve this
+ for(dim_t l = 0; l < dims[3]; l++) {
+ for(dim_t k = 0; k < dims[2]; k++) {
+ for(dim_t j = 0; j < dims[1]; j++) {
+ for(dim_t i = 0; i < dims[0]; i++) {
+ // Operation: out[index] = in[index + 1 * dim_size] - in[index]
+ int idx = getIdx(in.strides(), in.offsets(), i, j, k, l);
+ int jdx = getIdx(in.strides(), in.offsets(),
+ i + is_dim0, j + is_dim1,
+ k + is_dim2, l + is_dim3);
+ int kdx = getIdx(in.strides(), in.offsets(),
+ i + 2 * is_dim0, j + 2 * is_dim1,
+ k + 2 * is_dim2, l + 2 * is_dim3);
+ int odx = getIdx(outArray.strides(), outArray.offsets(), i, j, k, l);
+ outPtr[odx] = inPtr[kdx] + inPtr[idx] - inPtr[jdx] - inPtr[jdx];
+ }
}
}
}
- }
+ };
+
+ getQueue().enqueue(func, outArray, in);
return outArray;
}
--
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