MAGMA  1.2.0
MatrixAlgebraonGPUandMulticoreArchitectures
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
testings.h
Go to the documentation of this file.
1 #ifndef _TESTINGS_H_
2 #define _TESTINGS_H_
3 
4 #ifndef min
5 #define min(a,b) (((a)<(b))?(a):(b))
6 #endif
7 #ifndef max
8 #define max(a,b) (((a)<(b))?(b):(a))
9 #endif
10 
11 #define TESTING_CUDA_INIT() \
12  CUdevice dev; \
13  CUcontext context; \
14  if( CUDA_SUCCESS != cuInit( 0 ) ) { \
15  fprintf(stderr, "CUDA: Not initialized\n" ); exit(-1); \
16  } \
17  if( CUDA_SUCCESS != cuDeviceGet( &dev, 0 ) ) { \
18  fprintf(stderr, "CUDA: Cannot get the device\n"); exit(-1); \
19  } \
20  if( CUDA_SUCCESS != cuCtxCreate( &context, 0, dev ) ) { \
21  fprintf(stderr, "CUDA: Cannot create the context\n"); exit(-1); \
22  } \
23  if( CUBLAS_STATUS_SUCCESS != cublasInit( ) ) { \
24  fprintf(stderr, "CUBLAS: Not initialized\n"); exit(-1); \
25  } \
26  printout_devices( );
27 
28 
29 #define TESTING_CUDA_FINALIZE() \
30  cuCtxDetach( context ); \
31  cublasShutdown();
32 
33 #define TESTING_CUDA_INIT_MGPU() \
34 if( CUDA_SUCCESS != cuInit( 0 ) ) { \
35 fprintf(stderr, "CUDA: Not initialized\n" ); exit(-1); \
36 } \
37 { \
38 int ndevices; \
39 cuDeviceGetCount( &ndevices ); \
40 for(int idevice = 0; idevice < ndevices; ++idevice ){ \
41 cudaSetDevice(idevice); \
42 if( CUBLAS_STATUS_SUCCESS != cublasInit( ) ) { \
43 fprintf(stderr, "CUBLAS: Not initialized\n"); exit(-1); \
44 } \
45 } \
46 } \
47 cudaSetDevice(0); \
48 printout_devices( );
49 
50 
51 #define TESTING_CUDA_FINALIZE_MGPU() \
52 { \
53 int ndevices; \
54 cuDeviceGetCount( &ndevices ); \
55 for(int idevice = 0; idevice < ndevices; ++idevice ){ \
56 cudaSetDevice(idevice); \
57  cublasShutdown(); \
58 }}
59 
60 #define TESTING_MALLOC(__ptr, __type, __size) \
61  __ptr = (__type*)malloc((__size) * sizeof(__type)); \
62  if (__ptr == 0) { \
63  fprintf (stderr, "!!!! Malloc failed for: %s\n", #__ptr ); \
64  exit(-1); \
65  }
66 
67 #define TESTING_HOSTALLOC(__ptr, __type, __size) \
68  if( cudaSuccess != cudaMallocHost( (void**)&__ptr, (__size)*sizeof(__type) ) ) { \
69  fprintf (stderr, "!!!! cudaMallocHost failed for: %s\n", #__ptr ); \
70  exit(-1); \
71  }
72 
73 #define TESTING_DEVALLOC(__ptr, __type, __size) \
74  if( cudaSuccess != cudaMalloc( (void**)&__ptr, (__size)*sizeof(__type) ) ){ \
75  fprintf (stderr, "!!!! cublasAlloc failed for: %s\n", #__ptr ); \
76  exit(-1); \
77  }
78 
79 
80 #define TESTING_FREE(__ptr) \
81  free(__ptr);
82 
83 #define TESTING_HOSTFREE(__ptr) \
84  cudaFreeHost( __ptr );
85 
86 #define TESTING_DEVFREE(__ptr) \
87  cudaFree( __ptr );
88 
89 #endif /* _TESTINGS_H_ */