-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrthello.cpp
More file actions
116 lines (91 loc) · 2.5 KB
/
Copy pathtrthello.cpp
File metadata and controls
116 lines (91 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#include "engine.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "net.h"
#include <algorithm>
#include "benchmark.h"
#include "cpu.h"
#include "gpu.h"
#include <chrono>
#include <typeinfo>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <mpi.h>
int parseLine(char* line){
// This assumes that a digit will be found and the line ends in Kb.
int i = strlen(line);
const char* p = line;
while (*p <'0' || *p > '9') p++;
line[i-3] = '^@';
i = atoi(p);
return i;
}
int getVirtual(){ //Note: this value is in KB!
FILE* file = fopen("/proc/self/status", "r");
int result = -1;
char line[128];
while (fgets(line, 128, file) != NULL){
if (strncmp(line, "VmSize:", 7) == 0){
result = parseLine(line);
break;
}
}
fclose(file);
return result;
}
int getPhysical(){ //Note: this value is in KB!
FILE* file = fopen("/proc/self/status", "r");
int result = -1;
char line[128];
while (fgets(line, 128, file) != NULL){
if (strncmp(line, "VmRSS:", 6) == 0){
result = parseLine(line);
break;
}
}
fclose(file);
return result;
}
typedef std::chrono::high_resolution_clock Clock;
int main() {
ncnn::Mat data_0;
// Initialize the MPI environment
MPI_Init(NULL, NULL);
// Get the number of processes
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
// Get the rank of the process
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
// Get the name of the processor
char processor_name[MPI_MAX_PROCESSOR_NAME];
int name_len;
MPI_Get_processor_name(processor_name, &name_len);
if (world_rank ==1){
Options options;
options.optBatchSizes = {1};
Engine engine(options);
// TODO: Specify your model here.
// Must specify a dynamic batch size when exporting the model from onnx.
const std::string onnxModelpath = "../model.onnx";
bool succ = engine.build(onnxModelpath);
if (!succ) {
throw std::runtime_error("Unable to build TRT engine.");
}
succ = engine.loadNetwork();
if (!succ) {
throw std::runtime_error("Unable to load TRT engine.");
}
}
if (world_rank ==0){
// Print off a hello world message
std::cout << "MPI Success..." << std::endl;
}
// Finalize the MPI environment.
MPI_Finalize();
return 0;
}