PSkel
src/PSkelStencil.h
Go to the documentation of this file.
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_STENCIL_H
00036 #define PSKEL_STENCIL_H
00037 
00038 #ifdef PSKEL_TBB
00039   #include <tbb/blocked_range.h>
00040   #include <tbb/parallel_for.h>
00041   #include <tbb/task_scheduler_init.h>
00042 #endif
00043 
00044 #include "PSkelDefs.h"
00045 #include "PSkelArray.h"
00046 #include "PSkelMask.h"
00047 #include "PSkelStencilTiling.h"
00048 
00049 namespace PSkel{
00050 
00051 //*******************************************************************************************
00052 // Stencil Kernels that must be implemented by the users.
00053 //*******************************************************************************************
00054 
00065 template<typename T1, typename T2, class Args>
00066 __parallel__ void stencilKernel(Array<T1> input, Array<T1> output, Mask<T2> mask, Args args, size_t i);
00067 
00079 template<typename T1, typename T2, class Args>
00080 __parallel__ void stencilKernel(Array2D<T1> input, Array2D<T1> output, Mask2D<T2> mask, Args args, size_t h, size_t w);
00081 
00094 template<typename T1, typename T2, class Args>
00095 __parallel__ void stencilKernel(Array3D<T1> input, Array3D<T1> output, Mask3D<T2> mask, Args args, size_t h, size_t w, size_t d);
00096 
00097 //*******************************************************************************************
00098 // Stencil Base
00099 //*******************************************************************************************
00100 
00104 template<class Array, class Mask, class Args=int>
00105 class StencilBase{
00106 private:
00107 protected:
00108         Array input;
00109         Array output;
00110         Args args;
00111         Mask mask;
00112 
00113         virtual void runSeq(Array in, Array out) = 0;
00114         #ifdef PSKEL_TBB
00115         virtual void runTBB(Array in, Array out, size_t numThreads) = 0;
00116         #endif
00117         virtual void runOpenMP(Array in, Array out, size_t numThreads) = 0;
00118         void runCUDA(Array,Array,int);
00119         void runIterativeTilingCUDA(Array in, Array out, StencilTiling<Array,Mask> tiling, size_t GPUBlockSize);
00120 public:
00124         void runSequential();
00125 
00131         void runCPU(size_t numThreads=0);
00132 
00139         void runGPU(size_t GPUBlockSize=0);
00140 
00150         void runTilingGPU(size_t tilingWidth, size_t tilingHeight, size_t tilingDepth, size_t GPUBlockSize=0);
00151 
00159         void runAutoGPU(size_t GPUBlockSize=0);
00160 
00161         //void runHybrid(float GPUPartition, size_t GPUBlockSize, size_t numThreads);
00162 
00168         void runIterativeSequential(size_t iterations);
00169 
00177         void runIterativeCPU(size_t iterations, size_t numThreads=0);
00178 
00187         void runIterativeGPU(size_t iterations, size_t GPUBlockSize=0);
00188 
00202         void runIterativeTilingGPU(size_t iterations, size_t tilingWidth, size_t tilingHeight, size_t tilingDepth, size_t innerIterations=1, size_t GPUBlockSize=0);
00203 
00214         void runIterativeAutoGPU(size_t iterations, size_t GPUBlockSize=0);
00215 
00216         //void runIterativeHybrid(size_t iterations, float GPUPartition, size_t GPUBlockSize, size_t numThreads);
00217 };
00218 
00219 //*******************************************************************************************
00220 // Stencil 3D
00221 //*******************************************************************************************
00222 
00223 template<class Array, class Mask, class Args>
00224 class Stencil3D : public StencilBase<Array, Mask, Args>{
00225 protected:
00226         void runSeq(Array in, Array out);
00227         void runOpenMP(Array in, Array out, size_t numThreads);
00228         #ifdef PSKEL_TBB
00229         void runTBB(Array in, Array out, size_t numThreads);
00230         #endif
00231 public:
00232         Stencil3D();
00233         Stencil3D(Array _input, Array _output, Mask _mask, Args _args);
00234 };
00235 
00236 //*******************************************************************************************
00237 // Stencil 2D
00238 //*******************************************************************************************
00239 
00240 template<class Array, class Mask, class Args>
00241 class Stencil2D : public StencilBase<Array, Mask, Args>{
00242 protected:
00243         void runSeq(Array in, Array out);
00244         void runOpenMP(Array in, Array out, size_t numThreads);
00245         #ifdef PSKEL_TBB
00246         void runTBB(Array in, Array out, size_t numThreads);
00247         #endif
00248 public:
00249         Stencil2D();
00250         Stencil2D(Array _input, Array _output, Mask _mask, Args _args);
00251         //~Stencil2D();
00252 };
00253 
00254 //*******************************************************************************************
00255 // Stencil 1D
00256 //*******************************************************************************************
00257 
00258 
00259 template<class Array, class Mask, class Args>
00260 class Stencil: public StencilBase<Array, Mask, Args>{
00261 protected:
00262         void runSeq(Array in, Array out);
00263         void runOpenMP(Array in, Array out, size_t numThreads);
00264         #ifdef PSKEL_TBB
00265         void runTBB(Array in, Array out, size_t numThreads);
00266         #endif
00267 public:
00268         Stencil();
00269         Stencil(Array _input, Array _output, Mask _mask, Args _args);
00270 };
00271 
00272 }
00273 
00274 #include "PSkelStencil.hpp"
00275 
00276 #endif
 All Classes Files Functions