Date: 2022-08-02T03:13:32+00:00

Actual source code: viennaclvecimpl.h

      4: #include <petscviennacl.h>
      5: #include <petsc/private/vecimpl.h>
      6: #include <petsc/private/deviceimpl.h>

      8: #include <algorithm>
      9: #include <vector>
     10: #include <string>
     11: #include <exception>

     13: #include "viennacl/vector.hpp"

     15: #define ViennaCLWaitForGPU() if (PetscViennaCLSynchronize) viennacl::backend::finish();

     17: typedef viennacl::vector<PetscScalar>    ViennaCLVector;

     19: PETSC_EXTERN PetscErrorCode PetscViennaCLInit();

     21: PETSC_INTERN PetscErrorCode VecDotNorm2_SeqViennaCL(Vec,Vec,PetscScalar*, PetscScalar*);
     22: PETSC_INTERN PetscErrorCode VecPointwiseDivide_SeqViennaCL(Vec,Vec,Vec);
     23: PETSC_INTERN PetscErrorCode VecWAXPY_SeqViennaCL(Vec,PetscScalar,Vec,Vec);
     24: PETSC_INTERN PetscErrorCode VecMDot_SeqViennaCL(Vec,PetscInt,const Vec[],PetscScalar*);
     25: PETSC_INTERN PetscErrorCode VecSet_SeqViennaCL(Vec,PetscScalar);
     26: PETSC_INTERN PetscErrorCode VecMAXPY_SeqViennaCL(Vec,PetscInt,const PetscScalar*,Vec*);
     27: PETSC_INTERN PetscErrorCode VecAXPBYPCZ_SeqViennaCL(Vec,PetscScalar,PetscScalar,PetscScalar,Vec,Vec);
     28: PETSC_INTERN PetscErrorCode VecPointwiseMult_SeqViennaCL(Vec,Vec,Vec);
     29: PETSC_INTERN PetscErrorCode VecPlaceArray_SeqViennaCL(Vec,const PetscScalar*);
     30: PETSC_INTERN PetscErrorCode VecResetArray_SeqViennaCL(Vec);
     31: PETSC_INTERN PetscErrorCode VecReplaceArray_SeqViennaCL(Vec,const PetscScalar*);
     32: PETSC_INTERN PetscErrorCode VecDot_SeqViennaCL(Vec,Vec,PetscScalar*);
     33: PETSC_INTERN PetscErrorCode VecTDot_SeqViennaCL(Vec,Vec,PetscScalar*);
     34: PETSC_INTERN PetscErrorCode VecScale_SeqViennaCL(Vec,PetscScalar);
     35: PETSC_INTERN PetscErrorCode VecCopy_SeqViennaCL(Vec,Vec);
     36: PETSC_INTERN PetscErrorCode VecSwap_SeqViennaCL(Vec,Vec);
     37: PETSC_INTERN PetscErrorCode VecAXPY_SeqViennaCL(Vec,PetscScalar,Vec);
     38: PETSC_INTERN PetscErrorCode VecAXPBY_SeqViennaCL(Vec,PetscScalar,PetscScalar,Vec);
     39: PETSC_INTERN PetscErrorCode VecDuplicate_SeqViennaCL(Vec,Vec*);
     40: PETSC_INTERN PetscErrorCode VecNorm_SeqViennaCL(Vec,NormType,PetscReal*);
     41: PETSC_INTERN PetscErrorCode VecViennaCLCopyToGPU(Vec);
     42: PETSC_INTERN PetscErrorCode VecViennaCLAllocateCheck(Vec);
     43: PETSC_EXTERN PetscErrorCode VecViennaCLAllocateCheckHost(Vec);
     44: PETSC_EXTERN PetscErrorCode VecCreate_SeqViennaCL(Vec);
     45: PETSC_INTERN PetscErrorCode VecCreate_SeqViennaCL_Private(Vec,const ViennaCLVector *);
     46: PETSC_EXTERN PetscErrorCode VecView_Seq(Vec,PetscViewer);
     47: PETSC_INTERN PetscErrorCode VecDestroy_SeqViennaCL(Vec);
     48: PETSC_INTERN PetscErrorCode VecAYPX_SeqViennaCL(Vec,PetscScalar,Vec);
     49: PETSC_INTERN PetscErrorCode VecSetRandom_SeqViennaCL(Vec,PetscRandom);
     50: PETSC_INTERN PetscErrorCode VecGetArrayWrite_SeqViennaCL(Vec,PetscScalar**);
     51: PETSC_INTERN PetscErrorCode VecGetArray_SeqViennaCL(Vec,PetscScalar**);
     52: PETSC_INTERN PetscErrorCode VecRestoreArray_SeqViennaCL(Vec,PetscScalar**);

     54: PETSC_INTERN PetscErrorCode VecCreate_MPIViennaCL_Private(Vec,PetscBool,PetscInt,const ViennaCLVector *);

     56: PETSC_INTERN PetscErrorCode VecViennaCLCopyToGPU_Public(Vec);
     57: PETSC_INTERN PetscErrorCode VecViennaCLAllocateCheck_Public(Vec);

     59: struct Vec_ViennaCL {
     60:   viennacl::vector<PetscScalar> *GPUarray;           // this always holds the GPU data
     61:   viennacl::vector<PetscScalar> *GPUarray_allocated; // if the array was allocated by PETSc this is its pointer
     62: };

     64: #endif