超並列高速実行処理系 Hastega (ヘイスガ) ~ Lonestar ElixirConf 凱旋帰国

超並列高速実行処理系 Hastega (ヘイスガ) ~ Lonestar ElixirConf 凱旋帰国

Erlang & Elixir Fest 2019
山崎 進

Qiitaで連載され,論文も複数本数発表され,さらには Lonestar ElixirConf でセンセーショナルな世界デビューを果たした超並列高速実行処理系 Hastega (ヘイスガ) の凱旋帰国講演です!

しかもおそらく本イベントのある6月までには,ファーストリリースバージョンを公開できるか,秒読みに入るのではないかと予測しています。

Hastega は,可読性に優れる Enum.map とパイプライン演算子を組み合わせた有限長のリスト処理を,SIMD命令やマルチコア,GPUを駆動するネイティブコードに変換して高速実行する処理系です。プロトタイプ実装では,純粋なElixirコードの4〜8倍にも及ぶ実行速度向上を達成しています。

本発表では,瞬時にわかる Hastega プログラミングのやり方を紹介し,動作原理や内部構造を紹介し,将来展望を示します。厨二病の血が騒ぐ発表に仕上げていきたいと思います。

83722380372c00bd75ac920f2089f6aa?s=128

Susumu Yamazaki (ZACKY)

June 01, 2019
Tweet

