Shifting different amounts on each slice in a volume

[Old posts from the commercial version of ArrayFire] Discussion of ArrayFire using CUDA or OpenCL.

Moderator: pavanky

Shifting different amounts on each slice in a volume

Postby Cykel » Wed Feb 26, 2014 4:18 pm

Hello,

I'm seeing some interesting behavior with a shift routine. I have a 3D volume (set of images) and a 2D array of shift information (row and column shift definitions for each image). I've tried using the gfor loop as follows:

Code: Select all
gfor(array j, N) {
   shifted(span, span j) = af::shift(original(span, span, j), shifts(span, j));
}

This effort throws an exception.

The following "works":
Code: Select all
gfor(array j, N) {
   int *h_SHIFTS = shifts(span, j).host<int>();
   shifted(span, span, j) = af::shift(original(span, span, j), h_SHIFTS[0], h_SHIFTS[1]);
}

However, I can see that the shifted result is not always correct. Do I need to specify that the pointer is local to the tile?

As of right now, the only thing that really works is a sequential for loop:
Code: Select all
for(int i = 0; i < N; i++) {
   shifted.slice(i) = af::shift(original.slice(i), shifts.col(i));
}


This is not horribly slow, but improvement using gfor would be nice. Am I missing something with the syntax in the first code snippet? Am I simply asking too much of the GPU? I tried breaking down into smaller gfor segments but to no avail.

Thanks in advance!
Cykel
 
Posts: 15
Joined: Wed Oct 09, 2013 6:14 pm

Re: Shifting different amounts on each slice in a volume

Postby pavanky » Wed Feb 26, 2014 4:22 pm

Having "shifts" inside gfor is not supported right now.
Getting the data onto the host will only get you the first tile. Hence you will see the first shift performed across all the originals.
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: Shifting different amounts on each slice in a volume

Postby Cykel » Wed Feb 26, 2014 4:59 pm

Thanks for the quick response.

Is gfor support for the shift routine in development or is this something that is low priority?
Cykel
 
Posts: 15
Joined: Wed Oct 09, 2013 6:14 pm

Re: Shifting different amounts on each slice in a volume

Postby pavanky » Wed Feb 26, 2014 7:44 pm

Hi,

We do not have plans to support the gfor for "shifts" right now. But if you can tell us more about the kind of algorithm you are working on may be we can figure out an alternative for you ?
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: Shifting different amounts on each slice in a volume

Postby Cykel » Mon Mar 03, 2014 4:45 pm

Sure,

I am extracting 3x3 neighborhoods from each image; the area of interest for each is different (previously calculated).

So far I've tried:
1 - Shift images by the calculated amount in X and Y (which aligns AOI for each image to a set location), then extract
2 - Tile the image and extract from the calculated location
3 - Flatten the image, then tile it (less memory), and extract

Perhaps there is a better method? I simply need to avoid crossing image boundaries when the AOI is centered on an edge (wrap around is desired)

Thanks in advance!
Cory
Cykel
 
Posts: 15
Joined: Wed Oct 09, 2013 6:14 pm

Re: Shifting different amounts on each slice in a volume

Postby pavanky » Mon Mar 03, 2014 4:51 pm

How do you want to treat the boundary conditions ?

I just saw that you edited to mention wrap around is desired.

Here are some thoughts. I may not fully understand the problem yet so please modify the suggestions as necessary.

- Create a 3x3 arrays centered around the pixel of interest for all the images. This can probably done using seq or gfor.
- Add offsets for negative values
- convert them to linear indices (i.e. from x,y to y * width + height or something similar).
- extract data and reshape.

I can try to code this up, but I will not be able to get to this today. Let me know if you make any progress.
Pavan Yalamanchili,
ArrayFire
--
~ If it is not broken, you have not tried hard enough ~
User avatar
pavanky
Site Admin
 
Posts: 1123
Joined: Mon Mar 15, 2010 7:39 pm
Location: Atlanta, GA

Re: Shifting different amounts on each slice in a volume

Postby Cykel » Tue Mar 04, 2014 1:37 pm

Hi Pavan,

Thanks again for the help. I have tried some of the methods you listed. With sequencing I run into the issue of having to pull the indices to the host either using a pointer or using .scalar<double>(). This causes the routine to actually be slower (albeit not by much) than performing all of the shifts sequentially.

I can't use a host-side pointer to the full index array because then I cannot use the gfor iterator to access different parts.

Is there a good way to use data stored in arrays for the sequence parameters that I am missing?

Thanks,
Cory
Cykel
 
Posts: 15
Joined: Wed Oct 09, 2013 6:14 pm


Return to [archive-commercial] Programming & Development with ArrayFire

cron