Repository navigation
Expand file tree
/
Copy pathlevel1.go
More file actions
858 lines (734 loc) · 28.1 KB
/
Copy pathlevel1.go
File metadata and controls
858 lines (734 loc) · 28.1 KB
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
854
855
856
857
858
package cublas
/*
#include <cublas_v2.h>
*/
import "C"
import (
"unsafe"
"github.com/gocnn/gocu/cudart"
"github.com/gocnn/gomat/blas"
)
// Isamax finds the index of the element with maximum absolute value in a single precision real vector.
// Returns the 1-based index of the element with maximum absolute value.
func Isamax(h *Handle, n int, x cudart.DevicePtr, incX int) (int, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.int
err := Check(C.cublasIsamax(C.cublasHandle_t(h.h), C.int(n), (*C.float)(x), C.int(incX), &result))
return int(result), err
}
// Idamax finds the index of the element with maximum absolute value in a double precision real vector.
// Returns the 1-based index of the element with maximum absolute value.
func Idamax(h *Handle, n int, x cudart.DevicePtr, incX int) (int, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.int
err := Check(C.cublasIdamax(C.cublasHandle_t(h.h), C.int(n), (*C.double)(x), C.int(incX), &result))
return int(result), err
}
// Icamax finds the index of the element with maximum absolute value in a single precision complex vector.
// Returns the 1-based index of the element with maximum absolute value.
func Icamax(h *Handle, n int, x cudart.DevicePtr, incX int) (int, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.int
err := Check(C.cublasIcamax(C.cublasHandle_t(h.h), C.int(n), (*C.cuComplex)(x), C.int(incX), &result))
return int(result), err
}
// Izamax finds the index of the element with maximum absolute value in a double precision complex vector.
// Returns the 1-based index of the element with maximum absolute value.
func Izamax(h *Handle, n int, x cudart.DevicePtr, incX int) (int, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.int
err := Check(C.cublasIzamax(C.cublasHandle_t(h.h), C.int(n), (*C.cuDoubleComplex)(x), C.int(incX), &result))
return int(result), err
}
// Isamin finds the index of the element with minimum absolute value in a single precision real vector.
// Returns the 1-based index of the element with minimum absolute value.
func Isamin(h *Handle, n int, x cudart.DevicePtr, incX int) (int, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.int
err := Check(C.cublasIsamin(C.cublasHandle_t(h.h), C.int(n), (*C.float)(x), C.int(incX), &result))
return int(result), err
}
// Idamin finds the index of the element with minimum absolute value in a double precision real vector.
// Returns the 1-based index of the element with minimum absolute value.
func Idamin(h *Handle, n int, x cudart.DevicePtr, incX int) (int, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.int
err := Check(C.cublasIdamin(C.cublasHandle_t(h.h), C.int(n), (*C.double)(x), C.int(incX), &result))
return int(result), err
}
// Icamin finds the index of the element with minimum absolute value in a single precision complex vector.
// Returns the 1-based index of the element with minimum absolute value.
func Icamin(h *Handle, n int, x cudart.DevicePtr, incX int) (int, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.int
err := Check(C.cublasIcamin(C.cublasHandle_t(h.h), C.int(n), (*C.cuComplex)(x), C.int(incX), &result))
return int(result), err
}
// Izamin finds the index of the element with minimum absolute value in a double precision complex vector.
// Returns the 1-based index of the element with minimum absolute value.
func Izamin(h *Handle, n int, x cudart.DevicePtr, incX int) (int, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.int
err := Check(C.cublasIzamin(C.cublasHandle_t(h.h), C.int(n), (*C.cuDoubleComplex)(x), C.int(incX), &result))
return int(result), err
}
// Sasum computes the sum of the absolute values of elements in a single precision real vector.
// Returns the sum of absolute values of the vector elements.
func Sasum(h *Handle, n int, x cudart.DevicePtr, incX int) (float32, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.float
err := Check(C.cublasSasum(C.cublasHandle_t(h.h), C.int(n), (*C.float)(x), C.int(incX), &result))
return float32(result), err
}
// Dasum computes the sum of the absolute values of elements in a double precision real vector.
// Returns the sum of absolute values of the vector elements.
func Dasum(h *Handle, n int, x cudart.DevicePtr, incX int) (float64, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.double
err := Check(C.cublasDasum(C.cublasHandle_t(h.h), C.int(n), (*C.double)(x), C.int(incX), &result))
return float64(result), err
}
// Scasum computes the sum of the absolute values of elements in a single precision complex vector.
// Returns the sum of absolute values of the vector elements as a real number.
func Scasum(h *Handle, n int, x cudart.DevicePtr, incX int) (float32, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.float
err := Check(C.cublasScasum(C.cublasHandle_t(h.h), C.int(n), (*C.cuComplex)(x), C.int(incX), &result))
return float32(result), err
}
// Dzasum computes the sum of the absolute values of eleme
8000
nts in a double precision complex vector.
// Returns the sum of absolute values of the vector elements as a real number.
func Dzasum(h *Handle, n int, x cudart.DevicePtr, incX int) (float64, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.double
err := Check(C.cublasDzasum(C.cublasHandle_t(h.h), C.int(n), (*C.cuDoubleComplex)(x), C.int(incX), &result))
return float64(result), err
}
// Saxpy performs the vector operation y = alpha*x + y for single precision real vectors.
// The vectors x and y must have at least n elements with the given increments.
func Saxpy(h *Handle, n int, alpha float32, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasSaxpy(C.cublasHandle_t(h.h), C.int(n), (*C.float)(&alpha), (*C.float)(x), C.int(incX), (*C.float)(y), C.int(incY)))
}
// Daxpy performs the vector operation y = alpha*x + y for double precision real vectors.
// The vectors x and y must have at least n elements with the given increments.
func Daxpy(h *Handle, n int, alpha float64, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasDaxpy(C.cublasHandle_t(h.h), C.int(n), (*C.double)(&alpha), (*C.double)(x), C.int(incX), (*C.double)(y), C.int(incY)))
}
// Caxpy performs the vector operation y = alpha*x + y for single precision complex vectors.
// The vectors x and y must have at least n elements with the given increments.
func Caxpy(h *Handle, n int, alpha complex64, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasCaxpy(C.cublasHandle_t(h.h), C.int(n), (*C.cuComplex)(unsafe.Pointer(&alpha)), (*C.cuComplex)(x), C.int(incX), (*C.cuComplex)(y), C.int(incY)))
}
// Zaxpy performs the vector operation y = alpha*x + y for double precision complex vectors.
// The vectors x and y must have at least n elements with the given increments.
func Zaxpy(h *Handle, n int, alpha complex128, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasZaxpy(C.cublasHandle_t(h.h), C.int(n), (*C.cuDoubleComplex)(unsafe.Pointer(&alpha)), (*C.cuDoubleComplex)(x), C.int(incX), (*C.cuDoubleComplex)(y), C.int(incY)))
}
// Scopy copies a single precision real vector x to vector y.
// The vectors x and y must have at least n elements with the given increments.
func Scopy(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasScopy(C.cublasHandle_t(h.h), C.int(n), (*C.float)(x), C.int(incX), (*C.float)(y), C.int(incY)))
}
// Dcopy copies a double precision real vector x to vector y.
// The vectors x and y must have at least n elements with the given increments.
func Dcopy(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasDcopy(C.cublasHandle_t(h.h), C.int(n), (*C.double)(x), C.int(incX), (*C.double)(y), C.int(incY)))
}
// Ccopy copies a single precision complex vector x to vector y.
// The vectors x and y must have at least n elements with the given increments.
func Ccopy(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasCcopy(C.cublasHandle_t(h.h), C.int(n), (*C.cuComplex)(x), C.int(incX), (*C.cuComplex)(y), C.int(incY)))
}
// Zcopy copies a double precision complex vector x to vector y.
// The vectors x and y must have at least n elements with the given increments.
func Zcopy(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasZcopy(C.cublasHandle_t(h.h), C.int(n), (*C.cuDoubleComplex)(x), C.int(incX), (*C.cuDoubleComplex)(y), C.int(incY)))
}
// Sdot computes the dot product of two single precision real vectors.
// Returns the dot product x^T * y.
func Sdot(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) (float32, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
var result C.float
err := Check(C.cublasSdot(C.cublasHandle_t(h.h), C.int(n), (*C.float)(x), C.int(incX), (*C.float)(y), C.int(incY), &result))
return float32(result), err
}
// Ddot computes the dot product of two double precision real vectors.
// Returns the dot product x^T * y.
func Ddot(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) (float64, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
var result C.double
err := Check(C.cublasDdot(C.cublasHandle_t(h.h), C.int(n), (*C.double)(x), C.int(incX), (*C.double)(y), C.int(incY), &result))
return float64(result), err
}
// Cdotu computes the unconjugated dot product of two single precision complex vectors.
// Returns the dot product x^T * y (without conjugation).
func Cdotu(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) (complex64, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
var result complex64
err := Check(C.cublasCdotu(C.cublasHandle_t(h.h), C.int(n), (*C.cuComplex)(x), C.int(incX), (*C.cuComplex)(y), C.int(incY), (*C.cuComplex)(unsafe.Pointer(&result))))
return result, err
}
// Cdotc computes the conjugated dot product of two single precision complex vectors.
// Returns the dot product x^H * y (with conjugation of x).
func Cdotc(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) (complex64, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
var result complex64
err := Check(C.cublasCdotc(C.cublasHandle_t(h.h), C.int(n), (*C.cuComplex)(x), C.int(incX), (*C.cuComplex)(y), C.int(incY), (*C.cuComplex)(unsafe.Pointer(&result))))
return result, err
}
// Zdotu computes the unconjugated dot product of two double precision complex vectors.
// Returns the dot product x^T * y (without conjugation).
func Zdotu(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) (complex128, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
var result complex128
err := Check(C.cublasZdotu(C.cublasHandle_t(h.h), C.int(n), (*C.cuDoubleComplex)(x), C.int(incX), (*C.cuDoubleComplex)(y), C.int(incY), (*C.cuDoubleComplex)(unsafe.Pointer(&result))))
return result, err
}
// Zdotc computes the conjugated dot product of two double precision complex vectors.
// Returns the dot product x^H * y (with conjugation of x).
func Zdotc(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) (complex128, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
var result complex128
err := Check(C.cublasZdotc(C.cublasHandle_t(h.h), C.int(n), (*C.cuDoubleComplex)(x), C.int(incX), (*C.cuDoubleComplex)(y), C.int(incY), (*C.cuDoubleComplex)(unsafe.Pointer(&result))))
return result, err
}
// Snrm2 computes the Euclidean norm (2-norm) of a single precision real vector.
// Returns the 2-norm: sqrt(sum(x[i]^2)).
func Snrm2(h *Handle, n int, x cudart.DevicePtr, incX int) (float32, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.float
err := Check(C.cublasSnrm2(C.cublasHandle_t(h.h), C.int(n), (*C.float)(x), C.int(incX), &result))
return float32(result), err
}
// Dnrm2 computes the Euclidean norm (2-norm) of a double precision real vector.
// Returns the 2-norm: sqrt(sum(x[i]^2)).
func Dnrm2(h *Handle, n int, x cudart.DevicePtr, incX int) (float64, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.double
err := Check(C.cublasDnrm2(C.cublasHandle_t(h.h), C.int(n), (*C.double)(x), C.int(incX), &result))
return float64(result), err
}
// Scnrm2 computes the Euclidean norm (2-norm) of a single precision complex vector.
// Returns the 2-norm: sqrt(sum(|x[i]|^2)) as a real number.
func Scnrm2(h *Handle, n int, x cudart.DevicePtr, incX int) (float32, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.float
err := Check(C.cublasScnrm2(C.cublasHandle_t(h.h), C.int(n), (*C.cuComplex)(x), C.int(incX), &result))
return float32(result), err
}
// Dznrm2 computes the Euclidean norm (2-norm) of a double precision complex vector.
// Returns the 2-norm: sqrt(sum(|x[i]|^2)) as a real number.
func Dznrm2(h *Handle, n int, x cudart.DevicePtr, incX int) (float64, error) {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
var result C.double
err := Check(C.cublasDznrm2(C.cublasHandle_t(h.h), C.int(n), (*C.cuDoubleComplex)(x), C.int(incX), &result))
return float64(result), err
}
// Srot applies a Givens rotation to single precision real vectors x and y.
// Performs the transformation: x[i] = c*x[i] + s*y[i], y[i] = c*y[i] - s*x[i].
func Srot(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int, c, s float32) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasSrot(C.cublasHandle_t(h.h), C.int(n), (*C.float)(x), C.int(incX), (*C.float)(y), C.int(incY), (*C.float)(&c), (*C.float)(&s)))
}
// Drot applies a Givens rotation to double precision real vectors x and y.
// Performs the transformation: x[i] = c*x[i] + s*y[i], y[i] = c*y[i] - s*x[i].
func Drot(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int, c, s float64) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasDrot(C.cublasHandle_t(h.h), C.int(n), (*C.double)(x), C.int(incX), (*C.double)(y), C.int(incY), (*C.double)(&c), (*C.double)(&s)))
}
// Crot applies a Givens rotation to single precision complex vectors x and y.
// Performs the transformation: x[i] = c*x[i] + s*y[i], y[i] = c*y[i] - conj(s)*x[i].
func Crot(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int, c float32, s complex64) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasCrot(C.cublasHandle_t(h.h), C.int(n), (*C.cuComplex)(x), C.int(incX), (*C.cuComplex)(y), C.int(incY), (*C.float)(&c), (*C.cuComplex)(unsafe.Pointer(&s))))
}
// Csrot applies a real Givens rotation to single precision complex vectors x and y.
// Performs the transformation: x[i] = c*x[i] + s*y[i], y[i] = c*y[i] - s*x[i].
func Csrot(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int, c, s float32) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasCsrot(C.cublasHandle_t(h.h), C.int(n), (*C.cuComplex)(x), C.int(incX), (*C.cuComplex)(y), C.int(incY), (*C.float)(&c), (*C.float)(&s)))
}
// Zrot applies a Givens rotation to double precision complex vectors x and y.
// Performs the transformation: x[i] = c*x[i] + s*y[i], y[i] = c*y[i] - conj(s)*x[i].
func Zrot(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int, c float64, s complex128) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasZrot(C.cublasHandle_t(h.h), C.int(n), (*C.cuDoubleComplex)(x), C.int(incX), (*C.cuDoubleComplex)(y), C.int(incY), (*C.double)(&c), (*C.cuDoubleComplex)(unsafe.Pointer(&s))))
}
// Zdrot applies a real Givens rotation to double precision complex vectors x and y.
// Performs the transformation: x[i] = c*x[i] + s*y[i], y[i] = c*y[i] - s*x[i].
func Zdrot(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int, c, s float64) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasZdrot(C.cublasHandle_t(h.h), C.int(n), (*C.cuDoubleComplex)(x), C.int(incX), (*C.cuDoubleComplex)(y), C.int(incY), (*C.double)(&c), (*C.double)(&s)))
}
// Srotg generates the parameters for a Givens rotation matrix for single precision real values.
// Given input values a and b, computes c, s, and r such that:
// [c s] [a] = [r]
// [-s c] [b] [0]
// The function modifies a to contain r, and b to contain z (reconstruction parameter).
func Srotg(h *Handle, a, b float32) (c, s float32, err error) {
err = Check(C.cublasSrotg(C.cublasHandle_t(h.h), (*C.float)(&a), (*C.float)(&b), (*C.float)(&c), (*C.float)(&s)))
return c, s, err
}
// Drotg generates the parameters for a Givens rotation matrix for double precision real values.
// Given input values a and b, computes c, s, and r such that:
// [c s] [a] = [r]
// [-s c] [b] [0]
// The function modifies a to contain r, and b to contain z (reconstruction parameter).
func Drotg(h *Handle, a, b float64) (c, s float64, err error) {
err = Check(C.cublasDrotg(C.cublasHandle_t(h.h), (*C.double)(&a), (*C.double)(&b), (*C.double)(&c), (*C.double)(&s)))
return c, s, err
}
// Crotg generates the parameters for a Givens rotation matrix for single precision complex values.
// Given input values a and b, computes c, s, and r such that:
// [c s] [a] = [r]
// [-conj(s) c] [b] [0]
// The function modifies a to contain r, and b to contain z (reconstruction parameter).
func Crotg(h *Handle, a, b complex64) (c float32, s complex64, err error) {
err = Check(C.cublasCrotg(C.cublasHandle_t(h.h), (*C.cuComplex)(unsafe.Pointer(&a)), (*C.cuComplex)(unsafe.Pointer(&b)), (*C.float)(&c), (*C.cuComplex)(unsafe.Pointer(&s))))
return c, s, err
}
// Zrotg generates the parameters for a Givens rotation matrix for double precision complex values.
// Given input values a and b, computes c, s, and r such that:
// [c s] [a] = [r]
// [-conj(s) c] [b] [0]
// The function modifies a to contain r, and b to contain z (reconstruction parameter).
func Zrotg(h *Handle, a, b complex128) (c float64, s complex128, err error) {
err = Check(C.cublasZrotg(C.cublasHandle_t(h.h), (*C.cuDoubleComplex)(unsafe.Pointer(&a)), (*C.cuDoubleComplex)(unsafe.Pointer(&b)), (*C.double)(&c), (*C.cuDoubleComplex)(unsafe.Pointer(&s))))
return c, s, err
}
// Srotm applies a modified Givens rotation to single precision real vectors x and y.
// The rotation is defined by the param array which contains the rotation parameters.
// param[0] contains the flag indicating the form of the H matrix:
//
// -1.0: H has the form [[H11, H12], [H21, H22]]
// 0.0: H has the form [[1.0, H12], [H21, 1.0]]
// 1.0: H has the form [[H11, 1.0], [-1.0, H22]]
// -2.0: H is the identity matrix
func Srotm(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int, p SrotmParams) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasSrotm(C.cublasHandle_t(h.h), C.int(n), (*C.float)(x), C.int(incX), (*C.float)(y), C.int(incY), (*C.float)(unsafe.Pointer(&p))))
}
// Drotm applies a modified Givens rotation to double precision real vectors x and y.
// The rotation is defined by the param array which contains the rotation parameters.
// param[0] contains the flag indicating the form of the H matrix:
//
// -1.0: H has the form [[H11, H12], [H21, H22]]
// 0.0: H has the form [[1.0, H12], [H21, 1.0]]
// 1.0: H has the form [[H11, 1.0], [-1.0, H22]]
// -2.0: H is the identity matrix
func Drotm(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int, p DrotmParams) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasDrotm(C.cublasHandle_t(h.h), C.int(n), (*C.double)(x), C.int(incX), (*C.double)(y), C.int(incY), (*C.double)(unsafe.Pointer(&p))))
}
// Srotmg generates the parameters for a modified Givens rotation matrix for single precision real values.
// Given input values d1, d2, x1, and y1, computes the modified Givens rotation matrix H
// and the parameters stored in the param array. The function modifies d1, d2, and x1.
// param[0] contains the flag indicating the form of the H matrix:
//
// -1.0: H has the form [[H11, H12], [H21, H22]]
// 0.0: H has the form [[1.0, H12], [H21, 1.0]]
// 1.0: H has the form [[H11, 1.0], [-1.0, H22]]
// -2.0: H is the identity matrix
func Srotmg(h *Handle, d1, d2, x1, y1 float32) (p SrotmParams, err error) {
err = Check(C.cublasSrotmg(C.cublasHandle_t(h.h), (*C.float)(&d1), (*C.float)(&d2), (*C.float)(&x1), (*C.float)(&y1), (*C.float)(unsafe.Pointer(&p))))
return p, err
}
// Drotmg generates the parameters for a modified Givens rotation matrix for double precision real values.
// Given input values d1, d2, x1, and y1, computes the modified Givens rotation matrix H
// and the parameters stored in the param array. The function modifies d1, d2, and x1.
// param[0] contains the flag indicating the form of the H matrix:
//
// -1.0: H has the form [[H11, H12], [H21, H22]]
// 0.0: H has the form [[1.0, H12], [H21, 1.0]]
// 1.0: H has the form [[H11, 1.0], [-1.0, H22]]
// -2.0: H is the identity matrix
func Drotmg(h *Handle, d1, d2, x1, y1 float64) (p DrotmParams, err error) {
err = Check(C.cublasDrotmg(C.cublasHandle_t(h.h), (*C.double)(&d1), (*C.double)(&d2), (*C.double)(&x1), (*C.double)(&y1), (*C.double)(unsafe.Pointer(&p))))
return p, err
}
// Sscal scales a single precision real vector by a scalar.
// Performs the operation: x = alpha * x.
func Sscal(h *Handle, n int, alpha float32, x cudart.DevicePtr, incX int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
return Check(C.cublasSscal(C.cublasHandle_t(h.h), C.int(n), (*C.float)(&alpha), (*C.float)(x), C.int(incX)))
}
// Dscal scales a double precision real vector by a scalar.
// Performs the operation: x = alpha * x.
func Dscal(h *Handle, n int, alpha float64, x cudart.DevicePtr, incX int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
return Check(C.cublasDscal(C.cublasHandle_t(h.h), C.int(n), (*C.double)(&alpha), (*C.double)(x), C.int(incX)))
}
// Cscal scales a single precision complex vector by a complex scalar.
// Performs the operation: x = alpha * x.
func Cscal(h *Handle, n int, alpha complex64, x cudart.DevicePtr, incX int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
return Check(C.cublasCscal(C.cublasHandle_t(h.h), C.int(n), (*C.cuComplex)(unsafe.Pointer(&alpha)), (*C.cuComplex)(x), C.int(incX)))
}
// Csscal scales a single precision complex vector by a real scalar.
// Performs the operation: x = alpha * x (where alpha is real).
func Csscal(h *Handle, n int, alpha float32, x cudart.DevicePtr, incX int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
return Check(C.cublasCsscal(C.cublasHandle_t(h.h), C.int(n), (*C.float)(&alpha), (*C.cuComplex)(x), C.int(incX)))
}
// Zscal scales a double precision complex vector by a complex scalar.
// Performs the operation: x = alpha * x.
func Zscal(h *Handle, n int, alpha complex128, x cudart.DevicePtr, incX int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
return Check(C.cublasZscal(C.cublasHandle_t(h.h), C.int(n), (*C.cuDoubleComplex)(unsafe.Pointer(&alpha)), (*C.cuDoubleComplex)(x), C.int(incX)))
}
// Zdscal scales a double precision complex vector by a real scalar.
// Performs the operation: x = alpha * x (where alpha is real).
func Zdscal(h *Handle, n int, alpha float64, x cudart.DevicePtr, incX int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
return Check(C.cublasZdscal(C.cublasHandle_t(h.h), C.int(n), (*C.double)(&alpha), (*C.cuDoubleComplex)(x), C.int(incX)))
}
// Sswap swaps the elements of two single precision real vectors.
// Performs the operation: x <-> y (exchanges the contents of vectors x and y).
func Sswap(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasSswap(C.cublasHandle_t(h.h), C.int(n), (*C.float)(x), C.int(incX), (*C.float)(y), C.int(incY)))
}
// Dswap swaps the elements of two double precision real vectors.
// Performs the operation: x <-> y (exchanges the contents of vectors x and y).
func Dswap(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasDswap(C.cublasHandle_t(h.h), C.int(n), (*C.double)(x), C.int(incX), (*C.double)(y), C.int(incY)))
}
// Cswap swaps the elements of two single precision complex vectors.
// Performs the operation: x <-> y (exchanges the contents of vectors x and y).
func Cswap(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasCswap(C.cublasHandle_t(h.h), C.int(n), (*C.cuComplex)(x), C.int(incX), (*C.cuComplex)(y), C.int(incY)))
}
// Zswap swaps the elements of two double precision complex vectors.
// Performs the operation: x <-> y (exchanges the contents of vectors x and y).
func Zswap(h *Handle, n int, x cudart.DevicePtr, incX int, y cudart.DevicePtr, incY int) error {
if n < 0 {
panic(blas.ErrNLT0)
}
if incX == 0 {
panic(blas.ErrZeroIncX)
}
if incY == 0 {
panic(blas.ErrZeroIncY)
}
return Check(C.cublasZswap(C.cublasHandle_t(h.h), C.int(n), (*C.cuDoubleComplex)(x), C.int(incX), (*C.cuDoubleComplex)(y), C.int(incY)))
}