-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGenericNodes.h
More file actions
819 lines (646 loc) · 21.9 KB
/
GenericNodes.h
File metadata and controls
819 lines (646 loc) · 21.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
/* ----------------------------------------------------------------------
* Project: CMSIS DSP Library
* Title: GenericNodes.h
* Description: C++ support templates for the compute graph with static scheduler
*
*
* Target Processor: Cortex-M and Cortex-A cores
* --------------------------------------------------------------------
*
* Copyright (C) 2021-2023 ARM Limited or its affiliates. All rights reserved.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _SCHEDGEN_H_
#define _SCHEDGEN_H_
#include <vector>
#include <cstring>
#include <stdarg.h>
/*
Defined in cg_status.h by default but user
may want to use a different header to define the
error codes of the application
*/
#ifndef CG_SUCCESS_ID_CODE
#define CG_SUCCESS_ID_CODE (CG_SUCCESS)
#endif
#ifndef CG_SKIP_EXECUTION_ID_CODE
#define CG_SKIP_EXECUTION_ID_CODE (CG_SKIP_EXECUTION)
#endif
#ifndef CG_BUFFER_ERROR_ID_CODE
#define CG_BUFFER_ERROR_ID_CODE (CG_BUFFER_ERROR)
#endif
/*
For callback mode
*/
enum kCBStatus {
kNewExecution = 1,
kResumedExecution = 2
};
/* Node ID is -1 when nodes are not identified for the external
world */
#define CG_UNIDENTIFIED_NODE (-1)
namespace arm_cmsis_stream {
// FIFOS
#ifdef DEBUGSCHED
#include <iostream>
template<typename T>
struct debugtype{
typedef T type;
};
template<>
struct debugtype<char>{
typedef int type;
};
template<typename T>
using Debug = struct debugtype<T>;
#endif
/***************
*
* FIFOs
*
**************/
template<typename T>
class FIFOBase{
public:
virtual T* getWriteBuffer(int nb)=0;
virtual T* getReadBuffer(int nb)=0;
virtual ~FIFOBase() {};
/*
Used when FIFO buffer is enforced by a node.
Can only be used before the FIFO has been interacted with
*/
virtual void setBuffer(T *buffer)=0;
/*
Below functions are only useful in asynchronous mode.
Synchronous implementation can provide an empty
implementation.
*/
virtual bool willUnderflowWith(int nb) const = 0;
virtual bool willOverflowWith(int nb) const = 0;
virtual int nbSamplesInFIFO() const = 0;
virtual int nbOfFreeSamplesInFIFO() const = 0;
};
template<typename T, int length, int isArray=0, int isAsync = 0>
class FIFO;
/* Real FIFO, Synchronous */
template<typename T, int length>
class FIFO<T,length,0,0>: public FIFOBase<T>
{
public:
explicit FIFO(T *buffer,int delay=0):mBuffer(buffer),readPos(0),writePos(delay) {};
/* Constructor used for memory sharing optimization.
The buffer is a shared memory wrapper */
explicit FIFO(void *buffer,int delay=0):mBuffer((T*)buffer),readPos(0),writePos(delay) {};
void setBuffer(T *buffer){mBuffer = buffer;};
/*
FIFO are fixed and not made to be copied or moved.
*/
FIFO(const FIFO&) = delete;
FIFO(FIFO&&) = delete;
FIFO& operator=(const FIFO&) = delete;
FIFO& operator=(FIFO&&) = delete;
bool willUnderflowWith(int nb) const final
{
return((writePos - readPos - nb)<0);
}
bool willOverflowWith(int nb) const final
{
return((writePos - readPos + nb)>length);
}
int nbSamplesInFIFO() const final {return (writePos - readPos);};
int nbOfFreeSamplesInFIFO() const final {return (length - writePos + readPos);};
T * getWriteBuffer(int nb) final
{
T *ret;
if (readPos > 0)
{
/* This is re-aligning the read buffer.
Aligning buffer is better for vectorized code.
But it has an impact since more memcpy are
executed than required.
This is likely to be not so useful in practice
so a future version will optimize the memcpy usage
*/
memcpy((void*)mBuffer,(void*)(mBuffer+readPos),(writePos-readPos)*sizeof(T));
writePos -= readPos;
readPos = 0;
}
ret = mBuffer + writePos;
writePos += nb;
return(ret);
};
T* getReadBuffer(int nb) final
{
T *ret = mBuffer + readPos;
readPos += nb;
return(ret);
}
#ifdef DEBUGSCHED
void dump()
{
int nb=0;
std::cout << std::endl;
for(int i=0; i < length ; i++)
{
std::cout << (typename Debug<T>::type)mBuffer[i] << " ";
nb++;
if (nb == 10)
{
nb=0;
std::cout << std::endl;
}
}
std::cout << std::endl;
std::cout << std::endl;
}
#endif
protected:
T * mBuffer;
int readPos,writePos;
};
/* Buffer, Synchronous */
template<typename T, int length>
class FIFO<T,length,1,0>: public FIFOBase<T>
{
public:
/* No delay argument for this version of the FIFO.
This version will not be generated when there is a delay
*/
explicit FIFO(T *buffer):mBuffer(buffer) {};
explicit FIFO(void *buffer):mBuffer((T*)buffer) {};
void setBuffer(T *buffer){mBuffer = buffer;};
/*
FIFO are fixed and not made to be copied or moved.
*/
FIFO(const FIFO&) = delete;
FIFO(FIFO&&) = delete;
FIFO& operator=(const FIFO&) = delete;
FIFO& operator=(FIFO&&) = delete;
/*
Not used in synchronous mode
and this version of the FIFO is
never used in asynchronous mode
so empty functions are provided.
*/
bool willUnderflowWith(int nb) const final {(void)nb;return false;};
bool willOverflowWith(int nb) const final {(void)nb;return false;};
int nbSamplesInFIFO() const final {return(0);};
int nbOfFreeSamplesInFIFO() const final {return( 0);};
T* getWriteBuffer(int nb) final
{
(void)nb;
return(mBuffer);
};
T* getReadBuffer(int nb) final
{
(void)nb;
return(mBuffer);
}
#ifdef DEBUGSCHED
void dump()
{
int nb=0;
std::cout << std::endl;
for(int i=0; i < length ; i++)
{
std::cout << (typename Debug<T>::type)mBuffer[i] << " ";
nb++;
if (nb == 10)
{
nb=0;
std::cout << std::endl;
}
}
std::cout << std::endl;
std::cout << std::endl;
}
#endif
protected:
T * mBuffer;
};
/* Real FIFO, Asynchronous */
template<typename T, int length>
class FIFO<T,length,0,1>: public FIFOBase<T>
{
public:
explicit FIFO(T *buffer,int delay=0):mBuffer(buffer),readPos(0),writePos(delay) {};
explicit FIFO(void *buffer,int delay=0):mBuffer((T*)buffer),readPos(0),writePos(delay) {};
void setBuffer(T *buffer){mBuffer = buffer;};
/*
FIFO are fixed and not made to be copied or moved.
*/
FIFO(const FIFO&) = delete;
FIFO(FIFO&&) = delete;
FIFO& operator=(const FIFO&) = delete;
FIFO& operator=(FIFO&&) = delete;
/*
Check for overflow must have been done
before using this function
*/
T * getWriteBuffer(int nb) final
{
T *ret;
if (readPos > 0)
{
memcpy((void*)mBuffer,(void*)(mBuffer+readPos),(writePos-readPos)*sizeof(T));
writePos -= readPos;
readPos = 0;
}
ret = mBuffer + writePos;
writePos += nb;
return(ret);
};
/*
Check for undeflow must have been done
before using this function
*/
T* getReadBuffer(int nb) final
{
T *ret = mBuffer + readPos;
readPos += nb;
return(ret);
}
bool willUnderflowWith(int nb) const final
{
return((writePos - readPos - nb)<0);
}
bool willOverflowWith(int nb) const final
{
return((writePos - readPos + nb)>length);
}
int nbSamplesInFIFO() const final {return (writePos - readPos);};
int nbOfFreeSamplesInFIFO() const final {return (length - writePos + readPos);};
#ifdef DEBUGSCHED
void dump()
{
int nb=0;
std::cout << std::endl;
std::cout << "FIFO nb samples = " << (writePos - readPos) << std::endl;
for(int i=0; i < length ; i++)
{
std::cout << (typename Debug<T>::type)mBuffer[i] << " ";
nb++;
if (nb == 10)
{
nb=0;
std::cout << std::endl;
}
}
std::cout << std::endl;
std::cout << std::endl;
}
#endif
protected:
T * mBuffer;
int readPos,writePos;
};
/***************
*
* GENERIC NODES
*
**************/
class NodeBase
{
public:
virtual int run()=0;
virtual int prepareForRunning()=0;
virtual ~NodeBase() {};
NodeBase(){};
/*
Nodes are fixed and not made to be copied or moved.
*/
NodeBase(const NodeBase&) = delete;
NodeBase(NodeBase&&) = delete;
NodeBase& operator=(const NodeBase&) = delete;
NodeBase& operator=(NodeBase&&) = delete;
void setID(int id) {mNodeID = id;};
int nodeID() const {return(mNodeID);};
void setExecutionStatus(kCBStatus id) {mExecutionStatus = id;};
kCBStatus executionStatus() const {return(mExecutionStatus);};
private:
int mNodeID = CG_UNIDENTIFIED_NODE;
kCBStatus mExecutionStatus = kNewExecution;
};
template<typename IN, int inputSize,typename OUT, int outputSize>
class GenericNode:public NodeBase
{
public:
explicit GenericNode(FIFOBase<IN> &src,FIFOBase<OUT> &dst):mSrc(src),mDst(dst){};
protected:
OUT * getWriteBuffer(int nb = outputSize) {return mDst.getWriteBuffer(nb);};
IN * getReadBuffer(int nb = inputSize) {return mSrc.getReadBuffer(nb);};
bool willOverflow(int nb = outputSize) const {return mDst.willOverflowWith(nb);};
bool willUnderflow(int nb = inputSize) const {return mSrc.willUnderflowWith(nb);};
private:
FIFOBase<IN> &mSrc;
FIFOBase<OUT> &mDst;
};
template<typename IN, int inputSize,
typename OUT, int outputSize>
class GenericToManyNode:public NodeBase
{
public:
explicit GenericToManyNode(FIFOBase<IN> &src,
std::initializer_list<FIFOBase<OUT>*> dst):mSrc(src),mDstList(dst){};
protected:
size_t getNbOutputs() const {return(mDstList.size());};
IN * getReadBuffer(int nb = inputSize) {return mSrc.getReadBuffer(nb);};
OUT * getWriteBuffer(int id=0,int nb = outputSize) {return mDstList[id]->getWriteBuffer(nb);};
bool willUnderflow(int nb = inputSize) const {return mSrc.willUnderflowWith(nb);};
bool willOverflow(int id=0,int nb = outputSize) const {return mDstList[id]->willOverflowWith(nb);};
private:
FIFOBase<IN> &mSrc;
const std::vector<FIFOBase<OUT>*> mDstList;
};
template<typename IN, int inputSize,
typename OUT, int outputSize>
class GenericFromManyNode:public NodeBase
{
public:
explicit GenericFromManyNode(std::initializer_list<FIFOBase<IN>*> src,
FIFOBase<OUT> &dst):mSrcList(src),mDst(dst){};
protected:
size_t getNbInputs() const {return(mSrcList.size());};
IN *getReadBuffer(int id=0,int nb = inputSize) {return mSrcList[id]->getReadBuffer(nb);};
OUT *getWriteBuffer(int nb = outputSize) {return mDst.getWriteBuffer(nb);};
bool willUnderflow(int id=0,int nb = inputSize) const {return mSrcList[id]->willUnderflowWith(nb);};
bool willOverflow(int nb = outputSize) const {return mDst.willOverflowWith(nb);};
private:
const std::vector<FIFOBase<IN>*> mSrcList;
FIFOBase<OUT> &mDst;
};
template<typename IN, int inputSize,
typename OUT, int outputSize>
class GenericManyToManyNode:public NodeBase
{
public:
explicit GenericManyToManyNode(std::initializer_list<FIFOBase<IN>*> src,
std::initializer_list<FIFOBase<OUT>*> dst):mSrcList(src),mDstList(dst){};
protected:
size_t getNbInputs() const {return(mSrcList.size());};
size_t getNbOutputs() const {return(mDstList.size());};
IN *getReadBuffer(int id=0,int nb = inputSize) {return mSrcList[id]->getReadBuffer(nb);};
OUT *getWriteBuffer(int id=0,int nb = outputSize) {return mDstList[id]->getWriteBuffer(nb);};
bool willUnderflow(int id=0,int nb = inputSize) const {return mSrcList[id]->willUnderflowWith(nb);};
bool willOverflow(int id=0,int nb = outputSize) const {return mDstList[id]->willOverflowWith(nb);};
private:
const std::vector<FIFOBase<IN>*> mSrcList;
const std::vector<FIFOBase<OUT>*> mDstList;
};
template<typename IN, int inputSize,typename OUT1, int output1Size,typename OUT2, int output2Size>
class GenericNode12:public NodeBase
{
public:
explicit GenericNode12(FIFOBase<IN> &src,FIFOBase<OUT1> &dst1,FIFOBase<OUT2> &dst2):mSrc(src),
mDst1(dst1),mDst2(dst2){};
protected:
OUT1 * getWriteBuffer1(int nb=output1Size) {return mDst1.getWriteBuffer(nb);};
OUT2 * getWriteBuffer2(int nb=output2Size) {return mDst2.getWriteBuffer(nb);};
IN * getReadBuffer(int nb=inputSize) {return mSrc.getReadBuffer(nb);};
bool willOverflow1(int nb = output1Size) const {return mDst1.willOverflowWith(nb);};
bool willOverflow2(int nb = output2Size) const {return mDst2.willOverflowWith(nb);};
bool willUnderflow(int nb = inputSize) const {return mSrc.willUnderflowWith(nb);};
private:
FIFOBase<IN> &mSrc;
FIFOBase<OUT1> &mDst1;
FIFOBase<OUT2> &mDst2;
};
template<typename IN, int inputSize,
typename OUT1, int output1Size,
typename OUT2, int output2Size,
typename OUT3, int output3Size>
class GenericNode13:public NodeBase
{
public:
explicit GenericNode13(FIFOBase<IN> &src,
FIFOBase<OUT1> &dst1,
FIFOBase<OUT2> &dst2,
FIFOBase<OUT3> &dst3
):mSrc(src),
mDst1(dst1),mDst2(dst2),mDst3(dst3){};
protected:
OUT1 * getWriteBuffer1(int nb=output1Size) {return mDst1.getWriteBuffer(nb);};
OUT2 * getWriteBuffer2(int nb=output2Size) {return mDst2.getWriteBuffer(nb);};
OUT3 * getWriteBuffer3(int nb=output3Size) {return mDst3.getWriteBuffer(nb);};
IN * getReadBuffer(int nb=inputSize) {return mSrc.getReadBuffer(nb);};
bool willOverflow1(int nb = output1Size) const {return mDst1.willOverflowWith(nb);};
bool willOverflow2(int nb = output2Size) const {return mDst2.willOverflowWith(nb);};
bool willOverflow3(int nb = output3Size) const {return mDst3.willOverflowWith(nb);};
bool willUnderflow(int nb = inputSize) const {return mSrc.willUnderflowWith(nb);};
private:
FIFOBase<IN> &mSrc;
FIFOBase<OUT1> &mDst1;
FIFOBase<OUT2> &mDst2;
FIFOBase<OUT3> &mDst3;
};
template<typename IN1, int input1Size,typename IN2, int input2Size,typename OUT, int outputSize>
class GenericNode21:public NodeBase
{
public:
explicit GenericNode21(FIFOBase<IN1> &src1,FIFOBase<IN2> &src2,FIFOBase<OUT> &dst):mSrc1(src1),
mSrc2(src2),
mDst(dst){};
protected:
OUT * getWriteBuffer(int nb=outputSize) {return mDst.getWriteBuffer(nb);};
IN1 * getReadBuffer1(int nb=input1Size) {return mSrc1.getReadBuffer(nb);};
IN2 * getReadBuffer2(int nb=input2Size) {return mSrc2.getReadBuffer(nb);};
bool willOverflow(int nb = outputSize) const {return mDst.willOverflowWith(nb);};
bool willUnderflow1(int nb = input1Size) const {return mSrc1.willUnderflowWith(nb);};
bool willUnderflow2(int nb = input2Size) const {return mSrc2.willUnderflowWith(nb);};
private:
FIFOBase<IN1> &mSrc1;
FIFOBase<IN2> &mSrc2;
FIFOBase<OUT> &mDst;
};
template<typename IN1, int input1Size,
typename IN2, int input2Size,
typename IN3, int input3Size,
typename OUT, int outputSize>
class GenericNode31:public NodeBase
{
public:
explicit GenericNode31(FIFOBase<IN1> &src1,
FIFOBase<IN2> &src2,
FIFOBase<IN3> &src3,
FIFOBase<OUT> &dst):mSrc1(src1),
mSrc2(src2),
mSrc3(src3),
mDst(dst){};
protected:
OUT * getWriteBuffer(int nb=outputSize) {return mDst.getWriteBuffer(nb);};
IN1 * getReadBuffer1(int nb=input1Size) {return mSrc1.getReadBuffer(nb);};
IN2 * getReadBuffer2(int nb=input2Size) {return mSrc2.getReadBuffer(nb);};
IN3 * getReadBuffer3(int nb=input3Size) {return mSrc3.getReadBuffer(nb);};
bool willOverflow(int nb = outputSize) const {return mDst.willOverflowWith(nb);};
bool willUnderflow1(int nb = input1Size) const {return mSrc1.willUnderflowWith(nb);};
bool willUnderflow2(int nb = input2Size) const {return mSrc2.willUnderflowWith(nb);};
bool willUnderflow3(int nb = input3Size) const {return mSrc3.willUnderflowWith(nb);};
private:
FIFOBase<IN1> &mSrc1;
FIFOBase<IN2> &mSrc2;
FIFOBase<IN3> &mSrc3;
FIFOBase<OUT> &mDst;
};
template<typename OUT, int outputSize>
class GenericSource:public NodeBase
{
public:
explicit GenericSource(FIFOBase<OUT> &dst):mDst(dst){};
protected:
OUT * getWriteBuffer(int nb=outputSize) {return mDst.getWriteBuffer(nb);};
bool willOverflow(int nb = outputSize) const {return mDst.willOverflowWith(nb);};
private:
FIFOBase<OUT> &mDst;
};
template<typename IN,int inputSize>
class GenericSink:public NodeBase
{
public:
explicit GenericSink(FIFOBase<IN> &src):mSrc(src){};
protected:
IN * getReadBuffer(int nb=inputSize) {return mSrc.getReadBuffer(nb);};
bool willUnderflow(int nb = inputSize) const {return mSrc.willUnderflowWith(nb);};
private:
FIFOBase<IN> &mSrc;
};
#define REPEAT(N) for(int i=0;i<N;i++)
/***************
*
* BUFFER MANAGEMENT SUPPORT
*
* Classes to help manage buffers in a graph
*
**************/
template<typename T, bool shared=true>
struct Shared {
explicit Shared(T* t) : val_(t) {}
Shared(int) : val_(nullptr) {}
/*
When shared we can only get a pointer to
const data
*/
const T* get() const { return val_; }
Shared<T,true> share()
{
return(*this);
};
private:
T* val_;
};
template<typename T>
struct Shared<T,false> {
explicit Shared(T* t) : val_(t) {}
Shared(int) : val_(nullptr) {}
/*
When unique we can get a pointer to
non const data
*/
T* get() { return val_; }
const T* get() const { return val_; }
operator T*() { return val_; }
Shared<T,true> share()
{
Shared<T,true> res(val_);
return(res);
};
private:
T* val_;
};
template<typename IN, int inputSize,
typename OUT, int outputSize>
class Duplicate;
template<typename IO,
bool inputShareStatus,
int ioSize>
class Duplicate<Shared<IO,inputShareStatus>, ioSize,
Shared<IO,true>, ioSize>:
public GenericToManyNode<Shared<IO,inputShareStatus>, ioSize,
Shared<IO,true>, ioSize>
{
public:
explicit Duplicate(FIFOBase<Shared<IO,inputShareStatus>> &src,
std::initializer_list<FIFOBase<Shared<IO,true>>*> dst):
GenericToManyNode<Shared<IO,inputShareStatus> , ioSize,
Shared<IO,true>, ioSize>(src,dst)
{
};
int prepareForRunning() final
{
if (this->willUnderflow())
{
return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
}
for(unsigned int i=0;i<this->getNbOutputs();i++)
{
if (this->willOverflow(i))
{
return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
}
}
return(CG_SUCCESS_ID_CODE);
};
int run() final {
Shared<IO,inputShareStatus> *a=this->getReadBuffer();
for(unsigned int i=0;i<this->getNbOutputs();i++)
{
Shared<IO,true> *b=this->getWriteBuffer(i);
for(int k=0;k<ioSize;k++)
{
b[k] = a[k].share();
}
}
return(CG_SUCCESS_ID_CODE);
};
};
template<typename IO, int inputOutputSize>
class Duplicate<IO, inputOutputSize,
IO, inputOutputSize>:
public GenericToManyNode<IO, inputOutputSize,
IO, inputOutputSize>
{
public:
explicit Duplicate(FIFOBase<IO> &src,
std::initializer_list<FIFOBase<IO>*> dst):
GenericToManyNode<IO, inputOutputSize,IO, inputOutputSize>(src,dst)
{
};
int prepareForRunning() final
{
if (this->willUnderflow())
{
return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
}
for(unsigned int i=0;i<this->getNbOutputs();i++)
{
if (this->willOverflow(i))
{
return(CG_SKIP_EXECUTION_ID_CODE); // Skip execution
}
}
return(CG_SUCCESS_ID_CODE);
};
int run() final {
IO *a=this->getReadBuffer();
for(unsigned int i=0;i<this->getNbOutputs();i++)
{
IO *b=this->getWriteBuffer(i);
memcpy(b,a,sizeof(IO)*inputOutputSize);
}
return(CG_SUCCESS_ID_CODE);
};
};
} // End namespace
#endif