Skip to content

Commit

Permalink
c api test wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
RMeli committed Jun 17, 2024
1 parent 4c5ebe1 commit 09ae24c
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 0 deletions.
114 changes: 114 additions & 0 deletions include/dlaf_c/eigensolver/gen_eigensolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,52 @@ DLAF_EXTERN_C int dlaf_hermitian_generalized_eigensolver_z(
dlaf_complex_z* b, const struct DLAF_descriptor dlaf_descb, double* w, dlaf_complex_z* z,
const struct DLAF_descriptor dlaf_descz) DLAF_NOEXCEPT;

/// Generalized eigensolver
///
/// @pre The matrices \f$\mathbf{A}\f$, \f$\mathbf{B}\f$, and \f$\mathbf{Z}\f$ are assumed to be
/// distributed and in host memory. The vector of eigenvalues \f$\mathbf{w}\f$ is assumed to be local
/// (non-distributed) and in host memory. Moving to and from GPU memory is handled internally.
///
/// @pre The matrix \f$\mathbf{B}\f$ is assumed to be factorized; it is the result of a Cholesky
/// factorization
///
/// @post The pika runtime is resumed when this function is called and suspended when the call
/// terminates.
///
/// @param dlaf_context context associated to the DLA-Future grid created with @ref dlaf_create_grid
/// @param uplo indicates whether the upper ('U') or lower ('L') triangular part of the global submatrix
/// \f$\mathbf{A}\f$ is referenced
/// @param a Local part of the global matrix \f$\mathbf{A}\f$
/// @param dlaf_desca DLA-Future descriptor of the global matrix \f$\mathbf{A}\f$
/// @param b Local part of the Cholesky factorization of the global matrix \f$\mathbf{B}\f$
/// @param dlaf_descb DLA-Future descriptor of the global matrix \f$\mathbf{B}\f$
/// @param w Local vector of eigenvalues (non-distributed)
/// @param z Local part of the global matrix \f$\mathbf{Z}\f$
/// @param dlaf_descz DLA-Future descriptor of the global matrix \f$\mathbf{Z}\f$
/// @return 0 if the eigensolver completed normally
DLAF_EXTERN_C int dlaf_symmetric_generalized_eigensolver_factorized_s(
const int dlaf_context, const char uplo, float* a, const struct DLAF_descriptor dlaf_desca, float* b,
const struct DLAF_descriptor dlaf_descb, float* w, float* z,
const struct DLAF_descriptor dlaf_descz) DLAF_NOEXCEPT;

/// @copydoc dlaf_symmetric_generalized_eigensolver_factorized_s
DLAF_EXTERN_C int dlaf_symmetric_generalized_eigensolver_factorized_d(
const int dlaf_context, const char uplo, double* a, const struct DLAF_descriptor dlaf_desca,
double* b, const struct DLAF_descriptor dlaf_descb, double* w, double* z,
const struct DLAF_descriptor dlaf_descz) DLAF_NOEXCEPT;

/// @copydoc dlaf_symmetric_generalized_eigensolver_factorized_s
DLAF_EXTERN_C int dlaf_hermitian_generalized_eigensolver_factorized_c(
const int dlaf_context, const char uplo, dlaf_complex_c* a, const struct DLAF_descriptor dlaf_desca,
dlaf_complex_c* b, const struct DLAF_descriptor dlaf_descb, float* w, dlaf_complex_c* z,
const struct DLAF_descriptor dlaf_descz) DLAF_NOEXCEPT;

/// @copydoc dlaf_symmetric_generalized_eigensolver_factorized_s
DLAF_EXTERN_C int dlaf_hermitian_generalized_eigensolver_factorized_z(
const int dlaf_context, const char uplo, dlaf_complex_z* a, const struct DLAF_descriptor dlaf_desca,
dlaf_complex_z* b, const struct DLAF_descriptor dlaf_descb, double* w, dlaf_complex_z* z,
const struct DLAF_descriptor dlaf_descz) DLAF_NOEXCEPT;

#ifdef DLAF_WITH_SCALAPACK

/// Generalized eigensolver
Expand Down Expand Up @@ -121,4 +167,72 @@ DLAF_EXTERN_C void dlaf_pzhegvx(const char uplo, const int n, dlaf_complex_z* a,
const int jb, const int descb[9], double* w, dlaf_complex_z* z,
const int iz, const int jz, const int descz[9], int* info) DLAF_NOEXCEPT;

