-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDataLoader.cpp
75 lines (68 loc) · 1.81 KB
/
DataLoader.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "DataLoader.h"
#include <iostream>
#include "COO.h"
#include "cusparse/include/cuSparseMultiply.h"
template<typename T>
std::string typeExtension();
template<>
std::string typeExtension<float>()
{
return std::string("");
}
template<>
std::string typeExtension<double>()
{
return std::string("d_");
}
template class DataLoader<float>;
template class DataLoader<double>;
template <typename ValueType>
DataLoader<ValueType>::DataLoader(std::string path) : matrices()
{
std::string csrPath = path + typeExtension<ValueType>() + ".hicsr";
try
{
std::cout << "trying to load csr file \"" << csrPath << "\"\n";
matrices.cpuA = loadCSR<ValueType>(csrPath.c_str());
std::cout << "successfully loaded: \"" << csrPath << "\"\n";
}
catch (std::exception& ex)
{
std::cout << "could not load csr file:\n\t" << ex.what() << "\n";
try
{
std::cout << "trying to load mtx file \"" << path << "\"\n";
COO<ValueType> cooMat = loadMTX<ValueType>(path.c_str());
convert(matrices.cpuA, cooMat);
std::cout << "successfully loaded and converted: \"" << csrPath << "\"\n";
}
catch (std::exception& ex)
{
std::cout << ex.what() << std::endl;
std::cout << "could not load mtx file: \"" << path << "\"\n";
throw "could not load mtx file";
}
try
{
std::cout << "write csr file for future use\n";
storeCSR(matrices.cpuA, csrPath.c_str());
}
catch (std::exception& ex)
{
std::cout << ex.what() << std::endl;
}
}
convert(matrices.gpuA, matrices.cpuA, 0);
cuSPARSE::CuSparseTest<ValueType> cuSparse;
//calculate the transpose if matrix is not square
if (matrices.gpuA.rows != matrices.gpuA.cols)
{
cuSparse.Transpose(matrices.gpuA, matrices.gpuB);
convert(matrices.cpuB, matrices.gpuB);
}
else
{
convert(matrices.gpuB, matrices.cpuA, 0);
convert(matrices.cpuB, matrices.cpuA, 0);
}
}