-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
59 lines (47 loc) · 1.48 KB
/
main.cpp
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
#include "defs.h"
#include "NetManager.h"
#include "Parser.h"
#include "SharedMem.h"
#include <unistd.h>
#include <iostream>
#include <sys/mman.h>
#include <string.h>
int main(int argc, char * argv[])
{
vector<string> filenames;
/** this should be done differently (from defs or argv?) */
filenames.push_back("train-images-idx3-ubyte");
filenames.push_back("train-labels-idx1-ubyte");
filenames.push_back("t10k-images-idx3-ubyte");
filenames.push_back("t10k-labels-idx1-ubyte");
vector<unsigned> topology;
topology.push_back(PIXEL_COUNT);
topology.push_back(512);
topology.push_back(256);
topology.push_back(128);
topology.push_back(10);
void * address = mmap(NULL, (size_t) 2700,
PROT_READ|PROT_WRITE,
MAP_SHARED|MAP_ANONYMOUS, -1, 0);
if (address == MAP_FAILED) {
cerr << "Map Failed" << endl;
abort();
}
SharedMem * shmem = new(address) SharedMem();
pid_t pid = fork();
if (pid == 0) {
// Child Process
DEBUG_PRINT("Child Process");
shmem->setParserPID(getpid());
Parser myParser(shmem, filenames, MNIST_DATA_DIRECTORY);
}else if (pid > 0) {
// Parent process
DEBUG_PRINT("Parent Process");
shmem->setNetworkPID(getpid());
NetManager myManager(shmem, topology);
}else {
// fork failed
cerr << "Fork Failed" << endl;
return -1;
}
}