目录

记录GPU运行时常
#include "stdio.h"
#include<iostream>
#include <cuda.h>
#include <cuda_runtime.h>
#include "device_launch_parameters.h"
int main(void) {
//-----------------------------------------------记录时间------------------------------------------
cudaEvent_t e_start, e_stop;
cudaEventCreate(&e_start);
cudaEventCreate(&e_stop);
cudaEventRecord(e_start, 0);
//-----------------------------------------------记录时间------------------------------------------
// allocate the memory
;
//Initializing Arrays
// Copy input arrays from host to device memory
//Calling kernels passing device pointers as parameters
//Copy result back to host memory from device memory
//-----------------------------------------------记录时间------------------------------------------
cudaDeviceSynchronize();
cudaEventRecord(e_stop, 0);
cudaEventSynchronize(e_stop);
float elapsedTime;
cudaEventElapsedTime(&elapsedTime, e_start, e_stop);
printf("Time to add %d numbers: %3.1f ms\n", N, elapsedTime);
//-----------------------------------------------记录时间------------------------------------------
//Free up memory
}
结果如下:


作者: LEDyexu
博客: https://blog.csdn.net/LEDyexu
更新ing…
本文记录了在CUDA编程中如何测量GPU的运行时常,通过详细步骤展示了GPU耗时的跟踪与分析过程。
&spm=1001.2101.3001.5002&articleId=109658025&d=1&t=3&u=bace3a7a9f914d839672eb76a281b19a)
2115

被折叠的 条评论
为什么被折叠?