/// Generalized eigensolver
///
/// @remark This function is only available when DLAF_WITH_SCALAPACK=ON.
///
/// @pre The matrices \f$\mathbf{A}\f$, \f$\mathbf{B}\f$, and \f$\mathbf{Z}\f$ are assumed to be
/// distributed and in host memory. The vector of eigenvalues \f$\mathbf{w}\f$ is assumed to be local
/// (non-distributed) and in host memory. Moving to and from GPU memory is handled internally.
///
/// @pre The matrix \f$\mathbf{B}\f$ is assumed to be factorized; it is the result of a Cholesky
/// factorization
///
/// @pre Submatrices are currently not supported, so @p n is the size of the full matrices
/// \f$\mathbf{A}\f$, \f$\mathbf{B}\f$, and \f$\mathbf{Z}\f$ and @p ia, @p ja, @p ib, @p jb, @p iz, and
/// @p jz need to be 1.
///
/// @post The pika runtime is resumed when this function is called and suspended when the call
/// terminates.
///
/// @param uplo indicates whether the upper ('U') or lower ('L') triangular part of the global submatrix
/// \f$\mathbf{A}\f$ is referenced
/// @param n order of the sumbatrix \f$\mathbf{A}\f$ used in the computation
/// @param a Local part of the global matrix \f$\mathbf{A}\f$
/// @param ia row index of the global matrix \f$\mathbf{A}\f$ identifying the first row of the submatrix
/// $A$, has to be 1
/// @param ja column index of the global matrix \f$\mathbf{A}\f$ identifying the first column of the
/// submatrix \f$\mathbf{A}\f$, has to be 1
/// @param desca ScaLAPACK array descriptor of the global matrix \f$\mathbf{A}\f$
/// @param b Local part of the Cholesky factorization of the global matrix \f$\mathbf{B}\f$
/// @param ib row index of the global matrix \f$\mathbf{B}\f$ identifying the first row of the submatrix
/// \f$\mathbf{B}\f$, has to be 1
/// @param jb column index of the global matrix \f$\mathbf{A}\f$ identifying the first column of the
/// submatrix \f$\mathbf{B}\f$, has to be 1
/// @param descb ScaLAPACK array descriptor of the global matrix \f$\mathbf{B}\f$
/// @param w Local vector of eigenvalues (non-distributed)
/// @param z Local part of the global matrix \f$\mathbf{Z}\f$
/// @param iz row index of the global matrix \f$\mathbf{Z}\f$ identifying the first row of the submatrix
/// \f$\mathbf{Z}\f$, has to be 1
/// @param jz column index of the global matrix \f$\mathbf{A}\f$ identifying the first column of the
/// submatrix \f$\mathbf{A}\f$, has to be 1
/// @param descz ScaLAPACK array descriptor of the global matrix \f$\mathbf{Z}\f$
/// @param[out] info 0 if the eigensolver completed normally
DLAF_EXTERN_C void dlaf_pssygvx_factorized(const char uplo, const int n, float* a, const int ia,
const int ja, const int desca[9], float* b, const int ib,
const int jb, const int descb[9], float* w, float* z,
const int iz, const int jz, const int descz[9],
int* info) DLAF_NOEXCEPT;

/// @copydoc dlaf_pssygvx_factorized
DLAF_EXTERN_C void dlaf_pdsygvx_factorized(const char uplo, const int n, double* a, const int ia,
const int ja, const int desca[9], double* b, const int ib,
const int jb, const int descb[9], double* w, double* z,
const int iz, const int jz, const int descz[9],
int* info) DLAF_NOEXCEPT;

/// @copydoc dlaf_pssygvx_factorized
DLAF_EXTERN_C void dlaf_pchegvx_factorized(const char uplo, const int n, dlaf_complex_c* a, const int ia,
const int ja, const int desca[9], dlaf_complex_c* b,
const int ib, const int jb, const int descb[9], float* w,
dlaf_complex_c* z, const int iz, const int jz,
const int descz[9], int* info) DLAF_NOEXCEPT;

