Ajout des cas de tests pour les TP non-graphiques. Cleanage en tous genres.
[GPU.git] / WCudaMSE / Student_Cuda / src / cpp / main.cpp
1 #include <iostream>
2 #include <vector>
3 #include <stdlib.h>
4 #include <assert.h>
5 using namespace std;
6
7 #include "cudaTools.h"
8 #include "Device.h"
9 #include "LimitsTools.h"
10
11 /*----------------------------------------------------------------------*\
12 |* Declaration *|
13 \*---------------------------------------------------------------------*/
14
15 /*--------------------------------------*\
16 |* Imported *|
17 \*-------------------------------------*/
18
19 extern int mainCore(const vector<string>& args);
20 extern int mainTest();
21
22 /*--------------------------------------*\
23 |* Public *|
24 \*-------------------------------------*/
25
26 int main(int argc, char** argv);
27
28 /*--------------------------------------*\
29 |* Private *|
30 \*-------------------------------------*/
31
32 static void initCuda(int deviceId);
33 static int start(const vector<string>& args);
34
35 /*----------------------------------------------------------------------*\
36 |* Implementation *|
37 \*---------------------------------------------------------------------*/
38
39 /*--------------------------------------*\
40 |* Public *|
41 \*-------------------------------------*/
42
43 int main(int argc, char** argv)
44 {
45 cout << "main" << endl;
46
47 vector<string> args;
48 for (int i = 1; i < argc; ++i)
49 args.push_back(argv[i]);
50
51 // LimitsTools::rappelTypeSize();
52
53 if (Device::isCuda())
54 {
55 Device::printAll();
56 Device::printAllSimple();
57
58 // Server Cuda1: in [0,5]
59 // Server Cuda2: in [0,2]
60 int deviceId = 0;
61
62 int isOk = start(args);
63
64 //cudaDeviceReset causes the driver to clean up all state.
65 // While not mandatory in normal operation, it is good practice.
66 HANDLE_ERROR(cudaDeviceReset());
67
68 return isOk;
69 }
70 else
71 {
72 return EXIT_FAILURE;
73 }
74 }
75
76 void initCuda(int deviceId)
77 {
78 // Check deviceId area
79 int nbDevice = Device::getDeviceCount();
80 assert(deviceId >= 0 && deviceId < nbDevice);
81
82 //HANDLE_ERROR(cudaDeviceReset());
83
84 // Choose current device (state of host-thread)
85 HANDLE_ERROR(cudaSetDevice(deviceId));
86
87 // It can be usefull to preload driver, by example to practice benchmarking! (sometimes slow under linux)
88 Device::loadCudaDriver(deviceId);
89 // Device::loadCudaDriverAll();// Force driver to be load for all GPU
90 }
91
92 int start(const vector<string>& args)
93 {
94 Device::printCurrent();
95
96 if (args.size() == 0 || args[0] == "tests")
97 {
98 return mainTest();
99 }
100 else
101 {
102 return mainCore(args);
103 }
104 }
105
106 /*----------------------------------------------------------------------*\
107 |* End *|
108 \*---------------------------------------------------------------------*/
109