PCIe Webinar Banner
WP_Term Object
(
    [term_id] => 157
    [name] => EDA
    [slug] => eda
    [term_group] => 0
    [term_taxonomy_id] => 157
    [taxonomy] => category
    [description] => Electronic Design Automation
    [parent] => 0
    [count] => 3958
    [filter] => raw
    [cat_ID] => 157
    [category_count] => 3958
    [category_description] => Electronic Design Automation
    [cat_name] => EDA
    [category_nicename] => eda
    [category_parent] => 0
)

Generative AI for Silicon Design – Article 4 (Hunt for Bugs)

Generative AI for Silicon Design – Article 4 (Hunt for Bugs)
by Anshul Jain on 11-23-2023 at 8:00 am

Generative AI for Silicon Design 4

In the complex world of silicon design, ensuring the accuracy and reliability of our designs is paramount. As our chips become more sophisticated, the process of bug hunting—identifying and rectifying errors in our designs—becomes even more critical. Generative AI has the potential to revolutionize the silicon design industry by enhancing our bug-hunting capabilities. How? Let us experiment!

Experiment 4: Hunt for Bugs

To demonstrate the efficacy of Generative AI in silicon design, I conducted an experiment with OpenAI’s GPT-4. We provided the system with a design specification (sourced from https://mathcircle.berkeley.edu/sites/default/files/archivedocs/2010_2011/contest/1011contestpdf/comp8.pdf) alongside an implementation of the design. The goal? To see if GenAI could identify any bugs.

Design Specification:

On a 5 × 5 chessboard, a king moves according to the following rules:
1. It can move one square at a time, horizontally, vertically, or diagonally.
2. It can move in each of the eight allowable directions at most three times in its entire route.

Design Implementation in Verilog:

module chess (
    input clk,
    input reset,
    input [2:0] direction,      // 0-7 to indicate the 8 directions
    input move_request,         // Input to request a move
    output reg [2:0] cur_x_pos, // X position of the king
    output reg [2:0] cur_y_pos, // Y position of the king
    output move_ack,            // Acknowledgement of the move
    output reg error            // Error when a move in a direction exceeds limit
);

    // Define the directions: 0-7
    // 0: Right
    // 1: Left
    // 2: Up
    // 3: Down
    // 4: UpRight
    // 5: UpLeft
    // 6: DownRight
    // 7: DownLeft
    
    reg [2:0] cur_moves_count[7:0]; // Array to hold move counts for each direction
    reg [2:0] nxt_moves_count[7:0]; // Array to hold move counts for each direction
    always @(posedge clk) begin
	for (int dir = 0; dir < 8; dir++) begin
            if (reset) cur_moves_count[dir] <= 3'd0;
	    else cur_moves_count[dir] <= nxt_moves_count[dir];
	end
    end

    reg [2:0] nxt_x_pos, nxt_y_pos;
    always @(posedge clk) begin
        if (reset) begin
            cur_x_pos <= 3'd0;
            cur_y_pos <= 3'd0;
	end
	else begin
	    cur_x_pos <= nxt_y_pos;
	    cur_y_pos <= nxt_y_pos;
	end
    end

    always @(*) begin
        nxt_x_pos = cur_x_pos;
        nxt_y_pos = cur_y_pos;
        nxt_moves_count = cur_moves_count;
	error = 1'b0;
        if (move_request) begin
            case (direction)
                3'b000: if (cur_x_pos < 3'd4 && cur_moves_count[0] < 3'd3) begin
                            nxt_x_pos = cur_x_pos + 1'b1;
                            nxt_moves_count[0] = cur_moves_count[0] + 1'b1;
                        end
			else error = 1;
                3'b001: if (cur_x_pos > 3'd0 && cur_moves_count[1] < 3'd3) begin
                            nxt_x_pos = cur_x_pos - 1'b1;
                            nxt_moves_count[1] = cur_moves_count[1] + 1'b1;
                        end
			else error = 1;
                3'b010: if (cur_y_pos < 3'd4 && cur_moves_count[2] < 3'd3) begin
                            nxt_y_pos = cur_y_pos + 1'b1;
                            nxt_moves_count[2] = cur_moves_count[2] + 1'b1;
                        end
			else error = 1;
                3'b011: if (cur_y_pos > 3'd0 && cur_moves_count[3] < 3'd3) begin
                            nxt_y_pos = cur_y_pos - 1'b1;
                            nxt_moves_count[3] = cur_moves_count[3] + 1'b1;
                        end
			else error = 1;
                3'b100: if (cur_x_pos < 3'd4 && cur_y_pos < 3'd4 && cur_moves_count[4] < 3'd3) begin
                            nxt_x_pos = cur_x_pos + 1'b1;
                            nxt_y_pos = cur_y_pos + 1'b1;
                            nxt_moves_count[4] = cur_moves_count[4] + 1'b1;
                        end
			else error = 1;
                3'b101: if (cur_x_pos > 3'd0 && cur_y_pos < 3'd4 && cur_moves_count[5] < 3'd3) begin
                            nxt_x_pos = cur_x_pos - 1'b1;
                            nxt_y_pos = cur_y_pos + 1'b1;
                            nxt_moves_count[5] = cur_moves_count[5] + 1'b1;
                        end
			else error = 1;
                3'b110: if (cur_x_pos < 3'd4 && cur_y_pos > 3'd0 && cur_moves_count[6] < 3'd3) begin
                            nxt_x_pos = cur_x_pos + 1'b1;
                            nxt_y_pos = cur_y_pos - 1'b1;
                            nxt_moves_count[6] = cur_moves_count[6] + 1'b1;
                        end
			else error = 1;
                3'b111: if (cur_x_pos > 3'd0 && cur_y_pos > 3'd0 && cur_moves_count[7] < 3'd3) begin
                            nxt_x_pos = cur_x_pos - 1'b1;
                            nxt_y_pos = cur_y_pos - 1'b1;
                            nxt_moves_count[7] = cur_moves_count[7] + 1'b1;
                        end
			else error = 1'b1;
            endcase
        end
    end

    assign move_ack = move_request && !error;
	
