-
Notifications
You must be signed in to change notification settings - Fork 3
/
gpuVector.cpp
67 lines (63 loc) · 2.44 KB
/
gpuVector.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
#include "cuda_runtime.h"
#include "matlab_utils.h"
#include "Eigen/Eigen"
void pass_matrix_to_matlab(const char* namestr, float* pdata, int nrows, int ncols, int wordpitch, bool rowmajor = false) {
Eigen::Matrix<float, -1, -1> mat(nrows, ncols);
if (rowmajor) {
mat.resize(ncols, nrows);
cudaMemcpy2D(mat.data(), ncols * sizeof(float), pdata, wordpitch * sizeof(float),
ncols * sizeof(float), nrows, cudaMemcpyDeviceToHost);
mat.transposeInPlace();
}
else {
mat.resize(nrows, ncols);
cudaMemcpy2D(mat.data(), nrows * sizeof(float), pdata, wordpitch * sizeof(float),
nrows * sizeof(float), ncols, cudaMemcpyDeviceToHost);
}
eigen2ConnectedMatlab(namestr, mat);
}
void pass_matrix_to_matlab(const char* namestr, double* pdata, int nrows, int ncols, int wordpitch, bool rowmajor = false) {
Eigen::Matrix<double, -1, -1> mat(nrows, ncols);
if (rowmajor) {
mat.resize(ncols, nrows);
cudaMemcpy2D(mat.data(), ncols * sizeof(double), pdata, wordpitch * sizeof(double),
ncols * sizeof(double), nrows, cudaMemcpyDeviceToHost);
mat.transposeInPlace();
}
else {
mat.resize(nrows, ncols);
cudaMemcpy2D(mat.data(), nrows * sizeof(double), pdata, wordpitch * sizeof(double),
nrows * sizeof(double), ncols, cudaMemcpyDeviceToHost);
}
eigen2ConnectedMatlab(namestr, mat);
}
void pass_matrix_to_matlab(const char* namestr, int* pdata, int nrows, int ncols, int wordpitch, bool rowmajor = false) {
Eigen::Matrix<int, -1, -1> mat(nrows, ncols);
if (rowmajor) {
mat.resize(ncols, nrows);
cudaMemcpy2D(mat.data(), ncols * sizeof(int), pdata, wordpitch * sizeof(int),
ncols * sizeof(int), nrows, cudaMemcpyDeviceToHost);
mat.transposeInPlace();
}
else {
mat.resize(nrows, ncols);
cudaMemcpy2D(mat.data(), nrows * sizeof(int), pdata, wordpitch * sizeof(int),
nrows * sizeof(int), ncols, cudaMemcpyDeviceToHost);
}
eigen2ConnectedMatlab(namestr, mat);
}
void pass_matrix_to_matlab(const char* namestr, bool* pdata, int nrows, int ncols, int wordpitch, bool rowmajor = false) {
Eigen::Matrix<bool, -1, -1> mat(nrows, ncols);
if (rowmajor) {
mat.resize(ncols, nrows);
cudaMemcpy2D(mat.data(), ncols * sizeof(bool), pdata, wordpitch * sizeof(bool),
ncols * sizeof(bool), nrows, cudaMemcpyDeviceToHost);
mat.transposeInPlace();
}
else {
mat.resize(nrows, ncols);
cudaMemcpy2D(mat.data(), nrows * sizeof(bool), pdata, wordpitch * sizeof(bool),
nrows * sizeof(bool), ncols, cudaMemcpyDeviceToHost);
}
eigen2ConnectedMatlab(namestr, mat);
}