Skip to content

Instantly share code, notes, and snippets.

@arghdos
Last active Oct 17, 2017
Embed
What would you like to do?
updated output
__constant int const lookup[57] = { 0, 1, 2, 3, 4, 5, 6, 7, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 0, 1, 2, 3, 4, 5, 6, 0, 1, 2, 3, 4, 5, 6, 7, 0 };
__kernel void __attribute__ ((reqd_work_group_size(1, 1, 1))) indirect(int const start, int const end, int const match, __global int *__restrict__ out)
{
for (int i = start; i <= -1 + end; ++i)
if (lookup[i] == match)
out[0] = i + -1 * start;
}
__constant int const offsets[11] = { 0, 8, 9, 18, 22, 31, 39, 41, 48, 56, 57 };
__kernel void __attribute__ ((reqd_work_group_size(1, 1, 1))) loopy_kernel(__global double *__restrict__ out, __global double const *__restrict__ data, __global int *__restrict__ index)
{
index = 0;
for (int i = 0; i <= 9; ++i)
{
indirect(offsets[i], offsets[1 + i], 1, index);
out[i] = data[index[0]];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment