1 /* 2 * Copyright (c) 2014-2017, Siemens AG. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are met: 6 * 7 * 1. Redistributions of source code must retain the above copyright notice, 8 * this list of conditions and the following disclaimer. 9 * 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 18 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 24 * POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef EMBB_DATAFLOW_INTERNAL_SINK_EXECUTOR_H_ 28 #define EMBB_DATAFLOW_INTERNAL_SINK_EXECUTOR_H_ 29 30 #include <embb/base/function.h> 31 32 #include <embb/dataflow/internal/inputs.h> 33 34 #include <embb/mtapi/mtapi.h> 35 36 namespace embb { 37 namespace dataflow { 38 namespace internal { 39 40 template <class Inputs> 41 class SinkExecutor; 42 43 template <typename I1> 44 class SinkExecutor< Inputs<I1> > { 45 public: 46 typedef embb::base::Function<void, I1 const &> FunctionType; 47 SinkExecutor(FunctionType func)48 explicit SinkExecutor(FunctionType func) : function_(func) {} SinkExecutor(embb::mtapi::Job job)49 explicit SinkExecutor(embb::mtapi::Job job) 50 : job_(job) { 51 function_ = FunctionType(*this, &SinkExecutor::ExecuteJob); 52 } 53 Execute(int clock,Inputs<I1> & inputs)54 void Execute( 55 int clock, 56 Inputs<I1> & inputs) { 57 function_( 58 inputs.template Get<0>().GetValue(clock)); 59 } 60 61 private: 62 FunctionType function_; 63 embb::mtapi::Job job_; 64 ExecuteJob(I1 const & i1)65 void ExecuteJob(I1 const & i1) { 66 struct { 67 I1 i1_; 68 } inputs = { i1 }; 69 embb::mtapi::Node & node = embb::mtapi::Node::GetInstance(); 70 embb::mtapi::Task task = 71 node.Start(MTAPI_TASK_ID_NONE, job_.GetInternal(), 72 &inputs, sizeof(inputs), 73 MTAPI_NULL, 0, 74 MTAPI_DEFAULT_TASK_ATTRIBUTES); 75 task.Wait(); 76 } 77 }; 78 79 template <typename I1, typename I2> 80 class SinkExecutor< Inputs<I1, I2> > { 81 public: 82 typedef embb::base::Function<void, I1 const &, I2 const &> FunctionType; 83 SinkExecutor(FunctionType func)84 explicit SinkExecutor(FunctionType func) : function_(func) {} SinkExecutor(embb::mtapi::Job job)85 explicit SinkExecutor(embb::mtapi::Job job) 86 : job_(job) { 87 function_ = FunctionType(*this, &SinkExecutor::ExecuteJob); 88 } 89 Execute(int clock,Inputs<I1,I2> & inputs)90 void Execute( 91 int clock, 92 Inputs<I1, I2> & inputs) { 93 function_( 94 inputs.template Get<0>().GetValue(clock), 95 inputs.template Get<1>().GetValue(clock)); 96 } 97 98 private: 99 FunctionType function_; 100 embb::mtapi::Job job_; 101 ExecuteJob(I1 const & i1,I2 const & i2)102 void ExecuteJob(I1 const & i1, I2 const & i2) { 103 struct { 104 I1 i1_; 105 I2 i2_; 106 } inputs = { i1, i2 }; 107 embb::mtapi::Node & node = embb::mtapi::Node::GetInstance(); 108 embb::mtapi::Task task = 109 node.Start(MTAPI_TASK_ID_NONE, job_.GetInternal(), 110 &inputs, sizeof(inputs), 111 MTAPI_NULL, 0, 112 MTAPI_DEFAULT_TASK_ATTRIBUTES); 113 task.Wait(); 114 } 115 }; 116 117 template <typename I1, typename I2, typename I3> 118 class SinkExecutor< Inputs<I1, I2, I3> > { 119 public: 120 typedef embb::base::Function<void, I1 const &, I2 const &, I3 const &> 121 FunctionType; 122 SinkExecutor(FunctionType func)123 explicit SinkExecutor(FunctionType func) : function_(func) {} SinkExecutor(embb::mtapi::Job job)124 explicit SinkExecutor(embb::mtapi::Job job) 125 : job_(job) { 126 function_ = FunctionType(*this, &SinkExecutor::ExecuteJob); 127 } 128 Execute(int clock,Inputs<I1,I2,I3> & inputs)129 void Execute( 130 int clock, 131 Inputs<I1, I2, I3> & inputs) { 132 function_( 133 inputs.template Get<0>().GetValue(clock), 134 inputs.template Get<1>().GetValue(clock), 135 inputs.template Get<2>().GetValue(clock)); 136 } 137 138 private: 139 FunctionType function_; 140 embb::mtapi::Job job_; 141 ExecuteJob(I1 const & i1,I2 const & i2,I3 const & i3)142 void ExecuteJob(I1 const & i1, I2 const & i2, I3 const & i3) { 143 struct { 144 I1 i1_; 145 I2 i2_; 146 I3 i3_; 147 } inputs = { i1, i2, i3 }; 148 embb::mtapi::Node & node = embb::mtapi::Node::GetInstance(); 149 embb::mtapi::Task task = 150 node.Start(MTAPI_TASK_ID_NONE, job_.GetInternal(), 151 &inputs, sizeof(inputs), 152 MTAPI_NULL, 0, 153 MTAPI_DEFAULT_TASK_ATTRIBUTES); 154 task.Wait(); 155 } 156 }; 157 158 template <typename I1, typename I2, typename I3, typename I4> 159 class SinkExecutor< Inputs<I1, I2, I3, I4> > { 160 public: 161 typedef embb::base::Function<void, I1 const &, I2 const &, I3 const &, 162 I4 const &> FunctionType; 163 SinkExecutor(FunctionType func)164 explicit SinkExecutor(FunctionType func) : function_(func) {} SinkExecutor(embb::mtapi::Job job)165 explicit SinkExecutor(embb::mtapi::Job job) 166 : job_(job) { 167 function_ = FunctionType(*this, &SinkExecutor::ExecuteJob); 168 } 169 Execute(int clock,Inputs<I1,I2,I3,I4> & inputs)170 void Execute( 171 int clock, 172 Inputs<I1, I2, I3, I4> & inputs) { 173 function_( 174 inputs.template Get<0>().GetValue(clock), 175 inputs.template Get<1>().GetValue(clock), 176 inputs.template Get<2>().GetValue(clock), 177 inputs.template Get<3>().GetValue(clock)); 178 } 179 180 private: 181 FunctionType function_; 182 embb::mtapi::Job job_; 183 ExecuteJob(I1 const & i1,I2 const & i2,I3 const & i3,I4 const & i4)184 void ExecuteJob(I1 const & i1, I2 const & i2, I3 const & i3, 185 I4 const & i4) { 186 struct { 187 I1 i1_; 188 I2 i2_; 189 I3 i3_; 190 I4 i4_; 191 } inputs = { i1, i2, i3, i4 }; 192 embb::mtapi::Node & node = embb::mtapi::Node::GetInstance(); 193 embb::mtapi::Task task = 194 node.Start(MTAPI_TASK_ID_NONE, job_.GetInternal(), 195 &inputs, sizeof(inputs), 196 MTAPI_NULL, 0, 197 MTAPI_DEFAULT_TASK_ATTRIBUTES); 198 task.Wait(); 199 } 200 }; 201 202 template <typename I1, typename I2, typename I3, typename I4, 203 typename I5> 204 class SinkExecutor< Inputs<I1, I2, I3, I4, I5> > { 205 public: 206 typedef embb::base::Function<void, I1 const &, I2 const &, I3 const &, 207 I4 const &, I5 const &> FunctionType; 208 SinkExecutor(FunctionType func)209 explicit SinkExecutor(FunctionType func) : function_(func) {} SinkExecutor(embb::mtapi::Job job)210 explicit SinkExecutor(embb::mtapi::Job job) 211 : job_(job) { 212 function_ = FunctionType(*this, &SinkExecutor::ExecuteJob); 213 } 214 Execute(int clock,Inputs<I1,I2,I3,I4,I5> & inputs)215 void Execute( 216 int clock, 217 Inputs<I1, I2, I3, I4, I5> & inputs) { 218 function_( 219 inputs.template Get<0>().GetValue(clock), 220 inputs.template Get<1>().GetValue(clock), 221 inputs.template Get<2>().GetValue(clock), 222 inputs.template Get<3>().GetValue(clock), 223 inputs.template Get<4>().GetValue(clock)); 224 } 225 226 private: 227 FunctionType function_; 228 embb::mtapi::Job job_; 229 ExecuteJob(I1 const & i1,I2 const & i2,I3 const & i3,I4 const & i4,I5 const & i5)230 void ExecuteJob(I1 const & i1, I2 const & i2, I3 const & i3, 231 I4 const & i4, I5 const & i5) { 232 struct { 233 I1 i1_; 234 I2 i2_; 235 I3 i3_; 236 I4 i4_; 237 I5 i5_; 238 } inputs = { i1, i2, i3, i4, i5 }; 239 embb::mtapi::Node & node = embb::mtapi::Node::GetInstance(); 240 embb::mtapi::Task task = 241 node.Start(MTAPI_TASK_ID_NONE, job_.GetInternal(), 242 &inputs, sizeof(inputs), 243 MTAPI_NULL, 0, 244 MTAPI_DEFAULT_TASK_ATTRIBUTES); 245 task.Wait(); 246 } 247 }; 248 249 } // namespace internal 250 } // namespace dataflow 251 } // namespace embb 252 253 #endif // EMBB_DATAFLOW_INTERNAL_SINK_EXECUTOR_H_ 254