TISP User Guide
TISP_fft2d_superNode_test.cpp
Go to the documentation of this file.
1 #include "TISP_blockCopy.hpp"
3 #include "TISP_superNode.hpp"
4 #include "TISP_test.h"
5 #include "TISP_util.hpp"
6 #include <cstdint>
7 #include <memory>
8 #include <stdint.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <tisp.hpp>
12 
13 using namespace std;
14 
15 #include <vector>
16 
17 #define TOTAL_DMA_CHANNELS (2)
18 
19 // Below cycle count assume flat memory model, i.e, no memory-related stalls
20 #define FFTLIB_FFT1DBATCHED_16X512_CYCLES (12904)
21 #define FFTLIB_FFT1DATCHED_512X512_CYCLES (FFTLIB_FFT1DBATCHED_16X512_CYCLES) * (512 / 16)
22 #define DSPLIB_MAT_TRANS_CYCLES ((NUM_POINTS * NUM_CHANNELS) / 4)
23 
24 #define ESITMATED_TOTAL_CYCLE_COUNT ((2 * FFTLIB_FFT1DATCHED_512X512_CYCLES) + DSPLIB_MAT_TRANS_CYCLES)
25 
26 void TISP_fft2d_test_cn(float *pX, float *pW, float *pTemp, float *pY, size_t numPoints, size_t numChannels);
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 Udma_DrvHandle TISP::SuperNode::appDrvHandle;
33 
34 #if defined(HOST_EMULATION)
35 Udma_DrvObj appUdmaDrvObj;
36 #else
37 Udma_DrvObjectInt appUdmaDrvObj;
38 #endif
39 
40 void *create_graph()
41 {
42 
43 #ifdef HOST_EMULATION
44 #if defined(_MSC_VER)
45  /* pIntMmeBase = (uint8_t *) _aligned_malloc(L2SRAM_SIZE, L2SRAM_SIZE); */
46 #else
47  /* pIntMmeBase = (uint8_t *) memalign(128, L2SRAM_SIZE); */
48 #endif
49 #elif __C7X_VEC_SIZE_BITS__ == 512
50  int32_t retVal = 0;
51  Sciclient_ConfigPrms_t sciClientCfg;
52  Sciclient_configPrmsInit(&sciClientCfg);
53  retVal = Sciclient_init(&sciClientCfg);
54  if (retVal != 0) {
55  printf("Sciclient Init Failed \n");
56  }
57 
60 #else
62 #endif
63 
65 
66  uint32_t numPoints = NUM_POINTS;
67  uint32_t numChannels = NUM_CHANNELS;
68 
69  uint32_t blockWidth = BLOCK_WIDTH;
70  uint32_t blockHeight = BLOCK_HEIGHT;
71 
72  float *input = INPUT_ADDR;
73  float *inputCn = INPUT_CN_ADDR;
74  float *tempOut = TEMP_OUT_ADDR;
75  float *output = OUTPUT_ADDR;
76 
77  float *pInputBlock = INPUT_BLOCK_ADDR;
78  float *pTempBlock = TEMP_BLOCK_ADDR;
79  float *pOutputBlock = OUT_BLOCK_ADDR;
80 
81  /* FILE *inputFile; */
82  /* FILE *refOutFile; */
83 
84  /* inputFile = fopen("./data/FFTLIB/input_32fc.bin", "r"); */
85  /* refOutFile = fopen("./data/FFTLIB/refOut_32fc.bin", "r"); */
86 
87  /* printf("\nReading input data\n"); */
88  /* fread(input, sizeof(double), numChannels * numPoints, inputFile); */
89 
90  for (uint32_t i = 0; i < numChannels * numPoints * 2; i++) {
91  input[i] = (float) rand() / (float) (RAND_MAX / (2 * 8)) - 8;
92  inputCn[i] = input[i];
93  }
94 
95  /* printf("\nReading ref data\n"); */
96  /* fread(refOut, sizeof(double), numChannels * numPoints, refOutFile); */
97 
98  printf("\n------------------------------------------------");
99  printf("\n 2D FFT Demo using TISP (%d x %d ) ", (NUM_CHANNELS), (NUM_POINTS));
100  printf("\n------------------------------------------------\n");
101 
102  printf("\nCreating Graph using smart pointers and rtos task in DDR:\n");
103  printf("\nDDR-->L2-->1DBatchedFFT-->L2-->MatrixTranspose-->L2-->DDR-->L2-->1DBatchedFFT-->L2-->DDR\n");
104 
106 
107  auto k0 = std::make_unique<TISP::FFTLIB::fft1dBatched<float, TISP::DMA_IN>>(pInputBlock, pTempBlock, numPoints,
108  blockHeight);
109 
110  auto k1 = std::make_unique<TISP::DSPLIB::matTrans<double, TISP::DMA_OUT>>(
111  (double *) pTempBlock, (double *) pOutputBlock, blockWidth >> 1, blockHeight, blockWidth * sizeof(double) >> 1,
112  blockHeight * sizeof(double));
113 
114  auto myOpVec0 = make_unique<TISP::opVec>();
115 
116  myOpVec0->push_back(std::move(k0));
117  myOpVec0->push_back(std::move(k1));
118 
119  auto s0 = std::make_unique<TISP::SuperNode::i2d_to_o2dTranspose<double, double>>(
120  std::move(myOpVec0), (double *) input, (double *) tempOut, (double *) pInputBlock, (double *) pOutputBlock,
121  numPoints, numChannels, blockWidth >> 1, blockHeight, (numPoints) * sizeof(double), numChannels * sizeof(double),
123 
124  auto k2 = std::make_unique<TISP::FFTLIB::fft1dBatched<float, TISP::DMA_IN_OUT>>(pInputBlock, pOutputBlock,
125  numChannels, blockHeight);
126 
127  auto myOpVec1 = std::make_unique<TISP::opVec>();
128 
129  myOpVec1->push_back(std::move(k2));
130 
131  auto s1 = std::make_unique<TISP::SuperNode::i2d_to_o2d<float, float>>(
132  std::move(myOpVec1), tempOut, output, pInputBlock, pOutputBlock, numChannels << 1, numPoints, numChannels << 1,
133  blockHeight, (numChannels << 1) * sizeof(float), (numChannels << 1) * sizeof(float), (TOTAL_DMA_CHANNELS));
134 
135  /*********************************************************************/
136  /* */
137  /*********************************************************************/
138 
139  auto mySuperNodeVec = new TISP::SuperNode::superNodeVec();
140 
141  mySuperNodeVec->push_back(std::move(s0));
142  mySuperNodeVec->push_back(std::move(s1));
143 
145 
146  // C-callable pointer to mySuperNodeVec that has all the info about the graph
147  // prevents usage of smart pointer
148  void *myGraph = mySuperNodeVec;
149 
150  return myGraph;
151 }
152 
153 void execute_graph(void *myGraph)
154 {
155 
156  printf("\nExecuting 2D FFt %d times\n", NUM_REPS);
157 
158 #if (!HOST_EMULATION)
159  uint64_t startTime, endTime;
160  startTime = (__get_GTSC(1), __STSC);
161 #endif
162 
163  for (int32_t i = 0; i < NUM_REPS; i++) {
164  TISP::SuperNode::superNodeVec *mySuperNodeVec = static_cast<TISP::SuperNode::superNodeVec *>(myGraph);
165 
166  TISP::execute::graph(mySuperNodeVec);
167  }
168 
169 #if (!HOST_EMULATION)
170  endTime = (__get_GTSC(1), __STSC);
171  uint64_t totalTime = (endTime - startTime) / (NUM_REPS);
172  printf("Average cycles to execute graph = %llu\n", totalTime);
173 
174  printf("\nTheoritical cycle count (assuming flat memory w/ no stalls): %d\n", (ESITMATED_TOTAL_CYCLE_COUNT));
175  printf("\nObeserved/Theoritical: %.2f\n", (((float) totalTime) / (ESITMATED_TOTAL_CYCLE_COUNT)));
176  printf("\nMemory performance of 2D FFT: %.2f GB/sec\n", (8 * NUM_POINTS * NUM_CHANNELS * 2) / ((float) totalTime));
177 #endif
178 }
179 
180 void delete_graph(void *myGraph)
181 {
182 
183  TISP::SuperNode::superNodeVec *mySuperNodeVec = static_cast<TISP::SuperNode::superNodeVec *>(myGraph);
184 
185  delete (mySuperNodeVec);
186 
187  return;
188 }
189 
191 {
192 
193  uint32_t numPoints = NUM_POINTS;
194  uint32_t numChannels = NUM_CHANNELS;
195 
196  float *inputCn = INPUT_CN_ADDR;
197  float *tempOutCn = TEMP_OUT_CN_ADDR;
198  float *output = OUTPUT_ADDR;
199 
200  float *refOut = REF_OUT_ADDR;
201 
202  float *pWCn = TW_CN_ADDR;
203 
204  printf("\nRunning Natc for 2D FFT\n");
205  TISP_fft2d_test_cn(inputCn, pWCn, tempOutCn, refOut, numPoints, numChannels);
206 
207  int32_t status = TI_compare_mem_2D_float((void *) output, (void *) refOut, 0, (double) powf(2, -2), numChannels << 1,
208  numPoints, (numChannels << 1) * sizeof(float), sizeof(float));
209 
210  if (status == TI_TEST_KERNEL_PASS) {
211  printf("Opt and Ref match! PASSED! \n");
212  }
213  else {
214  printf("Opt and Ref DON'T match! FAILED!!! \n");
215  }
216 
217  return;
218 }
219 #ifdef __cplusplus
220 }
221 #endif
#define NUM_POINTS
#define TW_CN_ADDR
#define NUM_CHANNELS
#define TEMP_OUT_CN_ADDR
void TISP_fft2d_test_cn(float *pX, float *pW, float *pTemp, float *pY, size_t numPoints, size_t numChannels)
void execute_graph(void *myGraph)
void check_output()
Udma_DrvObjectInt appUdmaDrvObj
#define ESITMATED_TOTAL_CYCLE_COUNT
void * create_graph()
void delete_graph(void *myGraph)
#define TOTAL_DMA_CHANNELS
void App_dmautilsClecInitDru(void)
static Udma_DrvHandle setUdmaDrvHandle(Udma_DrvObjectInt &udmaDrvObj)
static void graph(const opVec &myOpVec)
This function takes in alias of the opeVec (list of nodes) and iterates through all the nodes calling...
Definition: TISP_util.hpp:34
std::vector< std::unique_ptr< TISP::SuperNode::superNode > > superNodeVec
void appC7xClecInitDru(void)
int32_t test_sciclientDmscGetVersion(char *version_str, uint32_t version_str_size)