[arrayfire] 31/284: converted susan fn in cpu backend to asynchronous call
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:16 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 743fb4a1e57dea918dc4465d4a25dc0279a286a4
Author: pradeep <pradeep at arrayfire.com>
Date: Mon Nov 23 13:28:55 2015 -0500
converted susan fn in cpu backend to asynchronous call
---
src/backend/cpu/susan.cpp | 59 ++++++++++++++++++++++++++++-------------------
1 file changed, 35 insertions(+), 24 deletions(-)
diff --git a/src/backend/cpu/susan.cpp b/src/backend/cpu/susan.cpp
index 7749391..e2c908c 100644
--- a/src/backend/cpu/susan.cpp
+++ b/src/backend/cpu/susan.cpp
@@ -11,18 +11,25 @@
#include <Array.hpp>
#include <cmath>
#include <math.hpp>
+#include <memory>
+#include <platform.hpp>
+#include <async_queue.hpp>
using af::features;
+using std::shared_ptr;
namespace cpu
{
template<typename T>
-void susan_responses(T* resp_out, const T* in,
+void susan_responses(Array<T> output, const Array<T> input,
const unsigned idim0, const unsigned idim1,
const int radius, const float t, const float g,
const unsigned border_len)
{
+ T* resp_out = output.get();
+ const T* in = input.get();
+
const unsigned r = border_len;
const int rSqrd = radius*radius;
@@ -51,10 +58,16 @@ void susan_responses(T* resp_out, const T* in,
}
template<typename T>
-void non_maximal(float* x_out, float* y_out, float* resp_out,
- unsigned* count, const unsigned idim0, const unsigned idim1,
- const T* resp_in, const unsigned border_len, const unsigned max_corners)
+void non_maximal(Array<float> xcoords, Array<float> ycoords, Array<float> response,
+ shared_ptr<unsigned> counter, const unsigned idim0, const unsigned idim1,
+ const Array<T> input, const unsigned border_len, const unsigned max_corners)
{
+ float* x_out = xcoords.get();
+ float* y_out = ycoords.get();
+ float* resp_out = response.get();
+ unsigned* count = counter.get();
+ const T* resp_in= input.get();
+
// Responses on the border don't have 8-neighbors to compare, discard them
const unsigned r = border_len + 1;
@@ -94,36 +107,34 @@ unsigned susan(Array<float> &x_out, Array<float> &y_out, Array<float> &resp_out,
const float feature_ratio, const unsigned edge)
{
dim4 idims = in.dims();
-
const unsigned corner_lim = in.elements() * feature_ratio;
- float* x_corners = memAlloc<float>(corner_lim);
- float* y_corners = memAlloc<float>(corner_lim);
- float* resp_corners = memAlloc<float>(corner_lim);
- T* resp = memAlloc<T>(in.elements());
- unsigned corners_found = 0;
+ auto x_corners = createEmptyArray<float>(dim4(corner_lim));
+ auto y_corners = createEmptyArray<float>(dim4(corner_lim));
+ auto resp_corners = createEmptyArray<float>(dim4(corner_lim));
+ auto response = createEmptyArray<T>(dim4(in.elements()));
+ auto corners_found= std::shared_ptr<unsigned>(memAlloc<unsigned>(1), memFree<unsigned>);
+ corners_found.get()[0] = 0;
- susan_responses<T>(resp, in.get(), idims[0], idims[1], radius, diff_thr, geom_thr, edge);
+ getQueue().enqueue(susan_responses<T>, response, in, idims[0], idims[1],
+ radius, diff_thr, geom_thr, edge);
+ getQueue().enqueue(non_maximal<T>, x_corners, y_corners, resp_corners, corners_found,
+ idims[0], idims[1], response, edge, corner_lim);
+ getQueue().sync();
- non_maximal<T>(x_corners, y_corners, resp_corners, &corners_found,
- idims[0], idims[1], resp, edge, corner_lim);
-
- memFree(resp);
-
- const unsigned corners_out = min(corners_found, corner_lim);
+ const unsigned corners_out = min((corners_found.get())[0], corner_lim);
if (corners_out == 0) {
- memFree(x_corners);
- memFree(y_corners);
- memFree(resp_corners);
x_out = createEmptyArray<float>(dim4());
y_out = createEmptyArray<float>(dim4());
resp_out = createEmptyArray<float>(dim4());
return 0;
} else {
-
- x_out = createDeviceDataArray<float>(dim4(corners_out), (void*)x_corners);
- y_out = createDeviceDataArray<float>(dim4(corners_out), (void*)y_corners);
- resp_out = createDeviceDataArray<float>(dim4(corners_out), (void*)resp_corners);
+ x_out = x_corners;
+ y_out = y_corners;
+ resp_out = resp_corners;
+ x_out.resetDims(dim4(corners_out));
+ y_out.resetDims(dim4(corners_out));
+ resp_out.resetDims(dim4(corners_out));
return corners_out;
}
}
--
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