OpenMPI  0.1.1
vt_cudartwrap.h
1 /**
2  * VampirTrace
3  * http://www.tu-dresden.de/zih/vampirtrace
4  *
5  * Copyright (c) 2005-2012, ZIH, TU Dresden, Federal Republic of Germany
6  *
7  * Copyright (c) 1998-2005, Forschungszentrum Juelich, Juelich Supercomputing
8  * Centre, Federal Republic of Germany
9  *
10  * See the file COPYING in the package base directory for details
11  **/
12 
13 #ifndef _VT_CUDARTWRAP_H_
14 #define _VT_CUDARTWRAP_H_
15 
16 #ifdef __cplusplus
17 # define EXTERN extern "C"
18 #else
19 # define EXTERN extern
20 #endif
21 
22 #include "vt_gpu.h" /* common for GPU */
23 #include "vt_libwrap.h" /* wrapping of CUDA Runtime API functions */
24 
25 #include "vt_cuda_runtime_api.h" /* includes CUDA runtime API functions */
26 
27 /*#if (defined(VT_CUDARTWRAP))*/
28 
29 /* library wrapper object */
30 EXTERN VTLibwrap* vt_cudart_lw;
31 
32 /* library wrapper attributes declaration */
33 EXTERN VTLibwrapAttr vt_cudart_lw_attr;
34 
35 /* internal initialization functions for the CUDA runtime library */
36 EXTERN void vt_cudartwrap_lw_attr_init(VTLibwrapAttr* attr);
37 EXTERN void vt_cudartwrap_init(void);
38 
39 /* flag: tracing of CUDA API enabled? */
40 EXTERN uint8_t vt_cudart_trace_enabled;
41 
42 /* flag: Is the CUDA runtime initialized? CUDA runtime function called? */
43 EXTERN uint8_t vt_cudart_initialized;
44 
45 EXTERN void vt_cudartwrap_finalize(void);
46 
47 /* Mutex for locking the CUDA runtime wrap environment */
48 #if (defined(VT_MT) || defined(VT_HYB))
49 EXTERN VTThrdMutex* VTThrdMutexCudart;
50 # define CUDARTWRAP_LOCK() VTThrd_lock(&VTThrdMutexCudart)
51 # define CUDARTWRAP_UNLOCK() VTThrd_unlock(&VTThrdMutexCudart)
52 #else /* VT_MT || VT_HYB */
53 # define CUDARTWRAP_LOCK()
54 # define CUDARTWRAP_UNLOCK()
55 #endif /* VT_MT || VT_HYB */
56 
57 /* do initialization before calling the first CUDA function
58  * no CUDA context creation */
59 #define CUDARTWRAP_FUNC_INIT(_lw, _lwattr, _func, _rettype, _argtypes, _file, \
60  _line) \
61  VT_LIBWRAP_FUNC_INIT(_lw, _lwattr, _func, _rettype, _argtypes, _file, \
62  _line); \
63  \
64  if(!vt_cudart_initialized){ \
65  CUDARTWRAP_LOCK(); \
66  if(!vt_cudart_initialized){ \
67  vt_cudartwrap_init(); \
68  } \
69  CUDARTWRAP_UNLOCK(); \
70  }
71 
72 #define CUDARTWRAP_FUNC_START(_lw) \
73  if(vt_cudart_trace_enabled){ \
74  VT_LIBWRAP_FUNC_START(_lw); \
75  }
76 
77 #define CUDARTWRAP_FUNC_END(_lw) \
78  if(vt_cudart_trace_enabled) VT_LIBWRAP_FUNC_END(_lw)
79 
80 /*#endif*/
81 
82 #endif /* _VT_CUDARTWRAP_H_ */
Definition: vt_libwrap.c:43
Definition: vt_libwrap.h:96