LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
LSSTDataManagementBasePackage
CudaMemory.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008 - 2012 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
38 #ifdef GPU_BUILD
39 
40 #include <cstdint>
41 
42 #include <cuda.h>
43 #include <cuda_runtime.h>
44 
45 #include "lsst/afw/image/Image.h"
49 
50 using namespace std;
51 
52 namespace lsst {
53 namespace afw {
54 namespace gpu {
55 namespace detail {
56 
57 template<typename T>
58 int GpuMemOwner<T>::TransferFromImageBase(const lsst::afw::image::ImageBase<T>& img)
59 {
60  const T* imgPtr=img.getArray().getData();
61  int const imgStride=img.getArray().getStrides()[0] ;
62  int const imgMemSize=imgStride * img.getHeight();
63  Transfer(imgPtr,imgMemSize);
64  return imgStride;
65 }
66 
67 template<typename T>
68 int GpuMemOwner<T>::AllocImageBaseBuffer(const lsst::afw::image::ImageBase<T>& img)
69 {
70  int const imgStride=img.getArray().getStrides()[0] ;
71  int const imgMemSize=imgStride * img.getHeight();
72  Alloc(imgMemSize);
73  return imgStride;
74 }
75 
76 template<typename T>
77 void GpuMemOwner<T>::CopyToImageBase(lsst::afw::image::ImageBase<T>& img) const
78 {
79  T* imgPtr=img.getArray().getData();
80  int const imgStride=img.getArray().getStrides()[0] ;
81  int const imgMemSize=imgStride * img.getHeight();
82  assert(imgMemSize==size);
83  CopyFromGpu(imgPtr);
84 }
85 
86 //
87 // Explicit instantiations
88 //
90 #define MASKEDIMAGE(PIXTYPE) afwImage::MaskedImage<PIXTYPE, afwImage::MaskPixel, afwImage::VariancePixel>
91 #define IMAGE(PIXTYPE) afwImage::Image<PIXTYPE>
92 #define NL /* */
93 
94 #define INSTANTIATE(PIXELT) \
95  template class GpuMemOwner<PIXELT>;
96 
97 INSTANTIATE(double)
98 INSTANTIATE(float)
99 INSTANTIATE(int)
100 INSTANTIATE(std::uint16_t)
102 
103 
104 }}}} // namespace lsst::afw::gpu::detail ends
105 
106 #endif
107 
additional GPU exceptions
The base class for all image classed (Image, Mask, MaskedImage, ...)
Definition: Image.h:115
contains GpuBuffer2D class (for simple handling of images or 2D arrays)
#define INSTANTIATE(T)
Support for 2-D images.
int getHeight() const
Return the number of rows in the image.
Definition: Image.h:241
Functions and a class to help allocating GPU global memory and transferring data to and from a GPU...