Date: 2025-03-29T05:58:34+00:00

Actual source code: matseqdensehip.hip.cpp

      1: #include "../matseqdensecupm.hpp"

      3: using namespace Petsc::mat::cupm;
      4: using Petsc::device::cupm::DeviceType;

      6: static constexpr impl::MatDense_Seq_CUPM<DeviceType::HIP> cupm_mat{};

      8: /*MC
      9:   MATSEQDENSEHIP - "seqdensehip" - A matrix type to be used for sequential dense matrices on
     10:   GPUs.

     12:   Options Database Keys:
     13: . -mat_type seqdensehip - sets the matrix type to `MATSEQDENSEHIP` during a call to
     14:                            `MatSetFromOptions()`

     16:   Level: beginner

     18: .seealso: `MATSEQDENSE`
     19: M*/
     20: PETSC_INTERN PetscErrorCode MatCreate_SeqDenseHIP(Mat A)
     21: {
     22:   PetscFunctionBegin;
     23:   PetscCall(cupm_mat.Create(A));
     24:   PetscFunctionReturn(PETSC_SUCCESS);
     25: }

     27: PETSC_INTERN PetscErrorCode MatSolverTypeRegister_DENSEHIP(void)
     28: {
     29:   PetscFunctionBegin;
     30:   PetscCall(impl::MatSolverTypeRegister_DENSECUPM<DeviceType::HIP>());
     31:   PetscFunctionReturn(PETSC_SUCCESS);
     32: }

     34: PetscErrorCode MatConvert_SeqDense_SeqDenseHIP(Mat A, MatType newtype, MatReuse reuse, Mat *newmat)
     35: {
     36:   PetscFunctionBegin;
     37:   PetscCall(cupm_mat.Convert_SeqDense_SeqDenseCUPM(A, newtype, reuse, newmat));
     38:   PetscFunctionReturn(PETSC_SUCCESS);
     39: }

     41: PetscErrorCode MatMatMultNumeric_SeqDenseHIP_SeqDenseHIP_Internal(Mat A, Mat B, Mat C, PetscBool TA, PetscBool TB)
     42: {
     43:   PetscFunctionBegin;
     44:   PetscCall(impl::MatMatMultNumeric_SeqDenseCUPM_SeqDenseCUPM<DeviceType::HIP>(A, B, C, TA, TB));
     45:   PetscFunctionReturn(PETSC_SUCCESS);
     46: }

     48: PetscErrorCode MatSeqDenseHIPInvertFactors_Internal(Mat A)
     49: {
     50:   PetscFunctionBegin;
     51:   PetscCall(cupm_mat.InvertFactors(A));
     52:   PetscFunctionReturn(PETSC_SUCCESS);
     53: }

     55: /*@C
     56:   MatCreateSeqDenseHIP - Creates a sequential matrix in dense format using HIP.

     58:   Collective

     60:   Input Parameters:
     61: + comm - MPI communicator
     62: . m    - number of rows
     63: . n    - number of columns
     64: - data - optional location of GPU matrix data. Pass `NULL` to let PETSc to control matrix
     65:          memory allocation

     67:   Output Parameter:
     68: . A - the matrix

     70:   Level: intermediate

     72: .seealso: `MATSEQDENSE`, `MatCreate()`, `MatCreateSeqDense()`
     73: @*/
     74: PetscErrorCode MatCreateSeqDenseHIP(MPI_Comm comm, PetscInt m, PetscInt n, PetscScalar *data, Mat *A)
     75: {
     76:   PetscFunctionBegin;
     77:   PetscCall(MatCreateSeqDenseCUPM<DeviceType::HIP>(comm, m, n, data, A));
     78:   PetscFunctionReturn(PETSC_SUCCESS);
     79: }