mercredi 1 juillet 2015

CUDA Thrust - How can I write a function using multiple device vectors with different sizes?

I've been trying figure out how to perform a simple entropy calculation using four thrust device vectors.

I have four device vectors, representing two key-value pairs. The first pair of vectors contains the keys and the number of times that key appears. The second pair contains keys paired with the bins for calculating the entropy. In this second vector pair, keys appear multiple times, with each instance representing a different bin.

It looks something like this:

Device Vector Pair 1

KeyVal 6 8 9

Counts 1 3 2

Device Vector Pair 2

KeyVal 6 8 8 9 9

BinVal 1 1 2 1 1

What I'm planning on doing is to use the first vector pair to check if a key appears enough times to calculate the entropy. If the count is large enough, the second vector pair will be used to calculate the entropy with the bin values for that key. I will need to use all of the bin values for that particular key. For example, if I wanted to calculate the entropy for keys that have appeared at least 3 times, I would find in the first vector pair that KeyVal 8 is ready. Then, I would search the second pair for all instances of KeyVal 8, and calculate the entropy using their corresponding BinVals.

However, I have no clue how to make this part work. I've tried using thrust::for_each to find all the keys that appear enough times to be tested, but I don't think it's possible to search for the keys in the second vector pair and perform the calculation within the for_each function.

Does anyone have suggestions on other ways to accomplish this?

Thank you for your help.

Aucun commentaire:

Enregistrer un commentaire