FPGA開発日記

カテゴリ別記事インデックス https://msyksphinz.github.io/github_pages , English Version https://fpgadevdiary.hatenadiary.com/

Branch Prediction Championship KitをDPI-Cで実RTLと接続する試行 (Gshare分岐予測器を接続する)

Branch Prediction Championship Kitの使い方がわかってきたので、これを実際のRTLと接続して性能検証する機能を作ってみようと思う。

前回Bimodalの分岐予測器を接続できたので、次はGShareの分岐予測器をRTLで実装して接続してみようと思う。

github.com

  • 分岐予測部分
logic [TABLE_W-1: 0] w_pred_pht_index;
assign w_pred_pht_index = {i_pred_pc[GHR_LEN] ^ r_ghr, i_pred_pc[PC_OFFSET-1: 0]};

//
// Prediction
//
always_ff @ (posedge i_clk, negedge i_reset_n) begin
  if (!i_reset_n) begin
    o_pred_taken <= 1'b0;
  end else begin
    if (i_pred_valid) begin
      o_pred_taken <= r_pht[w_pred_pht_index][1];
    end
  end
end
  • 分岐学習部分
logic [TABLE_W-1: 0] w_update_pht_index;
assign w_update_pht_index = {i_update_pc[GHR_LEN] ^ r_ghr, i_update_pc[PC_OFFSET-1: 0]};

always_ff @ (posedge i_clk, negedge i_reset_n) begin
  if (!i_reset_n) begin
    r_ghr <= 'h0;
    for (int i = 0; i < TABLE_SIZE; i++) begin
      r_pht[i] = 2'b10;
    end
  end else begin
    if (i_update_valid) begin
      r_pht[w_update_pht_index] <= i_result_taken ? inc_counter(r_pht[w_update_pht_index]) :
                                   dec_counter(r_pht[w_update_pht_index]);
      r_ghr <= {r_ghr[GHR_LEN-2: 0], i_result_taken};
    end
  end
end

同じように実行し、無事に動作できた。

../rtl_sim/sim_predictor ../traces/SHORT_MOBILE-24.bt9.trace.gz > ../results/gshare/SHORT_MOBILE-24.res

Bimodalの結果が以下。

  MPKBr_1K               :   188.0000
  MPKBr_10K              :    59.4000
  MPKBr_100K             :    52.5500
  MPKBr_1M               :    50.1430
  MPKBr_10M              :    50.0733
  MPKBr_30M              :    50.0662
  TRACE          : ../traces/SHORT_MOBILE-24.bt9.trace.gz
  NUM_INSTRUCTIONS               : 1000000000
  NUM_BR                         :   38684342
  NUM_UNCOND_BR                  :    2221649
  NUM_CONDITIONAL_BR             :   36462693
  NUM_MISPREDICTIONS             :    1936501
  MISPRED_PER_1K_INST            :     1.9365

GShareの結果が以下。

  MPKBr_1K               :   244.0000
  MPKBr_10K              :    44.7000
  MPKBr_100K             :    18.9700
  MPKBr_1M               :    15.9100
  MPKBr_10M              :    15.7185
  MPKBr_30M              :    15.8946
  TRACE          : ../traces/SHORT_MOBILE-24.bt9.trace.gz
  NUM_INSTRUCTIONS               : 1000000000
  NUM_BR                         :   38684342
  NUM_UNCOND_BR                  :    2221649
  NUM_CONDITIONAL_BR             :   36462693
  NUM_MISPREDICTIONS             :     621544
  MISPRED_PER_1K_INST            :     0.6215

かなり改善した。いいね。