This repository has been archived by the owner on Dec 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathentry_point.cu
149 lines (127 loc) · 4.81 KB
/
entry_point.cu
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include <string>
#include <stdexcept>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <vector>
#include "common/globals.hpp"
#include "common/cuda_error_check.cuh"
#include "common/initial_graph.hpp"
#include "common/parse_graph.hpp"
#include "cusha_src/cusha_format.cuh"
#include "csr_src/csr_format.cuh"
// Open files safely.
template <typename T_file>
void openFileToAccess( T_file& input_file, std::string file_name ) {
input_file.open( file_name.c_str() );
if( !input_file )
throw std::runtime_error( "Failed to open specified file: " + file_name + "\n" );
}
// Execution entry point.
int main( int argc, char** argv )
{
std::string usage =
"\tRequired command line arguments:\n\
-Input file: E.g., --input in.txt\n\
-Processing method: CW, GS, VWC. E.g., --method CW\n\
Additional arguments:\n\
-Output file (default: out.txt). E.g., --output myout.txt.\n\
-Is the input graph directed (default:yes). To make it undirected: --undirected\n\
-Device ID (default: 0). E.g., --device 1\n\
-GPU kernels Block size for CW and GS (default: chosen based on analysis). E.g., --bsize 512.\n\
-Virtual warp size for VWC (default: 32). E.g., --vwsize 8.\n\
-User's arbitrary parameter (default: 0). E.g., --arbparam 17.\n";
try {
GraphProcessingMethod procesingMethod = UNSPECIFIED;
std::ifstream inputFile;
std::ofstream outputFile;
int selectedDevice = 0;
int bsize = 0;
int vwsize = 32;
int threads = 1;
long long arbparam = 0;
bool nonDirectedGraph = false; // By default, the graph is directed.
/********************************
* GETTING INPUT PARAMETERS.
********************************/
for( int iii = 1; iii < argc; ++iii )
if ( !strcmp(argv[iii], "--method") && iii != argc-1 ) {
if ( !strcmp(argv[iii+1], "CW") )
procesingMethod = CW;
if ( !strcmp(argv[iii+1], "GS") )
procesingMethod = GS;
if ( !strcmp(argv[iii+1], "VWC") )
procesingMethod = VWC;
}
else if( !strcmp( argv[iii], "--input" ) && iii != argc-1 /*is not the last one*/)
openFileToAccess< std::ifstream >( inputFile, std::string( argv[iii+1] ) );
else if( !strcmp( argv[iii], "--output" ) && iii != argc-1 /*is not the last one*/)
openFileToAccess< std::ofstream >( outputFile, std::string( argv[iii+1] ) );
else if( !strcmp( argv[iii], "--device" ) && iii != argc-1 /*is not the last one*/)
selectedDevice = std::atoi( argv[iii+1] );
else if( !strcmp( argv[iii], "--bsize" ) && iii != argc-1 /*is not the last one*/)
bsize = std::atoi( argv[iii+1] );
else if( !strcmp( argv[iii], "--vwsize" ) && iii != argc-1 /*is not the last one*/)
vwsize = std::atoi( argv[iii+1] );
else if( !strcmp( argv[iii], "--arbparam" ) && iii != argc-1 /*is not the last one*/)
arbparam = std::atoll( argv[iii+1] );
else if( !strcmp(argv[iii], "--undirected"))
nonDirectedGraph = true;
if( !inputFile.is_open() || procesingMethod == UNSPECIFIED ) {
std::cerr << "Usage: " << usage;
throw std::runtime_error( "\nAn initialization error happened.\nExiting." );
}
if( !outputFile.is_open() )
openFileToAccess< std::ofstream >( outputFile, "out.txt" );
CUDAErrorCheck( cudaSetDevice( selectedDevice ) );
std::cout << "Device with ID " << selectedDevice << " is selected to process the graph.\n";
if( procesingMethod == VWC ) {
if( vwsize != 2 && vwsize !=4 && vwsize != 8 && vwsize != 16 && vwsize != 32 )
vwsize = 32;
std::cout << "Virtual-Warp Centric method will be employed to process the graph with virtual warp size " << vwsize << ".\n";
}
/********************************
* Read the input graph file.
********************************/
std::cout << "Collecting the input graph ...\n";
std::vector<initial_vertex> parsedGraph( 0 );
uint nEdges = parse_graph::parse(
inputFile, // Input file.
parsedGraph, // The parsed graph.
arbparam,
nonDirectedGraph ); // Arbitrary user-provided parameter.
std::cout << "Input graph collected with " << parsedGraph.size() << " vertices and " << nEdges << " edges.\n";
/********************************
* Process the graph.
********************************/
if( procesingMethod == GS || procesingMethod == CW ) {
cusha_format::process(
procesingMethod,
bsize,
&parsedGraph,
nEdges,
outputFile );
}
else {
csr_format::process(
((procesingMethod==VWC)?vwsize:threads),
&parsedGraph,
nEdges,
outputFile );
}
/********************************
* It's done here.
********************************/
CUDAErrorCheck( cudaDeviceReset() );
std::cout << "Done.\n";
return( EXIT_SUCCESS );
}
catch( const std::exception& strException ) {
std::cerr << strException.what() << "\n";
return( EXIT_FAILURE );
}
catch(...) {
std::cerr << "An exception has occurred." << std::endl;
return( EXIT_FAILURE );
}
}