-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeckoHierarchy.cpp
More file actions
120 lines (93 loc) · 2.63 KB
/
geckoHierarchy.cpp
File metadata and controls
120 lines (93 loc) · 2.63 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
117
118
119
//
// Created by millad on 11/29/18.
//
#include "geckoHierarchy.h"
#include "geckoHierarchicalTree.h"
#include <string.h>
extern GeckoError geckoInit();
extern GeckoCUDAProp geckoCUDA;
inline
void __geckoHierDeclAll(const char *child_name, int all, int &begin, int &end) {
if(all) {
char name[128];
sprintf(&name[0], "%s[%d]", child_name, 0);
GeckoLocation *child = GeckoLocation::find(string(name));
if(child == NULL) {
fprintf(stderr, "===GECKO: Unable to find (%s)!\n", child_name);
exit(1);
}
GeckoLocationType locObj = child->getLocationType();
if(locObj.type == GECKO_X64) {
// putting NUMA-related API calls in here
begin = 0;
end = 2;
}
#ifdef CUDA_ENABLED
else if(locObj.type == GECKO_NVIDIA) {
begin = 0;
end = geckoCUDA.deviceCountTotal;
}
#else
if(locObj.type == GECKO_NVIDIA) {
fprintf(stderr, "===GECKO: No CUDA is available on this system.\n");
exit(1);
}
#endif
}
}
GeckoLocation * __geckoDetermineParent(char operation, const char *parent_name) {
GeckoLocation *parentNode = NULL;
if(operation == '+') {
parentNode = GeckoLocation::find(string(parent_name));
if (parentNode == NULL) {
fprintf(stderr, "===GECKO: Unable to find parent (%s)!\n", parent_name);
exit(1);
}
}
return parentNode;
}
GeckoError geckoHierarchyDeclare(char operation, const char *child_name, const char *parent_name, int all, int start,
int count) {
geckoInit();
if(operation != '+' && operation != '-') {
fprintf(stderr, "===GECKO: Unrecognizeable operation ('%c') in hierarchy declaration for location '%s'.\n",
operation, child_name);
exit(1);
}
int begin, end;
if(start == -1) {
begin = 0;
end = 1;
} else {
begin = start;
end = start + count;
}
__geckoHierDeclAll(child_name, all, begin, end);
GeckoLocation *parentNode = __geckoDetermineParent(operation, parent_name);
#ifdef INFO
char operation_name[16];
strcpy(&operation_name[0], operation == '+' ? "Declaring" : "Removing");
#endif
for(int devID=begin;devID<end;devID++) {
char name[128];
if(all)
sprintf(&name[0], "%s[%d]", child_name, devID);
else
sprintf(&name[0], "%s", child_name);
GeckoLocation *childNode = GeckoLocation::find(string(&name[0]));
if(childNode == NULL) {
fprintf(stderr, "===GECKO (%s:%d): Unable to find child (%s)!\n", __FILE__, __LINE__, &name[0]);
exit(1);
}
childNode->setParent(parentNode);
if(operation == '+') {
parentNode->appendChild(childNode);
} else {
parentNode->removeChild(childNode);
}
#ifdef INFO
fprintf(stderr, "===GECKO: %s '%s' as child of '%s'.\n", &operation_name[0], &name[0], parent_name);
#endif
}
return GECKO_SUCCESS;
}