Making Array insctance

Hello,

I want to make a big array of instance from macro file.

When I make one cell, and make it and array by myself, even if it is super big, it creates really fast.
However, when I try to make it from the macro code, it takes a lot of time. sometime, when the input(size of column) is too big, the program stops working.
I used for loop for this implementation.

here is my code.
row and col will be input from initialize method.
and this code is running in the produce_impl method.

'''

row.times do |i| # x axis
      col.times do |j| # y axis
        # lb_u => Left Below point of upper PCell // ru_u => Right Upper point of upper PCell
        # lu_l => Left Upper point of Lower PCell // rb_l => Right Below point of Lower PCell
        # Upper PCell
        # s_1
        # rule 1
        puts "#{cnt}"
        cnt += 1
        x_s_1_lb_u = j * width
        y_s_1_lb_u = i*h_whole # Since it is half squre, so it should go up for the next row as 1.5 times of whole hight
        x_s_1_ru_u = x_s_1_lb_u + width
        y_s_1_ru_u = y_s_1_lb_u + viaSource/2
        # s_2 
        # rule 2
        x_s_2_lb_u = x_s_1_lb_u
        y_s_2_lb_u = y_s_1_lb_u
        x_s_2_ru_u = x_s_1_ru_u
        y_s_2_ru_u = y_s_2_lb_u + ohmSource/2
        # s_3
        # rule 3, 4
        x_s_3_lb_u = x_s_1_lb_u
        y_s_3_lb_u = y_s_1_lb_u
        x_s_3_ru_u = x_s_1_ru_u
        y_s_3_ru_u = y_s_3_lb_u + pPlus/2
        # s_4
        # rule 5
        #### need to edit!!
        x_s_4_lb_u = x_s_1_lb_u
        y_s_4_lb_u = y_s_2_ru_u + 1.5 # 1.5 is temporary default value
        x_s_4_ru_u = x_s_1_ru_u
        y_s_4_ru_u = y_s_4_lb_u + pGate
        # s_5
        # rule 6
        x_s_5_lb_u = x_s_1_lb_u
        x_s_5_ru_u = x_s_1_ru_u
        y_s_5_ru_u = y_s_4_lb_u + 0.75 # 0.75 is temporary default value
        y_s_5_lb_u = y_s_5_ru_u - nSource

        # s_6
        # rule 7
        x_s_6_lb_u = x_s_1_lb_u
        y_s_6_lb_u = y_s_1_lb_u
        x_s_6_ru_u = x_s_1_ru_u
        y_s_6_ru_u = y_s_5_ru_u + nChan
        # s_7
        # rule 8, 11
        x_s_7_lb_u = x_s_1_lb_u
        x_s_7_ru_u = x_s_1_ru_u
        y_s_7_ru_u = y_s_6_ru_u + jFET
        y_s_7_lb_u = y_s_7_ru_u - ohmGate
        # s_8
        # rule 9, 10
        x_s_8_lb_u = x_s_1_lb_u
        x_s_8_ru_u = x_s_1_ru_u
        y_s_8_ru_u = y_s_7_ru_u
        y_s_8_lb_u = y_s_8_ru_u - viaGate

        # Lower PCell
        x_s_1_lu_l = x_s_1_lb_u
        y_s_1_lu_l = -y_s_1_lb_u + i*h_whole*2
        x_s_1_rb_l = x_s_1_ru_u
        y_s_1_rb_l = -y_s_1_ru_u + i*h_whole*2

        x_s_2_lu_l = x_s_2_lb_u
        y_s_2_lu_l = -y_s_2_lb_u + i*h_whole*2
        x_s_2_rb_l = x_s_2_ru_u
        y_s_2_rb_l = -y_s_2_ru_u + i*h_whole*2

        x_s_3_lu_l = x_s_3_lb_u
        y_s_3_lu_l = -y_s_3_lb_u + i*h_whole*2
        x_s_3_rb_l = x_s_3_ru_u
        y_s_3_rb_l = -y_s_3_ru_u + i*h_whole*2

        x_s_4_lu_l = x_s_4_lb_u
        y_s_4_lu_l = -y_s_4_lb_u + i*h_whole*2
        x_s_4_rb_l = x_s_4_ru_u
        y_s_4_rb_l = -y_s_4_ru_u + i*h_whole*2

        x_s_5_lu_l = x_s_5_lb_u
        y_s_5_lu_l = -y_s_5_lb_u + i*h_whole*2
        x_s_5_rb_l = x_s_5_ru_u
        y_s_5_rb_l = -y_s_5_ru_u + i*h_whole*2

        x_s_6_lu_l = x_s_6_lb_u
        y_s_6_lu_l = -y_s_6_lb_u + i*h_whole*2
        x_s_6_rb_l = x_s_6_ru_u
        y_s_6_rb_l = -y_s_6_ru_u + i*h_whole*2

        x_s_7_lu_l = x_s_7_lb_u
        y_s_7_lu_l = -y_s_7_lb_u + i*h_whole*2
        x_s_7_rb_l = x_s_7_ru_u
        y_s_7_rb_l = -y_s_7_ru_u + i*h_whole*2

        x_s_8_lu_l = x_s_8_lb_u
        y_s_8_lu_l = -y_s_8_lb_u + i*h_whole*2
        x_s_8_rb_l = x_s_8_ru_u
        y_s_8_rb_l = -y_s_8_ru_u + i*h_whole*2

        # Upper PCell
        cell.shapes(layout.layer(1000, 0)).insert(RBA::Box::new(x_s_1_lb_u/dbu, y_s_1_lb_u/dbu, x_s_1_ru_u/dbu, y_s_1_ru_u/dbu))
        cell.shapes(layout.layer(1000, 0)).insert(RBA::Box::new(x_s_8_lb_u/dbu, y_s_8_lb_u/dbu, x_s_8_ru_u/dbu, y_s_8_ru_u/dbu))

        cell.shapes(layout.layer(1001, 0)).insert(RBA::Box::new(x_s_2_lb_u/dbu, y_s_2_lb_u/dbu, x_s_2_ru_u/dbu, y_s_2_ru_u/dbu))
        cell.shapes(layout.layer(1001, 0)).insert(RBA::Box::new(x_s_7_lb_u/dbu, y_s_7_lb_u/dbu, x_s_7_ru_u/dbu, y_s_7_ru_u/dbu))

        cell.shapes(layout.layer(1002, 0)).insert(RBA::Box::new(x_s_4_lb_u/dbu, y_s_4_lb_u/dbu, x_s_4_ru_u/dbu, y_s_4_ru_u/dbu))

        cell.shapes(layout.layer(1003, 0)).insert(RBA::Box::new(x_s_3_lb_u/dbu, y_s_3_lb_u/dbu, x_s_3_ru_u/dbu, y_s_3_ru_u/dbu))

        cell.shapes(layout.layer(1004, 0)).insert(RBA::Box::new(x_s_5_lb_u/dbu, y_s_5_lb_u/dbu, x_s_5_ru_u/dbu, y_s_5_ru_u/dbu))
        cell.shapes(layout.layer(1005, 0)).insert(RBA::Box::new(x_s_6_lb_u/dbu, y_s_6_lb_u/dbu, x_s_6_ru_u/dbu, y_s_6_ru_u/dbu))
#        puts"#{x_s_5_lb_u}, #{y_s_5_lb_u}, #{x_s_5_ru_u}, #{y_s_5_ru_u}"

        # Lower PCell         
        cell.shapes(layout.layer(1000, 0)).insert(RBA::Box::new(x_s_1_lu_l/dbu, y_s_1_lu_l/dbu, x_s_1_rb_l/dbu, y_s_1_rb_l/dbu))
        cell.shapes(layout.layer(1000, 0)).insert(RBA::Box::new(x_s_8_lu_l/dbu, y_s_8_lu_l/dbu, x_s_8_rb_l/dbu, y_s_8_rb_l/dbu))

        cell.shapes(layout.layer(1001, 0)).insert(RBA::Box::new(x_s_2_lu_l/dbu, y_s_2_lu_l/dbu, x_s_2_rb_l/dbu, y_s_2_rb_l/dbu))
        cell.shapes(layout.layer(1001, 0)).insert(RBA::Box::new(x_s_7_lu_l/dbu, y_s_7_lu_l/dbu, x_s_7_rb_l/dbu, y_s_7_rb_l/dbu))

        cell.shapes(layout.layer(1002, 0)).insert(RBA::Box::new(x_s_4_lu_l/dbu, y_s_4_lu_l/dbu, x_s_4_rb_l/dbu, y_s_4_rb_l/dbu))

        cell.shapes(layout.layer(1003, 0)).insert(RBA::Box::new(x_s_3_lu_l/dbu, y_s_3_lu_l/dbu, x_s_3_rb_l/dbu, y_s_3_rb_l/dbu))

        cell.shapes(layout.layer(1004, 0)).insert(RBA::Box::new(x_s_5_lu_l/dbu, y_s_5_lu_l/dbu, x_s_5_rb_l/dbu, y_s_5_rb_l/dbu))
        cell.shapes(layout.layer(1005, 0)).insert(RBA::Box::new(x_s_6_lu_l/dbu, y_s_6_lu_l/dbu, x_s_6_rb_l/dbu, y_s_6_rb_l/dbu))      
      end            
    end

'''

