问题
I want to find combination of all possible words that could be formed from a given tile set of 11 words. Is it possible to do that on CUDA? If yes than how. Thanks!
回答1:
Yes, you can do permutations in CUDA, in fact, sr. Wong Shao Voon has an implementation of a Permutations algorithm with CUDA and OpenCL.
He did not use String as you want, but this is not a major problem you just have to make a method that converts the symbols that he used (letters) to yours (words) after the algorithm is finished. Imagining that he saved all the permutations in a 2D array of characters, you perambulate all the matrix and instead of printing the actual char you print the word that you want (e.g. if(matrix[i][j] == 'A') printf("Anaconda");).
Benchmark
"I have benchmarked the CUDA against the CPU application. The CPU and GPU used in the benchmark, are Intel i7 870 (8 cores), 2.93Ghz and NVidia Geforce 460 respectively. The CPU application make full use of the 8 cores to find permutations. The CPU application is using factorial decomposition to split the nth permutations among different CPU cores and in each worker threads, STL next_permutation is used to find every consecutive permutation from the first nth permutation. The results of computing permutations of 11 elements is listed below. The total number of permutations of 11 elements found is 39,916,800. The size of the array need to store the results is 39,916,800 x 11 = 439,084,800. This is the maximum number of permutations which my 1GB memory GPU can store."
Collapse | Copy Code CPU : 550ms
Version 1 with pure factorial decomposition (Average timing) CUDA : 550ms OpenCL : 581ms
Version 2 with 1 next_permutation per factorial decomposition (Average timing) CUDA : 317ms OpenCL : 373ms
Version 3 with 9 next_permutation per factorial decomposition (Average timing) CUDA : 681ms OpenCL : 456ms
回答2:
Take a look at https://github.com/kkilictepe/CudaCombination It is python implementation with numba but helps.
来源:https://stackoverflow.com/questions/13284835/use-cuda-to-compute-all-possible-combinations-of-words