/// @copydoc dlaf_pssygvx_factorized
DLAF_EXTERN_C void dlaf_pzhegvx_factorized(const char uplo, const int n, dlaf_complex_z* a, const int ia,
const int ja, const int desca[9], dlaf_complex_z* b,
const int ib, const int jb, const int descb[9], double* w,
dlaf_complex_z* z, const int iz, const int jz,
const int descz[9], int* info) DLAF_NOEXCEPT;

#endif
56 changes: 56 additions & 0 deletions test/unit/c_api/eigensolver/test_gen_eigensolver_c_api_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,36 @@ int C_dlaf_hermitian_generalized_eigensolver_z(const int dlaf_context, const cha
return dlaf_hermitian_generalized_eigensolver_z(dlaf_context, uplo, a, desca, b, descb, w, z, descz);
}

int C_dlaf_symmetric_generalized_eigensolver_factorized_s(const int dlaf_context, const char uplo, float* a,
const struct DLAF_descriptor desca, float* b,
const struct DLAF_descriptor descb, float* w, float* z,
const struct DLAF_descriptor descz) {
return dlaf_symmetric_generalized_eigensolver_factorized_s(dlaf_context, uplo, a, desca, b, descb, w, z, descz);
}

int C_dlaf_symmetric_generalized_eigensolver_factorized_d(const int dlaf_context, const char uplo, double* a,
const struct DLAF_descriptor desca, double* b,
const struct DLAF_descriptor descb, double* w, double* z,
const struct DLAF_descriptor descz) {
return dlaf_symmetric_generalized_eigensolver_factorized_d(dlaf_context, uplo, a, desca, b, descb, w, z, descz);
}

int C_dlaf_hermitian_generalized_eigensolver_factorized_c(const int dlaf_context, const char uplo,
dlaf_complex_c* a, const struct DLAF_descriptor desca,
dlaf_complex_c* b, const struct DLAF_descriptor descb,
float* w, dlaf_complex_c* z,
const struct DLAF_descriptor descz) {
return dlaf_hermitian_generalized_eigensolver_factorized_c(dlaf_context, uplo, a, desca, b, descb, w, z, descz);
}

int C_dlaf_hermitian_generalized_eigensolver_factorized_z(const int dlaf_context, const char uplo,
dlaf_complex_z* a, const struct DLAF_descriptor desca,
dlaf_complex_z* b, const struct DLAF_descriptor descb,
double* w, dlaf_complex_z* z,
const struct DLAF_descriptor descz) {
return dlaf_hermitian_generalized_eigensolver_factorized_z(dlaf_context, uplo, a, desca, b, descb, w, z, descz);
}

#ifdef DLAF_WITH_SCALAPACK