Firstly, I calculated all four points of boxes, and then, put them on the layers.

I found if I take cell.shapes out (Just simply commented them out), the running speed increased a lot, but still took a lot of time.
but when I put them in the double for loop, if I input big number when I create this instance, CPU runs a lot and it almost runs infinitely.

I know this is really inefficient way to create many cells as one instance.
I hope there is any other efficient way to create big array of cells.

Thank you very much :)

Comments

  • Hi,

    first of all you can speed up your code by taking out a few calls from your loop, e.g.

    shapes_1000 = cell.shapes(layout.layer(1000, 0))
    
    row.times do |i| # x axis
          col.times do |j| # y axis
               ...
               shapes_1000.insert(RBA::Box::new(...))
          end
    end
    

    From what I see, your code multiplies the same pattern, so you can write

    shapes_1000 = cell.shapes(layout.layer(1000, 0))
    
    # precompute a box for row,column = 0.0
    # (NOTE: In DBU units!)
    box_1000 = RBA::Box::new(...)
    
    dx = width / dbu
    dy = h_whole / dbu
    
    row.times do |i| # x axis
          col.times do |j| # y axis
               ...
               shapes_1000.insert(box_1000.moved(dx * j, dy * i))
          end
    end
    

    It should be faster then as it precomputes the box and uses a single call to move it to the target position.

    You should also take out the "puts" - it will consume a lot of time.

    If this is still too slow, consider creating a cell containing the precomputed geometry and using an instance array to place it:

    # precompute a box for row,column = 0.0
    # (NOTE: In DBU units!)
    box_1000 = RBA::Box::new(...)
    ...
    
    single_inst_name = "INTERNAL_GEO"
    single_inst_cell = layout.cell(single_inst_name) || layout.create_cell(single_inst_name)
    single_inst_cell.shapes(layout.layer(1000, 0)).insert(box_1000)
    ...
    
    # produce an array instance
    
    dx = width / dbu
    dy = h_whole / dbu
    
    cell.insert(RBA::CellInstArray::new(single_inst_cell.cell_index, RBA::Trans::new, RBA::Vector::new(dx, 0), RBA::Vector::new(0, dy), column, row))
    

    Matthias

Sign In or Register to comment.