Skip to content

Generating a matrix in tta_stream_v1.in but not able to write the matrix on tta_stream_v1.out #252

@Rhrifateee

Description

@Rhrifateee

Hi, I can generate a matrix of 10x20 dimension of random integers in tta_stream_v1.in, the FU has been added from "Add from HDB".
main_architecture
stream_in_HDB
stream_out_HDB
random_h

The code to generate 10x20 matrix in tta_stream_v1.in is (this file is named as: "random.c")

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#include "random.h"
void generateRandomMatrix(int rows, int cols, FILE *file) {

for (int i = 0; i < rows; ++i) {

    for (int j = 0; j < cols; ++j) {

        //fprintf(file, "%0.4f", ((double)rand() / (double)RAND_MAX));

        

         fprintf(file, "%d ", rand() % 100);

    }

    fprintf(file, "\n");

}

}

int main() {

//int hiddenSize1=10;

//int inputSize=20;

srand(time(NULL)); 

FILE *outputFile = fopen("tta_stream_v1.in", "w");



if (outputFile == NULL) {

    fprintf(stderr, "Error opening the file.\n");

    return 1;

}



// Generate a random 10x20 matrix and write it to the file

generateRandomMatrix(hiddenSize1, inputSize, outputFile);



fclose(outputFile);

printf("Random numbers have been written to 'tta_stream_v1.in'.\n");



return 0;

}

The tta_stream_v1.in writes the matrix from the above code as follows:

tta_stream_v1_in

Now I want to read the matrix from tta_stream_v1.in and write it to tta_stream_v1.out by writing another code random_main.c. The code is given below:
#include <tceops.h>

//#include <time.h>

#include <stdlib.h>

//#include <math.h>

#include <stdio.h>

#include "random.h"
int main()

{

int X[hiddenSize1][inputSize];

int test[hiddenSize1][inputSize]={{0},{0}};

//int test = 0;

for (int i = 0; i < hiddenSize1; i++) 

{

    for (int j = 0; j < inputSize; j++) 

    {

    _TCE_STREAM_IN_V1(0,test[i][j]);

    //_TCE_STREAM_IN_V1(0,test);

       X[i][j] = test[i][j];

       //X[i][j] = test;

       _TCE_STREAM_OUT_V1(X[i][j]);

       }

  }

return 0;

}

The output in tta_stream_v1.out is:
image

What modification should I do in my random_main.c code to write the matrix in tta_stream_v1.out exactly as it is in tta_stream_v1.in?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions