cudaHandleError.h
1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#ifndef CUDA_HANDLE_ERROR_H
#define CUDA_HANDLE_ERROR_H
//handle error macro
static void HandleError( cudaError_t err, const char *file, int line ) {
if (err != cudaSuccess) {
FILE* outfile = fopen("cudaErrorLog.txt", "w");
fprintf(outfile, "%s in %s at line %d\n", cudaGetErrorString( err ), file, line );
fclose(outfile);
exit( EXIT_FAILURE );
printf("%s in %s at line %d\n", cudaGetErrorString( err ), file, line );
}
}
#define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
static cudaEvent_t tStartEvent;
static cudaEvent_t tStopEvent;
static void gpuStartTimer()
{
//set up timing events
cudaEventCreate(&tStartEvent);
cudaEventCreate(&tStopEvent);
cudaEventRecord(tStartEvent, 0);
}
static float gpuStopTimer()
{
cudaEventRecord(tStopEvent, 0);
cudaEventSynchronize(tStopEvent);
float elapsedTime;
cudaEventElapsedTime(&elapsedTime, tStartEvent, tStopEvent);
cudaEventDestroy(tStartEvent);
cudaEventDestroy(tStopEvent);
return elapsedTime;
}
#endif