-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutil.h
More file actions
217 lines (179 loc) · 6.56 KB
/
util.h
File metadata and controls
217 lines (179 loc) · 6.56 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
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**
*
* OHIO STATE UNIVERSITY SOFTWARE DISTRIBUTION LICENSE
*
* Parallel CCD++ on GPU (the “Software”) Copyright (c) 2017, The Ohio State
* University. All rights reserved.
*
* The Software is available for download and use subject to the terms and
* conditions of this License. Access or use of the Software constitutes acceptance
* and agreement to the terms and conditions of this License. Redistribution and
* use of the Software in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the capitalized paragraph below.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the capitalized paragraph below in the documentation
* and/or other materials provided with the distribution.
*
* 3. The names of Ohio State University, or its faculty, staff or students may not
* be used to endorse or promote products derived from the Software without
* specific prior written permission.
*
* This software was produced with support from the National Science Foundation
* (NSF) through Award 1629548. Nothing in this work should be construed as
* reflecting the official policy or position of the Defense Department, the United
* States government, Ohio State University.
*
* THIS SOFTWARE HAS BEEN APPROVED FOR PUBLIC RELEASE, UNLIMITED DISTRIBUTION. THE
* SOFTWARE IS PROVIDED “AS IS” AND WITHOUT ANY EXPRESS, IMPLIED OR STATUTORY
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF ACCURACY, COMPLETENESS,
* NONINFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. ACCESS OR USE OF THE SOFTWARE IS ENTIRELY AT THE USER’S RISK. IN
* NO EVENT SHALL OHIO STATE UNIVERSITY OR ITS FACULTY, STAFF OR STUDENTS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE SOFTWARE
* USER SHALL INDEMNIFY, DEFEND AND HOLD HARMLESS OHIO STATE UNIVERSITY AND ITS
* FACULTY, STAFF AND STUDENTS FROM ANY AND ALL CLAIMS, ACTIONS, DAMAGES, LOSSES,
* LIABILITIES, COSTS AND EXPENSES, INCLUDING ATTORNEYS’ FEES AND COURT COSTS,
* DIRECTLY OR INDIRECTLY ARISING OUT OF OR IN CONNECTION WITH ACCESS OR USE OF THE
* SOFTWARE.
*
*/
/**
*
* Author:
* Israt (nisa.1@osu.edu)
*
* Contacts:
* Israt (nisa.1@osu.edu)
* Aravind Sukumaran-Rajam (sukumaranrajam.1@osu.edu)
* P. (Saday) Sadayappan (sadayappan.1@osu.edu)
*
*/
#ifndef UTIL
#define UTIL
#include <iostream>
#include <fstream>
#include <sys/time.h>
#include <memory>
#include <limits>
#include <vector>
#include <omp.h>
#include <cassert>
inline double seconds() {
struct timeval tp;
gettimeofday(&tp, NULL);
return ((double) tp.tv_sec + (double) tp.tv_usec * 1.e-6);
}
#define DTYPE float
//#define DTYPE double
using std::vector;
using std::ifstream;
class TestData;
class SparseMatrix;
class Options;
using VecData = vector<DTYPE>;
using MatData = vector<VecData>;
using VecInt = vector<int>;
using MatInt = vector<VecInt>;
void ccdr1(SparseMatrix &R, MatData &W, MatData &H, TestData &T,
Options &options);
void load_from_binary(const char* srcdir, SparseMatrix &R, TestData &data);
MatData load_mat_t(FILE *fp, bool row_major = true);
void init_random(MatData &X, long k, long n);
class SparseMatrix {
public:
long rows_, cols_, nnz_, max_row_nnz_, max_col_nnz_;
void read_binary_file(long rows, long cols, long nnz,
std::string fname_csr_row_ptr,
std::string fname_csr_col_indx, std::string fname_csr_val,
std::string fname_csc_col_ptr, std::string fname_csc_row_indx,
std::string fname_csc_val);
SparseMatrix get_shallow_transpose();
int* get_csc_col_ptr() const {
return csc_col_ptr_.get();
}
unsigned int* get_csc_row_indx() const {
return csc_row_indx_.get();
}
DTYPE* get_csc_val() const {
return csc_val_.get();
}
unsigned int* get_csr_col_indx() const {
return csr_col_indx_.get();
}
int* get_csr_row_ptr() const {
return csr_row_ptr_.get();
}
DTYPE* get_csr_val() const {
return csr_val_.get();
}
private:
void read_compressed(std::string fname_cs_ptr, std::string fname_cs_indx,
std::string fname_cs_val, std::shared_ptr<int>&cs_ptr,
std::shared_ptr<unsigned int> &cs_indx,
std::shared_ptr<DTYPE>& cs_val, long num_elems_in_cs_ptr,
long &max_nnz_in_one_dim);
std::shared_ptr<int> csc_col_ptr_, csr_row_ptr_, col_nnz_, row_nnz_;
std::shared_ptr<DTYPE> csr_val_, csc_val_;
std::shared_ptr<unsigned int> csc_row_indx_, csr_col_indx_;
};
class TestData {
public:
long rows_ { 0 }, cols_ { 0 }, nnz_ { 0 };
void read_binary_file(long rows, long cols, long nnz,
std::string fname_coo_row, std::string fname_coo_col,
std::string fname_coo_val);
// void read(long rows, long cols, long nnz, std::string filename) {
// this->rows_ = rows;
// this->cols_ = cols;
// this->nnz_ = nnz;
// test_row = std::unique_ptr<unsigned int[]>(new unsigned int[nnz]);
// test_col = std::unique_ptr<unsigned int[]>(new unsigned int[nnz]);
// test_val = std::unique_ptr<DTYPE[]>(new DTYPE[nnz]);
// ifstream fp(filename);
// for (long idx = 0; idx < nnz; ++idx) {
// fp >> test_row[idx] >> test_col[idx] >> test_val[idx];
// }
// }
unsigned int* getTestCol() const {
return test_col.get();
}
unsigned int* getTestRow() const {
return test_row.get();
}
DTYPE* getTestVal() const {
return test_val.get();
}
private:
void read_compressed(std::string fname_coo_row,
std::string fname_coo_col, std::string fname_coo_val,
std::unique_ptr<unsigned int>&coo_row, std::unique_ptr<unsigned int> &coo_col,
std::unique_ptr<DTYPE>& coo_val);
std::unique_ptr<unsigned int> test_row, test_col;
std::unique_ptr<DTYPE> test_val;
};
class Options {
public:
int k = 10;
int maxiter = 5;
int maxinneriter = 1;DTYPE lambda = .05;
int tileSizeW = 499999999;
int tileSizeH = 499999999;
void print() {
std::cout << "k = " << k << '\n';
std::cout << "iterinner = " << maxinneriter << '\n';
std::cout << "outeriter = " << maxiter << '\n';
std::cout << "tsw = " << tileSizeW << '\n';
std::cout << "tsh = " << tileSizeH << '\n';
std::cout << "lambda = " << lambda << '\n';
}
};
#endif