cuda编程笔记4(记录gpu耗时)

目录

  • 记录GPU运行时常

记录GPU运行时常

#include "stdio.h"
#include
#include 
#include 
#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…

你可能感兴趣的:(gpu,time)