byzhang / cudpp

Automatically exported from code.google.com/p/cudpp
Other
0 stars 0 forks source link

How to config the cudppSort to sort in descending order? #76

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I just want to know how to config the cudppSort so that it will sort in 
descending order?

Also, what is the difference between the cudpp radixsort and the RadixSort 
example from the CUDA SDK?

Original issue reported on code.google.com by liuxiaod...@gmail.com on 18 May 2011 at 6:49

GoogleCodeExporter commented 9 years ago

Original comment by harr...@gmail.com on 6 Jul 2011 at 2:36

GoogleCodeExporter commented 9 years ago
This is fixed in trunk, will be included in the CUDPP 2.0 release.  Simply 
specify the CUDPP_OPTION_BACKWARD option when creating the plan for 
cudppRadixSort.

Original comment by harr...@gmail.com on 7 Jul 2011 at 7:58

GoogleCodeExporter commented 9 years ago
I don't know what you're talking about. This doesn't work.

void sortOnGPU(float* arrayToSort,unsigned int numElements, Order order){
    cout<<"sorting has begun"<<endl;

    long startTime_,now_;
    startTime_ = GetTickCount();
    now_ = GetTickCount() - startTime_;

    cout<<"it took "<<now_<<endl;//zero here

    const int sortByLeastSignificant = 8*sizeof(float);//8 is the number of bits in a byte
    unsigned int memSize = sizeof( float) * numElements;

    float* d_idata;

    CUDPPConfiguration config;

    config.op = CUDPP_ADD;
    config.datatype = CUDPP_FLOAT;
    config.algorithm = CUDPP_SORT_RADIX;

    if(order == Ascending){
        config.options = CUDPP_OPTION_KEYS_ONLY;
    }
    else{//order == Descending
        config.options = CUDPP_OPTION_KEYS_ONLY | CUDPP_OPTION_BACKWARD;
    }

    CUDPPHandle scanplan = 0;
    CUDPPResult plan = cudppPlan(&scanplan, config, numElements, 1, 0);  

    if (CUDPP_SUCCESS != plan){
        cout<<"error in sortOnGpu"<<endl;
        printf("Error creating CUDPPPlan\n");
        exit(-1);
    }

    //cout<<"now sorting."<<endl;
    startTime_ = GetTickCount();
    CUDPPResult result = cudppSort(plan,arrayToSort,arrayToSort,sortByLeastSignificant,numElements);

    if (CUDPP_SUCCESS != result){
        printf("Error sorting\n");
        exit(-1);
    }
//  now_ = GetTickCount() - startTime_;
//  cout<<"sorting took "<<now_<<" milliseconds"<<endl;
}

call to sortOnGPU works fine with order==Ascending (sorts in ascending order)
and sorts also in ascending order with order==Descending.

Original comment by noamz...@gmail.com on 26 Jul 2011 at 6:34

GoogleCodeExporter commented 9 years ago
Howdy, are you running the trunk version (from svn) of CUDPP? I'm not quite 
sure you are looking at the code you sent.

Original comment by jow...@gmail.com on 27 Jul 2011 at 11:47