PSkel
|
00001 //------------------------------------------------------------------------------- 00002 // Copyright (c) 2015, ICEI - PUC Minas 00003 // All rights reserved. 00004 // 00005 // Redistribution and use in source and binary forms, with or without 00006 // modification, are permitted provided that the following conditions are met: 00007 // 00008 // 1. Redistributions of source code must retain the above copyright notice, this 00009 // list of conditions and the following disclaimer. 00010 // 00011 // 2. Redistributions in binary form must reproduce the above copyright notice, 00012 // this list of conditions and the following disclaimer in the documentation 00013 // and/or other materials provided with the distribution. 00014 // 00015 // 3. Neither the name of the copyright holder nor the names of its contributors 00016 // may be used to endorse or promote products derived from this software without 00017 // specific prior written permission. 00018 // 00019 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00020 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00021 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00023 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00024 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00025 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00026 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00027 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 //------------------------------------------------------------------------------- 00030 00035 #ifndef PSKEL_MASK_H 00036 #define PSKEL_MASK_H 00037 00038 #include "PSkelArray.h" 00039 00040 namespace PSkel{ 00041 00046 template<typename T> 00047 class MaskBase{ 00048 protected: 00049 int *hostMask, *deviceMask; 00050 //size_t maskRadius; 00051 T *hostWeight, *deviceWeight; 00052 T haloValue; 00053 00063 MaskBase(size_t size=0, size_t dimension=0, T haloVal=T(0), size_t range=0); 00064 public: 00065 size_t size, dimension; 00066 size_t range; 00067 00071 void deviceAlloc(); 00072 void copyToDevice(); 00076 void deviceFree(); 00077 00081 void hostAlloc(); 00082 00086 void hostFree(); 00087 00092 size_t memSize() const; 00093 00094 //__device__ __host__ size_t size() const; 00095 00101 __device__ __host__ T getWeight(size_t n); 00102 00103 }; 00104 00105 00106 //******************************************************************************************* 00107 // MASK3D 00108 //******************************************************************************************* 00109 00110 template<typename T> 00111 class Mask3D : public MaskBase<T>{ 00112 public: 00121 Mask3D(size_t size=0, T haloVal=T(0), size_t range=0); 00122 00131 __device__ __host__ void set(size_t n, int h, int w, int d, T weight=T(0)); 00132 00133 //__device__ __host__ void set(size_t n,int x,int y,int z); 00134 00144 template<typename V> 00145 __forceinline__ __device__ __host__ T get(size_t n, Array3D<V> array, size_t h, size_t w, size_t d); 00146 00147 __device__ __host__ size_t getRange(); 00148 /* 00149 template<typename Arrays> 00150 int setMaskRadius(Arrays array); 00151 */ 00152 }; 00153 00154 //******************************************************************************************* 00155 // MASK2D 00156 //******************************************************************************************* 00157 00158 template<typename T> 00159 class Mask2D : public MaskBase<T>{ 00160 public: 00169 Mask2D(size_t size=0, T haloVal=T(0), size_t range=0); 00170 00178 __device__ __host__ void set(size_t n, int h, int w, T weight=T(0)); 00179 00180 //__device__ __host__ void set(size_t n,int x,int y); 00181 00190 template<typename V> 00191 __forceinline__ __device__ __host__ T get(size_t n, Array2D<V> array, size_t h, size_t w); 00192 00193 __device__ __host__ size_t getRange(); 00194 /* 00195 template<typename Arrays> 00196 int setMaskRadius(Arrays array); 00197 */ 00198 }; 00199 00200 //******************************************************************************************* 00201 // MASK 00202 //******************************************************************************************* 00203 00204 template<typename T> 00205 class Mask : public MaskBase<T>{ 00206 public: 00215 Mask(size_t size=0, T haloVal=T(0), size_t range=0); 00216 00217 //__device__ __host__ void set(size_t n,int x); 00218 00225 __device__ __host__ void set(size_t n, int i, T weight=T(0)); 00226 00234 template<typename V> 00235 __forceinline__ __device__ __host__ T get(size_t n, Array<V> array, size_t i); 00236 00237 __device__ __host__ size_t getRange(); 00238 /* 00239 template<typename Arrays> 00240 int setMaskRadius(Arrays array); 00241 */ 00242 }; 00243 00244 }//end namespace 00245 00246 #include "PSkelMask.hpp" 00247 00248 #endif