vipinkmenon / neuralNetwork

MIT License
245 stars 73 forks source link

Issue on filename #4

Open qcsui opened 7 months ago

qcsui commented 7 months ago

When running simulation on the top_sim.v of Tut-5 on verification of neural network, I encountered the following error:

                $readmemb(fileName, config_mem);

Error: first argument of $readmemb must be a file name.

I think the reg type is not recognized as the string type needed for the readmemb.

qcsui commented 7 months ago

found some alternative:

using the following code of python, I can generate the verilog code without dynamically alter the file name.

# generate_verilog.py

num_layers = 4  
num_neurons = [30, 30, 10, 10]  
num_weights = [784, 30, 30, 10]

verilog_code = ""

for k in range(1, num_layers + 1):
    for j in range(num_neurons[k-1]):
        if j > 9:
            file_name = f'"w_{k}_{j}.mif"'
        else:
            file_name = f'"w_{k}_0{j}.mif"' #f'"fim.0{j}_{k}_w"'

        verilog_code += f'$readmemb({file_name}, config_mem);\n'
        verilog_code += f'        writeAxi(16,{j}); // Write neuron number\n'
        for t in range(num_weights[k-1]):
            verilog_code += f'        writeAxi(0,{{15\'d0,config_mem[{t}]}});end \n'

with open("generated_verilog.v", "w") as file:
    file.write(verilog_code)