void C_dlaf_pssygvx(char uplo, const int m, float* a, const int ia, const int ja, const int desca[9],
Expand Down Expand Up @@ -72,4 +102,30 @@ void C_dlaf_pzhegvx(const char uplo, const int m, dlaf_complex_z* a, const int i
dlaf_pzhegvx(uplo, m, a, ia, ja, desca, b, ib, jb, descb, w, z, iz, jz, descz, info);
}

void C_dlaf_pssygvx_factorized(char uplo, const int m, float* a, const int ia, const int ja, const int desca[9],
float* b, const int ib, const int jb, const int descb[9], float* w, float* z,
const int iz, const int jz, const int descz[9], int* info) {
dlaf_pssygvx(uplo, m, a, ia, ja, desca, b, ib, jb, descb, w, z, iz, jz, descz, info);
}

void C_dlaf_pdsygvx_factorized(const char uplo, const int m, double* a, const int ia, const int ja,
const int desca[9], double* b, const int ib, const int jb, const int descb[9],
double* w, double* z, const int iz, const int jz, const int descz[9], int* info) {
dlaf_pdsygvx_factorized(uplo, m, a, ia, ja, desca, b, ib, jb, descb, w, z, iz, jz, descz, info);
}

void C_dlaf_pchegvx_factorized(const char uplo, const int m, dlaf_complex_c* a, const int ia, const int ja,
const int desca[9], dlaf_complex_c* b, const int ib, const int jb,
const int descb[9], float* w, dlaf_complex_c* z, const int iz, const int jz,
const int descz[9], int* info) {
dlaf_pchegvx_factorized(uplo, m, a, ia, ja, desca, b, ib, jb, descb, w, z, iz, jz, descz, info);
}

void C_dlaf_pzhegvx_factorized(const char uplo, const int m, dlaf_complex_z* a, const int ia, const int ja,
const int desca[9], dlaf_complex_z* b, const int ib, const int jb,
const int descb[9], double* w, dlaf_complex_z* z, const int iz, const int jz,
const int descz[9], int* info) {
dlaf_pzhegvx_factorized(uplo, m, a, ia, ja, desca, b, ib, jb, descb, w, z, iz, jz, descz, info);
}

#endif
40 changes: 40 additions & 0 deletions test/unit/c_api/eigensolver/test_gen_eigensolver_c_api_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ DLAF_EXTERN_C int C_dlaf_hermitian_generalized_eigensolver_z(
dlaf_complex_z* b, const struct DLAF_descriptor descb, double* w, dlaf_complex_z* z,
const struct DLAF_descriptor descz);

DLAF_EXTERN_C int C_dlaf_symmetric_generalized_eigensolver_factorized_s(
const int dlaf_context, const char uplo, float* a, const struct DLAF_descriptor desca, float* b,
const struct DLAF_descriptor descb, float* w, float* z, const struct DLAF_descriptor descz);

DLAF_EXTERN_C int C_dlaf_symmetric_generalized_eigensolver_factorized_d(
const int dlaf_context, const char uplo, double* a, const struct DLAF_descriptor desca, double* b,
const struct DLAF_descriptor descb, double* w, double* z, const struct DLAF_descriptor descz);

DLAF_EXTERN_C int C_dlaf_hermitian_generalized_eigensolver_factorized_c(
const int dlaf_context, const char uplo, dlaf_complex_c* a, const struct DLAF_descriptor desca,
dlaf_complex_c* b, const struct DLAF_descriptor descb, float* w, dlaf_complex_c* z,
const struct DLAF_descriptor descz);

DLAF_EXTERN_C int C_dlaf_hermitian_generalized_eigensolver_factorized_z(
const int dlaf_context, const char uplo, dlaf_complex_z* a, const struct DLAF_descriptor desca,
dlaf_complex_z* b, const struct DLAF_descriptor descb, double* w, dlaf_complex_z* z,
const struct DLAF_descriptor descz);

#ifdef DLAF_WITH_SCALAPACK
DLAF_EXTERN_C void C_dlaf_pssygvx(char uplo, const int m, float* a, const int ia, const int ja,
const int desca[9], float* b, const int ib, const int jb,
Expand All @@ -54,4 +72,26 @@ DLAF_EXTERN_C void C_dlaf_pzhegvx(const char uplo, const int m, dlaf_complex_z*
const int ja, const int desca[9], dlaf_complex_z* b, const int ib,
const int jb, const int descb[9], double* w, dlaf_complex_z* z,
const int iz, const int jz, const int descz[9], int* info);

DLAF_EXTERN_C void C_dlaf_pssygvx_factorized(char uplo, const int m, float* a, const int ia,
const int ja, const int desca[9], float* b, const int ib,
const int jb, const int descb[9], float* w, float* z,
const int iz, const int jz, const int descz[9], int* info);

DLAF_EXTERN_C void C_dlaf_pdsygvx_factorized(const char uplo, const int m, double* a, const int ia,
const int ja, const int desca[9], double* b, const int ib,
const int jb, const int descb[9], double* w, double* z,
const int iz, const int jz, const int descz[9], int* info);

DLAF_EXTERN_C void C_dlaf_pchegvx_factorized(const char uplo, const int m, dlaf_complex_c* a,
const int ia, const int ja, const int desca[9],
dlaf_complex_c* b, const int ib, const int jb,
const int descb[9], float* w, dlaf_complex_c* z,
const int iz, const int jz, const int descz[9], int* info);

DLAF_EXTERN_C void C_dlaf_pzhegvx_factorized(const char uplo, const int m, dlaf_complex_z* a,
const int ia, const int ja, const int desca[9],
dlaf_complex_z* b, const int ib, const int jb,
const int descb[9], double* w, dlaf_complex_z* z,
const int iz, const int jz, const int descz[9], int* info);
#endif

0 comments on commit 09ae24c

Please sign in to comment.