Skip to content

Commit 98b8c4e

Browse files
author
Giorgi Lomia
committed
Starting to move tools into RDGInspection.h
1 parent 87391c7 commit 98b8c4e

File tree

4 files changed

+331
-269
lines changed

4 files changed

+331
-269
lines changed
Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
#ifndef KATANA_LIBTSUBA_RDGINSPECTION_H_
2+
#define KATANA_LIBTSUBA_RDGINSPECTION_H_
3+
4+
#include <cstdlib>
5+
#include <iostream>
6+
#include <vector>
7+
8+
#include "katana/BufferedGraph.h"
9+
#include "katana/FileGraph.h"
10+
#include "katana/Galois.h"
11+
#include "katana/LCGraph.h"
12+
#include "katana/OfflineGraph.h"
13+
#include "llvm/Support/CommandLine.h"
14+
15+
namespace tsuba {
16+
17+
namespace cll = llvm::cl;
18+
19+
enum StatMode {
20+
degreehist,
21+
degrees,
22+
maxDegreeNode,
23+
dsthist,
24+
indegreehist,
25+
sortedlogoffsethist,
26+
sparsityPattern,
27+
summary
28+
};
29+
30+
typedef katana::OfflineGraph Graph;
31+
typedef Graph::GraphNode GNode;
32+
33+
using Writer = katana::FileGraphWriter;
34+
35+
void
36+
doSummary(Graph& graph) {
37+
std::cout << "NumNodes: " << graph.size() << "\n";
38+
std::cout << "NumEdges: " << graph.sizeEdges() << "\n";
39+
std::cout << "SizeofEdge: " << graph.edgeSize() << "\n";
40+
}
41+
42+
void
43+
doDegrees(Graph& graph) {
44+
for (auto n : graph) {
45+
std::cout << graph.edges(n).size() << "\n";
46+
}
47+
}
48+
49+
void
50+
findMaxDegreeNode(Graph& graph) {
51+
uint64_t nodeID = 0;
52+
size_t MaxDegree = 0;
53+
uint64_t MaxDegreeNode = 0;
54+
for (auto n : graph) {
55+
size_t degree = graph.edges(n).size();
56+
if (MaxDegree < degree) {
57+
MaxDegree = degree;
58+
MaxDegreeNode = nodeID;
59+
}
60+
++nodeID;
61+
}
62+
std::cout << "MaxDegreeNode : " << MaxDegreeNode
63+
<< " , MaxDegree : " << MaxDegree << "\n";
64+
}
65+
66+
void
67+
printHistogram(
68+
const std::string& name, std::map<uint64_t, uint64_t>& hists,
69+
const uint64_t& number_of_bins) {
70+
auto max = hists.rbegin()->first;
71+
if (number_of_bins <= 0) {
72+
std::cout << name << "Bin,Start,End,Count\n";
73+
for (unsigned x = 0; x <= max; ++x) {
74+
std::cout << x << ',' << x << ',' << x + 1 << ',';
75+
if (hists.count(x)) {
76+
std::cout << hists[x] << '\n';
77+
} else {
78+
std::cout << "0\n";
79+
}
80+
}
81+
} else {
82+
std::vector<uint64_t> bins(number_of_bins);
83+
auto bwidth = (max + 1) / number_of_bins;
84+
if ((max + 1) % number_of_bins) {
85+
++bwidth;
86+
}
87+
// std::cerr << "* " << max << " " << number_of_bins << " " << bwidth << "\n";
88+
for (auto p : hists) {
89+
bins.at(p.first / bwidth) += p.second;
90+
}
91+
std::cout << name << "Bin,Start,End,Count\n";
92+
for (unsigned x = 0; x < bins.size(); ++x) {
93+
std::cout << x << ',' << x * bwidth << ',' << (x * bwidth + bwidth) << ','
94+
<< bins[x] << '\n';
95+
}
96+
}
97+
}
98+
99+
void
100+
doSparsityPattern(
101+
Graph& graph, const int64_t& columns,
102+
std::function<void(unsigned, unsigned, bool)> printFn) {
103+
unsigned blockSize = (graph.size() + columns - 1) / columns;
104+
105+
for (int i = 0; i < columns; ++i) {
106+
std::vector<bool> row(columns);
107+
auto p = katana::block_range(graph.begin(), graph.end(), i, columns);
108+
for (auto ii = p.first, ei = p.second; ii != ei; ++ii) {
109+
for (auto jj : graph.edges(*ii)) {
110+
row[graph.getEdgeDst(jj) / blockSize] = true;
111+
}
112+
}
113+
for (int x = 0; x < columns; ++x) {
114+
printFn(x, i, row[x]);
115+
}
116+
}
117+
}
118+
119+
void
120+
doDegreeHistogram(Graph& graph, const uint64_t& numBins) {
121+
std::map<uint64_t, uint64_t> hist;
122+
for (auto ii : graph) {
123+
++hist[graph.edges(ii).size()];
124+
}
125+
printHistogram("Degree", hist, numBins);
126+
}
127+
128+
void
129+
doInDegreeHistogram(Graph& graph, const uint64_t& numBins) {
130+
std::vector<uint64_t> inv(graph.size());
131+
std::map<uint64_t, uint64_t> hist;
132+
for (auto ii : graph) {
133+
for (auto jj : graph.edges(ii)) {
134+
++inv[graph.getEdgeDst(jj)];
135+
}
136+
}
137+
for (uint64_t n : inv) {
138+
++hist[n];
139+
}
140+
printHistogram("InDegree", hist, numBins);
141+
}
142+
143+
struct EdgeComp {
144+
typedef katana::EdgeSortValue<GNode, void> Edge;
145+
146+
bool operator()(const Edge& a, const Edge& b) const { return a.dst < b.dst; }
147+
};
148+
149+
int
150+
getLogIndex(ptrdiff_t x) {
151+
int logvalue = 0;
152+
int sign = x < 0 ? -1 : 1;
153+
154+
if (x < 0) {
155+
x = -x;
156+
}
157+
158+
while ((x >>= 1) != 0) {
159+
++logvalue;
160+
}
161+
return sign * logvalue;
162+
}
163+
164+
void
165+
doSortedLogOffsetHistogram([[maybe_unused]] Graph& graph) {
166+
// Graph copy;
167+
// {
168+
// // Original FileGraph is immutable because it is backed by a file
169+
// copy = graph;
170+
// }
171+
172+
// std::vector<std::map<int, size_t> > hists;
173+
// hists.emplace_back();
174+
// auto hist = &hists.back();
175+
// int curHist = 0;
176+
// auto p = katana::block_range(
177+
// boost::counting_iterator<size_t>(0),
178+
// boost::counting_iterator<size_t>(graph.sizeEdges()),
179+
// curHist,
180+
// numHist);
181+
// for (auto ii = graph.begin(), ei = graph.end(); ii != ei; ++ii) {
182+
// copy.sortEdges<void>(*ii, EdgeComp());
183+
184+
// GNode last = 0;
185+
// bool first = true;
186+
// for (auto jj = copy.edge_begin(*ii), ej = copy.edge_end(*ii); jj != ej;
187+
// ++jj) {
188+
// GNode dst = copy.getEdgeDst(jj);
189+
// ptrdiff_t diff = dst - (ptrdiff_t) last;
190+
191+
// if (!first) {
192+
// int index = getLogIndex(diff);
193+
// ++(*hist)[index];
194+
// }
195+
// first = false;
196+
// last = dst;
197+
// if (++p.first == p.second) {
198+
// hists.emplace_back();
199+
// hist = &hists.back();
200+
// curHist += 1;
201+
// p = katana::block_range(
202+
// boost::counting_iterator<size_t>(0),
203+
// boost::counting_iterator<size_t>(graph.sizeEdges()),
204+
// curHist,
205+
// numHist);
206+
// }
207+
// }
208+
// }
209+
210+
// printHistogram("LogOffset", hists);
211+
}
212+
213+
void
214+
doDestinationHistogram(Graph& graph, const uint64_t& numBins) {
215+
std::map<uint64_t, uint64_t> hist;
216+
for (auto ii : graph) {
217+
for (auto jj : graph.edges(ii)) {
218+
++hist[graph.getEdgeDst(jj)];
219+
}
220+
}
221+
printHistogram("DestinationBin", hist, numBins);
222+
}
223+
224+
/**
225+
* Create node map from file
226+
*/
227+
std::map<uint32_t, uint32_t>
228+
createNodeMap(const std::string& mappingFilename) {
229+
katana::gInfo("Creating node map");
230+
// read new mapping
231+
std::ifstream mapFile(mappingFilename);
232+
mapFile.seekg(0, std::ios_base::end);
233+
234+
int64_t endOfFile = mapFile.tellg();
235+
if (!mapFile) {
236+
KATANA_DIE("failed to read file");
237+
}
238+
239+
mapFile.seekg(0, std::ios_base::beg);
240+
if (!mapFile) {
241+
KATANA_DIE("failed to read file");
242+
}
243+
244+
// remap node listed on line n in the mapping to node n
245+
std::map<uint32_t, uint32_t> remapper;
246+
uint64_t counter = 0;
247+
while (((int64_t)mapFile.tellg() + 1) != endOfFile) {
248+
uint64_t nodeID;
249+
mapFile >> nodeID;
250+
if (!mapFile) {
251+
KATANA_DIE("failed to read file");
252+
}
253+
remapper[nodeID] = counter++;
254+
}
255+
256+
KATANA_LOG_ASSERT(remapper.size() == counter);
257+
katana::gInfo("Remapping ", counter, " nodes");
258+
259+
katana::gInfo("Node map created");
260+
261+
return remapper;
262+
}
263+
264+
} // namespace tsuba
265+
#endif

