Challenge #10: Identify bottlenecks using LLM! - jtristan123/HW-for-AI-ML-ECE-410 GitHub Wiki
FrozenLake code
Use LLM to find bottlenecks
LLM to identiy bottlenecks
state = env.reset()
for t in range(max_steps):
action = choose_action(Q, state)
next_state, reward, done, _ = env.step(action)
Q[state, action] = update_rule(…)
state = next_state
if done: break
the LLM idenity this The pure‐Python loop overhead here—especially the inner loop run tens of thousands of times—dominates runtime.
does it make sense?
HW implementation
parameter DATA_WIDTH = 16,
parameter FRAC_WIDTH = 8,
parameter ALPHA = 8'h20, // α = 0.125 in Q8.8
parameter GAMMA = 8'h80 // γ = 0.5 in Q8.8
)(
input logic clk,
input logic rst_n,
input logic [DATA_WIDTH-1:0] Q_old,
input logic [DATA_WIDTH-1:0] reward,
input logic [DATA_WIDTH-1:0] maxQ_next,
output logic [DATA_WIDTH-1:0] Q_new
);
// Fixed-point multiplication function
function automatic logic [DATA_WIDTH-1:0] mult;
input logic [DATA_WIDTH-1:0] a, b;
logic [2*DATA_WIDTH-1:0] prod;
begin
prod = a * b;
// Truncate to Q8.8 by dropping lower FRAC_WIDTH bits
mult = prod[FRAC_WIDTH +: DATA_WIDTH];
end
endfunction
// Pipeline registers
logic [DATA_WIDTH-1:0] term1, term2, sum1, sum2;
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
term1 <= '0;
term2 <= '0;
sum1 <= '0;
sum2 <= '0;
Q_new <= '0;
end else begin
// term1 = (1-α) * Q_old
term1 <= mult({8'hFF, 8'hFF} - ALPHA, Q_old);
// term2 = α * (reward + γ*maxQ_next)
sum1 <= reward + mult(GAMMA, maxQ_next);
term2 <= mult(ALPHA, sum1);
// final sum
sum2 <= term1 + term2;
Q_new <= sum2;
end
end
endmodule