endmodule

Identify functional bugs present in the Verilog implementation, create a counterexample for each functional bug with detailed input scenario, design transitions and a comparison of actual outcome versus expected outcome as per design specification.

Following is the output from GenAI model:

1. Bug: Overwriting the cur_x_pos with cur_y_pos

else begin
	cur_x_pos <= nxt_y_pos;
	cur_y_pos <= nxt_y_pos;
end

This section will cause the current x position of the king (cur_x_pos) to always take the value of nxt_y_pos, which is incorrect.

Counterexample:

Input Scenario: Assume the king is at position (2,2) and the move_request is provided with direction = 3'b010 (Up).
Design Transition:
   Expected: cur_x_pos remains 2 and cur_y_pos becomes 3.
   Actual: Both cur_x_pos and cur_y_pos become 3.
Outcome:
   Expected Outcome: King moves to (2,3).
   Actual Outcome: King moves to (3,3).
2. Bug: cur_moves_count[] initialization to zero

if (reset) cur_moves_count[dir] <= 3'd0;

All directions' move counts are initialized to zero upon reset. However, the condition to check for maximum moves uses < 3'd3, meaning the king can move 4 times in each direction before an error is raised.

Counterexample:

Input Scenario: Assume the king is at position (0,0) and four consecutive move_requests are provided with direction = 3'b000 (Right).
Design Transition:
   Expected: After 3 moves to the right, the 4th move should trigger an error.
   Actual: King moves four times to the right without triggering an error.
Outcome:
   Expected Outcome: King moves to (3,0) and then error is triggered.
   Actual Outcome: King moves to (4,0) without an error.
3. Bug: Lack of Boundary Check
Although the code contains boundary checks for the movement of the king on the chessboard, it does not account for the possibility that adding or subtracting from the 3-bit values might result in roll-over errors. For instance, if cur_x_pos is 3'd7 (which shouldn't happen based on the current design, but might due to external influences or other design issues), subtracting 1 might result in 0 rather than an expected 6 due to bit roll-over.

Counterexample:
This might be a theoretical bug as the current design does not allow for such a scenario to happen. However, it's essential to consider this for robust design.

Recommendation: Boundary checks can be improved, and additional sanity checks can be added to ensure that the position of the king never goes outside the valid range.
Intriguing Observations
  1. Bug Identification: GenAI model pinpointed a specific discrepancy between the design specification and its implementation with a proper counterexample including the scenario, transitions and actual vs expected outcome analysis. This was indeed a genuine bug that needed rectification.
  2. False Negative: Like any tool, Generative AI is not infallible. It did highlight an issue which, upon closer inspection, turned out not to be a bug. This serves as a reminder that while AI can be a valuable assistant, human expertise and judgment remain crucial in the validation process.
  3. Enhancement Issue: Beyond just bug hunting, GenAI model also proposed an enhancement—a suggestion for improving the design that wasn’t necessarily fixing a bug but rather optimizing the design further. This unexpected benefit demonstrates how AI can not only help in finding mistakes but also in suggesting innovations.

Tomorrow’s Landscape – GenAI powered HDL Code Editors/Analyzers!

The implications of this experiment are profound. By integrating Generative AI tools into our HDL code development flow, we can:

  • Accelerate the bug-hunting process: Automating the initial stages of bug detection can reduce the man-hours spent in the debugging long simulation waveforms.
  • Reduce verification cost: With fewer bugs left for verification tools/engineers to find, verification closure can be achieved sooner, leading to cost savings in the long run.
In Conclusion

As the semiconductor industry continues to evolve, leveraging tools like Generative AI can give us an edge, ensuring that our designs are not only error-free but also pushing the boundaries of what’s possible. It is only a matter of time when co-pilots and plug-ins gain wide adoption across the industry.

Also Read:

Generative AI for Silicon Design – Article 3 (Simulate My Design)

Generative AI for Silicon Design – Article 2 (Debug My Waveform)

Generative AI for Silicon Design – Article 1 (Code My FSM)

Share this post via:

Comments

There are no comments yet.

You must register or log in to view/post comments.