Date: 2026-03-01T05:25:25+00:00

Actual source code: viennaclvecimpl.h

      1: #pragma once

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

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

     12: #include "viennacl/vector.hpp"

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

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

     19: PETSC_EXTERN PetscErrorCode PetscViennaCLInit(void);

     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_INTERN PetscErrorCode VecDestroy_SeqViennaCL(Vec);
     47: PETSC_INTERN PetscErrorCode VecAYPX_SeqViennaCL(Vec, PetscScalar, Vec);
     48: PETSC_INTERN PetscErrorCode VecSetRandom_SeqViennaCL(Vec, PetscRandom);
     49: PETSC_INTERN PetscErrorCode VecGetArrayWrite_SeqViennaCL(Vec, PetscScalar **);
     50: PETSC_INTERN PetscErrorCode VecGetArray_SeqViennaCL(Vec, PetscScalar **);
     51: PETSC_INTERN PetscErrorCode VecRestoreArray_SeqViennaCL(Vec, PetscScalar **);

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

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

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