Date: 2013-07-02T14:40:02+00:00

Actual source code: cuspvecimpl.h
petsc-3.4.2 2013-07-02
4: #include <petsccusp.h> 5: #include <petsc-private/vecimpl.h> 7: #include <algorithm> 8: #include <vector> 9: #include <string> 11: #include <cublas.h> 12: #include <cusp/blas.h> 13: #include <thrust/host_vector.h> 14: #include <thrust/device_vector.h> 15: #include <thrust/iterator/constant_iterator.h> 16: #include <thrust/transform.h> 17: #include <thrust/iterator/permutation_iterator.h> 19: #define CUSPARRAY cusp::array1d<PetscScalar,cusp::device_memory> 20: #define CUSPARRAYCPU cusp::array1d<PetscScalar,cusp::host_memory> 21: #define CUSPINTARRAYGPU cusp::array1d<PetscInt,cusp::device_memory> 22: #define CUSPINTARRAYCPU cusp::array1d<PetscInt,cusp::host_memory> 24: PETSC_INTERN PetscErrorCode VecDotNorm2_SeqCUSP(Vec,Vec,PetscScalar*, PetscScalar*); 25: PETSC_INTERN PetscErrorCode VecPointwiseDivide_SeqCUSP(Vec,Vec,Vec); 26: PETSC_INTERN PetscErrorCode VecWAXPY_SeqCUSP(Vec,PetscScalar,Vec,Vec); 27: PETSC_INTERN PetscErrorCode VecMDot_SeqCUSP(Vec,PetscInt,const Vec[],PetscScalar*); 28: PETSC_INTERN PetscErrorCode VecSet_SeqCUSP(Vec,PetscScalar); 29: PETSC_INTERN PetscErrorCode VecMAXPY_SeqCUSP(Vec,PetscInt,const PetscScalar*,Vec*); 30: PETSC_INTERN PetscErrorCode VecAXPBYPCZ_SeqCUSP(Vec,PetscScalar,PetscScalar,PetscScalar,Vec,Vec); 31: PETSC_INTERN PetscErrorCode VecPointwiseMult_SeqCUSP(Vec,Vec,Vec); 32: PETSC_INTERN PetscErrorCode VecPlaceArray_SeqCUSP(Vec,const PetscScalar*); 33: PETSC_INTERN PetscErrorCode VecResetArray_SeqCUSP(Vec); 34: PETSC_INTERN PetscErrorCode VecReplaceArray_SeqCUSP(Vec,const PetscScalar*); 35: PETSC_INTERN PetscErrorCode VecDot_SeqCUSP(Vec,Vec,PetscScalar*); 36: PETSC_INTERN PetscErrorCode VecTDot_SeqCUSP(Vec,Vec,PetscScalar*); 37: PETSC_INTERN PetscErrorCode VecScale_SeqCUSP(Vec,PetscScalar); 38: PETSC_INTERN PetscErrorCode VecCopy_SeqCUSP(Vec,Vec); 39: PETSC_INTERN PetscErrorCode VecSwap_SeqCUSP(Vec,Vec); 40: PETSC_INTERN PetscErrorCode VecAXPY_SeqCUSP(Vec,PetscScalar,Vec); 41: PETSC_INTERN PetscErrorCode VecAXPBY_SeqCUSP(Vec,PetscScalar,PetscScalar,Vec); 42: PETSC_INTERN PetscErrorCode VecDuplicate_SeqCUSP(Vec,Vec*); 43: PETSC_INTERN PetscErrorCode VecNorm_SeqCUSP(Vec,NormType,PetscReal*); 44: PETSC_INTERN PetscErrorCode VecCUSPCopyToGPU(Vec); 45: PETSC_INTERN PetscErrorCode VecCUSPAllocateCheck(Vec); 46: PETSC_INTERN PetscErrorCode VecCUSPAllocateCheckHost(Vec); 47: PETSC_EXTERN PetscErrorCode VecCreate_SeqCUSP(Vec); 48: PETSC_INTERN PetscErrorCode VecView_Seq(Vec,PetscViewer); 49: PETSC_INTERN PetscErrorCode VecDestroy_SeqCUSP(Vec); 50: PETSC_INTERN PetscErrorCode VecAYPX_SeqCUSP(Vec,PetscScalar,Vec); 51: PETSC_INTERN PetscErrorCode VecSetRandom_SeqCUSP(Vec,PetscRandom); 53: PETSC_INTERN PetscErrorCode VecCUSPCopyToGPU_Public(Vec); 54: PETSC_INTERN PetscErrorCode VecCUSPAllocateCheck_Public(Vec); 56: #if defined(PETSC_HAVE_TXPETSCGPU) 57: #include "tx_vector_interface.h" 58: #endif 60: struct _p_PetscCUSPIndices { 61: #if defined(PETSC_HAVE_TXPETSCGPU) 62: GPU_Indices<PetscInt, PetscScalar> * sendIndices; 63: GPU_Indices<PetscInt, PetscScalar> * recvIndices; 64: #else 65: CUSPINTARRAYCPU sendIndicesCPU; 66: CUSPINTARRAYGPU sendIndicesGPU; 68: CUSPINTARRAYCPU recvIndicesCPU; 69: CUSPINTARRAYGPU recvIndicesGPU; 70: #endif 71: }; 73: #if defined(PETSC_HAVE_TXPETSCGPU) 74: PETSC_INTERN PetscErrorCode VecCUSPCopySomeToContiguousBufferGPU(Vec, PetscCUSPIndices); 75: PETSC_INTERN PetscErrorCode VecCUSPCopySomeFromContiguousBufferGPU(Vec, PetscCUSPIndices); 76: #endif 78: #define CHKERRCUSP(err) if (((int)err) != (int)CUBLAS_STATUS_SUCCESS) SETERRQ1(PETSC_COMM_SELF,PETSC_ERR_LIB,"CUSP error %d",err) 80: #define VecCUSPCastToRawPtr(x) thrust::raw_pointer_cast(&(x)[0]) 82: #define WaitForGPU() PetscCUSPSynchronize ? cudaThreadSynchronize() : 0 84: struct Vec_CUSP { 85: CUSPARRAY *GPUarray; /* this always holds the GPU data */ 86: #if defined(PETSC_HAVE_TXPETSCGPU) 87: GPU_Vector<PetscInt, PetscScalar> * GPUvector; /* this always holds the GPU data */ 88: #endif 89: }; 91: #endif