Mercurial > hg > Gears > GearsAgda
comparison src/parallel_execution/helper_cuda.h @ 304:9755206813cb
helper_string.h for ANSI C
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 14 Feb 2017 11:36:41 +0900 |
parents | 1dbaef86593b |
children | ec0a5b4fba05 |
comparison
equal
deleted
inserted
replaced
303:1dbaef86593b | 304:9755206813cb |
---|---|
286 return "cudaErrorNvlinkUncorrectable"; | 286 return "cudaErrorNvlinkUncorrectable"; |
287 } | 287 } |
288 | 288 |
289 return "<unknown>"; | 289 return "<unknown>"; |
290 } | 290 } |
291 #endif | 291 #else |
292 | |
293 #ifdef __cuda_cuda_h__ | |
294 // CUDA Driver API errors | 292 // CUDA Driver API errors |
295 const char *_cudaGetErrorEnum(CUresult error) | 293 const char *_cudaGetErrorEnum(CUresult error) |
296 { | 294 { |
297 switch (error) | 295 switch (error) |
298 { | 296 { |
979 #ifndef DEVICE_RESET | 977 #ifndef DEVICE_RESET |
980 #define DEVICE_RESET | 978 #define DEVICE_RESET |
981 #endif | 979 #endif |
982 #endif | 980 #endif |
983 | 981 |
984 template< typename T > | 982 #ifndef __DRIVER_TYPES_H__ |
985 void check(T result, char const *const func, const char *const file, int const line) | 983 static inline void check(CUresult result, char const *const func, const char *const file, int const line) |
986 { | 984 { |
987 if (result) | 985 if (result) |
988 { | 986 { |
989 fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", | 987 fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", |
990 file, line, static_cast<unsigned int>(result), _cudaGetErrorEnum(result), func); | 988 file, line, (unsigned int)(result), _cudaGetErrorEnum(result), func); |
991 DEVICE_RESET | 989 DEVICE_RESET |
992 // Make sure we call CUDA Device Reset before exiting | 990 // Make sure we call CUDA Device Reset before exiting |
993 exit(EXIT_FAILURE); | 991 exit(EXIT_FAILURE); |
994 } | 992 } |
995 } | 993 } |
994 #else | |
995 static inline void check(cudaError_t result, char const *const func, const char *const file, int const line) | |
996 { | |
997 if (result) | |
998 { | |
999 fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", | |
1000 file, line, (unsigned int)(result), _cudaGetErrorEnum(result), func); | |
1001 DEVICE_RESET | |
1002 // Make sure we call CUDA Device Reset before exiting | |
1003 exit(EXIT_FAILURE); | |
1004 } | |
1005 } | |
1006 #endif | |
996 | 1007 |
997 #ifdef __DRIVER_TYPES_H__ | 1008 #ifdef __DRIVER_TYPES_H__ |
998 // This will output the proper CUDA error strings in the event that a CUDA host call returns an error | 1009 // This will output the proper CUDA error strings in the event that a CUDA host call returns an error |
999 #define checkCudaErrors(val) check ( (val), #val, __FILE__, __LINE__ ) | 1010 #define checkCudaErrors(val) check ( (val), #val, __FILE__, __LINE__ ) |
1000 | 1011 |
1027 | 1038 |
1028 // Beginning of GPU Architecture definitions | 1039 // Beginning of GPU Architecture definitions |
1029 inline int _ConvertSMVer2Cores(int major, int minor) | 1040 inline int _ConvertSMVer2Cores(int major, int minor) |
1030 { | 1041 { |
1031 // Defines for GPU Architecture types (using the SM version to determine the # of cores per SM | 1042 // Defines for GPU Architecture types (using the SM version to determine the # of cores per SM |
1032 typedef struct | 1043 typedef struct sSMtoCores |
1033 { | 1044 { |
1034 int SM; // 0xMm (hexidecimal notation), M = SM Major version, and m = SM minor version | 1045 int SM; // 0xMm (hexidecimal notation), M = SM Major version, and m = SM minor version |
1035 int Cores; | 1046 int Cores; |
1036 } sSMtoCores; | 1047 } sSMtoCores; |
1037 | 1048 |
1095 fprintf(stderr, ">> gpuDeviceInit (-device=%d) is not a valid GPU device. <<\n", devID); | 1106 fprintf(stderr, ">> gpuDeviceInit (-device=%d) is not a valid GPU device. <<\n", devID); |
1096 fprintf(stderr, "\n"); | 1107 fprintf(stderr, "\n"); |
1097 return -devID; | 1108 return -devID; |
1098 } | 1109 } |
1099 | 1110 |
1100 cudaDeviceProp deviceProp; | 1111 struct cudaDeviceProp deviceProp; |
1101 checkCudaErrors(cudaGetDeviceProperties(&deviceProp, devID)); | 1112 checkCudaErrors(cudaGetDeviceProperties(&deviceProp, devID)); |
1102 | 1113 |
1103 if (deviceProp.computeMode == cudaComputeModeProhibited) | 1114 if (deviceProp.computeMode == cudaComputeModeProhibited) |
1104 { | 1115 { |
1105 fprintf(stderr, "Error: device is running in <Compute Mode Prohibited>, no threads can use ::cudaSetDevice().\n"); | 1116 fprintf(stderr, "Error: device is running in <Compute Mode Prohibited>, no threads can use ::cudaSetDevice().\n"); |
1125 int max_perf_device = 0; | 1136 int max_perf_device = 0; |
1126 int device_count = 0, best_SM_arch = 0; | 1137 int device_count = 0, best_SM_arch = 0; |
1127 int devices_prohibited = 0; | 1138 int devices_prohibited = 0; |
1128 | 1139 |
1129 unsigned long long max_compute_perf = 0; | 1140 unsigned long long max_compute_perf = 0; |
1130 cudaDeviceProp deviceProp; | 1141 struct cudaDeviceProp deviceProp; |
1131 cudaGetDeviceCount(&device_count); | 1142 cudaGetDeviceCount(&device_count); |
1132 | 1143 |
1133 checkCudaErrors(cudaGetDeviceCount(&device_count)); | 1144 checkCudaErrors(cudaGetDeviceCount(&device_count)); |
1134 | 1145 |
1135 if (device_count == 0) | 1146 if (device_count == 0) |
1214 | 1225 |
1215 | 1226 |
1216 // Initialization code to find the best CUDA Device | 1227 // Initialization code to find the best CUDA Device |
1217 inline int findCudaDevice(int argc, const char **argv) | 1228 inline int findCudaDevice(int argc, const char **argv) |
1218 { | 1229 { |
1219 cudaDeviceProp deviceProp; | 1230 struct cudaDeviceProp deviceProp; |
1220 int devID = 0; | 1231 int devID = 0; |
1221 | 1232 |
1222 // If the command-line has a device number specified, use it | 1233 // If the command-line has a device number specified, use it |
1223 if (checkCmdLineFlag(argc, argv, "device")) | 1234 if (checkCmdLineFlag(argc, argv, "device")) |
1224 { | 1235 { |
1253 } | 1264 } |
1254 | 1265 |
1255 // General check for CUDA GPU SM Capabilities | 1266 // General check for CUDA GPU SM Capabilities |
1256 inline bool checkCudaCapabilities(int major_version, int minor_version) | 1267 inline bool checkCudaCapabilities(int major_version, int minor_version) |
1257 { | 1268 { |
1258 cudaDeviceProp deviceProp; | 1269 struct cudaDeviceProp deviceProp; |
1259 deviceProp.major = 0; | 1270 deviceProp.major = 0; |
1260 deviceProp.minor = 0; | 1271 deviceProp.minor = 0; |
1261 int dev; | 1272 int dev; |
1262 | 1273 |
1263 checkCudaErrors(cudaGetDevice(&dev)); | 1274 checkCudaErrors(cudaGetDevice(&dev)); |