yashas89 Posted February 14 Report Share Posted February 14 #include <iostream> #include <systemc> using namespace sc_core; using namespace sc_dt; using namespace std; // Define the PE module SC_MODULE(PE) { sc_in<sc_uint<16>> element_in; sc_in<sc_uint<16>> pSum_in; sc_in<bool> clk, clear; sc_out<sc_uint<16>> element_out; sc_out<sc_uint<16>> pSum_out; // Constructor SC_CTOR(PE) { SC_METHOD(compute); sensitive << clk.pos() << clear; dont_initialize(); element_out.initialize(0); pSum_out.initialize(0); } // Compute method void compute() { if (clear.read()) { element_out.write(0); pSum_out.write(0); } else { element_out.write(element_in.read()); pSum_out.write(pSum_in.read()); } } }; // Define the ADDER module SC_MODULE(Adder) { // Define inputs and outputs sc_in<sc_uint<16>> a, b; sc_out<sc_uint<32>> sum; // Constructor SC_CTOR(Adder) { SC_METHOD(add); sensitive << a << b; sum.initialize(0); } // Add method void add() { sum.write(a.read() + b.read()); } }; // Define the WALLACE module SC_MODULE(Wallace) { // Define inputs and outputs sc_in<sc_uint<16>> a_0, b_0; sc_out<sc_uint<32>> result; // Constructor SC_CTOR(Wallace) { SC_METHOD(multiply); sensitive << a_0 << b_0; result.initialize(0); } // Multiply method void multiply() { result.write(a_0.read() * b_0.read()); } }; // Define the CPA module SC_MODULE(CPA) { // Define inputs and outputs sc_in<sc_uint<16>> p, g; sc_out<sc_uint<16>> c; // Constructor SC_CTOR(CPA) { SC_METHOD(compute); sensitive << p << g; c.initialize(0); } // Compute method void compute() { c.write(p.read() + g.read()); } }; SC_MODULE(SystolicArray) { sc_in<bool> clk, clear; sc_in<sc_uint<16>> data_in1,data_in2, data_in3, data_in4, data_in5; sc_out<sc_uint<16>>data_out1, data_out2, data_out3, data_out4, data_out5; PE *pes[5][5]; SC_CTOR(SystolicArray) { for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; ++j) { pes[i][j] = new PE(sc_gen_unique_name("pe")); } } for (int i = 0; i <5; ++i) { for (int j = 0; j < 5; ++j) { pes[i][j]->clk(clk); pes[i][j]->clear(clear); if (i > 0) { pes[i][j]->element_in(pes[i - 1][j]->element_out); pes[i][j]->pSum_in(pes[i - 1][j]->pSum_out); } else { pes[i][j]->element_in(data_in1); pes[i][j]->pSum_in(data_in1); } if (j > 0) { pes[i][j]->element_in(pes[i][j - 1]->element_out); pes[i][j]->pSum_in(pes[i][j - 1]->pSum_out); } else{ pes[i][j]->element_out(data_out1); pes[i][j]->pSum_out(data_out1); } } } } }; // Define the testbench module SC_MODULE(Testbench) { // Define signals for testbench sc_signal<sc_uint<16>> data_in1, data_in2, data_in3, data_in4, data_in5; sc_signal<sc_uint<16>> data_out1, data_out2, data_out3, data_out4, data_out5; sc_clock clk_sig; sc_in<bool> clk; sc_signal<bool> clear, go; // Systolic array instance SystolicArray *sys; // Constructor SC_CTOR(Testbench) : clk_sig("clk", 1, SC_NS) { sys = new SystolicArray("sys"); sys->clk(clk); sys->clear(clear); sys->data_in1(data_in1); sys->data_in2(data_in2); sys->data_in3(data_in3); sys->data_in4(data_in4); sys->data_in5(data_in5); sys->data_out1(data_out1); sys->data_out2(data_out2); sys->data_out3(data_out3); sys->data_out4(data_out4); sys->data_out5(data_out5); SC_THREAD(run); sensitive << clk.pos(); dont_initialize(); clear = false; go = true; data_in1 = 0; data_in2 = 0; data_in3 = 0; data_in4 = 0; data_in5 = 0; } // Testbench run method void run() { clear = true; wait(5, SC_NS); clear = false; while (go) { wait(5, SC_NS); clk != clk; } sc_stop(); } }; // Main function int sc_main(int argc, char *argv[]) { Testbench tb("tb"); sc_trace_file *tf = sc_create_vcd_trace_file("systolic_array"); sc_trace(tf, tb.clk, "clk"); sc_trace(tf, tb.clear, "clear"); sc_trace(tf, tb.data_in1, "data_in1"); sc_trace(tf, tb.data_in2, "data_in2"); sc_trace(tf, tb.data_in3, "data_in3"); sc_trace(tf, tb.data_in4, "data_in4"); sc_trace(tf, tb.data_in5, "data_in5"); sc_trace(tf, tb.data_out1, "data_out1"); sc_trace(tf, tb.data_out2, "data_out2"); sc_trace(tf, tb.data_out3, "data_out3"); sc_trace(tf, tb.data_out4, "data_out4"); sc_trace(tf, tb.data_out5, "data_out5"); sc_start(); sc_close_vcd_trace_file(tf); return 0; } Quote Link to comment Share on other sites More sharing options...
Eyck Posted February 14 Report Share Posted February 14 Dumping a bunch of code with some screenshots is not really helpfull, you even did not ask a question. Looking at you unformatted and hard to read pasted code, pe[i][j]->pSum_out port is not bound if j is larger than 0. If you would name your ports properly (which is fairly straight forward using C++11), the error message would exactly tell you this. Quote Link to comment Share on other sites More sharing options...
yashas89 Posted February 15 Author Report Share Posted February 15 @EYCK ,i am really sorry for that , i accepts my mistake and i will make sure not to happen one more time, actually the code is not written by me i used chatgpt to generate it , so well i am working on systolic array where have created processing processing element(https://github.com/mig9mili/SYSTEMC---learning/tree/main/systollicarray__PE) now i have build systolic array for matrix multiplication so just get idea i used chatgpt but i end up with mess i am really sorry. Quote Link to comment Share on other sites More sharing options...
David Black Posted February 15 Report Share Posted February 15 Using AI for coding will likely result in you having very little true understanding of SystemC. I don't think it fair to ask a forum to correct errors introduced by chatGPT; otherwise, we could spend our lives enslaved to answering questions to teach AI. maehne and yashas89 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.