Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone please help me with how to use CUB library. I found out that it has a function that help me to radix sort on the basis of key value pair. But i am unable to use it even for a sample demo. so that later i can use it in my real project.

my requiremement for demo is:


C++
       unsigned int *h_keys = (unsigned int*)malloc(numElements*sizeof(unsigned int));
       unsigned int *h_keysSorted = (unsigned int*)malloc(numElements*sizeof(unsigned int));
       unsigned int *h_values     = 0;
        h_values = (unsigned int *)malloc(numElements*sizeof(unsigned int));
	unsigned int *d_keys;
        unsigned int *d_values;
	cudaMalloc((void **)&d_keys, numElements*sizeof(unsigned int));
	cudaMalloc((void **)&d_values, numElements*sizeof(unsigned int));
	cudaMemset(d_keys,10, numElements*sizeof(unsigned int));
	cudaMemset(d_values,2, numElements*sizeof(unsigned int));
	for(int i=0; i < loopSize; ++i)   
	{ 
	    h_keys[i] = rand()%100;
	    h_values[i] = i; 
	}
	/**************************

          using cub library here and pass h_keys and h_values to its radix sort function 
and finally recive the sorted h_key value and in accordance of it the change in h_value.

        *************************/
		cudaMemcpy(d_keys, h_keys, loopSize * sizeof(unsigned int), cudaMemcpyHostToDevice);
		cudaMemcpy(d_values, h_values, loopSize * sizeof(unsigned int), cudaMemcpyHostToDevice);
		radixsort.sort(d_keys, d_values, loopSize, keybits);
	
		// Get results back to host for correctness checking
		cudaMemcpy(h_keysSorted, d_keys, loopSize * sizeof(unsigned int), cudaMemcpyDeviceToHost);
		cudaMemcpy(h_values, d_values, loopSize * sizeof(unsigned int), cudaMemcpyDeviceToHost);
		std::cout<<std::endl<<"After Sorting.............."<<std::endl;
	    for(int i =0; i<50 ;i++)
		{
			std::cout<<"h_values["<<i<<"]="<<h_values[i]<<"  "<<"h_keysSorted["<<i<<"]="<<h_keysSorted[i]<<std::endl;
		}


Thank in advance. please help it anyone has used cub libaray before...
http://nvlabs.github.io/cub/[^]
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900