Transcript

  1. ௒ฒྻߴ଎࣮ߦॲཧܥ )BTUFHB ϔΠεΨ ʙ -POFTUBS&MJYJS$POG֌ટؼࠃ ࢁ࡚ਐ 1 ˜4VTVNV:BNB[BLJ

  2. ࣗݾ঺հ w 5XJUUFS'BDFCPPL(JU)VC(.BJM
 ͢΂ͯ[BDLZ w ๺۝भࢢཱେֶࠃࡍ؀ڥ޻ֶ෦।ڭत w &MJYJSਪ͠GVLVPLBFY)BTUFHB w φοδࣾձ࣮૷ݚڀηϯλʔηϯλʔ௕

    w ֶੜɾब৬ࢧԉ୲౰ w 1FSTPOBM7JTJPO$P$SFBUPS w ,,4)J'5 w ٕज़૬ஊɼڞಉݚڀґཔɼਐ࿏૬ஊɼ
 ద৬਍அͳͲɼਵ࣌ड෇·͢   ˜4VTVNV:BNB[BLJ
  3. )BTUFHB ϔΠεΨ 
 ͬͯԿʁ 3 ˜4VTVNV:BNB[BLJ

  4. )BTUFHB ϔΠεΨ w ΢ΣϒΞϓϦέʔγϣϯͰ༻͍Δ
 ը૾ॲཧɾػցֶश౳Λ w &MJYJSͰ؆ܿʹهड़ͯ͠ w αʔόʔɼ΢ΣϒΫϥΠΞϯτɼ
 Τοδ্ͷ$16(16ʹෛՙ෼ࢄ


    ͤ͞ͳ͕Βߴ଎ʹฒྻ࣮ߦͤ͞Δ
 ͜ͱΛ໨ࢦ͢ॲཧܥ w ໊শ͸''༝དྷ
 ஥ؒΛߴ଎Խͤ͞Δຐ๏  w ৄࡉ͸ޙड़   ˜4VTVNV:BNB[BLJ
  5. -POFTUBS&MJYJS$POG ͬͯԿʁ 5 ˜4VTVNV:BNB[BLJ

  6. -POFTUBS&MJYJS$POG w ౙʹςΩαεभΦʔεςΟϯͰ։࠵ ͞ΕΔ&MJYJSͷΧϯϑΝϨϯε w -POFTUBS͸ςΩαεभͷभضͷ
 γϯϘϧ w ೥͸݄೔ʙ݄೔ʹ։࠵
 IUUQTXXXMPOFTUBSFMJYJSDPOGDPN

    w &MJYJSઐ໳ͷΧϯϑΝϨϯεͰ͋Δ &MJYJS$POG64ɼ&MJYJS$POG&6ʹ ͙࣍ୈҐͷن໛   ˜4VTVNV:BNB[BLJ
  7. -POFTUBS&MJYJS$POG ʹԿ͠ʹߦͬͨͷʁ 7 ˜4VTVNV:BNB[BLJ

  8. )BTUFHBւ֎σϏϡʔ w -POFTUBS&MJYJS$POGͰ )BTUFHBΛൃද͠·ͨ͠ʂ   ˜4VTVNV:BNB[BLJ IUUQTZPVUVCFMZQRM(M,4P IUUQTXXXMPOFTUBSFMJYJSDPOGDPNTQFBLFSTTVTVNVZBNB[BLJ

  9. ͲΜͳൃදͨ͠ͷʁ 9 ˜4VTVNV:BNB[BLJ

  10. Hastega: Challenge for GPGPU on Elixir Susumu Yamazaki (ZACKY) Associate

    Professor at Univ. of Kitakyushu Adviser at fukuoka.ex
  11. We’re three Samurais from fukuoka.ex, like “Les Trois Mousquetaires” (The

    Three Musketeers)
  12. We’ll show you
 our spirits of
 Samurai and Zen…

  13. Long, long distance… The world with
 destructive updates is…

  14. Dystopia! © 2014, Teresa Prater

  15. © 2011, Pavel Medzyun Their works become
 dystopia!

  16. Our solution:
 Hastega!!!

  17. Hastega • It’s a magic!! • the highest evolved magic

    to accelerate our party in Final Fantasy!
 (Stronger than Haste) • It will be the highest evolved technology to accelerate our machines in the Elixir ecosystem! It’s inspired by Flow
  18. Let’s cast a spell of Hastega on Samurai

  19. 4-8x faster than Elixir using Flow! and also faster than

    P-map
 (Parallel map) ↑ Slower ↓ Faster Flow
  20. 3x+ faster than Python with GPU (CuPy) !!! ↑ Slower

    ↓ Faster
  21. Only a little slower than native code (Rust)!! Dead heat!!

    ↑ Slower ↓ Faster
  22. Overwhelming Effectiveness like a berserk Samurai

  23. By the way,
 which is better, 
 recursive call and

    Enum.map?
  24. Enum.map is simpler! It’s like Zen! ˜4UFQIBOF%"MV

  25. Why is Enum.map Zen? ˜4UFQIBOF%"MV • Zen is the essential

    beauty • The essential of programming is data transformation • Enum.map describes only data transformation list = 1..1_000_000 |> Enum.to_list list 
 |> Enum.map(&foo(&1))
 |> Enum.map(&bar(&1))
  26. 1..1_000_000 
 |> Enum.map(&foo(&1))
 |> Enum.map(&bar(&1)) • We propose to

    call it the Elixir Zen style to write in Enum.map • It is a good programming custom • Because it’s more readable and maintainable The Elixir Zen style
  27. Then, what will happen? ˜4UFQIBOF%"MV

  28. In Elixir on Erlang VM, the Elixir Zen style is

    20 percents slower than recursive call list = 1..1_000_000 |> Enum.to_list list 
 |> Enum.map(&foo(&1))
 |> Enum.map(&bar(&1)) list
 |> func()
 
 def func( [] ), do: [] def func( [ head | tail ] ) do
 [ head |> foo |> bar 
 | func(tail) ]
 end 6msec ↑ Slower ↓ Faster Performance Evaluation
  29. © 2011, Pavel Medzyun It’s Zen, but not Samurai…! It

    will cause dystopia!
  30. • make the Elixir Zen styled code faster • by

    casting the spell of it on Samurai to be berserk • that is, to be transformed into the fastest native code, 
 using all computing resources, • not only multi-core CPUs (with SIMD instructions)
 but also GPUs Hastaga will… We feel it Wabi-Sabi
  31. Hastega makes the most beautiful code to be transformed the

    fastest!
  32. Do you wanna get power of Hastega, now?

  33. I’m sorry, but the 1st practical use version of Hastega

    will be released before Summer, 2019 m(_ _)m
  34. ͳΜͰ)BTUFHBΛ
 ։ൃͨ͠ͷʁ 34 ˜4VTVNV:BNB[BLJ

  35. ৘ใྔരൃ ೥ʹσʔλͷ૯ྔ͕θλόΠτ ೥ʹθλόΠτʹୡ͢ΔݟࠐΈ 35 ˜4VTVNV:BNB[BLJ

  36. ৘ใྔരൃ ೥ʹຖ݄ΤΫαόΠτ૿Ճ ೥ʹຖ݄ΤΫαόΠτ૿ՃݟࠐΈ ৘ใͷ૿Ճྔ͕Ճ଎ 36 ˜4VTVNV:BNB[BLJ

  37. ܭࢉೳྗ͕௥͍͔ͭͳ͍ )FOOFTZ1BUUFSTPO
 ೥ʹ$16ΫϩοΫप೾਺͸಄ଧͪʹ 37 ˜4VTVNV:BNB[BLJ

  38. ͳͥΫϩοΫप೾਺Λ৳͹ͤͳ͍͔ʁ w ΫϩοΫप೾਺ͷ૿େ͸ফඅిྗͱൃ೤ྔͷ૿େΛট͘ w ిݯڙڅྔͱ೤఻ಋ཰͓Αͼྫྷ٫ೳྗ͕௥͍͔ͭͳ͍ w ʙ()[ఔ౓ͰৗԹͰ҆ఆಈ࡞͢ΔݶքΛܴ͍͑ͯΔ w ڝٕ༻ΦʔόʔΫϩοΫͰ͸ӷମ஠ૉ౳ʹਁ͚Δ౳ʹ ΑΓ()[Ҏ্Ͱಈ࡞͍ͤͯ͞Δ

    w ௨ৗͷ1$΍αʔόʔͰ͸ৗԹՔಇͰ͖Δ͜ͱ͕ཁ݅ 38 ˜4VTVNV:BNB[BLJ
  39. ͔ΘΓʹίΞ਺͕૿Ճ w ೥Ҏ߱ͷϓϩηοαͷਐԽ w ºΫϩοΫप೾਺ w ˓ίΞ਺   ˜4VTVNV:BNB[BLJ

    *O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γϣϯ w -POFTUBS&MJYJS$POGͰ͸ &MJYJS1IPFOJYͱର౳ͳଘࡏͱ͠ ͯ঺հ͞Ε͍ͯͨ w ,FZOPUFຊ


    1SFTFOUBUJPOຊ
 5SBJOJOHຊ
 -5ຊ w ৄ͘͠͸ߴ੉ઌੜͷൃදΛָ͠Έ ʹ͍ͯͩ͘͠͞ʂ   ˜4VTVNV:BNB[BLJ IUUQTZPVUVCF*U*WOEU['.
  45. 1IPFOJY-JWF7JFX w 1IPFOJYͷ࡞ऀ$ISJTͷൃද
 -JWF7JFX w ΋͏ϦϦʔε͞ΕͨͷͰɼ
 ࢼͨ͠ਓ΋ଟ͍ͷͰ͸ʁ w /FSWFTͱ-JWF7JFXΛ઀ଓ ͨ͠σϞ΋͋Γ

      ˜4VTVNV:BNB[BLJ
  46. -VODIJTPEF w ೔໨ͷϥϯνλΠϜʹ
 ߨԋऀઐ༻ͷ෦԰Ͱٞ࿦ͨ͠
 ༷ࢠΛऩ࿥ w &MJYJS1IPFOJY/FSWFTͷ
 ະདྷʹ͍ͭͯޠΓ߹͏ w )BTUFHBʹ͍ͭͯ΋Ұੜݒ໋

    ͠Ό΂Γ·ͨ͠ w ࠓɼฉ͍ͯ΋ɼ൒෼͘Β͍͠ ͔ฉ͖औΕͳ͍ɻɻɻ   ˜4VTVNV:BNB[BLJ IUUQTQPEDBTUTNBSUMPHJDJPTQFDJBMMPOFTUBSFMJYJS
  47. &MJYJSOFYU5IF3JWFS w ٕज़ίϛϡχςΟͷਐาͷྺ࢙Λ
 େՏͷྲྀΕʹͨͱ͑Δ w ্ྲྀ͔ΒԼྲྀʹྲྀΕΔʹͭΕͯ
 ίϛϡχςΟͷ͋Γํ͕ม࣭͢Δ w ίϛϡχςΟʹͲ͏ؔΘΔ΂͖͔ w

    ίϛϡχςΟ΁ฦ͢ɼߩݙ͢Δ w ʮ7PUF౤ථͤΑʯ w ʮ௨աّྱʯతηογϣϯ w ࠷΋ݟΔ΂͖ϓϨθϯςʔγϣϯ   ˜4VTVNV:BNB[BLJ IUUQTZPVUVCF,8S81H*
  48. &SMBOH&DPTZTUFN'PVOEBUJPO w &MJYJSͷ࡞ऀ+PTÉ7BMJNͷ
 ,FZOPUFຊ໨ ຊ໨΋ݟͯͶ  w &MJYJSOFYU͔ΒͷྲྀΕΛड͚
 &MJYJSͷ฼ମͰ͋Δ&SMBOHͱ
 Ͳ͏͍͏ؔ܎ੑΛ΋͔ͭʁ


    ʹ͍ͭͯ+PTÉ͔ΒޠΒΕͨ w &SMBOH&DPTZTUFN'PVOEBUJPO ʹՃೖͯ͠ʮ7PUF౤ථʯͯ͠
 ΄͍͠ͱݺͼ͔͚ͨ w &SMBOH΁ͷϦεϖΫτΛ෷͍ɼ
 &MJYJS͔Β୅දΛग़ͦ͏ͱ͍͏ಈ͖   ˜4VTVNV:BNB[BLJ IUUQTZPVUVCFR$"2V51P.
  49. +PTÉͱͷަྲྀ w )BTUFHBߨԋޙɼ+PTÉ͕೤৺ ʹ࣭໰͖ͯͨ͠ w +PTÉͷߨԋޙɼࢲ΋ٞ࿦͢Δ w )BTUFHB͕+PTÉͷߏ૝͢Δ ϩʔυϚοϓ্ͷཁૉٕज़
 Ͱ͋Δ͜ͱΛ֬ೝ

    w ؼࠃޙϝʔϧͰจ௨͢Δ஥ʹ   ˜4VTVNV:BNB[BLJ
  50. +PTÉ͕໌Β͔ʹͨ͠
 ڻዼͷࣄ࣮ 50 ˜4VTVNV:BNB[BLJ

  51. ܦҢ w +PTÉ͸)BTUFHBʹͱͯ΋ڵຯΛ࣋ͬͯ͘Ε w ͳΜͱɼࢲͷॻ͍ͨ೔ຊޠͷ࿦จΛࣗ෼Ͱ຋༁ͯ͠ಡΜͰ͘Εͨ w ͦͷͱ͖ʹ͜Μͳϝʔϧ͕ૹΒΕ͖ͯͨ 51 ˜4VTVNV:BNB[BLJ

  52. ˜4VTVNV:BNB[BLJ

  53. ˜4VTVNV:BNB[BLJ

  54. ˜4VTVNV:BNB[BLJ

  55. ˜4VTVNV:BNB[BLJ

  56. ʜͰɼ)BTUFHBͷ
 ϦϦʔε͸ɼ·ͩͳͷʁ 56 ˜4VTVNV:BNB[BLJ

  57. ·ͩͰ͢ʂ
 +PTÉͷॿݴͱֶੜͷKPJOͰ
 ΑΓύϫʔΞοϓͯ͠ઈࢍ։ൃதʂ 57 ˜4VTVNV:BNB[BLJ

  58. Our adventure of Samurai, Zen and Wabi-Sabi continues…

  59. I’ll be back! to share new research results

  60. THE END

  61. 0OFNPSFUIJOH 61 ˜4VTVNV:BNB[BLJ

  62. &MJYJS$POG64 ݄೔ʙ೔ w )BTUFHBͷൃදΛ͠·͢ʂ w ৽ͨʹݚڀ։ൃͨ͠৽ٕज़Λ ൃද͠·͢ʂ w ϓϩάϥϜ͸੝Γͩ͘͞Μ w

    ΈΜͳͰߦ͜͏Αʂ w ੈքͷைྲྀΛײ͡Α͏ʂ   ˜4VTVNV:BNB[BLJ IUUQTFMJYJSDPOGDPNTQFBLFST
  63. ݚڀʹ͝ڠྗ͍ͩ͘͞ʂ w ͞ΒͳΔίʔυ࠷దԽͷݚڀʹඞཁͳ࣮ߦ࣌৘ใΛऩू͢ΔͨΊͷϓϩϑΝΠϥ Λ೥౓தʹ։ൃ͢Δ༧ఆͰ͢ w ऩू͢Δ৘ใͷྫ
 $16ͷछྨϝϞϦɾΩϟογϡϝϞϦ༰ྔϦεταΠζɾཁૉͷܕ
 ϓϩηε਺ΠςϨʔγϣϯதίʔυྔ&MJYJS;FOελΠϧίʔυͷׂ߹ͳͲ w Ͱ͖Ε͹࣮ӡ༻ʹ͍ۙ৘ใΛऩू͍ͨ͠ͱߟ͍͑ͯ·͢

    w ࢲୡͷνʔϜ͚ͩͰσʔλΛಠ઎͢ΔΘ͚Ͱ͸ͳ͘ɼ౷ܭॲཧ্ͨ͠Ͱɼ
 اۀ໊ɾݸਓ໊౳Λ໌͔ͣ͞ʹɼݚڀऀ޲͚ʹσʔλఏڙ͍ͨ͠ͱߟ͍͑ͯ·͢ w ͝ڠྗ͍͚ͨͩΔاۀɾݸਓͷํ͸ɼ͝࿈བྷ͍ͩ͘͞ʂ
 ࢁ࡚ਐ[BDLZ!LJUBLZVVBDKQ 63 ˜4VTVNV:BNB[BLJ
  64. ݄೔ͷ༧ఆΛۭ͚ͯͶʂ ࠃ಺ͰͷΠϕϯτاըத 64 ˜4VTVNV:BNB[BLJ