-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.h
96 lines (81 loc) · 1.84 KB
/
utils.h
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* utils.h
*
* Created on: 30/11/2020
* Author: Nvixnu
*/
#ifndef UTILS_H_
#define UTILS_H_
#define STR_HELPER(x) #x
/**
* Converts a number to string
*/
#define NUM2STR(x) STR_HELPER(x)
/**
* Macro to clean the terminal
*/
#ifdef _WIN32
#include <conio.h>
#else
#include <stdio.h>
#define clrscr() printf("\e[1;1H\e[2J")
#endif
/**
* Calculates the elapsed time from the struct timespec start and stop values
*/
#define HOST_DURATION_MS(start, stop) (stop.tv_sec - start.tv_sec) * 1e3 + (stop.tv_nsec - start.tv_nsec) / 1e6
/**
* Start the host timers
*/
#define HOST_TIC(n) \
float duration##n; \
struct timespec start##n, stop##n; \
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start##n);
/**
* Stop the host timer and calculates and print the elapsed time
*/
#define HOST_TOC(n) \
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &stop##n); \
duration##n = HOST_DURATION_MS(start##n, stop##n); \
printf("\nHost elapsed time: %lf ms\n", duration##n);
/**
* Start the device timers
*/
#define DEVICE_TIC(n) \
float duration##n; \
cudaEvent_t start##n, stop##n; \
CCE(cudaEventCreate(&start##n)); \
CCE(cudaEventCreate(&stop##n)); \
CCE(cudaEventRecord(start##n));
/**
* Stop the device timer and calculates and print the elapsed time
*/
#define DEVICE_TOC(n) \
CCE(cudaEventRecord(stop##n)); \
CCE(cudaEventSynchronize(stop##n)); \
CCE(cudaEventElapsedTime(&duration##n, start##n, stop##n)); \
printf("\nKernel elapsed time: %f ms\n", duration##n);
/**
* Indicates which environment should run the function
*/
typedef enum {
Host,
Device
} env_e;
/**
* Struct for holding 3d information
*/
typedef struct{
int x;
int y;
int z;
} dim_t;
/**
* Kernel configuration
*/
typedef struct{
dim_t block_dim = {1024, 1, 1};
const char *kernel_version;
size_t shared_memory_size;
} kernel_config_t;
#endif /* UTILS_H_ */