libtsuba/src/RDGInspection.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This file belongs to the Galois project, a C++ library for exploiting
3+
* parallelism. The code is being released under the terms of the 3-Clause BSD
4+
* License (a copy is located in LICENSE.txt at the top-level directory).
5+
*
6+
* Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7+
* UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8+
* SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9+
* FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10+
* PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11+
* DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12+
* RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13+
* shall University be liable for incidental, special, indirect, direct or
14+
* consequential damages or loss of profits, interruption of business, or
15+
* related expenses which may arise from use of Software or Documentation,
16+
* including but not limited to those resulting from defects in Software and/or
17+
* Documentation, or loss or inaccuracy of data of any kind.
18+
*/
19+
20+
#include "RDGInspection.h"
21+
22+
#include <cstdlib>
23+
#include <iostream>
24+
#include <vector>
25+
26+
#include "katana/Galois.h"
27+
#include "katana/LCGraph.h"
28+
#include "katana/OfflineGraph.h"
29+
#include "llvm/Support/CommandLine.h"
30+
31+
namespace cll = llvm::cl;

tools/graph-remap/graph-remap.cpp

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "katana/FileGraph.h"
2222
#include "katana/Galois.h"
2323
#include "llvm/Support/CommandLine.h"
24+
#include "tsuba/RDGInspection.h"
2425

