PSkel
src/PSkelMap.h
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 
00031 #ifndef PSKEL_MAP_H
00032 #define PSKEL_MAP_H
00033 
00034 #include <cuda.h>
00035 #ifdef PSKEL_TBB
00036   #include <tbb/blocked_range.h>
00037 #endif
00038 
00039 #include "PSkelDefs.h"
00040 #include "PSkelArray.h"
00041 
00042 namespace PSkel{
00043 
00044 //*******************************************************************************************
00045 // Kernels a serem implementados pelo usuário
00046 //*******************************************************************************************
00047 
00048 template<typename T, class Args>
00049 __parallel__ void mapKernel(Array<T> input, Array<T> output, Args args, size_t i);
00050 
00051 template<typename T, class Args>
00052 __parallel__ void mapKernel(Array2D<T> input, Array2D<T> output, Args args, size_t h, size_t w);
00053 
00054 template<typename T, class Args>
00055 __parallel__ void mapKernel(Array3D<T> input, Array3D<T> output, Args args, size_t h, size_t w, size_t d);
00056 
00057 //*******************************************************************************************
00058 // Map Base
00059 //*******************************************************************************************
00060 
00061 
00062 template<class Arrays, class Args=int>
00063 class MapBase{
00064 private:
00065 protected:
00066         Arrays input;
00067         Arrays output;
00068         Args args;
00069         
00070         virtual void runSeq(Arrays in, Arrays out) = 0;
00071         virtual void runOpenMP(Array in, Array out, size_t numThreads) = 0;
00072         #ifdef PSKEL_TBB
00073         virtual void runTBB(Arrays in, Arrays out, size_t numThreads) = 0;
00074         #endif
00075         virtual void runCUDA(Arrays input, Arrays output, size_t blockSize) = 0;
00076 public:
00077         void runSequential();
00078         void runCPU(size_t numThreads=0);
00079         void runGPU(size_t blockSize=0);
00080         //void runHybrid(float GPUPartition, size_t GPUBlockSize, size_t numThreads);
00081 
00082         void runIterativeSequential(size_t iterations);
00083         void runIterativeCPU(size_t iterations, size_t numThreads=0);
00084         void runIterativeGPU(size_t iterations, size_t blockSize=0);
00085         //void runIterativeHybrid(size_t iterations, float GPUPartition, size_t GPUBlockSize, size_t numThreads);
00086 };
00087 
00088 //*******************************************************************************************
00089 // Map 3D
00090 //*******************************************************************************************
00091 
00092 
00093 template<class Arrays, class Args>
00094 class Map3D : public MapBase<Arrays, Args>{
00095 protected:
00096         void runSeq(Arrays in, Arrays out);
00097         void runOpenMP(size_t numThreads);
00098         #ifdef PSKEL_TBB
00099         void runTBB(Arrays in, Arrays out, size_t numThreads);
00100         #endif
00101         void runCUDA(Arrays in, Arrays out, int blockSize);
00102 public:
00103         Map3D();
00104         Map3D(Arrays input, Arrays output, Args args);
00105 };
00106 
00107 //*******************************************************************************************
00108 // Stencil 2D
00109 //*******************************************************************************************
00110 
00111 template<class Arrays, class Args>
00112 class Map2D : public MapBase<Arrays, Args>{
00113 protected:
00114         void runSeq(Arrays in, Arrays out);
00115         void runOpenMP(size_t numThreads);
00116         #ifdef PSKEL_TBB
00117         void runTBB(Arrays in, Arrays out, size_t numThreads);
00118         #endif
00119         void runCUDA(Arrays in, Arrays out, int blockSize);
00120 public:
00121         Map2D();
00122         Map2D(Arrays input, Arrays output, Args args);
00123 };
00124 
00125 //*******************************************************************************************
00126 // Stencil 1D
00127 //*******************************************************************************************
00128 
00129 
00130 template<class Arrays, class Args>
00131 class Map: public MapBase<Arrays, Args>{
00132 protected:
00133         void runSeq(Arrays in, Arrays out);
00134         void runOpenMP(size_t numThreads);
00135         #ifdef PSKEL_TBB
00136         void runTBB(Arrays in, Arrays out, size_t numThreads);
00137         #endif
00138         void runCUDA(Arrays in, Arrays out, int blockSize);
00139 public:
00140         Map();
00141         Map(Arrays input, Arrays output, Args args);
00142 };
00143 
00144 }//end namespace
00145 
00146 #include "PSkelMap.hpp"
00147 
00148 #endif
 All Classes Files Functions