-
Notifications
You must be signed in to change notification settings - Fork 0
/
GPUloadCmat.c
80 lines (61 loc) · 2.46 KB
/
GPUloadCmat.c
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
/** @file GPUloadCmat.c
*/
#ifdef HAVE_CUDA
#include <cublas_v2.h>
#include "CommandLineInterface/CLIcore.h"
#include "cudacomp_types.h"
extern GPUMATMULTCONF gpumatmultconf[20];
errno_t GPUloadCmat(
int index
)
{
printf("LOADING MATRIX TO GPU ... ");
fflush(stdout);
for(int device = 0; device < gpumatmultconf[index].NBstreams; device++)
{
for(unsigned int n = gpumatmultconf[index].Noffset[device];
n < gpumatmultconf[index].Noffset[device] + gpumatmultconf[index].Nsize[device];
n++)
{
if(gpumatmultconf[index].orientation == 0)
{
for(unsigned int m = 0; m < gpumatmultconf[index].M; m++)
{
gpumatmultconf[index].cMat_part[device][(n -
gpumatmultconf[index].Noffset[device])*gpumatmultconf[index].M + m] =
gpumatmultconf[index].cMat[m * gpumatmultconf[index].N + n];
}
}
else
{
for(unsigned int m = 0; m < gpumatmultconf[index].M; m++)
{
gpumatmultconf[index].cMat_part[device][(n -
gpumatmultconf[index].Noffset[device])*gpumatmultconf[index].M + m] =
gpumatmultconf[index].cMat[n * gpumatmultconf[index].M + m];
}
}
}
}
for(int device = 0; device < gpumatmultconf[index].NBstreams; device++)
{
cudaSetDevice(gpumatmultconf[index].GPUdevice[device]);
cublasStatus_t error = cublasSetMatrix(
gpumatmultconf[index].M,
gpumatmultconf[index].Nsize[device],
sizeof(float),
gpumatmultconf[index].cMat_part[device],
gpumatmultconf[index].M,
gpumatmultconf[index].d_cMat[device],
gpumatmultconf[index].M);
if(error != CUBLAS_STATUS_SUCCESS)
{
printf("cudblasSetMatrix returned error code %d, line(%d)\n", (int) error, __LINE__);
exit(EXIT_FAILURE);
}
}
printf("done\n");
fflush(stdout);
return RETURN_SUCCESS;
}
#endif