C
C
Clay2019-04-27 22:26:25
CUDA
Clay, 2019-04-27 22:26:25

Time difference?

Hello, can you please tell me what is the difference between:

clock_t start1 = clock();
...
clock_t end1 = clock();
  double seconds1 = (double)(end1 - start1) / CLOCKS_PER_SEC;
  cout << "Time:  " << seconds1 << " sec" << endl;

and
cudaEvent_t start, stop;
  cudaEventCreate(&start);
  cudaEventCreate(&stop);
  cudaEventRecord(start, 0);
...
        cudaThreadSynchronize();
  cudaEventRecord(stop, 0);
  cudaEventSynchronize(stop);
  float elapsedtime;
  cudaEventElapsedTime(&elapsedtime, start, stop);
  printf("Time = %3.1f ms\n", elapsedtime);
  cudaEventDestroy(start);
  cudaEventDestroy(stop);

I understand that one is for cuda, and the second is for the CPU, but what is their fundamental difference. Why do they measure the same piece of code differently (do they show different times?).
Thanks in advance for your reply, and sorry newbie for such stupid questions...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2019-04-30
@Pushunter

The fundamental difference is that the cuda interface is asynchronous, i.e. the time between start/stop will change the rate at which code is sent to the GPU.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question