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

  • Home
  • SEARCH
  • 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 7887991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:43:22+00:00 2026-06-03T05:43:22+00:00

I have a cuda code which performs calculation on GPU. I am using clock();

  • 0

I have a cuda code which performs calculation on GPU.
I am using clock(); to find out timings

My code structure is

__global__ static void sum(){

// calculates sum 
}

extern "C"
int run_kernel(int array[],int nelements){
 clock_t start, end;
  start = clock();
  //perform operation on gpu - call sum
 end = clock();
 double elapsed_time = ((double) (end - start)) / CLOCKS_PER_SEC;
 printf("time required : %lf", elapsed_time);
}

But the time is always 0.0000
I checked printing start and end time. Start has some value but end time is always zero.

Any idea what might be the cause? Any alternatives to measure time.

Any help would be appreciated.

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-06-03T05:43:23+00:00Added an answer on June 3, 2026 at 5:43 am

    There are two problems here:

    1. The clock() function has too low resolution to measure the duration of the event you are trying to time
    2. The CUDA kernel launch is an asynchronous operation, so it consumes almost no time (typically 10-20 microseconds on a sane platform). Unless you use a synchronous CUDA API call to force the host CPU to block until the kernel finishes running, you are not going to be measuring the execution time.

    CUDA has its own high precision timing API, and it is the recommended way to time operations which run on the GPU. The code to use it would look something like this:

    int run_kernel(int array[],int nelements){
    
        cudaEvent_t start,stop;
        cudaEventCreate(&start);
        cudaEventCreate(&stop);
    
        cudaEventRecord(start, 0);
    
        //
        //perform operation on gpu - call sum
        //
    
        cudaEventRecord(stop, 0); 
        cudaEventSynchronize(stop); 
        float elapsedTime; 
        cudaEventElapsedTime(&elapsedTime, start, stop); 
        printf("time required : %f", elapsed_time); 
    
        cudaEventDestroy(start);
        cudaEventDestroy(stop);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a weird problem .. I have written a CUDA code which
When compiling your CUDA code, you have to select for which architecture your code
hi i have a cuda program which run successfully here is code for cuda
I have made a Simple CUDA dll the code which I am displaying below.
I ran some CUDA code that updated an array of floats. I have a
In a CUDA kernel, I have code similar to the following. I am trying
CUDA has an option to compile code in emulation mode, which is supported in
I have written a CUDA code to solve an NP-Complete problem, but the performance
When I compile my CUDA code with NVCC and I have already defined a
I am trying to compile an application that contains CUDA code. I have a

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.