-
Notifications
You must be signed in to change notification settings - Fork 2
/
hipsolver.hpp
146 lines (127 loc) · 3.19 KB
/
hipsolver.hpp
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
#if defined(__HIPCC__)
#include <hipsolver/hipsolver.h>
#if 0
void
hipsolver_test(int n, half *A, int lda, half *W, int batchSize)
{
}
#endif
void
hipsolver_test(int n, double *A, int lda, double *W, int batchSize)
{
hipsolverHandle_t hipsolverH = NULL;
hipsolverCreate(&hipsolverH);
hipStream_t stream = NULL;
hipStreamCreateWithFlags(&stream, hipStreamNonBlocking);
hipsolverSetStream(hipsolverH, stream);
hipsolverSyevjInfo_t syevj_params = NULL;
hipsolverDnCreateSyevjInfo(&syevj_params);
double constexpr EPS = (double)std::numeric_limits<double>::epsilon();
hipsolverDnXsyevjSetTolerance(syevj_params,EPS*512);
hipsolverDnXsyevjSetMaxSweeps(syevj_params,10);
hipsolverDnXsyevjSetSortEig(syevj_params,0);
int lwork;
hipsolverDsyevjBatched_bufferSize(
hipsolverH,
HIPSOLVER_EIG_MODE_VECTOR,
HIPSOLVER_FILL_MODE_UPPER,
n,
A,
lda,
W,
&lwork,
syevj_params,
batchSize
);
double *d_work;
hipMalloc((void**)&d_work, sizeof(double)*lwork);
int *d_info;
hipMalloc((void**)&d_info, sizeof(int)*batchSize);
hipsolverDsyevjBatched(
hipsolverH,
HIPSOLVER_EIG_MODE_VECTOR,
HIPSOLVER_FILL_MODE_UPPER,
n,
A,
lda,
W,
d_work,
lwork,
d_info,
syevj_params,
batchSize
);
hipFree(d_work);
int * info = (int *)malloc(sizeof(int)*batchSize);
hipMemcpy(info,d_info,sizeof(int)*batchSize,hipMemcpyDeviceToHost);
hipFree(d_info);
for(int i=0;i<batchSize;i++){
if(info[i]!=0) {
printf("[%06d] Gave up the iteration.\n",i); break;
}
}
free(info);
hipsolverDnDestroySyevjInfo(syevj_params);
hipsolverDnDestroy(hipsolverH);
hipStreamDestroy(stream);
}
void
hipsolver_test(int n, float *A, int lda, float *W, int batchSize)
{
hipsolverHandle_t hipsolverH = NULL;
hipsolverCreate(&hipsolverH);
hipStream_t stream = NULL;
hipStreamCreateWithFlags(&stream, hipStreamNonBlocking);
hipsolverSetStream(hipsolverH, stream);
hipsolverSyevjInfo_t syevj_params = NULL;
hipsolverDnCreateSyevjInfo(&syevj_params);
double constexpr EPS = (double)std::numeric_limits<float>::epsilon();
hipsolverDnXsyevjSetTolerance(syevj_params,EPS*16);
hipsolverDnXsyevjSetMaxSweeps(syevj_params,10);
hipsolverDnXsyevjSetSortEig(syevj_params,0);
int lwork;
hipsolverSsyevjBatched_bufferSize(
hipsolverH,
HIPSOLVER_EIG_MODE_VECTOR,
HIPSOLVER_FILL_MODE_UPPER,
n,
A,
lda,
W,
&lwork,
syevj_params,
batchSize
);
float *s_work;
hipMalloc((void**)&s_work, sizeof(float)*lwork);
int *s_info;
hipMalloc((void**)&s_info, sizeof(int)*batchSize);
hipsolverSsyevjBatched(
hipsolverH,
HIPSOLVER_EIG_MODE_VECTOR,
HIPSOLVER_FILL_MODE_UPPER,
n,
A,
lda,
W,
s_work,
lwork,
s_info,
syevj_params,
batchSize
);
hipFree(s_work);
int * info = (int *)malloc(sizeof(int)*batchSize);
hipMemcpy(info,s_info,sizeof(int)*batchSize,hipMemcpyDeviceToHost);
hipFree(s_info);
for(int i=0;i<batchSize;i++){
if(info[i]!=0) {
printf("[%06d] Gave up the iteration.\n",i); break;
}
}
free(info);
hipsolverDnDestroySyevjInfo(syevj_params);
hipsolverDnDestroy(hipsolverH);
hipStreamDestroy(stream);
}
#endif