X-Git-Url: http://git.euphorik.ch/index.cgi?a=blobdiff_plain;f=WCudaMSE%2FStudent_Cuda%2Fsrc%2Fcpp%2Fmain.cpp;fp=WCudaMSE%2FStudent_Cuda%2Fsrc%2Fcpp%2Fmain.cpp;h=3fad4508230608599458964b5b377392ee579b07;hb=8d08c12b29c2a14684f35c023ee39e694bb80d25;hp=0000000000000000000000000000000000000000;hpb=226de81f7e1f1fbf4ac79d0d089e8a05ec7159a0;p=GPU.git diff --git a/WCudaMSE/Student_Cuda/src/cpp/main.cpp b/WCudaMSE/Student_Cuda/src/cpp/main.cpp new file mode 100755 index 0000000..3fad450 --- /dev/null +++ b/WCudaMSE/Student_Cuda/src/cpp/main.cpp @@ -0,0 +1,108 @@ +#include +#include +#include + +#include "cudaTools.h" +#include "Device.h" +#include "LimitsTools.h" + +using std::cout; +using std::endl; + +/*----------------------------------------------------------------------*\ + |* Declaration *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Imported *| + \*-------------------------------------*/ + +extern int mainCore(); +extern int mainTest(); + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +int main(void); + +/*--------------------------------------*\ + |* Private *| + \*-------------------------------------*/ + +static void initCuda(int deviceId); +static int start(void); + +/*----------------------------------------------------------------------*\ + |* Implementation *| + \*---------------------------------------------------------------------*/ + +/*--------------------------------------*\ + |* Public *| + \*-------------------------------------*/ + +int main(void) + { + cout << "main" << endl; + + // LimitsTools::rappelTypeSize(); + + if (Device::isCuda()) + { + Device::printAll(); + Device::printAllSimple(); + + // Server Cuda1: in [0,5] + // Server Cuda2: in [0,2] + int deviceId = 0; + + int isOk = start(); + + //cudaDeviceReset causes the driver to clean up all state. + // While not mandatory in normal operation, it is good practice. + HANDLE_ERROR(cudaDeviceReset()); + + return isOk; + } + else + { + return EXIT_FAILURE; + } + } + +void initCuda(int deviceId) + { + // Check deviceId area + int nbDevice = Device::getDeviceCount(); + assert(deviceId >= 0 && deviceId < nbDevice); + + //HANDLE_ERROR(cudaDeviceReset()); + + // Choose current device (state of host-thread) + HANDLE_ERROR(cudaSetDevice(deviceId)); + + // It can be usefull to preload driver, by example to practice benchmarking! (sometimes slow under linux) + Device::loadCudaDriver(deviceId); + // Device::loadCudaDriverAll();// Force driver to be load for all GPU + } + +int start(void) + { + Device::printCurrent(); + + bool IS_TEST = true; + + if (IS_TEST) + { + return mainTest(); + } + else + { + return mainCore(); + } + } + +/*----------------------------------------------------------------------*\ + |* End *| + \*---------------------------------------------------------------------*/ +