Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

ElixirでFPGAを設計する

2,006 views

Published on

fpgax #12 での発表資料です
https://fpgax.connpass.com/event/152964/

なおエリクシールではありません.

Published in: Software
  • From A Cup To c Cup In 6 Weeks with this... ★★★ https://dwz1.cc/YYZPZbuh
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

ElixirでFPGAを設計する

  1. 1. ElixirでFPGAを設計する 高瀬 英希 (京都大学/JSTさきがけ) takase@i.kyoto-u.ac.jp
  2. 2. @takasehideki − 京都大学 情報学研究科 准教授 − JSTさきがけ 兼任研究者 − SWEST プログラム委員長 − IPSJ-SIGEMB 運営幹事 − TOPPERSプロジェクト 特別会員 − ROS Japan UG  関西勉強会 主催  ROSCon JP 実行委員 − IoT ALGYAN (あるじゃん) 運営委員 − Elixir: NervesJP fukuoka.ex 主な研究開発プロジェクト − mROS: 組込み向けROS軽量実行環境 − Cockatrice: Elixir for HLS 自己紹介 2 Cockatrice
  3. 3. 3
  4. 4. Elixirとは?
  5. 5. Elixirとは? 2012年に登場した新たな関数型言語 5 Erlang VM上で動作 • 高い並列性能を誇る • 軽量かつ頑強なプロセスモデル • 耐障害性が極めて高い Rubyを基にした言語設計 • 習得しやすく生産性が向上する • WebフレームワークPhoenixを持つ 応答性が極めて高い
  6. 6. Elixir Zen Style • Enum: データコレクションを操作 • Flow: 並列処理を直接的に記述 − MapReduce処理モデル • |>:パイプライン演算子 データの流れを表現 • Zen(禅) とは本質美である − プログラミングの本質であるデータと並列処理の 流れを Enum Flow |> で直感的に記述できる − Programming should be about transforming data 6 1..1000 |> Flow.from_enumerable() |> Flow.map(& foo(&1)) |> Flow.map(& bar(&1)) |> Enum.to_list |> Enum.sort
  7. 7. Elixirの気持ちよさ • Zen Style!! • (やや)強い動的型付け • オブジェクトの イミュータブル性(不変性) • バイナリ操作と パターンマッチ • 軽量かつ堅牢な プロセスモデル • マクロプログラミング • IoTに使える!!? 7 ダッシュ ボード Link Super Visor one_for_one App 液晶 データ ロガー Link センサ 監視 制御 Link ボタン
  8. 8. ElixirでIoT!! 8 • HWもSWもErlangセットで提供!! ü300MHz Cortex-M7 & 64MB Flash üOn-board WLAN & Pmodコネクタ • V2のKickstarter Project達成︕︕ • ラズパイ等が主な対象 • メモリサイズ数10MB︕ • Elixir ecosystem連携︕ • ESP32/STM32で Elixir/Elarngが動く!! • ファームは約700KB!! • 機能実装はまだ限定的
  9. 9. Nerves!! 9 https://nerves-project.org
  10. 10. Platform • ブートローダ+rootfs+ Erlang OTP+Elixirアプリ − 一括でビルドして SDカード等に書込み 10
  11. 11. Framework • IoTデバイス開発に欠かせない 強力なライブラリ −Elixir Circuits: GPIO, I2C, SPI, UART −IoTモジュール向けライブラリも • 通常のElixirライブラリも利用可 −描画系ライブラリ Scenic や Webフレームワーク Phoenixとも 容易に連携可能! 11
  12. 12. Tooling • mixによるプロジェクト管理 − いつものElixirアプリ開発と一緒! − クロスコンパイルは裏でよしなに • IExでのインタプリタ実行も可能 − VirtualEther越しのssh接続 − /dev/tty* 越しのserial接続 • ファーム・アプリの書き込み − SDカードに書き込み − VirtualEther越しの更新 − NervesHub : Device to the Cloud!! サーバ経由のOTAでアプリをリモートデプロイ! 12
  13. 13. https://nerves-jp.connpass.com/ 13 サッポロビーム
  14. 14. FPGAと高位合成
  15. 15. Computational Resources 15 design flexibility development cost power efficiency performance FPGA processor with software ASIC as hardware
  16. 16. What is FPGA? • Field Programmable Gate Array − LSIs whose contents can be changed any time − We can design a unique digital circuit (HW) on it − Two major vendors Xilinx・Altera (powered by Intel) 16 IOB SB CB LB IOB IOB SB IOB LB SB CB CB SB CB SB SB CB CBLB IOBIOB LB SB SB SB IOB IOB CB CB CB CB CB CB I/O block connection blockLB logic block IOBSB switching block CB LUT IN OUT 0000 1 0001 0 0010 0 … … 1110 1 1111 0 D-FF D Q
  17. 17. How to Use of FPGA 17 processor 通信バス FPGA Offloading heavy processing HW HW interface IF circuit performance improvement and low power consumption can be achieved SW SW communication between SW/HW SW SW IF driver
  18. 18. Advantages of FPGA 18 FPGA Memory Func Func Func FuncFunc Func FuncFunc FuncFunc • Various systems can be designed onto one LSI • High performance / low power consumption • Parallel processing can be realized at task/data level • Data streaming processing can be realized
  19. 19. Current Technology Trends • Increase in circuit scale and amount of LB − High performance systems can be realized − Further increase will continue by new technology  multi-die, 3D stacking,,, • Tightly coupling with processors − General-purpose: Connection via PCIe to processors − Embedded: Integration with embedded processors 19 high-quality system design in a short time has become difficult,,,
  20. 20. High Level Synthesis (HLS) • Solution to improve design productivity! − Technology for synthesizing HDL from behavioral descriptions with a programming language C/C++ or its extension is commonly used − Abstraction level of design becomes higher 20 int func (int x) { int a[N]; int i; for(i=0;i<N;i++){ a[i] = ・・・; : : } : } x func i a
  21. 21. Commercial HLS Tools • Xilinx Vivado HLS − Synthesize from C/C++ − #pragma is offered to indicate the optimization 21 • Intel SDK for OpenCL − Synthesize from OpenCL parallelized code − Can be executed with same description as the host PC Ref: Xilinx Inc. White paper UG902 D. Neto, Optimizing OpenCL for Altera FPGAs, Int’l Workshop on Open CL, 2014. It is essential to understand #pragma and libraries deeply for deriving optimized hardware
  22. 22. not only C/C++!! • Chisel: Scala based − Object Oriented / Functional styled DSL • CλaSH: Haskell based − Synthesize HDL from description of functional language • Karuta: original scripting language • Synthesijer: Java based − HLS from the subset of Java specification • PyCoRAM, Polyphony: Python based  Veriloggen: Python library for HDL design • Mulvery: Ruby based − Synthesis from Reactive Programming • Octopus🐙:OCaml based 22 developed by hls-friends!!
  23. 23. 23
  24. 24. OK, What We Want is,,, 24 We want to design HW by Elixir!! We want to operate HW from our Elixir code!!
  25. 25. Concept of Cockatrice • Why Elixir would be suitable for HW design? • HW synthesis flow from Elixir code • SW/HW communication interface
  26. 26. What is Cockatrice? • Summoned beast that appears in FF4 (^^; − The effect is to make all enemies to stones • Hardware design environment with Elixir! • Features − It synthesizes Elixir Zen Styled code to the description of HW circuits − It provides communication interface between Elixir code and HW circuits 26 Your Elixir code can be accelerated, and low-powered!! NOTE: Current logo of cockatrice is from Wikipedia
  27. 27. Zen’s process model 27 input_list |> Flow.from_enumerable(stages: 4) |> Flow.map(& foo(&1)) |> Flow.map(fn a->-a end) |> Enum.to_list |> Enum.sort from_ enumerable input_list foo foo foo foo sortto_list arbitrator -a -a -a -a It’s similar to efficient HW architecture!!
  28. 28. Zen is suitable for HW design! 28 Cockatrice input_list |> Flow.from_enumerable(stages: 4) |> Flow.map(& foo(&1)) |> Flow.map(fn a->-a end) |> Enum.to_list |> Enum.sort from_ enumerable input_list foo foo foo foo sortto_list arbitrator -a -a -a -a We summon Cockatrice to lithify Elixir Zen Styled Code as parallel HW stones!!
  29. 29. Effect of Cockatrice 29 Input List from_ enume rable to_list sort foo -a foo -a foo -a foo -a arbitrator foo -a foo -a foo -a foo -a foo -a foo foo -a foo -a foo -a -a foo -a foo -afoo -a foo -a
  30. 30. HW Description by Elixir • defcockatrice part will be treat as HW description − It is completely equivalent to native Elixir code You do not need to consider HW design It can be verified at functional level • HW module can be called as same as SW function − We assume SW/HW cooperative systems 30
  31. 31. Synthesis Flow 31 Code analysis & AST optimization design desc. Elixir templates for IP DSL info. of desc. AST Synthesis of HW modules from Elixir function HW IP modules HDL data flow HW circuit HDL HW circuits bitstream logic synthesis SW app Elixir+C(NIF) Compilation of SW Generation of device driver of I/F circuit Synthesis of data flow I/F driver C(NIF)
  32. 32. Code analysis & AST optimization design desc. Elixir templates for IP DSL info. of desc. AST Synthesis of HW modules from Elixir function HW IP modules HDL data flow HW circuit HDL HW circuits bitstream logic synthesis SW app Elixir+C(NIF) Compilation of SW Generation of device driver of I/F circuit Synthesis of data flow I/F driver C(NIF) Synthesis Flow 32 Metaprogramming method is employed to derive AST of Zen styled design description by Quote function
  33. 33. Code analysis & AST optimization design desc. Elixir templates for IP DSL info. of desc. AST Synthesis of HW modules from Elixir function HW IP modules HDL data flow HW circuit HDL HW circuits bitstream logic synthesis SW app Elixir+C(NIF) Compilation of SW Generation of device driver of I/F circuit Synthesis of data flow I/F driver C(NIF) Synthesis Flow 33 we provide templates of HDL code that are equivalent to Enum functions as DSL files HDL code is synthesized by applying pattern matching with AST and DSL
  34. 34. Code analysis & AST optimization design desc. Elixir templates for IP DSL info. of desc. AST Synthesis of HW modules from Elixir function HW IP modules HDL data flow HW circuit HDL HW circuits bitstream logic synthesis SW app Elixir+C(NIF) Compilation of SW Generation of device driver of I/F circuit Synthesis of data flow I/F driver C(NIF) Synthesis Flow 34 each modules is connected as data flow from AST representation of |> and Flow data flow and parallel processing HW circuit is finally synthesized!!
  35. 35. Code analysis & AST optimization design desc. Elixir templates for IP DSL info. of desc. AST Synthesis of HW modules from Elixir function HW IP modules HDL data flow HW circuit HDL HW circuits bitstream logic synthesis SW app Elixir+C(NIF) Compilation of SW Generation of device driver of I/F circuit Synthesis of data flow I/F driver C(NIF) Synthesis Flow 35 communication interface and its driver are generated as NIF function
  36. 36. Code analysis & AST optimization design desc. Elixir templates for IP DSL info. of desc. AST Synthesis of HW modules from Elixir function HW IP modules HDL data flow HW circuit HDL HW circuits bitstream logic synthesis SW app Elixir+C(NIF) Compilation of SW Generation of device driver of I/F circuit Synthesis of data flow I/F driver C(NIF) SW binary and HW bit files are compiled by respective tools Synthesis Flow 36 SW binary and HW bit files are compiled by respective tools
  37. 37. SW/HW Comm. Interface • Activation/Operation to HW from Elixir code • Data communication between SW and HW − AXI4 bus on Zynq is used • We implement device driver as C/NIF module − ikwzm/udmabuf is used for DMA transfer − Elixir/Erlang list should be converted to C array 37 FPGA processor DMA buffer HW circuits Elixir app Erlang VM device driver (NIF module) interface circuit
  38. 38. FPGA processor DMA buffer HW circuits Elixir app Erlang VM device driver (NIF module) interface circuit SW/HW Comm. Interface 38 SWの関数呼び出しと 同じ記述でHWを起動
  39. 39. FPGA processor DMA buffer HW circuits Elixir app Erlang VM device driver (NIF module) interface circuit SW/HW Comm. Interface 39 SWの関数呼び出しと 同じ記述でHWを起動 ErlangのNIF機能で C実装デバドラをラッピング
  40. 40. FPGA processor DMA buffer HW circuits Elixir app Erlang VM device driver (NIF module) interface circuit SW/HW Comm. Interface 40 SWの関数呼び出しと 同じ記述でHWを起動 ErlangのNIF機能で C実装デバドラをラッピング Elixirのリストと Cの配列を相互変換 Xilinx Zynq搭載の AMBA AXI4に準拠して通信 Xilinx Zynq搭載の AMBA AXI4に準拠して通信 Elixirライブラリ関数と 機能等価なHDL IP
  41. 41. Our Targets 41 Zynq-7000 Zynq UltraScale+
  42. 42. Demonstration Time?? • Board: Avnet Ultra96-V2 − Zynq UltraScale+ ZU3EG − 1.5GHz quad-core Arm Cortex-A53 − 16nm FinFET+ programmable logic $249.00 • EDA tool: Xilinx Vivado 2019.1 • Software platform − Linux Kernel v4.19.0 with debian10-rootfs-vanilla from ikwzm/ZynqMP-FPGA-Linux build-v2019.1 with udmabuf v1.4.2 as kernel module − Elixir 1.9.1-otp-22 / Erlang 22.0.7 42
  43. 43. Discussion & Future Direction
  44. 44. Discussion • Currently, we just implement prototypes − We will publish them as Hex pkgs very soon,,, − Currently supported features are limited IOW, we only synthesize Zen styled code Are another Elixir/Erlang process models suitable for efficient HW architecture? − Quantitative evaluation of our proposal will be also important (to verify academic contribution^^; 44
  45. 45. Discussion • Applicable range of Cockatrice? − Not only embedded, but also HPC domain!? Bigger data for Cockatrice would be suitable since there is some overhead on SW/HW comm. − AI/ML would be a killer application Big data stream processing for IoT Cloud processing that allows users to change functions flexibly − We are planning to support large-scale FPGA boards with comm. interface for PCIe bus 45
  46. 46. BTW, I love Nerves!! • Experiences at Lonestar2019 was great for me! • I made a presentation to promote the innovation of Nerves to Japan at Erlang & Elixir Fest 2019!! 46 Nervesが開拓する 『ElixirでIoT』 の新世界 ⾼瀬 英希 (京都⼤学/JSTさきがけ) takase@i.kyoto-u.ac.jp 18 ライブデモのお品書き 1. Nervesプロジェクトの準備とビルド 2. microSDに書き込んでブート・IEx実⾏ 3. ソース編集してlocal ssh書き込み 4. NervesHubから書き込み 5. Scenic連携&GPIOデバイスの制御 Raspberry Pi Zero WH Adafruit 128x64 OLED Bonnet https://github.com/takasehideki/eefest19demo NervesKey 『ElixirでIoT』の新世界︕ 25 デバイス エッジサーバ クラウド あらゆるモノ・コト・ヒトを ネットワーク化︕ 情報科学の総合格闘技︕ 新たな社会的価値を創出!! みんなで⼀緒に IoTを創ろう︕ 14 NervesHub •サーバ経由のOTA (Over The Air) で Nervesアプリをリモートデプロイ︕ - X.509署名証明書とNervesKey回路で セキュアな接続経路を実現 - 更新先とファームを任意指定可
  47. 47. Future Direction 47 What will happen when Nerves meets Cockatrice? Please help us, to evolve the new era of "IoT development with Elixir"
  48. 48. Future of “Elixir for IoT” 48 device edge server cloud これがワタシの Extreme Computing!!
  49. 49. Thank to,,, with Wabi-Sabi • My students in lab. − Kentaro Matsui − Yasuhiro Nitta • My research partners at fukuoka.ex − @zacky1972 − @hisawayex − @piacere_ex − @enpedasi • My friends at hls-friends − Tech comm. for self-made high-level synthesis tools 49

×