@@ -509,6 +509,143 @@ for (celty, elty) in ((:ComplexF32, :Float32), (:ComplexF64, :Float64), (:Comple
509509 end
510510end
511511
512+ for (jname, bname, fname, elty, relty) in
513+ ((:heevj_batched! , :cusolverDnSsyevjBatched_bufferSize , :cusolverDnSsyevjBatched ,
514+ :Float32 , :Float32 ),
515+ (:heevj_batched! , :cusolverDnDsyevjBatched_bufferSize , :cusolverDnDsyevjBatched ,
516+ :Float64 , :Float64 ),
517+ (:heevj_batched! , :cusolverDnCheevjBatched_bufferSize , :cusolverDnCheevjBatched ,
518+ :ComplexF32 , :Float32 ),
519+ (:heevj_batched! , :cusolverDnZheevjBatched_bufferSize , :cusolverDnZheevjBatched ,
520+ :ComplexF64 , :Float64 ))
521+ @eval begin
522+ function $jname (A:: StridedCuArray{$elty, 3} ,
523+ W:: StridedCuMatrix{$relty} = CuMatrix {$relty} (undef, size (A, 2 ), size (A, 3 )),
524+ V:: StridedCuArray{$elty, 3} = CuArray {$elty, 3} (undef, size (A)... );
525+ check:: Bool = CHECK_LIBRARY_CALLS[],
526+ uplo:: Char = ' U' ,
527+ tol:: $relty = eps ($ relty),
528+ max_sweeps:: Int = 100 )
529+ # Set up information for the solver arguments
530+ chkuplo (uplo)
531+ m, n, batch_size = size (A)
532+ m == n || throw (DimensionMismatch (" A must be square in its leading two dimensions" ))
533+ size (V) == size (A) || size (V) == (0 , 0 , batch_size) || throw (DimensionMismatch (" size mismatch between A and V" ))
534+ lda = max (1 , stride (A, 2 ))
535+ n == size (W, 1 ) || throw (DimensionMismatch (" size mismatch between A and W" ))
536+ batch_size == size (W, 2 ) || throw (DimensionMismatch (" batch size mismatch between A and W" ))
537+ if length (V) == 0
538+ jobz = ' N'
539+ else
540+ jobz = ' V'
541+ end
542+ params = Ref {cuSOLVER.syevjInfo_t} (C_NULL )
543+
544+ dh = cuSOLVER. dense_handle ()
545+ resize! (dh. info, batch_size)
546+
547+ # Initialize the solver parameters
548+ cuSOLVER. cusolverDnCreateSyevjInfo (params)
549+ cuSOLVER. cusolverDnXsyevjSetTolerance (params[], tol)
550+ cuSOLVER. cusolverDnXsyevjSetMaxSweeps (params[], max_sweeps)
551+
552+ # Calculate the workspace size
553+ function bufferSize ()
554+ out = Ref {Cint} (0 )
555+ cuSOLVER.$ bname (dh, jobz, uplo, n, A, lda, W, out, params[], batch_size)
556+ return out[] * sizeof ($ elty)
557+ end
558+
559+ # Run the solver
560+ with_workspace (dh. workspace_gpu, bufferSize) do buffer
561+ return cuSOLVER.$ fname (dh, jobz, uplo, n, A, lda, W, buffer,
562+ sizeof (buffer) ÷ sizeof ($ elty), dh. info, params[], batch_size)
563+ end
564+
565+ if check
566+ # Copy the solver info and delete the device memory
567+ info = collect (dh. info)
568+
569+ # Double check the solver's exit status
570+ foreach (chkargsok ∘ BlasInt, info)
571+ end
572+ cuSOLVER. cusolverDnDestroySyevjInfo (params[])
573+
574+ # Return eigenvalues (in W) and possibly eigenvectors (in V)
575+ if jobz == ' N'
576+ return W
577+ elseif jobz == ' V'
578+ if V != = A
579+ copy! (V, A)
580+ end
581+ return W, V
582+ end
583+ end
584+ end
585+ end
586+
587+ function heev_batched! (A:: StridedCuArray{T, 3} ,
588+ W:: StridedCuMatrix{Tr} = CuMatrix {Tr} (undef, size (A, 2 ), size (A, 3 )),
589+ V:: StridedCuArray{T, 3} = CuArray {T, 3} (undef, size (A)... );
590+ check:: Bool = CHECK_LIBRARY_CALLS[],
591+ uplo:: Char = ' U' ,
592+ ) where {T <: BlasFloat , Tr <: BlasReal }
593+ # Set up information for the solver arguments
594+ chkuplo (uplo)
595+ m, n, batch_size = size (A)
596+ m == n || throw (DimensionMismatch (" A must be square in its leading two dimensions" ))
597+ size (V) == size (A) || size (V) == (0 , 0 , batch_size) || throw (DimensionMismatch (" size mismatch between A and V" ))
598+ lda = max (1 , stride (A, 2 ))
599+ n == size (W, 1 ) || throw (DimensionMismatch (" size mismatch between A and W" ))
600+ batch_size == size (W, 2 ) || throw (DimensionMismatch (" batch size mismatch between A and W" ))
601+ if length (V) == 0
602+ jobz = ' N'
603+ else
604+ jobz = ' V'
605+ end
606+
607+ dh = cuSOLVER. dense_handle ()
608+ resize! (dh. info, batch_size)
609+ params = cuSOLVER. CuSolverParameters ()
610+
611+ # Calculate the workspace size
612+ function bufferSize ()
613+ out_cpu = Ref {Csize_t} (0 )
614+ out_gpu = Ref {Csize_t} (0 )
615+ cuSOLVER. cusolverDnXsyevBatched_bufferSize (dh, params, jobz, uplo, n, T, A, lda,
616+ Tr, W, T, out_gpu, out_cpu, batch_size)
617+ return out_gpu[], out_cpu[]
618+ end
619+
620+ # Run the solver
621+ cuSOLVER. with_workspaces (
622+ dh. workspace_gpu, dh. workspace_cpu,
623+ bufferSize ()...
624+ ) do buffer_gpu, buffer_cpu
625+ return cuSOLVER. cusolverDnXsyevBatched (dh, jobz, uplo, n, T, A, lda, Tr, W, T,
626+ buffer_gpu, sizeof (buffer_gpu), buffer_cpu,
627+ sizeof (buffer_cpu), dh. info, batch_size)
628+ end
629+
630+ if check
631+ # Copy the solver info and delete the device memory
632+ info = collect (dh. info)
633+
634+ # Double check the solver's exit status
635+ foreach (chkargsok ∘ BlasInt, info)
636+ end
637+
638+ if jobz == ' V' && V != = A
639+ copy! (V, A)
640+ end
641+ # Return eigenvalues (in W) and possibly eigenvectors (in V)
642+ if jobz == ' N'
643+ return W
644+ elseif jobz == ' V'
645+ return W, V
646+ end
647+ end
648+
512649# for (jname, bname, fname, elty, relty) in
513650# ((:sygvd!, :cusolverDnSsygvd_bufferSize, :cusolverDnSsygvd, :Float32, :Float32),
514651# (:sygvd!, :cusolverDnDsygvd_bufferSize, :cusolverDnDsygvd, :Float64, :Float64),
612749# end
613750# end
614751
615- # for (jname, bname, fname, elty, relty) in
616- # ((:syevjBatched!, :cusolverDnSsyevjBatched_bufferSize, :cusolverDnSsyevjBatched,
617- # :Float32, :Float32),
618- # (:syevjBatched!, :cusolverDnDsyevjBatched_bufferSize, :cusolverDnDsyevjBatched,
619- # :Float64, :Float64),
620- # (:heevjBatched!, :cusolverDnCheevjBatched_bufferSize, :cusolverDnCheevjBatched,
621- # :ComplexF32, :Float32),
622- # (:heevjBatched!, :cusolverDnZheevjBatched_bufferSize, :cusolverDnZheevjBatched,
623- # :ComplexF64, :Float64))
624- # @eval begin
625- # function $jname(jobz::Char,
626- # uplo::Char,
627- # A::StridedCuArray{$elty};
628- # check::Bool = CHECK_LIBRARY_CALLS[],
629- # tol::$relty=eps($relty),
630- # max_sweeps::Int=100)
631-
632- # # Set up information for the solver arguments
633- # chkuplo(uplo)
634- # n = checksquare(A)
635- # lda = max(1, stride(A, 2))
636- # batchSize = size(A, 3)
637- # W = CuArray{$relty}(undef, n, batchSize)
638- # params = Ref{syevjInfo_t}(C_NULL)
639-
640- # dh = dense_handle()
641- # resize!(dh.info, batchSize)
642-
643- # # Initialize the solver parameters
644- # cusolverDnCreateSyevjInfo(params)
645- # cusolverDnXsyevjSetTolerance(params[], tol)
646- # cusolverDnXsyevjSetMaxSweeps(params[], max_sweeps)
647-
648- # # Calculate the workspace size
649- # function bufferSize()
650- # out = Ref{Cint}(0)
651- # $bname(dh, jobz, uplo, n, A, lda, W, out, params[], batchSize)
652- # return out[] * sizeof($elty)
653- # end
654-
655- # # Run the solver
656- # with_workspace(dh.workspace_gpu, bufferSize) do buffer
657- # return $fname(dh, jobz, uplo, n, A, lda, W, buffer,
658- # sizeof(buffer) ÷ sizeof($elty), dh.info, params[], batchSize)
659- # end
660-
661- # if check
662- # # Copy the solver info and delete the device memory
663- # info = collect(dh.info)
664-
665- # # Double check the solver's exit status
666- # for i in 1:batchSize
667- # chkargsok(BlasInt(info[i]))
668- # end
669- # end
670- # cusolverDnDestroySyevjInfo(params[])
671-
672- # # Return eigenvalues (in W) and possibly eigenvectors (in A)
673- # if jobz == 'N'
674- # return W
675- # elseif jobz == 'V'
676- # return W, A
677- # end
678- # end
679- # end
680- # end
681752
682753# for (fname, elty) in ((:cusolverDnSpotrsBatched, :Float32),
683754# (:cusolverDnDpotrsBatched, :Float64),
@@ -704,15 +775,15 @@ end
704775# end
705776# lda = max(1, stride(A[1], 2))
706777# ldb = max(1, stride(B[1], 2))
707- # batchSize = length(A)
778+ # batch_size = length(A)
708779
709780# Aptrs = unsafe_batch(A)
710781# Bptrs = unsafe_batch(B)
711782
712783# dh = dense_handle()
713784
714785# # Run the solver
715- # $fname(dh, uplo, n, nrhs, Aptrs, lda, Bptrs, ldb, dh.info, batchSize )
786+ # $fname(dh, uplo, n, nrhs, Aptrs, lda, Bptrs, ldb, dh.info, batch_size )
716787
717788# if check
718789# # Copy the solver info and delete the device memory
@@ -735,22 +806,22 @@ end
735806# chkuplo(uplo)
736807# n = checksquare(A[1])
737808# lda = max(1, stride(A[1], 2))
738- # batchSize = length(A)
809+ # batch_size = length(A)
739810
740811# Aptrs = unsafe_batch(A)
741812
742813# dh = dense_handle()
743- # resize!(dh.info, batchSize )
814+ # resize!(dh.info, batch_size )
744815
745816# # Run the solver
746- # $fname(dh, uplo, n, Aptrs, lda, dh.info, batchSize )
817+ # $fname(dh, uplo, n, Aptrs, lda, dh.info, batch_size )
747818
748819# if check
749820# # Copy the solver info and delete the device memory
750821# info = collect(dh.info)
751822
752823# # Double check the solver's exit status
753- # for i in 1:batchSize
824+ # for i in 1:batch_size
754825# chkargsok(BlasInt(info[i]))
755826# end
756827# end
0 commit comments