SlideShare uma empresa Scribd logo
1 de 34
Baixar para ler offline
Bluespec
           電気通信大学
           大学院情報システム学研究科
           三好健文


      2010.08.31
                       1
2
Bluespecとは

➢
    RTLから検証まで一貫した記述
    ➢
        シミュレーション
    ➢
        Verilogコードの生成

➢
    型によるコンパイル時チェック
➢
    多数のライブラリ群
    ➢
        有限ステートマシン
    ➢
        サーバレスポンス/リクエスト



                         3
なぜ、Bluespec??


                                      教育コス
                生産性   速度       合成可能   ト

  Bluespec       ◎     ◎         ○     ??

C/C++/SystemC     ○        ○     ×      ○

 Verilog HDL     △     ×/◎       ○     △



                                             4
目次

➢
    とりあえずコードをみてみよう
➢
    Bluespecツール群

➢
    Bluespecのいろいろ
    ➢
        クロックはどこへ消えた
    ➢
        強力な型システム
    ➢
        ライブラリ探訪

➢
    並列プログラミングの今後

                      5
Bluespecデザインコンテストのサン
  プル       http://www.cybernet.co.jp/bluespec/documents/Sort_Sample.pd
interface BubSort_IFC;          f
  method Action start(Vector#(5, int) a);
  method Vector#(5, int) result();              rule fin (x[0] != 0);
endinterface                                     sorted <= True;
                                                endrule
(* execution_order ="disp, fin" *)
(* preempts =                                   for (Integer i=0; i<4; i=i+1) begin
    "(swap_3, swap_2, swap_1, swap), fin" *)      rule swap ((x[i] > x[i+1]));
(* synthesize *)                                   x[i] <= x[i+1];
module mkBubSort (BubSort_IFC);                    x[i+1] <= x[i];
  Vector#(5, Reg#(int)) x                         endrule
                    <- replicateM(mkReg(0));    end
  Reg#(Bool) sorted <- mkDReg(False);
                                                method Action start(Vector#(5, int) a);
 rule disp ;                                     writeVReg(x, a);
  $write("%2d : ", $time);                      endmethod
  for (Integer i=0; i<5; i=i+1)
    $write("x[%0d]=%2d, ", i, x[i]);            method Vector#(5, int) result() if (sorted);
    $display("");                                return readVReg(x);
 endrule                                        endmethod

                                               endmodule
                                                                                               6
Bluespecデザインコンテストのサン
  プル       http://www.cybernet.co.jp/bluespec/documents/Sort_Sample.pd
interface BubSort_IFC;          f               rule fin (x[0] != 0);
  method Action start(Vector#(5, int) a);        sorted <= True;
  method Vector#(5, int) result();                   外部へのエクスポー
                                                endrule
endinterface
                                                    ト
                                                for (Integer i=0; i<4; i=i+1) begin
(* execution_order ="disp, fin" *)                   と実装
                                                  rule swap ((x[i] > x[i+1]));
(* preempts =                                      x[i] <= x[i+1];
    "(swap_3, swap_2, swap_1, swap), fin" *)       x[i+1] <= x[i];
(* synthesize *)                                  endrule
module mkBubSort (BubSort_IFC);                 end
  Vector#(5, Reg#(int)) x
                    <- replicateM(mkReg(0));    method Action start(Vector#(5, int) a);
  Reg#(Bool) sorted <- mkDReg(False);            writeVReg(x, a);
                                                endmethod
 rule disp ;
  $write("%2d : ", $time);                      method Vector#(5, int) result() if (sorted);
  for (Integer i=0; i<5; i=i+1)                  return readVReg(x);
    $write("x[%0d]=%2d, ", i, x[i]);            endmethod
    $display("");
 endrule                                       endmodule


                                                                                               7
Bluespecデザインコンテストのサン
  プル
interface BubSort_IFC;
  method Action start(Vector#(5, int) a);
  method Vector#(5, int) result();
endinterface

            start                                         result


            int                                               int
            int                                               int




                                                                    result()
  start()




            int                                               int
            int                                               int
            int                                               int




                                            BubSort_IFC

                                                                               8
Bluespecデザインコンテストのサン
  プル       http://www.cybernet.co.jp/bluespec/documents/Sort_Sample.pd
interface BubSort_IFC;          f              rule fin (x[0] != 0);
  method Action start(Vector#(5, int) a);       sorted <= True;
  method Vector#(5, int) result();             endrule
endinterface
                                               for (Integer i=0; i<4; i=i+1) begin
(* execution_order ="disp, fin" *)               rule swap ((x[i] > x[i+1]));
(* preempts =                                     x[i] <= x[i+1];
    "(swap_3, swap_2, swap_1, swap), fin" *)      x[i+1] <= x[i];
(* synthesize *)                                 endrule
module mkBubSort (BubSort_IFC);                end
  Vector#(5, Reg#(int)) x
                    <- replicateM(mkReg(0));   method Action start(Vector#(5, int) a);
  Reg#(Bool) sorted <- mkDReg(False);           writeVReg(x, a);
                                               endmethod
 rule disp ;
  $write("%2d : ", $time);                     method Vector#(5, int) result() if (sorted);
  for (Integer i=0; i<5; i=i+1)                 return readVReg(x);
    $write("x[%0d]=%2d, ", i, x[i]);           endmethod
    $display("");
 endrule                                        条件を満たすときに実行され
                                               endmodule
                                               る
                                               組み合わせ回路
                                                                                              9
Bluespecデザインコンテストのサン
プル
forは繰り返しではなくて生成
文                                      rule swap ((x[0] > x[1]));
 for (Integer i=0; i<4; i=i+1) begin      x[0] <= x[1];
   rule swap ((x[i] > x[i+1]));           x[1] <= x[0];
    x[i] <= x[i+1];                    endrule
    x[i+1] <= x[i];
                                       rule swap ((x[1] > x[2]));
   endrule
                                          x[1] <= x[2];
 end
                                          x[2] <= x[1];
                                       endrule
                                       ...
                                       rule swap ((x[3] > x[4]));
                                          x[3] <= x[4];
                                          x[4] <= x[3];
                                       endrule
                                                                    10
Bluespecデザインコンテストのサン
  プル       http://www.cybernet.co.jp/bluespec/documents/Sort_Sample.pd
interface BubSort_IFC;          f                  rule fin (x[0] != 0);
  method Action start(Vector#(5, int) a);           sorted <= True;
  method Vector#(5, int) result();                 endrule
endinterface
                                                   for (Integer i=0; i<4; i=i+1) begin
(* execution_order ="disp, fin" *)                   rule swap ((x[i] > x[i+1]));
(* preempts =                                         x[i] <= x[i+1];
    "(swap_3, swap_2, swap_1, swap), fin" *)          x[i+1] <= x[i];
(* synthesize *)                                     endrule
module mkBubSort (BubSort_IFC);                    end
  Vector#(5, Reg#(int)) x
                    <- replicateM(mkReg(0));       method Action start(Vector#(5, int) a);
  Reg#(Bool) sorted <- mkDReg(False);               writeVReg(x, a);
                                                   endmethod
 rule disp ;
  $write("%2d : ", $time);                    method Vector#(5, int) result() if (sorted);
  for (Integer i=0; i<5; i=i+1)                return readVReg(x);
                                        finが呼ばれる前に
    $write("x[%0d]=%2d, ", i, x[i]);          endmethod
    $display("");                       swap_3~swap_1が実行され
 endrule                                安定するまでfinの実行が待たされ
                                              endmodule
                                        る
                                                                                             11
目次

➢
    とりあえずコードをみてみよう
➢
    Bluespecツール群

➢
    Bluespecのいろいろ
    ➢
        クロックはどこへ消えた
    ➢
        強力な型システム
    ➢
        ライブラリ探訪

➢
    並列プログラミングの今後

                      12
Bluespecシステムツール群


           > bsc -u -sim ram.bsv
           > bsc -sim -o sim.out -e tbBram 
           tbBram.ba



           > bsc -verilog -g mkBram_Test 
           ram.bsv




                                          13
Bluespecシステムツール群

他言語との連携
➢
    C/C++
➢
    RTL(Verilog HDL/VHDL)




                            14
Bluespecシステムツール群

他言語との連携(C)

➢
    BluespecでCの関数を呼ぶための準備
    import "BDPI" function Bool my_and (Bool, Bool);

➢
    実際に呼び出される関数
    unsigned char my_and (unsigned char x,
                          unsigned char y);


                                                       15
Bluespecシステムツール群

他言語との連携(Verilog)
 module mkVerilog_SRAM_model (clk, v_in_address, v_in_data,
                 v_in_write_not_read, v_in_enable, v_out_data);
    parameter FILENAME = "Verilog_SRAM_model.data";
    parameter ADDRESS_WIDTH = 10;
    parameter DATA_WIDTH = 8;
    parameter NWORDS = (1 << ADDRESS_WIDTH);

     input clk;
     input [ADDRESS_WIDTH-1:0] v_in_address;
     input [DATA_WIDTH-1:0] v_in_data;
     input v_in_write_not_read;
     input v_in_enable;
     output [DATA_WIDTH-1:0] v_out_data;
     ...
 endmodule                               呼び出されるモジュール
                                                                  16
Bluespecシステムツール群

他言語との連携(Verilog)
 import "BVI" mkVerilog_SRAM_model =
  module mkSRAM #(String filename) (SRAM_Ifc #(addr_t, data_t))
   provisos(Bits#(addr_t, addr_width), Bits#(data_t, data_width));
    parameter FILENAME = filename;
    parameter ADDRESS_WIDTH = valueOf(addr_width);
    parameter DATA_WIDTH = valueof(data_width);
    method request (v_in_address, v_in_data, v_in_write_not_read)
               enable (v_in_enable);
    method v_out_data read_response;
    default_clock clk(clk, (*unused*) clk_gate);
    default_reset no_reset;
    schedule (read_response) SB (request);
 endmodule
                                             呼び出すための準備
                                                                     17
Bluespecシステムツール群

FPGAによるシミュレーション(SCE-MI)




                          18
(脱線)FAME分類

[0bit目] 0:Direct, 1:Decoupled
[1bit目] 0:Full RTL, 1:Abstracted Machine
[2bit目] 0:Single-Threade, 1:Multi-Threaded


Level 000: Direct FAME (ex. Quickturn)
Level 001: Decoupled FAME
      (ex. Green Flash memory system)
Level 011: Abstract FAME (ex. HAsim)
Level 111: Multithreaded FAME (ex. RAMP Gold)


                                                19
目次

➢
    とりあえずコードをみてみよう
➢
    Bluespecツール群

➢
    Bluespecのいろいろ
    ➢
        クロックはどこへ消えた
    ➢
        強力な型システム
    ➢
        ライブラリ探訪

➢
    並列プログラミングの今後

                      20
クロックはどこへ消えた

 interface Test_ifc;
    method Bit#(26) result();
 endinterface
 module mkTest(Test_ifc);
   Reg#(Bit#(26)) counter <- mkReg(0);
   rule r0;
     counter <= counter + 1;
   endrule
   method Bit#(26) result();
     return readReg(counter);
   endmethod
 endmodule



                                         21
クロックはどこへ消えた
module mkTest(CLK, RST_N, result, RDY_result);
 input CLK;
 input RST_N;
 // value method result
 output [25 : 0] result;
 output RDY_result;
/* snip */
 always@(posedge CLK)
 begin
   if (!RST_N)
     begin
       counter <= `BSV_ASSIGNMENT_DELAY 26'd0;
     end
   else
     begin
       if (counter$EN) counter <= `BSV_ASSIGNMENT_DELAY counter$D_IN;
     end
 end
/* snip */
endmodule // mkTest


                                                                        22
Bluespecの型システム

型って何?
➢
    HaskellとかOcamlとかのあれ
➢
    型チェックで安全プログラミング??
➢
    なんか格好いい

で、Bluespecでは?
➢
    かなり厳格な型システム
➢
    データの種類ではなくてオブジェクトの種類

                           23
Bluespecの型システム

型って何?
➢
    HaskellとかOcamlとかのあれ
➢
    型チェックで安全プログラミング??
➢
    なんか格好いい

で、Bluespecでは?
➢
    かなり厳格な型システム
➢
    データの種類ではなくてオブジェクトの種類
➢
    型クラス
                           24
Bluespecの型システム

➢
    Bit型
    ➢
        Bit#(n) (= bit[n-1:0]), Bool (= Bit#(1) )
    ➢
        Int#(n), int (= Int#(32) )
    ➢
        Uint#(n)
➢
    Non Bit型
    ➢
        Integer
    ➢
        String
    ➢
        Interfaces, Modules, Rules
    ➢
        Action, ActionValue
    ➢
        functions
                                                    25
Bluespecの型システム

➢
    Bit型
    ➢
        Bit#(n) (= bit[n-1:0]), Bool (= Bit#(1) )
    ➢
        Int#(n), int (= Int#(32) )
    ➢
        Uint#(n)
➢
    Non Bit型
                          この”n”もnumeric typeという型をもつ
    ➢
        Integer
    ➢
        String
    ➢
        Interfaces, Modules, Rules
    ➢
        Action, ActionValue
    ➢
        functions
                                                    26
Bluespecの型システム

明示的な型変換
➢
    pack/unpack (= to Bit#(n)/from Bit#(n))
➢
    zeroExtend/signedExtend
➢
    truncate
➢
    fromInteger
➢
    valueOf




                                              27
Bluespecの型システム

Bluespec Library型
 ➢
     Reg#(a)
 ➢
     Wire#(a)
 ➢
     FIFO#(a)
 ➢
     PulseWriter#(a)/PulseReader#(a)




                                       28
ライブラリ探訪

StmtFSM




          29
ライブラリ探訪

Vector




          30
ライブラリ探訪

ClientServer




               31
目次

➢
    とりあえずコードをみてみよう
➢
    Bluespecツール群

➢
    Bluespecのいろいろ
    ➢
        クロックはどこへ消えた
    ➢
        強力な型システム
    ➢
        ライブラリ探訪

➢
    並列プログラミングの今後

                      32
並列プログラミングの今後

Bluespecに学ぶ
➢
    rule/methodはいいなあ
    ➢
        細粒度並列性はHDL系が一番書きやすいかも
    ➢
        ruleの切り出しが鍵か?

➢
    Bluespecシミュレータはマルチプロセッサ非
    対応



                                33
並列プログラミングの今後

➢
    そもそも並列プログラミングは存在しえるか?
    ➢
        Bamboo
    ➢
        Molatomium

➢
    並列化コンパイラ?
    ➢
        OSCARコンパイラ
    ➢


➢
    ディレクティブ?
    ➢
        *Ss
    ➢
        XcalableMP
                            34

Mais conteúdo relacionado

Mais procurados

LINQソースでGO!
LINQソースでGO!LINQソースでGO!
LINQソースでGO!Kouji Matsui
 
ゲーム開発者のための C++11/C++14
ゲーム開発者のための C++11/C++14ゲーム開発者のための C++11/C++14
ゲーム開発者のための C++11/C++14Ryo Suzuki
 
unique_ptrにポインタ以外のものを持たせるとき
unique_ptrにポインタ以外のものを持たせるときunique_ptrにポインタ以外のものを持たせるとき
unique_ptrにポインタ以外のものを持たせるときShintarou Okada
 
An other world awaits you
An other world awaits youAn other world awaits you
An other world awaits you信之 岩永
 
Visual C++で使えるC++11
Visual C++で使えるC++11Visual C++で使えるC++11
Visual C++で使えるC++11nekko1119
 
クロージャデザインパターン
クロージャデザインパターンクロージャデザインパターン
クロージャデザインパターンMoriharu Ohzu
 
オブジェクト指向できていますか?
オブジェクト指向できていますか?オブジェクト指向できていますか?
オブジェクト指向できていますか?Moriharu Ohzu
 
Java Puzzlers JJUG CCC 2016
Java Puzzlers JJUG CCC 2016Java Puzzlers JJUG CCC 2016
Java Puzzlers JJUG CCC 2016Yoshio Terada
 
C#を始めたばかりの人へのLINQ to Objects
C#を始めたばかりの人へのLINQ to ObjectsC#を始めたばかりの人へのLINQ to Objects
C#を始めたばかりの人へのLINQ to ObjectsFumitaka Yamada
 
Continuation with Boost.Context
Continuation with Boost.ContextContinuation with Boost.Context
Continuation with Boost.ContextAkira Takahashi
 
Boost.Coroutine
Boost.CoroutineBoost.Coroutine
Boost.Coroutinemelpon
 
組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由kikairoya
 
イマドキC++erのモテカワリソース管理術
イマドキC++erのモテカワリソース管理術イマドキC++erのモテカワリソース管理術
イマドキC++erのモテカワリソース管理術Kohsuke Yuasa
 
C++11概要 ライブラリ編
C++11概要 ライブラリ編C++11概要 ライブラリ編
C++11概要 ライブラリ編egtra
 
C++ ポインタ ブートキャンプ
C++ ポインタ ブートキャンプC++ ポインタ ブートキャンプ
C++ ポインタ ブートキャンプKohsuke Yuasa
 
BoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうかBoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうかYuki Miyatake
 
テーマ「最適化」
テーマ「最適化」テーマ「最適化」
テーマ「最適化」technocat
 

Mais procurados (20)

Objc lambda
Objc lambdaObjc lambda
Objc lambda
 
LINQソースでGO!
LINQソースでGO!LINQソースでGO!
LINQソースでGO!
 
ゲーム開発者のための C++11/C++14
ゲーム開発者のための C++11/C++14ゲーム開発者のための C++11/C++14
ゲーム開発者のための C++11/C++14
 
C#6.0の新機能紹介
C#6.0の新機能紹介C#6.0の新機能紹介
C#6.0の新機能紹介
 
unique_ptrにポインタ以外のものを持たせるとき
unique_ptrにポインタ以外のものを持たせるときunique_ptrにポインタ以外のものを持たせるとき
unique_ptrにポインタ以外のものを持たせるとき
 
An other world awaits you
An other world awaits youAn other world awaits you
An other world awaits you
 
Visual C++で使えるC++11
Visual C++で使えるC++11Visual C++で使えるC++11
Visual C++で使えるC++11
 
クロージャデザインパターン
クロージャデザインパターンクロージャデザインパターン
クロージャデザインパターン
 
オブジェクト指向できていますか?
オブジェクト指向できていますか?オブジェクト指向できていますか?
オブジェクト指向できていますか?
 
Map
MapMap
Map
 
Java Puzzlers JJUG CCC 2016
Java Puzzlers JJUG CCC 2016Java Puzzlers JJUG CCC 2016
Java Puzzlers JJUG CCC 2016
 
C#を始めたばかりの人へのLINQ to Objects
C#を始めたばかりの人へのLINQ to ObjectsC#を始めたばかりの人へのLINQ to Objects
C#を始めたばかりの人へのLINQ to Objects
 
Continuation with Boost.Context
Continuation with Boost.ContextContinuation with Boost.Context
Continuation with Boost.Context
 
Boost.Coroutine
Boost.CoroutineBoost.Coroutine
Boost.Coroutine
 
組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由組み込みでこそC++を使う10の理由
組み込みでこそC++を使う10の理由
 
イマドキC++erのモテカワリソース管理術
イマドキC++erのモテカワリソース管理術イマドキC++erのモテカワリソース管理術
イマドキC++erのモテカワリソース管理術
 
C++11概要 ライブラリ編
C++11概要 ライブラリ編C++11概要 ライブラリ編
C++11概要 ライブラリ編
 
C++ ポインタ ブートキャンプ
C++ ポインタ ブートキャンプC++ ポインタ ブートキャンプ
C++ ポインタ ブートキャンプ
 
BoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうかBoostAsioで可読性を求めるのは間違っているだろうか
BoostAsioで可読性を求めるのは間違っているだろうか
 
テーマ「最適化」
テーマ「最適化」テーマ「最適化」
テーマ「最適化」
 

Semelhante a Bluespec @waseda(PDF)

ぱっと見でわかるC++11
ぱっと見でわかるC++11ぱっと見でわかるC++11
ぱっと見でわかるC++11えぴ 福田
 
Python physicalcomputing
Python physicalcomputingPython physicalcomputing
Python physicalcomputingNoboru Irieda
 
for JSDeferred Code Reading
for JSDeferred Code Readingfor JSDeferred Code Reading
for JSDeferred Code ReadingKenichirou Oyama
 
DE0でラジコンカー作ってみた 関西de0 fpga勉強会20120519
DE0でラジコンカー作ってみた 関西de0 fpga勉強会20120519DE0でラジコンカー作ってみた 関西de0 fpga勉強会20120519
DE0でラジコンカー作ってみた 関西de0 fpga勉強会20120519Yasuhiro Ishii
 
Polyphony の行く末(2018/3/3)
Polyphony の行く末(2018/3/3)Polyphony の行く末(2018/3/3)
Polyphony の行く末(2018/3/3)ryos36
 
x86とコンテキストスイッチ
x86とコンテキストスイッチx86とコンテキストスイッチ
x86とコンテキストスイッチMasami Ichikawa
 
テーマ「最適化 その2」
テーマ「最適化 その2」テーマ「最適化 その2」
テーマ「最適化 その2」technocat
 
Android Lecture #03 @PRO&BSC Inc.
Android Lecture #03 @PRO&BSC Inc.Android Lecture #03 @PRO&BSC Inc.
Android Lecture #03 @PRO&BSC Inc.Yuki Higuchi
 
Lispmeetup #53 PythonベースのLisp方言、 Hyのすすめ
Lispmeetup #53 PythonベースのLisp方言、 HyのすすめLispmeetup #53 PythonベースのLisp方言、 Hyのすすめ
Lispmeetup #53 PythonベースのLisp方言、 HyのすすめSatoshi imai
 
F#入門 ~関数プログラミングとは何か~
F#入門 ~関数プログラミングとは何か~F#入門 ~関数プログラミングとは何か~
F#入門 ~関数プログラミングとは何か~Nobuhisa Koizumi
 
プログラミング技法特論第8回
プログラミング技法特論第8回プログラミング技法特論第8回
プログラミング技法特論第8回Noritada Shimizu
 
PBL1-v1-006j.pptx
PBL1-v1-006j.pptxPBL1-v1-006j.pptx
PBL1-v1-006j.pptxNAIST
 
RでGISハンズオンセッション
RでGISハンズオンセッションRでGISハンズオンセッション
RでGISハンズオンセッションarctic_tern265
 
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目hecomi
 
C++0x 言語の未来を語る
C++0x 言語の未来を語るC++0x 言語の未来を語る
C++0x 言語の未来を語るAkira Takahashi
 
Material
MaterialMaterial
Material_TUNE_
 

Semelhante a Bluespec @waseda(PDF) (20)

ぱっと見でわかるC++11
ぱっと見でわかるC++11ぱっと見でわかるC++11
ぱっと見でわかるC++11
 
Python physicalcomputing
Python physicalcomputingPython physicalcomputing
Python physicalcomputing
 
Prosym2012
Prosym2012Prosym2012
Prosym2012
 
for JSDeferred Code Reading
for JSDeferred Code Readingfor JSDeferred Code Reading
for JSDeferred Code Reading
 
DE0でラジコンカー作ってみた 関西de0 fpga勉強会20120519
DE0でラジコンカー作ってみた 関西de0 fpga勉強会20120519DE0でラジコンカー作ってみた 関西de0 fpga勉強会20120519
DE0でラジコンカー作ってみた 関西de0 fpga勉強会20120519
 
Polyphony の行く末(2018/3/3)
Polyphony の行く末(2018/3/3)Polyphony の行く末(2018/3/3)
Polyphony の行く末(2018/3/3)
 
x86とコンテキストスイッチ
x86とコンテキストスイッチx86とコンテキストスイッチ
x86とコンテキストスイッチ
 
テーマ「最適化 その2」
テーマ「最適化 その2」テーマ「最適化 その2」
テーマ「最適化 その2」
 
秀スクリプトの話
秀スクリプトの話秀スクリプトの話
秀スクリプトの話
 
VerilatorとSystemC
VerilatorとSystemCVerilatorとSystemC
VerilatorとSystemC
 
Android Lecture #03 @PRO&BSC Inc.
Android Lecture #03 @PRO&BSC Inc.Android Lecture #03 @PRO&BSC Inc.
Android Lecture #03 @PRO&BSC Inc.
 
フラグを愛でる
フラグを愛でるフラグを愛でる
フラグを愛でる
 
Lispmeetup #53 PythonベースのLisp方言、 Hyのすすめ
Lispmeetup #53 PythonベースのLisp方言、 HyのすすめLispmeetup #53 PythonベースのLisp方言、 Hyのすすめ
Lispmeetup #53 PythonベースのLisp方言、 Hyのすすめ
 
F#入門 ~関数プログラミングとは何か~
F#入門 ~関数プログラミングとは何か~F#入門 ~関数プログラミングとは何か~
F#入門 ~関数プログラミングとは何か~
 
プログラミング技法特論第8回
プログラミング技法特論第8回プログラミング技法特論第8回
プログラミング技法特論第8回
 
PBL1-v1-006j.pptx
PBL1-v1-006j.pptxPBL1-v1-006j.pptx
PBL1-v1-006j.pptx
 
RでGISハンズオンセッション
RでGISハンズオンセッションRでGISハンズオンセッション
RでGISハンズオンセッション
 
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
Node.js × 音声認識 - 東京Node学園 2012 LT枠 6番目
 
C++0x 言語の未来を語る
C++0x 言語の未来を語るC++0x 言語の未来を語る
C++0x 言語の未来を語る
 
Material
MaterialMaterial
Material
 

Mais de Takefumi MIYOSHI

ACRi_webinar_20220118_miyo
ACRi_webinar_20220118_miyoACRi_webinar_20220118_miyo
ACRi_webinar_20220118_miyoTakefumi MIYOSHI
 
ACRiルーム1年間の活動と 新たな取り組み
ACRiルーム1年間の活動と 新たな取り組みACRiルーム1年間の活動と 新たな取り組み
ACRiルーム1年間の活動と 新たな取り組みTakefumi MIYOSHI
 
RISC-V introduction for SIG SDR in CQ 2019.07.29
RISC-V introduction for SIG SDR in CQ 2019.07.29RISC-V introduction for SIG SDR in CQ 2019.07.29
RISC-V introduction for SIG SDR in CQ 2019.07.29Takefumi MIYOSHI
 
Misc for edge_devices_with_fpga
Misc for edge_devices_with_fpgaMisc for edge_devices_with_fpga
Misc for edge_devices_with_fpgaTakefumi MIYOSHI
 
Synthesijer - HLS frineds 20190511
Synthesijer - HLS frineds 20190511Synthesijer - HLS frineds 20190511
Synthesijer - HLS frineds 20190511Takefumi MIYOSHI
 
Abstracts of FPGA2017 papers (Temporary Version)
Abstracts of FPGA2017 papers (Temporary Version)Abstracts of FPGA2017 papers (Temporary Version)
Abstracts of FPGA2017 papers (Temporary Version)Takefumi MIYOSHI
 
Synthesijer and Synthesijer.Scala in HLS-friends 201512
Synthesijer and Synthesijer.Scala in HLS-friends 201512Synthesijer and Synthesijer.Scala in HLS-friends 201512
Synthesijer and Synthesijer.Scala in HLS-friends 201512Takefumi MIYOSHI
 
Synthesijer jjug 201504_01
Synthesijer jjug 201504_01Synthesijer jjug 201504_01
Synthesijer jjug 201504_01Takefumi MIYOSHI
 
Synthesijer zynq qs_20150316
Synthesijer zynq qs_20150316Synthesijer zynq qs_20150316
Synthesijer zynq qs_20150316Takefumi MIYOSHI
 
Synthesijer fpgax 20150201
Synthesijer fpgax 20150201Synthesijer fpgax 20150201
Synthesijer fpgax 20150201Takefumi MIYOSHI
 

Mais de Takefumi MIYOSHI (20)

ACRi_webinar_20220118_miyo
ACRi_webinar_20220118_miyoACRi_webinar_20220118_miyo
ACRi_webinar_20220118_miyo
 
DAS_202109
DAS_202109DAS_202109
DAS_202109
 
ACRiルーム1年間の活動と 新たな取り組み
ACRiルーム1年間の活動と 新たな取り組みACRiルーム1年間の活動と 新たな取り組み
ACRiルーム1年間の活動と 新たな取り組み
 
RISC-V introduction for SIG SDR in CQ 2019.07.29
RISC-V introduction for SIG SDR in CQ 2019.07.29RISC-V introduction for SIG SDR in CQ 2019.07.29
RISC-V introduction for SIG SDR in CQ 2019.07.29
 
Misc for edge_devices_with_fpga
Misc for edge_devices_with_fpgaMisc for edge_devices_with_fpga
Misc for edge_devices_with_fpga
 
Cq off 20190718
Cq off 20190718Cq off 20190718
Cq off 20190718
 
Synthesijer - HLS frineds 20190511
Synthesijer - HLS frineds 20190511Synthesijer - HLS frineds 20190511
Synthesijer - HLS frineds 20190511
 
Reconf 201901
Reconf 201901Reconf 201901
Reconf 201901
 
Hls friends 201803.key
Hls friends 201803.keyHls friends 201803.key
Hls friends 201803.key
 
Abstracts of FPGA2017 papers (Temporary Version)
Abstracts of FPGA2017 papers (Temporary Version)Abstracts of FPGA2017 papers (Temporary Version)
Abstracts of FPGA2017 papers (Temporary Version)
 
Hls friends 20161122.key
Hls friends 20161122.keyHls friends 20161122.key
Hls friends 20161122.key
 
Slide
SlideSlide
Slide
 
Synthesijer and Synthesijer.Scala in HLS-friends 201512
Synthesijer and Synthesijer.Scala in HLS-friends 201512Synthesijer and Synthesijer.Scala in HLS-friends 201512
Synthesijer and Synthesijer.Scala in HLS-friends 201512
 
Das 2015
Das 2015Das 2015
Das 2015
 
Microblaze loader
Microblaze loaderMicroblaze loader
Microblaze loader
 
Reconf 201506
Reconf 201506Reconf 201506
Reconf 201506
 
Synthesijer jjug 201504_01
Synthesijer jjug 201504_01Synthesijer jjug 201504_01
Synthesijer jjug 201504_01
 
Synthesijer zynq qs_20150316
Synthesijer zynq qs_20150316Synthesijer zynq qs_20150316
Synthesijer zynq qs_20150316
 
Synthesijer fpgax 20150201
Synthesijer fpgax 20150201Synthesijer fpgax 20150201
Synthesijer fpgax 20150201
 
Synthesijer hls 20150116
Synthesijer hls 20150116Synthesijer hls 20150116
Synthesijer hls 20150116
 

Bluespec @waseda(PDF)

  • 1. Bluespec 電気通信大学 大学院情報システム学研究科 三好健文 2010.08.31 1
  • 2. 2
  • 3. Bluespecとは ➢ RTLから検証まで一貫した記述 ➢ シミュレーション ➢ Verilogコードの生成 ➢ 型によるコンパイル時チェック ➢ 多数のライブラリ群 ➢ 有限ステートマシン ➢ サーバレスポンス/リクエスト 3
  • 4. なぜ、Bluespec?? 教育コス 生産性 速度 合成可能 ト Bluespec ◎ ◎ ○ ?? C/C++/SystemC ○ ○ × ○ Verilog HDL △ ×/◎ ○ △ 4
  • 5. 目次 ➢ とりあえずコードをみてみよう ➢ Bluespecツール群 ➢ Bluespecのいろいろ ➢ クロックはどこへ消えた ➢ 強力な型システム ➢ ライブラリ探訪 ➢ 並列プログラミングの今後 5
  • 6. Bluespecデザインコンテストのサン プル http://www.cybernet.co.jp/bluespec/documents/Sort_Sample.pd interface BubSort_IFC; f method Action start(Vector#(5, int) a); method Vector#(5, int) result(); rule fin (x[0] != 0); endinterface sorted <= True; endrule (* execution_order ="disp, fin" *) (* preempts = for (Integer i=0; i<4; i=i+1) begin "(swap_3, swap_2, swap_1, swap), fin" *) rule swap ((x[i] > x[i+1])); (* synthesize *) x[i] <= x[i+1]; module mkBubSort (BubSort_IFC); x[i+1] <= x[i]; Vector#(5, Reg#(int)) x endrule <- replicateM(mkReg(0)); end Reg#(Bool) sorted <- mkDReg(False); method Action start(Vector#(5, int) a); rule disp ; writeVReg(x, a); $write("%2d : ", $time); endmethod for (Integer i=0; i<5; i=i+1) $write("x[%0d]=%2d, ", i, x[i]); method Vector#(5, int) result() if (sorted); $display(""); return readVReg(x); endrule endmethod endmodule 6
  • 7. Bluespecデザインコンテストのサン プル http://www.cybernet.co.jp/bluespec/documents/Sort_Sample.pd interface BubSort_IFC; f rule fin (x[0] != 0); method Action start(Vector#(5, int) a); sorted <= True; method Vector#(5, int) result(); 外部へのエクスポー endrule endinterface ト for (Integer i=0; i<4; i=i+1) begin (* execution_order ="disp, fin" *) と実装 rule swap ((x[i] > x[i+1])); (* preempts = x[i] <= x[i+1]; "(swap_3, swap_2, swap_1, swap), fin" *) x[i+1] <= x[i]; (* synthesize *) endrule module mkBubSort (BubSort_IFC); end Vector#(5, Reg#(int)) x <- replicateM(mkReg(0)); method Action start(Vector#(5, int) a); Reg#(Bool) sorted <- mkDReg(False); writeVReg(x, a); endmethod rule disp ; $write("%2d : ", $time); method Vector#(5, int) result() if (sorted); for (Integer i=0; i<5; i=i+1) return readVReg(x); $write("x[%0d]=%2d, ", i, x[i]); endmethod $display(""); endrule endmodule 7
  • 8. Bluespecデザインコンテストのサン プル interface BubSort_IFC; method Action start(Vector#(5, int) a); method Vector#(5, int) result(); endinterface start result int int int int result() start() int int int int int int BubSort_IFC 8
  • 9. Bluespecデザインコンテストのサン プル http://www.cybernet.co.jp/bluespec/documents/Sort_Sample.pd interface BubSort_IFC; f rule fin (x[0] != 0); method Action start(Vector#(5, int) a); sorted <= True; method Vector#(5, int) result(); endrule endinterface for (Integer i=0; i<4; i=i+1) begin (* execution_order ="disp, fin" *) rule swap ((x[i] > x[i+1])); (* preempts = x[i] <= x[i+1]; "(swap_3, swap_2, swap_1, swap), fin" *) x[i+1] <= x[i]; (* synthesize *) endrule module mkBubSort (BubSort_IFC); end Vector#(5, Reg#(int)) x <- replicateM(mkReg(0)); method Action start(Vector#(5, int) a); Reg#(Bool) sorted <- mkDReg(False); writeVReg(x, a); endmethod rule disp ; $write("%2d : ", $time); method Vector#(5, int) result() if (sorted); for (Integer i=0; i<5; i=i+1) return readVReg(x); $write("x[%0d]=%2d, ", i, x[i]); endmethod $display(""); endrule 条件を満たすときに実行され endmodule る 組み合わせ回路 9
  • 10. Bluespecデザインコンテストのサン プル forは繰り返しではなくて生成 文 rule swap ((x[0] > x[1])); for (Integer i=0; i<4; i=i+1) begin x[0] <= x[1]; rule swap ((x[i] > x[i+1])); x[1] <= x[0]; x[i] <= x[i+1]; endrule x[i+1] <= x[i]; rule swap ((x[1] > x[2])); endrule x[1] <= x[2]; end x[2] <= x[1]; endrule ... rule swap ((x[3] > x[4])); x[3] <= x[4]; x[4] <= x[3]; endrule 10
  • 11. Bluespecデザインコンテストのサン プル http://www.cybernet.co.jp/bluespec/documents/Sort_Sample.pd interface BubSort_IFC; f rule fin (x[0] != 0); method Action start(Vector#(5, int) a); sorted <= True; method Vector#(5, int) result(); endrule endinterface for (Integer i=0; i<4; i=i+1) begin (* execution_order ="disp, fin" *) rule swap ((x[i] > x[i+1])); (* preempts = x[i] <= x[i+1]; "(swap_3, swap_2, swap_1, swap), fin" *) x[i+1] <= x[i]; (* synthesize *) endrule module mkBubSort (BubSort_IFC); end Vector#(5, Reg#(int)) x <- replicateM(mkReg(0)); method Action start(Vector#(5, int) a); Reg#(Bool) sorted <- mkDReg(False); writeVReg(x, a); endmethod rule disp ; $write("%2d : ", $time); method Vector#(5, int) result() if (sorted); for (Integer i=0; i<5; i=i+1) return readVReg(x); finが呼ばれる前に $write("x[%0d]=%2d, ", i, x[i]); endmethod $display(""); swap_3~swap_1が実行され endrule 安定するまでfinの実行が待たされ endmodule る 11
  • 12. 目次 ➢ とりあえずコードをみてみよう ➢ Bluespecツール群 ➢ Bluespecのいろいろ ➢ クロックはどこへ消えた ➢ 強力な型システム ➢ ライブラリ探訪 ➢ 並列プログラミングの今後 12
  • 13. Bluespecシステムツール群 > bsc -u -sim ram.bsv > bsc -sim -o sim.out -e tbBram tbBram.ba > bsc -verilog -g mkBram_Test ram.bsv 13
  • 15. Bluespecシステムツール群 他言語との連携(C) ➢ BluespecでCの関数を呼ぶための準備 import "BDPI" function Bool my_and (Bool, Bool); ➢ 実際に呼び出される関数 unsigned char my_and (unsigned char x, unsigned char y); 15
  • 16. Bluespecシステムツール群 他言語との連携(Verilog) module mkVerilog_SRAM_model (clk, v_in_address, v_in_data, v_in_write_not_read, v_in_enable, v_out_data); parameter FILENAME = "Verilog_SRAM_model.data"; parameter ADDRESS_WIDTH = 10; parameter DATA_WIDTH = 8; parameter NWORDS = (1 << ADDRESS_WIDTH); input clk; input [ADDRESS_WIDTH-1:0] v_in_address; input [DATA_WIDTH-1:0] v_in_data; input v_in_write_not_read; input v_in_enable; output [DATA_WIDTH-1:0] v_out_data; ... endmodule 呼び出されるモジュール 16
  • 17. Bluespecシステムツール群 他言語との連携(Verilog) import "BVI" mkVerilog_SRAM_model = module mkSRAM #(String filename) (SRAM_Ifc #(addr_t, data_t)) provisos(Bits#(addr_t, addr_width), Bits#(data_t, data_width)); parameter FILENAME = filename; parameter ADDRESS_WIDTH = valueOf(addr_width); parameter DATA_WIDTH = valueof(data_width); method request (v_in_address, v_in_data, v_in_write_not_read) enable (v_in_enable); method v_out_data read_response; default_clock clk(clk, (*unused*) clk_gate); default_reset no_reset; schedule (read_response) SB (request); endmodule 呼び出すための準備 17
  • 19. (脱線)FAME分類 [0bit目] 0:Direct, 1:Decoupled [1bit目] 0:Full RTL, 1:Abstracted Machine [2bit目] 0:Single-Threade, 1:Multi-Threaded Level 000: Direct FAME (ex. Quickturn) Level 001: Decoupled FAME       (ex. Green Flash memory system) Level 011: Abstract FAME (ex. HAsim) Level 111: Multithreaded FAME (ex. RAMP Gold) 19
  • 20. 目次 ➢ とりあえずコードをみてみよう ➢ Bluespecツール群 ➢ Bluespecのいろいろ ➢ クロックはどこへ消えた ➢ 強力な型システム ➢ ライブラリ探訪 ➢ 並列プログラミングの今後 20
  • 21. クロックはどこへ消えた interface Test_ifc; method Bit#(26) result(); endinterface module mkTest(Test_ifc); Reg#(Bit#(26)) counter <- mkReg(0); rule r0; counter <= counter + 1; endrule method Bit#(26) result(); return readReg(counter); endmethod endmodule 21
  • 22. クロックはどこへ消えた module mkTest(CLK, RST_N, result, RDY_result); input CLK; input RST_N; // value method result output [25 : 0] result; output RDY_result; /* snip */ always@(posedge CLK) begin if (!RST_N) begin counter <= `BSV_ASSIGNMENT_DELAY 26'd0; end else begin if (counter$EN) counter <= `BSV_ASSIGNMENT_DELAY counter$D_IN; end end /* snip */ endmodule // mkTest 22
  • 23. Bluespecの型システム 型って何? ➢ HaskellとかOcamlとかのあれ ➢ 型チェックで安全プログラミング?? ➢ なんか格好いい で、Bluespecでは? ➢ かなり厳格な型システム ➢ データの種類ではなくてオブジェクトの種類 23
  • 24. Bluespecの型システム 型って何? ➢ HaskellとかOcamlとかのあれ ➢ 型チェックで安全プログラミング?? ➢ なんか格好いい で、Bluespecでは? ➢ かなり厳格な型システム ➢ データの種類ではなくてオブジェクトの種類 ➢ 型クラス 24
  • 25. Bluespecの型システム ➢ Bit型 ➢ Bit#(n) (= bit[n-1:0]), Bool (= Bit#(1) ) ➢ Int#(n), int (= Int#(32) ) ➢ Uint#(n) ➢ Non Bit型 ➢ Integer ➢ String ➢ Interfaces, Modules, Rules ➢ Action, ActionValue ➢ functions 25
  • 26. Bluespecの型システム ➢ Bit型 ➢ Bit#(n) (= bit[n-1:0]), Bool (= Bit#(1) ) ➢ Int#(n), int (= Int#(32) ) ➢ Uint#(n) ➢ Non Bit型 この”n”もnumeric typeという型をもつ ➢ Integer ➢ String ➢ Interfaces, Modules, Rules ➢ Action, ActionValue ➢ functions 26
  • 27. Bluespecの型システム 明示的な型変換 ➢ pack/unpack (= to Bit#(n)/from Bit#(n)) ➢ zeroExtend/signedExtend ➢ truncate ➢ fromInteger ➢ valueOf 27
  • 28. Bluespecの型システム Bluespec Library型 ➢ Reg#(a) ➢ Wire#(a) ➢ FIFO#(a) ➢ PulseWriter#(a)/PulseReader#(a) 28
  • 32. 目次 ➢ とりあえずコードをみてみよう ➢ Bluespecツール群 ➢ Bluespecのいろいろ ➢ クロックはどこへ消えた ➢ 強力な型システム ➢ ライブラリ探訪 ➢ 並列プログラミングの今後 32
  • 33. 並列プログラミングの今後 Bluespecに学ぶ ➢ rule/methodはいいなあ ➢ 細粒度並列性はHDL系が一番書きやすいかも ➢ ruleの切り出しが鍵か? ➢ Bluespecシミュレータはマルチプロセッサ非 対応 33
  • 34. 並列プログラミングの今後 ➢ そもそも並列プログラミングは存在しえるか? ➢ Bamboo ➢ Molatomium ➢ 並列化コンパイラ? ➢ OSCARコンパイラ ➢ ➢ ディレクティブ? ➢ *Ss ➢ XcalableMP 34