I'm trying to do a naive GPU parallel implementation of K-nearest neighbors using Matlab (i.e. I'm trying to avoid going to CUDA for now). Let's say I have a function
idx=MyKnn(A,x,k)
which computes the indices of the k rows of A which have smallest distance to x. We think of A as an N-by-d matrix, i.e. N vectors in d-dimensions. x is a single d-dimensional vector.
Now, say I have two (or more) vectors x and y, and I want to compute MyKnn(A,x,k) and MyKnn(A,y,k) (with both querying the same array A). Shouldn't I be able to run this in parallel on my GPU? Matlab has the arrayfun() method for applying the same function to every element of an array, but how would I apply the same function to say every row or column of an array?
If "use a for loop" is the best answer, that's fine - that's what I have going right now, it just seems like I should be able to eek a little more parallelism out.