-
Notifications
You must be signed in to change notification settings - Fork 0
/
cuda_blas.cu
854 lines (752 loc) · 32.2 KB
/
cuda_blas.cu
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
#include "cublas_v2.h"
#include <cusparse.h>
#include "cuda_blas.h"
#if USE_FP64
#define cuda_data_type CUDA_R_64F
#else
#define cuda_data_type CUDA_R_32F
#endif
static cublasHandle_t handle_cublas;
static cusparseHandle_t handle_cusparse;
static void *mv_buffer;
static void *L_buffer;
static void *U_buffer;
static void *ichol_buffer; // in ichol, we can get away with one buffer
static cusparseSpMatDescr_t matA = NULL;
static cusparseSpMatDescr_t matL;
static cusparseSpMatDescr_t matU;
static cusparseMatDescr_t descrL, descrU, descrLt, descrM; // last two are used only for incomplete CHolesky
static csrsv2Info_t infoL, infoU, infoLt;
csric02Info_t infoM = 0; // used only for Incomplete Cholesky
#define policy CUSPARSE_SOLVE_POLICY_USE_LEVEL
void initialize_handles(){
//printf("initializing handles! \n");
cublasCreate(&handle_cublas);
cusparseCreate(&handle_cusparse);
}
void initialize_spmv_buffer(const int n,
const int nnz,
int *ia,
int *ja,
real_type *a,
const real_type *x,
real_type *result,
real_type *al,
real_type *bet){
cusparseDnVecDescr_t vecX;
cusparseDnVecDescr_t vecY;
size_t mv_buffer_size;
cusparseStatus_t status_cusparse;
status_cusparse = cusparseCreateDnVec(&vecX,
n,
(void*) x,
cuda_data_type);
// printf("matX creation status %d\n", status_cusparse);
status_cusparse = cusparseCreateDnVec(&vecY,
n,
(void *) result,
cuda_data_type);
// printf("vecY creation status %d\n", status_cusparse);
status_cusparse = cusparseCreateCsr(&matA,
n,
n,
nnz,
ia,
ja,
a,
CUSPARSE_INDEX_32I,
CUSPARSE_INDEX_32I,
CUSPARSE_INDEX_BASE_ZERO,
cuda_data_type);
// printf("matA creation status %d\n", status_cusparse);
status_cusparse = cusparseSpMV_bufferSize(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
al,
matA,
vecX,
bet,
vecY,
cuda_data_type,
#if V100
CUSPARSE_CSRMV_ALG2,
#else
CUSPARSE_SPMV_CSR_ALG2,
#endif
&mv_buffer_size);
cudaDeviceSynchronize();
// printf("mv buffer size %d alpha %f beta %f status %d \n", mv_buffer_size, *al, *bet, status_cusparse);
cudaError t = cudaMalloc( &mv_buffer, mv_buffer_size);
if (t != 0) printf("allocated mv_buffer: is it NULL? %d, error %d \n", mv_buffer == NULL, t);
cusparseDestroyDnVec(vecX);
cusparseDestroyDnVec(vecY);
}
void initialize_and_analyze_L_and_U_solve(const int n,
const int nnzL,
int *lia,
int *lja,
real_type *la,
const int nnzU,
int *uia,
int *uja,
real_type *ua){
cusparseCreateMatDescr(&(descrL));
cusparseSetMatIndexBase(descrL, CUSPARSE_INDEX_BASE_ZERO);
cusparseSetMatFillMode(descrL, CUSPARSE_FILL_MODE_LOWER);
cusparseCreateMatDescr(&(descrU));
cusparseSetMatIndexBase(descrU, CUSPARSE_INDEX_BASE_ZERO);
cusparseSetMatFillMode(descrU, CUSPARSE_FILL_MODE_UPPER);
cusparseCreateCsrsv2Info(&infoL);
cusparseCreateCsrsv2Info(&infoU);
int L_buffer_size;
int U_buffer_size;
#if USE_FP64 // it is double
cusparseDcsrsv2_bufferSize(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzL,
descrL,
la,
lia,
lja,
infoL,
&L_buffer_size);
//printf("buffer size L %d\n", L_buffer_size);
cudaMalloc((void**)&(L_buffer), L_buffer_size);
cusparseDcsrsv2_bufferSize(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzU,
descrU,
ua,
uia,
uja,
infoU,
&U_buffer_size);
//printf("buffer size U %d\n", U_buffer_size);
cudaMalloc((void**)&(U_buffer), U_buffer_size);
cusparseStatus_t status_cusparse;
status_cusparse = cusparseDcsrsv2_analysis(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzL,
descrL,
la,
lia,
lja,
infoL,
policy,
L_buffer);
status_cusparse = cusparseDcsrsv2_analysis(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzU,
descrU,
ua,
uia,
uja,
infoU,
policy,
U_buffer);
#else
// it is 4 bytes so SINGLE
cusparseScsrsv2_bufferSize(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzL,
descrL,
la,
lia,
lja,
infoL,
&L_buffer_size);
//printf("buffer size L %d\n", L_buffer_size);
cudaMalloc((void**)&(L_buffer), L_buffer_size);
cusparseScsrsv2_bufferSize(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzU,
descrU,
ua,
uia,
uja,
infoU,
&U_buffer_size);
//printf("buffer size U %d\n", U_buffer_size);
cudaMalloc((void**)&(U_buffer), U_buffer_size);
cusparseStatus_t status_cusparse;
status_cusparse = cusparseScsrsv2_analysis(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzL,
descrL,
la,
lia,
lja,
infoL,
policy,
L_buffer);
status_cusparse = cusparseScsrsv2_analysis(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzU,
descrU,
ua,
uia,
uja,
infoU,
policy,
U_buffer);
#endif
}
void initialize_L_and_U_descriptors(const int n,
const int nnzL,
int *lia,
int *lja,
real_type *la,
const int nnzU,
int *uia,
int *uja,
real_type *ua){
cusparseCreateCsr(&matL,
n,
n,
nnzL,
lia,
lja,
la,
CUSPARSE_INDEX_32I,
CUSPARSE_INDEX_32I,
CUSPARSE_INDEX_BASE_ZERO,
cuda_data_type);
cusparseCreateCsr(&matU,
n,
n,
nnzU,
uia,
uja,
ua,
CUSPARSE_INDEX_32I,
CUSPARSE_INDEX_32I,
CUSPARSE_INDEX_BASE_ZERO,
cuda_data_type);
}
void initialize_ichol(const int n,
const int nnzA,
int *ia,
int *ja,
real_type *a)
{
printf("initializing ICHOL \n");
cusparseCreateMatDescr(&descrM);
cusparseSetMatIndexBase(descrM, CUSPARSE_INDEX_BASE_ZERO);
cusparseSetMatType(descrM, CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseCreateMatDescr(&descrL);
cusparseSetMatIndexBase(descrL, CUSPARSE_INDEX_BASE_ZERO);
cusparseSetMatType(descrL, CUSPARSE_MATRIX_TYPE_GENERAL);
cusparseSetMatFillMode(descrL, CUSPARSE_FILL_MODE_LOWER);
cusparseSetMatDiagType(descrL, CUSPARSE_DIAG_TYPE_NON_UNIT);
cusparseCreateCsric02Info(&infoM);
cusparseCreateCsrsv2Info(&infoL);
cusparseCreateCsrsv2Info(&infoLt);
int structural_zero;
int numerical_zero;
cusparseStatus_t status_cusparse;
/* figure out the buffer size */
int bufferSize, bufferSizeL, bufferSizeLt, bufferSizeM;
#if USE_FP64 // it is double
status_cusparse = cusparseDcsric02_bufferSize(handle_cusparse,
n,
nnzA,
descrM,
a,
ia,
ja,
infoM,
&bufferSizeM);
status_cusparse = cusparseDcsrsv2_bufferSize(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzA,
descrL,
a,
ia,
ja,
infoL,
&bufferSizeL);
status_cusparse = cusparseDcsrsv2_bufferSize(handle_cusparse,
CUSPARSE_OPERATION_TRANSPOSE,
n,
nnzA,
descrL,
a,
ia,
ja,
infoLt,
&bufferSizeLt);
#else
status_cusparse = cusparseScsric02_bufferSize(handle_cusparse,
n,
nnzA,
descrM,
a,
ia,
ja,
infoM,
&bufferSizeM);
status_cusparse = cusparseScsrsv2_bufferSize(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzA,
descrL,
a,
ia,
ja,
infoL,
&bufferSizeL);
status_cusparse = cusparseScsrsv2_bufferSize(handle_cusparse,
CUSPARSE_OPERATION_TRANSPOSE,
n,
nnzA,
descrL,
a,
ia,
ja,
infoLt,
&bufferSizeLt);
#endif
bufferSize = max(bufferSizeM, max(bufferSizeL, bufferSizeLt));
cudaMalloc((void**) &ichol_buffer, bufferSize);
/* and now analyze */
#if USE_FP64 // it is double
status_cusparse = cusparseDcsric02_analysis(handle_cusparse,
n,
nnzA,
descrM,
a,
ia,
ja,
infoM,
policy,
ichol_buffer);
status_cusparse = cusparseXcsric02_zeroPivot(handle_cusparse, infoM, &structural_zero);
if (CUSPARSE_STATUS_ZERO_PIVOT == status_cusparse) {
printf("We have a problem: A(%d,%d) is missing\n", structural_zero, structural_zero);
}
/* analyze the solves as well */
status_cusparse = cusparseDcsrsv2_analysis(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzA,
descrL,
a,
ia,
ja,
infoL,
policy,
ichol_buffer);
status_cusparse = cusparseDcsrsv2_analysis(handle_cusparse,
CUSPARSE_OPERATION_TRANSPOSE,
n,
nnzA,
descrL,
a,
ia,
ja,
infoLt,
policy,
ichol_buffer);
/* decompose */
status_cusparse = cusparseDcsric02(handle_cusparse,
n,
nnzA,
descrM,
a,
ia,
ja,
infoM,
policy,
ichol_buffer);
status_cusparse = cusparseXcsric02_zeroPivot(handle_cusparse,
infoM,
&numerical_zero);
if (CUSPARSE_STATUS_ZERO_PIVOT == status_cusparse) {
printf("We have another problem: L(%d,%d) is zero\n", numerical_zero, numerical_zero);
}
#else
status_cusparse = cusparseScsric02_analysis(handle_cusparse,
n,
nnzA,
descrM,
a,
ia,
ja,
infoM,
policy,
ichol_buffer);
status_cusparse = cusparseXcsric02_zeroPivot(handle_cusparse, infoM, &structural_zero);
if (CUSPARSE_STATUS_ZERO_PIVOT == status_cusparse) {
printf("We have a problem: A(%d,%d) is missing\n", structural_zero, structural_zero);
}
/* analyze the solves as well */
status_cusparse = cusparseScsrsv2_analysis(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzA,
descrL,
a,
ia,
ja,
infoL,
policy,
ichol_buffer);
status_cusparse = cusparseScsrsv2_analysis(handle_cusparse,
CUSPARSE_OPERATION_TRANSPOSE,
n,
nnzA,
descrL,
a,
ia,
ja,
infoLt,
policy,
ichol_buffer);
/* decompose */
status_cusparse = cusparseScsric02(handle_cusparse,
n,
nnzA,
descrM,
a,
ia,
ja,
infoM,
policy,
ichol_buffer);
status_cusparse = cusparseXcsric02_zeroPivot(handle_cusparse,
infoM,
&numerical_zero);
if (CUSPARSE_STATUS_ZERO_PIVOT == status_cusparse) {
printf("We have another problem: L(%d,%d) is zero\n", numerical_zero, numerical_zero);
}
#endif
}
void cuda_ichol(const int *ia,
const int *ja,
real_type *a,
const int nnzA,
pdata *prec_data,
real_type *x,
real_type *y) {
real_type one = 1.0;
#if USE_FP64 // it is double
cusparseDcsrsv2_solve(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
prec_data->n,
nnzA,
&one,
descrL, // replace with cusparseSpSV
prec_data->ichol_vals,
ia,
ja,
infoL,
x,//input
prec_data->aux_vec1, //output
policy,
ichol_buffer);
/* solve L'*y = aux_vec1 */
cusparseDcsrsv2_solve(handle_cusparse,
CUSPARSE_OPERATION_TRANSPOSE,
prec_data->n,
nnzA, &one,
descrL, // replace with cusparseSpSV
prec_data->ichol_vals,
ia,
ja,
infoLt,
prec_data->aux_vec1,
y,
policy,
ichol_buffer);
#else //sp
cusparseScsrsv2_solve(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
prec_data->n,
nnzA,
&one,
descrL, // replace with cusparseSpSV
prec_data->ichol_vals,
ia,
ja,
infoL,
x,//input
prec_data->aux_vec1, //output
policy,
ichol_buffer);
/* solve L'*y = aux_vec1 */
cusparseScsrsv2_solve(handle_cusparse,
CUSPARSE_OPERATION_TRANSPOSE,
prec_data->n,
nnzA, &one,
descrL, // replace with cusparseSpSV
prec_data->ichol_vals,
ia,
ja,
infoLt,
prec_data->aux_vec1,
y,
policy,
ichol_buffer);
#endif
}
__global__ void cuda_vec_vec_kernel(const int n,
const real_type *x,
const real_type *y,
real_type *z){
int idx = blockIdx.x * blockDim.x + threadIdx.x;
while (idx < n){
z[idx] = x[idx]*y[idx];
idx += blockDim.x * gridDim.x;
}
}
__global__ void cuda_vec_reciprocal_kernel(const int n,
const real_type *x,
real_type *z){
int idx = blockIdx.x * blockDim.x + threadIdx.x;
while (idx < n){
if (x[idx] != 0.0 ){
z[idx] = 1.0/x[idx];
} else {
z[idx] = 0.0;
}
idx += blockDim.x * gridDim.x;
}
}
__global__ void cuda_vec_sqrt_kernel(const int n,
const real_type *x,
real_type *z){
int idx = blockIdx.x * blockDim.x + threadIdx.x;
while (idx < n){
if (x[idx]>0) {
z[idx] = sqrt(x[idx]);
} else {
z[idx] = 0.0;
}
idx += blockDim.x * gridDim.x;
}
}
__global__ void cuda_vec_zero_kernel(const int n,
real_type *x){
int idx = blockIdx.x * blockDim.x + threadIdx.x;
while (idx < n){
x[idx] = 0.0;
idx += blockDim.x * gridDim.x;
}
}
real_type cuda_dot (const int n, const real_type *v, const real_type *w){
real_type sum;
cublasStatus_t status;
#if USE_FP64
status = cublasDdot (handle_cublas,
n,
v,
1,
w,
1,
&sum);
#else
status = cublasSdot (handle_cublas,
n,
v,
1,
w,
1,
&sum);
#endif
//printf("DOT product status %d\n", status);
return sum;
}
void cuda_scal (const int n, const real_type alpha, real_type *v){
#if USE_FP64
cublasDscal(handle_cublas,
n,
&alpha,
v,
1);
#else
cublasSscal(handle_cublas,
n,
&alpha,
v,
1);
#endif
}
void cuda_axpy (const int n, const real_type alpha, const real_type *x, real_type *y){
cublasStatus_t status;
#if USE_FP64
status = cublasDaxpy(handle_cublas,
n,
&alpha,
x,
1,
y,
1);
#else
status = cublasSaxpy(handle_cublas,
n,
&alpha,
x,
1,
y,
1);
#endif
}
void cuda_csr_matvec(const int n, const int nnz, const int *ia, const int *ja, const real_type *a, const real_type *x, real_type *result, const real_type*al, const real_type *bet){
/* y = alpha *A* x + beta * y */
cusparseDnVecDescr_t vecX;
cusparseDnVecDescr_t vecY;
cusparseSpMatDescr_t matCSR;
cusparseCreateDnVec(&vecX,
n,
(void*) x,
cuda_data_type);
cusparseCreateDnVec(&vecY,
n,
(void *) result,
cuda_data_type);
cusparseStatus_t status_cusparse;
status_cusparse = cusparseCreateCsr(&matCSR,
n,
n,
nnz,
(void *)ia,
(void *)ja,
(void *)a,
CUSPARSE_INDEX_32I,
CUSPARSE_INDEX_32I,
CUSPARSE_INDEX_BASE_ZERO,
cuda_data_type);
// printf("before matvec: input^Tinput %5.16e, output^Toutput %5.16e alpha %f beta %f\n", cuda_dot(n, x,x), cuda_dot(n, result, result), *al, *bet);
status_cusparse = cusparseSpMV(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
al,
matCSR,
vecX,
bet,
vecY,
cuda_data_type,
#if V100
CUSPARSE_CSRMV_ALG2,
#else
CUSPARSE_SPMV_CSR_ALG2,
#endif
mv_buffer);
// printf("matvec status: %d is MV BUFFER NULL? %d is matA null? %d\n", status_cusparse, mv_buffer == NULL, matA==NULL);
// printf("after matvec: input^Tinput %5.16e, output^Toutput %5.16e\n", cuda_dot(n, x,x), cuda_dot(n,result, result));
cusparseDestroySpMat(matCSR);
cusparseDestroyDnVec(vecX);
cusparseDestroyDnVec(vecY);
}
void cuda_lower_triangular_solve(const int n,
const int nnzL,
const int *lia,
const int *lja,
const real_type *la,
const real_type *diagonal,
const real_type *x, real_type *result){
/* compute result = L^{-1}x */
/* we DO NOT assume anything about L diagonal */
/* d_x3 = L^(-1)dx2 */
real_type one = 1.0;
#if USE_FP64
cusparseStatus_t status = cusparseDcsrsv2_solve(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzL,
&one,
descrL,
la,
lia,
lja,
infoL,
x,
result,
policy,
L_buffer);
//printf("status after tri solve is %d \n", status);
#else
cusparseStatus_t status = cusparseScsrsv2_solve(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzL,
&one,
descrL,
la,
lia,
lja,
infoL,
x,
result,
policy,
L_buffer);
#endif
}
void cuda_upper_triangular_solve(const int n,
const int nnzU,
const int *uia,
const int *uja,
const real_type *ua,
const real_type *diagonal,
const real_type *x,
real_type *result){
/* compute result = U^{-1}x */
real_type one = 1.0;
#if USE_FP64
cusparseDcsrsv2_solve(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzU,
&one,
descrU,
ua,
uia,
uja,
infoU,
x,
result,
policy,
U_buffer);
#else
cusparseScsrsv2_solve(handle_cusparse,
CUSPARSE_OPERATION_NON_TRANSPOSE,
n,
nnzU,
&one,
descrU,
ua,
uia,
uja,
infoU,
x,
result,
policy,
U_buffer);
#endif
}
/* not std blas but needed and embarassingly parallel */
/* cuda vec-vec computes an element-wise product (needed for scaling) */
void cuda_vec_vec(const int n, const real_type *x, const real_type *y, real_type *res){
cuda_vec_vec_kernel<<<1024, 1024>>>(n, x, y, res);
}
/* vector reciprocal computes 1./d */
void cuda_vector_reciprocal(const int n, const real_type *v, real_type *res){
cuda_vec_reciprocal_kernel<<<1024, 1024>>>(n, v, res);
}
/* vector sqrt takes an sqrt from each vector entry */
void cuda_vector_sqrt(const int n, const real_type *v, real_type *res){
cuda_vec_sqrt_kernel<<<1024, 1024>>>(n, v, res);
}
void cuda_vec_copy(const int n, const real_type *src, real_type *dest){
cudaMemcpy(dest, src, sizeof(real_type) * n, cudaMemcpyDeviceToDevice);
}
void cuda_vec_zero(const int n, real_type *vec){
cuda_vec_zero_kernel<<<1024, 1024>>>(n, vec);
}