bitfield Posted September 9, 2022 Report Share Posted September 9, 2022 Hello, I am trying to figure out a design for a systolic array. For that I will need to instantiate shift registers with different delays for each row. E.g. the first row has no delay, the second one is delayed by one cycle, the third by two cycles etc. I have tried to do the following template<int WIDTH, int HEIGT> class SystolicArray : sc_module{ sc_module shift_registers[HEIGHT]; SC_CTOR(SystolicArray){ for(int h = 1; h < HEIGHT; h++){ shift_registers[h-1] = new ShiftRegister<h> //Connect stuff } } This fails with an error: # Error: systolic_array.h(61): error: the value of ‘h’ is not usable in a constant expression. My question then is: How would I go about designing this? Because all the information is available at compile time through the templates of SystolicArray I just can't figure out how to do this. Also, I want to stick to the synthesizable subset of SystemC. Thank you! Quote Link to comment Share on other sites More sharing options...
David Black Posted September 9, 2022 Report Share Posted September 9, 2022 If you are using Modern C++ (C++14 or C++17 would be best), then you could accomplish this with constexpr functions. You should also consider using sc_vector. Vanilla C/C++ arrays are simply evil anyhow. For non-SystemC components (i.e., modules, ports, channels) use std::vector<T> or std::array<T>). Also, you would save some code space if you used simple constructor arguments for your ShiftRegister and implement with std::vector. Quote Link to comment Share on other sites More sharing options...
Eyck Posted September 9, 2022 Report Share Posted September 9, 2022 This is basic C++: you try to use a local variable (h) declared in the for loop as a template parameter. This does not work. You need to modify your ShiftRegister class to take h as a constructor argument. David Black 1 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.