2526
namespace cll = llvm::cl;
2627

@@ -33,52 +34,12 @@ static cll::opt<std::string> outputFilename(
3334

3435
using Writer = katana::FileGraphWriter;
3536

36-
/**
37-
* Create node map from file
38-
*/
39-
std::map<uint32_t, uint32_t>
40-
createNodeMap() {
41-
katana::gInfo("Creating node map");
42-
// read new mapping
43-
std::ifstream mapFile(mappingFilename);
44-
mapFile.seekg(0, std::ios_base::end);
45-
46-
int64_t endOfFile = mapFile.tellg();
47-
if (!mapFile) {
48-
KATANA_DIE("failed to read file");
49-
}
50-
51-
mapFile.seekg(0, std::ios_base::beg);
52-
if (!mapFile) {
53-
KATANA_DIE("failed to read file");
54-
}
55-
56-
// remap node listed on line n in the mapping to node n
57-
std::map<uint32_t, uint32_t> remapper;
58-
uint64_t counter = 0;
59-
while (((int64_t)mapFile.tellg() + 1) != endOfFile) {
60-
uint64_t nodeID;
61-
mapFile >> nodeID;
62-
if (!mapFile) {
63-
KATANA_DIE("failed to read file");
64-
}
65-
remapper[nodeID] = counter++;
66-
}
67-
68-
KATANA_LOG_ASSERT(remapper.size() == counter);
69-
katana::gInfo("Remapping ", counter, " nodes");
70-
71-
katana::gInfo("Node map created");
72-
73-
return remapper;
74-
}
75-
7637
int
7738
main(int argc, char** argv) {
7839
katana::SharedMemSys G;
7940
llvm::cl::ParseCommandLineOptions(argc, argv);
8041

81-
std::map<uint32_t, uint32_t> remapper = createNodeMap();
42+
std::map<uint32_t, uint32_t> remapper = tsuba::createNodeMap(mappingFilename);
8243

8344
katana::gInfo("Loading graph to remap");
8445
katana::BufferedGraph<void> graphToRemap;

0 commit comments

Comments
 (0)