Skip to content

Instantly share code, notes, and snippets.

@JonnoFTW
Created September 7, 2018 05:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonnoFTW/f22c2f44bc04c099900a0255738afced to your computer and use it in GitHub Desktop.
Save JonnoFTW/f22c2f44bc04c099900a0255738afced to your computer and use it in GitHub Desktop.
__kernel void shuffle_data(
const __global float* data, // array to be shuffled
const __global uint2* swaps // array of swaps to perform
) {
const int gid = get_global_id(0);
const int field = get_global_id(1);
const int num_fields = get_global_size(1);
// swap row r1 with r2 from swaps[gid]
uint2 swap = swaps[gid];
const int r1 = num_fields* swap.x + field;
const int r2 = num_fields* swap.y + field;
float tmp = data[r2];
data[r2] = data[r1];
data[r1] = tmp;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment