# HG changeset patch # User Shinji KONO # Date 1487039801 -32400 # Node ID 9755206813cb2321df82e995d2b4b63a18d8f9a6 # Parent 1dbaef86593b643acdf602aab80e4d40542dd51a helper_string.h for ANSI C diff -r 1dbaef86593b -r 9755206813cb src/parallel_execution/CMakeLists.txt --- a/src/parallel_execution/CMakeLists.txt Mon Feb 13 18:23:29 2017 +0900 +++ b/src/parallel_execution/CMakeLists.txt Tue Feb 14 11:36:41 2017 +0900 @@ -12,7 +12,7 @@ set(NVCCFLAG "-std=c++11" "-g" "-O0" ) set(CUDA_LINK_FLAGS "-framework CUDA -lc++ -Wl,-search_paths_first -Wl,-headerpad_max_install_names /Developer/NVIDIA/CUDA-8.0/lib/libcudart_static.a -Wl,-rpath,/usr/local/cuda/lib") find_package(CUDA REQUIRED) - add_definitions("-Wall -g -DUSE_CUDAWorker") + add_definitions("-Wall -g -DUSE_CUDAWorker=1") else() add_definitions("-Wall -g") endif() diff -r 1dbaef86593b -r 9755206813cb src/parallel_execution/CUDAWorker.cbc --- a/src/parallel_execution/CUDAWorker.cbc Mon Feb 13 18:23:29 2017 +0900 +++ b/src/parallel_execution/CUDAWorker.cbc Tue Feb 14 11:36:41 2017 +0900 @@ -2,19 +2,16 @@ #include #include #include - +#include #include - #include #include "helper_cuda.h" -#include - #include "../context.h" static void start_CUDAworker(Worker* worker); -union Data* createCUDAWorker(struct Context* context, int id, Queue* queue) { +Worker* createCUDAWorker(struct Context* context, int id, Queue* queue) { struct Worker* worker = ALLOC(context, Worker); struct CUDAWorker* CUDAWorker = ALLOC(context, CUDAWorker); worker->worker = (union Data*)CUDAWorker; @@ -23,7 +20,7 @@ worker->taskReceive = C_taskReceiveCUDAWorker; worker->shutdown = C_shutdownCUDAWorker; pthread_create(&worker->worker->CUDAWorker.thread, NULL, (void*)&start_CUDAworker, worker); - return (union Data*)(worker); + return worker; } static void start_CUDAworker(Worker* worker) { diff -r 1dbaef86593b -r 9755206813cb src/parallel_execution/context.h --- a/src/parallel_execution/context.h Mon Feb 13 18:23:29 2017 +0900 +++ b/src/parallel_execution/context.h Tue Feb 14 11:36:41 2017 +0900 @@ -3,7 +3,7 @@ #define CONTEXT_H #include #include -#ifdef USE_CUDA +#ifdef USE_CUDAWorker #include #endif diff -r 1dbaef86593b -r 9755206813cb src/parallel_execution/helper_cuda.h --- a/src/parallel_execution/helper_cuda.h Mon Feb 13 18:23:29 2017 +0900 +++ b/src/parallel_execution/helper_cuda.h Tue Feb 14 11:36:41 2017 +0900 @@ -288,9 +288,7 @@ return ""; } -#endif - -#ifdef __cuda_cuda_h__ +#else // CUDA Driver API errors const char *_cudaGetErrorEnum(CUresult error) { @@ -981,18 +979,31 @@ #endif #endif -template< typename T > -void check(T result, char const *const func, const char *const file, int const line) +#ifndef __DRIVER_TYPES_H__ +static inline void check(CUresult result, char const *const func, const char *const file, int const line) { if (result) { fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", - file, line, static_cast(result), _cudaGetErrorEnum(result), func); + file, line, (unsigned int)(result), _cudaGetErrorEnum(result), func); DEVICE_RESET // Make sure we call CUDA Device Reset before exiting exit(EXIT_FAILURE); } } +#else +static inline void check(cudaError_t result, char const *const func, const char *const file, int const line) +{ + if (result) + { + fprintf(stderr, "CUDA error at %s:%d code=%d(%s) \"%s\" \n", + file, line, (unsigned int)(result), _cudaGetErrorEnum(result), func); + DEVICE_RESET + // Make sure we call CUDA Device Reset before exiting + exit(EXIT_FAILURE); + } +} +#endif #ifdef __DRIVER_TYPES_H__ // This will output the proper CUDA error strings in the event that a CUDA host call returns an error @@ -1029,7 +1040,7 @@ inline int _ConvertSMVer2Cores(int major, int minor) { // Defines for GPU Architecture types (using the SM version to determine the # of cores per SM - typedef struct + typedef struct sSMtoCores { int SM; // 0xMm (hexidecimal notation), M = SM Major version, and m = SM minor version int Cores; @@ -1097,7 +1108,7 @@ return -devID; } - cudaDeviceProp deviceProp; + struct cudaDeviceProp deviceProp; checkCudaErrors(cudaGetDeviceProperties(&deviceProp, devID)); if (deviceProp.computeMode == cudaComputeModeProhibited) @@ -1127,7 +1138,7 @@ int devices_prohibited = 0; unsigned long long max_compute_perf = 0; - cudaDeviceProp deviceProp; + struct cudaDeviceProp deviceProp; cudaGetDeviceCount(&device_count); checkCudaErrors(cudaGetDeviceCount(&device_count)); @@ -1216,7 +1227,7 @@ // Initialization code to find the best CUDA Device inline int findCudaDevice(int argc, const char **argv) { - cudaDeviceProp deviceProp; + struct cudaDeviceProp deviceProp; int devID = 0; // If the command-line has a device number specified, use it @@ -1255,7 +1266,7 @@ // General check for CUDA GPU SM Capabilities inline bool checkCudaCapabilities(int major_version, int minor_version) { - cudaDeviceProp deviceProp; + struct cudaDeviceProp deviceProp; deviceProp.major = 0; deviceProp.minor = 0; int dev; diff -r 1dbaef86593b -r 9755206813cb src/parallel_execution/helper_string.h --- a/src/parallel_execution/helper_string.h Mon Feb 13 18:23:29 2017 +0900 +++ b/src/parallel_execution/helper_string.h Tue Feb 14 11:36:41 2017 +0900 @@ -15,7 +15,6 @@ #include #include -#include #include #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) @@ -142,36 +141,6 @@ return bFound; } -// This function wraps the CUDA Driver API into a template function -template -inline bool getCmdLineArgumentValue(const int argc, const char **argv, const char *string_ref, T *value) -{ - bool bFound = false; - - if (argc >= 1) - { - for (int i=1; i < argc; i++) - { - int string_start = stringRemoveDelimiter('-', argv[i]); - const char *string_argv = &argv[i][string_start]; - int length = (int)strlen(string_ref); - - if (!STRNCASECMP(string_argv, string_ref, length)) - { - if (length+1 <= (int)strlen(string_argv)) - { - int auto_inc = (string_argv[length] == '=') ? 1 : 0; - *value = (T)atoi(&string_argv[length + auto_inc]); - } - - bFound = true; - i=argc; - } - } - } - - return bFound; -} inline int getCmdLineArgumentInt(const int argc, const char **argv, const char *string_ref) { @@ -285,243 +254,5 @@ return bFound; } -////////////////////////////////////////////////////////////////////////////// -//! Find the path for a file assuming that -//! files are found in the searchPath. -//! -//! @return the path if succeeded, otherwise 0 -//! @param filename name of the file -//! @param executable_path optional absolute path of the executable -////////////////////////////////////////////////////////////////////////////// -inline char *sdkFindFilePath(const char *filename, const char *executable_path) -{ - // defines a variable that is replaced with the name of the executable - - // Typical relative search paths to locate needed companion files (e.g. sample input data, or JIT source files) - // The origin for the relative search may be the .exe file, a .bat file launching an .exe, a browser .exe launching the .exe or .bat, etc - const char *searchPath[] = - { - "./", // same dir - "./_data_files/", - "./common/", // "/common/" subdir - "./common/data/", // "/common/data/" subdir - "./data/", // "/data/" subdir - "./src/", // "/src/" subdir - "./src//data/", // "/src//data/" subdir - "./inc/", // "/inc/" subdir - "./0_Simple/", // "/0_Simple/" subdir - "./1_Utilities/", // "/1_Utilities/" subdir - "./2_Graphics/", // "/2_Graphics/" subdir - "./3_Imaging/", // "/3_Imaging/" subdir - "./4_Finance/", // "/4_Finance/" subdir - "./5_Simulations/", // "/5_Simulations/" subdir - "./6_Advanced/", // "/6_Advanced/" subdir - "./7_CUDALibraries/", // "/7_CUDALibraries/" subdir - "./8_Android/", // "/8_Android/" subdir - "./samples/", // "/samples/" subdir - - "./0_Simple//data/", // "/0_Simple//data/" subdir - "./1_Utilities//data/", // "/1_Utilities//data/" subdir - "./2_Graphics//data/", // "/2_Graphics//data/" subdir - "./3_Imaging//data/", // "/3_Imaging//data/" subdir - "./4_Finance//data/", // "/4_Finance//data/" subdir - "./5_Simulations//data/", // "/5_Simulations//data/" subdir - "./6_Advanced//data/", // "/6_Advanced//data/" subdir - "./7_CUDALibraries//", // "/7_CUDALibraries//" subdir - "./7_CUDALibraries//data/", // "/7_CUDALibraries//data/" subdir - - "../", // up 1 in tree - "../common/", // up 1 in tree, "/common/" subdir - "../common/data/", // up 1 in tree, "/common/data/" subdir - "../data/", // up 1 in tree, "/data/" subdir - "../src/", // up 1 in tree, "/src/" subdir - "../inc/", // up 1 in tree, "/inc/" subdir - - "../0_Simple//data/", // up 1 in tree, "/0_Simple//" subdir - "../1_Utilities//data/", // up 1 in tree, "/1_Utilities//" subdir - "../2_Graphics//data/", // up 1 in tree, "/2_Graphics//" subdir - "../3_Imaging//data/", // up 1 in tree, "/3_Imaging//" subdir - "../4_Finance//data/", // up 1 in tree, "/4_Finance//" subdir - "../5_Simulations//data/", // up 1 in tree, "/5_Simulations//" subdir - "../6_Advanced//data/", // up 1 in tree, "/6_Advanced//" subdir - "../7_CUDALibraries//data/",// up 1 in tree, "/7_CUDALibraries//" subdir - "../8_Android//data/", // up 1 in tree, "/8_Android//" subdir - "../samples//data/", // up 1 in tree, "/samples//" subdir - "../../", // up 2 in tree - "../../common/", // up 2 in tree, "/common/" subdir - "../../common/data/", // up 2 in tree, "/common/data/" subdir - "../../data/", // up 2 in tree, "/data/" subdir - "../../src/", // up 2 in tree, "/src/" subdir - "../../inc/", // up 2 in tree, "/inc/" subdir - "../../sandbox//data/", // up 2 in tree, "/sandbox//" subdir - "../../0_Simple//data/", // up 2 in tree, "/0_Simple//" subdir - "../../1_Utilities//data/", // up 2 in tree, "/1_Utilities//" subdir - "../../2_Graphics//data/", // up 2 in tree, "/2_Graphics//" subdir - "../../3_Imaging//data/", // up 2 in tree, "/3_Imaging//" subdir - "../../4_Finance//data/", // up 2 in tree, "/4_Finance//" subdir - "../../5_Simulations//data/", // up 2 in tree, "/5_Simulations//" subdir - "../../6_Advanced//data/", // up 2 in tree, "/6_Advanced//" subdir - "../../7_CUDALibraries//data/", // up 2 in tree, "/7_CUDALibraries//" subdir - "../../8_Android//data/", // up 2 in tree, "/8_Android//" subdir - "../../samples//data/", // up 2 in tree, "/samples//" subdir - "../../../", // up 3 in tree - "../../../src//", // up 3 in tree, "/src//" subdir - "../../../src//data/", // up 3 in tree, "/src//data/" subdir - "../../../src//src/", // up 3 in tree, "/src//src/" subdir - "../../../src//inc/", // up 3 in tree, "/src//inc/" subdir - "../../../sandbox//", // up 3 in tree, "/sandbox//" subdir - "../../../sandbox//data/", // up 3 in tree, "/sandbox//data/" subdir - "../../../sandbox//src/", // up 3 in tree, "/sandbox//src/" subdir - "../../../sandbox//inc/", // up 3 in tree, "/sandbox//inc/" subdir - "../../../0_Simple//data/", // up 3 in tree, "/0_Simple//" subdir - "../../../1_Utilities//data/", // up 3 in tree, "/1_Utilities//" subdir - "../../../2_Graphics//data/", // up 3 in tree, "/2_Graphics//" subdir - "../../../3_Imaging//data/", // up 3 in tree, "/3_Imaging//" subdir - "../../../4_Finance//data/", // up 3 in tree, "/4_Finance//" subdir - "../../../5_Simulations//data/", // up 3 in tree, "/5_Simulations//" subdir - "../../../6_Advanced//data/", // up 3 in tree, "/6_Advanced//" subdir - "../../../7_CUDALibraries//data/", // up 3 in tree, "/7_CUDALibraries//" subdir - "../../../8_Android//data/", // up 3 in tree, "/8_Android//" subdir - "../../../0_Simple//", // up 3 in tree, "/0_Simple//" subdir - "../../../1_Utilities//", // up 3 in tree, "/1_Utilities//" subdir - "../../../2_Graphics//", // up 3 in tree, "/2_Graphics//" subdir - "../../../3_Imaging//", // up 3 in tree, "/3_Imaging//" subdir - "../../../4_Finance//", // up 3 in tree, "/4_Finance//" subdir - "../../../5_Simulations//", // up 3 in tree, "/5_Simulations//" subdir - "../../../6_Advanced//", // up 3 in tree, "/6_Advanced//" subdir - "../../../7_CUDALibraries//", // up 3 in tree, "/7_CUDALibraries//" subdir - "../../../8_Android//", // up 3 in tree, "/8_Android//" subdir - "../../../samples//data/", // up 3 in tree, "/samples//" subdir - "../../../common/", // up 3 in tree, "../../../common/" subdir - "../../../common/data/", // up 3 in tree, "../../../common/data/" subdir - "../../../data/", // up 3 in tree, "../../../data/" subdir - "../../../../", // up 4 in tree - "../../../../src//", // up 4 in tree, "/src//" subdir - "../../../../src//data/", // up 4 in tree, "/src//data/" subdir - "../../../../src//src/", // up 4 in tree, "/src//src/" subdir - "../../../../src//inc/", // up 4 in tree, "/src//inc/" subdir - "../../../../sandbox//", // up 4 in tree, "/sandbox//" subdir - "../../../../sandbox//data/", // up 4 in tree, "/sandbox//data/" subdir - "../../../../sandbox//src/", // up 4 in tree, "/sandbox//src/" subdir - "../../../../sandbox//inc/", // up 4 in tree, "/sandbox//inc/" subdir - "../../../../0_Simple//data/", // up 4 in tree, "/0_Simple//" subdir - "../../../../1_Utilities//data/", // up 4 in tree, "/1_Utilities//" subdir - "../../../../2_Graphics//data/", // up 4 in tree, "/2_Graphics//" subdir - "../../../../3_Imaging//data/", // up 4 in tree, "/3_Imaging//" subdir - "../../../../4_Finance//data/", // up 4 in tree, "/4_Finance//" subdir - "../../../../5_Simulations//data/",// up 4 in tree, "/5_Simulations//" subdir - "../../../../6_Advanced//data/", // up 4 in tree, "/6_Advanced//" subdir - "../../../../7_CUDALibraries//data/", // up 4 in tree, "/7_CUDALibraries//" subdir - "../../../../8_Android//data/", // up 4 in tree, "/8_Android//" subdir - "../../../../0_Simple//", // up 4 in tree, "/0_Simple//" subdir - "../../../../1_Utilities//", // up 4 in tree, "/1_Utilities//" subdir - "../../../../2_Graphics//", // up 4 in tree, "/2_Graphics//" subdir - "../../../../3_Imaging//", // up 4 in tree, "/3_Imaging//" subdir - "../../../../4_Finance//", // up 4 in tree, "/4_Finance//" subdir - "../../../../5_Simulations//",// up 4 in tree, "/5_Simulations//" subdir - "../../../../6_Advanced//", // up 4 in tree, "/6_Advanced//" subdir - "../../../../7_CUDALibraries//", // up 4 in tree, "/7_CUDALibraries//" subdir - "../../../../8_Android//", // up 4 in tree, "/8_Android//" subdir - "../../../../samples//data/", // up 4 in tree, "/samples//" subdir - "../../../../common/", // up 4 in tree, "../../../common/" subdir - "../../../../common/data/", // up 4 in tree, "../../../common/data/" subdir - "../../../../data/", // up 4 in tree, "../../../data/" subdir - "../../../../../", // up 5 in tree - "../../../../../src//", // up 5 in tree, "/src//" subdir - "../../../../../src//data/", // up 5 in tree, "/src//data/" subdir - "../../../../../src//src/", // up 5 in tree, "/src//src/" subdir - "../../../../../src//inc/", // up 5 in tree, "/src//inc/" subdir - "../../../../../sandbox//", // up 5 in tree, "/sandbox//" subdir - "../../../../../sandbox//data/", // up 5 in tree, "/sandbox//data/" subdir - "../../../../../sandbox//src/", // up 5 in tree, "/sandbox//src/" subdir - "../../../../../sandbox//inc/", // up 5 in tree, "/sandbox//inc/" subdir - "../../../../../0_Simple//data/", // up 5 in tree, "/0_Simple//" subdir - "../../../../../1_Utilities//data/", // up 5 in tree, "/1_Utilities//" subdir - "../../../../../2_Graphics//data/", // up 5 in tree, "/2_Graphics//" subdir - "../../../../../3_Imaging//data/", // up 5 in tree, "/3_Imaging//" subdir - "../../../../../4_Finance//data/", // up 5 in tree, "/4_Finance//" subdir - "../../../../../5_Simulations//data/",// up 5 in tree, "/5_Simulations//" subdir - "../../../../../6_Advanced//data/", // up 5 in tree, "/6_Advanced//" subdir - "../../../../../7_CUDALibraries//data/", // up 5 in tree, "/7_CUDALibraries//" subdir - "../../../../../8_Android//data/", // up 5 in tree, "/8_Android//" subdir - "../../../../../samples//data/", // up 5 in tree, "/samples//" subdir - "../../../../../common/", // up 5 in tree, "../../../common/" subdir - "../../../../../common/data/", // up 5 in tree, "../../../common/data/" subdir - }; - - // Extract the executable name - std::string executable_name; - - if (executable_path != 0) - { - executable_name = std::string(executable_path); - -#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) - // Windows path delimiter - size_t delimiter_pos = executable_name.find_last_of('\\'); - executable_name.erase(0, delimiter_pos + 1); - - if (executable_name.rfind(".exe") != std::string::npos) - { - // we strip .exe, only if the .exe is found - executable_name.resize(executable_name.size() - 4); - } - -#else - // Linux & OSX path delimiter - size_t delimiter_pos = executable_name.find_last_of('/'); - executable_name.erase(0,delimiter_pos+1); -#endif - } - - // Loop over all search paths and return the first hit - for (unsigned int i = 0; i < sizeof(searchPath)/sizeof(char *); ++i) - { - std::string path(searchPath[i]); - size_t executable_name_pos = path.find(""); - - // If there is executable_name variable in the searchPath - // replace it with the value - if (executable_name_pos != std::string::npos) - { - if (executable_path != 0) - { - path.replace(executable_name_pos, strlen(""), executable_name); - } - else - { - // Skip this path entry if no executable argument is given - continue; - } - } - -#ifdef _DEBUG - printf("sdkFindFilePath <%s> in %s\n", filename, path.c_str()); -#endif - - // Test if the file exists - path.append(filename); - FILE *fp; - FOPEN(fp, path.c_str(), "rb"); - - if (fp != NULL) - { - fclose(fp); - // File found - // returning an allocated array here for backwards compatibility reasons - char *file_path = (char *) malloc(path.length() + 1); - STRCPY(file_path, path.length() + 1, path.c_str()); - return file_path; - } - - if (fp) - { - fclose(fp); - } - } - - // File not found - return 0; -} #endif