Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7085433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:25:25+00:00 2026-05-28T07:25:25+00:00

I am trying to time the thrust sort function . Present, i am using

  • 0

I am trying to time the thrust sort function . Present, i am using cuda events. but i was curious if cuda events will give me the wrong value. This is because, on my computer, thrust is sorting 2 million floats in GPU in 34 ms. But this seems too fast

I tried both CPU and GPU times and got following:

CPU ( takes around 36 ms)

__int64 ctr1 = 0 , ctr2 = 0 , freq = 0 ;
    QueryPerformanceFrequency((LARGE_INTEGER *) &freq);
    QueryPerformanceCounter((LARGE_INTEGER *) &ctr1);
    thrust::sort(D.begin(),D.end());
    // transfer data back to host   
    thrust::copy(D.begin(), D.end(), H.begin());
    cudaThreadSynchronize(); // block until kernel is finished

   QueryPerformanceCounter((LARGE_INTEGER *)&ctr2);
    double ans = ((ctr2 - ctr1) * 1.0 / freq);
    printf("The time elapsed in milliseconds is %f\n",(ans*1000));

GPU

cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start, 0);
thrust::sort(D.begin(),D.end());

thrust::copy(D.begin(), D.end(), H.begin());
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
float elapsedTime; 
cudaEventElapsedTime(&elapsedTime , start, stop);
printf("time is %f ms", elapsedTime);

Please let me know which timing is correct

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:25:26+00:00Added an answer on May 28, 2026 at 7:25 am

    Both timings are correct from different aspects. The CPU timing will include the overhead caused by the API calls and the synchronization. If you are interested in this overhead you should use the CPU timer.

    The event based timing is isolating the timing on the GPU and gives you the time of the GPU execution.

    Other differences between CPU and Event Timing is that if the thrust::sort() is the first call to the GPU from the current thread the call to will need to setup the CUDA context and give you a timing which includes the context setup. You will not get this problem if you use the event based timing because the context will be setup when calling cudaEventCreate().

    If you want to time GPU algorithms to in order to get a performance figure, the best way to do this is to use event based timing but also run the algorithms in a loop a number of times.

    cudaEvent_t start, stop;
    cudaEventCreate(&start);
    cudaEventCreate(&stop);
    cudaEventRecord(start, 0);
    for(int i=0; i < 100; i++){
    thrust::sort(D.begin(),D.end());
    
    thrust::copy(D.begin(), D.end(), H.begin());
    }
    cudaEventRecord(stop, 0);
    cudaEventSynchronize(stop);
    float elapsedTime; 
    cudaEventElapsedTime(&elapsedTime , start, stop);
    printf("Avg. time is %f ms", elapsedTime/100);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I spent some time trying to generate certain tab icons using Android Asset Studio
I am trying pause time using C#/.NET. I am able to set the time
I'm trying to time an order statistic function implemented in SBCL . Googling around
Been spending some time trying to get a solution in place that will determine
long-time listener, first-time caller! I’m trying to connect to MySQL using the ADO.NET Entity
I spent some time trying to remove layout (defined in _ViewStart) using: @Layout =
first time trying to deal with this call_user_func_array, but something isn't working, since I
I've been quite some time trying to use the Containable Behavior in CakePHP but
trying first time WPF user. I read through some WPF layout docs but am
First time trying to deal with users logging in with ASP.net and haven't had

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.