title: Timing CUDA kernels which should be executed more than 1 time
body: <p>I want to count the time of kernel which should be runned for more than 1 times,the data to be processed is different for each kernel being executed.My code is below, for the time of cudaMemcpy should not be counted.</p>
  
  <pre><code>1 cudaEvent_t start;
  2 error = cudaEventCreate(&amp;start);
  3 cudaEvent_t stop;
  4 error = cudaEventCreate(&amp;stop);
  6 float msecTotal = 0.0f;
  7 int nIter = 300;
  8 for (int j = 0; j &lt; nIter; j++)
  9 {            
  10      cudaMemcpy(...);
          // Record the start event
  11      error = cudaEventRecord(start, NULL);
  12      matrixMulCUDA1&lt;&lt;&lt; grid, threads &gt;&gt;&gt;(...);
         // Record the stop event
  13      error = cudaEventRecord(stop, NULL);
  14      error = cudaEventSynchronize(stop);
  15      float msec = 0.0f;
  16      error = cudaEventElapsedTime(&amp;msec, start, stop);
  17      msecTotal+=msec;
  18 }
  19 cout&lt;&lt;"Total time = "&lt;&lt;msecTotal&lt;&lt;endl;
  </code></pre>
  
  <p>To be fair,the contrast algorithm should be below:</p>
  
  <pre><code>1 cudaEvent_t start;
  2 error = cudaEventCreate(&amp;start);
  3 cudaEvent_t stop;
  4 error = cudaEventCreate(&amp;stop);
  6 float msecTotal = 0.0f;
  7 int nIter = 300;
  8 for (int j = 0; j &lt; nIter; j++)
  9 {
          // Record the start event    
  11      error = cudaEventRecord(start, NULL);
  12      matrixMulCUDA2&lt;&lt;&lt; grid, threads &gt;&gt;&gt;(...);
         // Record the stop event
  13      error = cudaEventRecord(stop, NULL);
  14      error = cudaEventSynchronize(stop);
  15      float msec = 0.0f;
  16      error = cudaEventElapsedTime(&amp;msec, start, stop);
  17      msecTotal+=msec;
  18 }
  19 cout&lt;&lt;"Total time = "&lt;&lt;msecTotal&lt;&lt;endl;
  </code></pre>
  
  <p>My question is that the method is right? for I am not sure.
  Obviously,the time should be more longer than normal.</p>