Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to GPU Programming in Python

Introduction to GPU Programming in Python

Yuki Ishikawa

April 21, 2018
Tweet

More Decks by Yuki Ishikawa

Other Decks in Technology

Transcript

  1. Introduction to GPU Programming in Python 2018.04.21 PyData.Okinawa #34 @hoto17296

  2. None
  3. None
  4. @hoto17296 • ͪΎΒσʔλגࣜձࣾ • σʔλ෼ੳϚϯ • JavaScript / Python /

    AWS • IPv6 ͕Θ͔Βͳ͍ࠓ೔͜ͷ͝Ζ
  5. Ͳͷ͝Ոఉʹ΋͋Δ GPU Ϛγϯ

  6. ࢖͍͜ͳͯ͠·͔͢ʁʁʁ

  7. ࣗ෼ͷ GPU ͷΠϝʔδ Λ଎͘ಈ͔ͤΔ΍ͭʂ

  8. ΋͍ͬͨͳ͍

  9. GPU Λ࢖͍౗ͨ͢Ίʹ CUDA Λ৮ͬͯΈΑ͏

  10. GPU ͱ͸ • Graphics Processing Unit • άϥϑΟοΫॲཧͷͨΊͷϓϩηοα • ୯७ͳॲཧΛฒྻԋࢉͰ͖Δ

    • άϥϑΟοΫҎ֎ʹ΋׆༻͞ΕΔ (GPGPU) • σΟʔϓϥʔχϯάͱ͔
  11. (NVIDIA) GPU ͷத਎ ετϦʔϛϯά Ϛϧνϓϩηοα ଞʹ΋ϝϞϦͱ͔ Ωϟογϡͱ͔ ৭ʑ͋Δ͚Ͳলུ CUDA ίΞ

  12. CUDA ͱ͸ • Compute Unified Device Architecture • NVIDIA GPU

    Λ࢖ͬͯฒྻܭࢉΛ͢ΔͨΊͷ
 ϓϩάϥϛϯάϞσϧ
  13. CUDA ༻ޠ • ϗετͱσόΠε • CPU ଆΛϗετ, GPU ଆΛσόΠε ͱݺͿ

    • Χʔωϧؔ਺ • GPU ଆͰ࣮ߦ͢ΔॲཧΛهड़ͨؔ͠਺
  14. CUDA ϓϩάϥϛϯάϞσϧ • ฒྻ਺͕๲େʹͳΔ • εϨου, ϒϩοΫ, άϦου ͱ͍͏
 ·ͱ·ΓͰฒྻॲཧΛߦ͏

  15. ग़యɿ http://www.nvidia.co.jp/object/cuda_education_jp_old.html

  16. CUDA ϓϩάϥϛϯάϞσϧ • ฒྻ਺ = εϨου਺ x ϒϩοΫ਺ x άϦου਺

    • 1ϒϩοΫ͋ͨΓ࠷େ 512 εϨου • 1άϦου͋ͨΓ࠷େ 65536^2 ϒϩοΫ 1GPU ͋ͨΓ࠷େ 2 ஹ ฒྻʂʂʂ
 ✌('ω'✌ )ࡾ✌('ω')✌ࡾ( ✌’ω')✌
  17. CUDA ϓϩάϥϛϯά ΍Γͨ͘ͳ͖ͬͯ·ͨ͠Ͷ ʁʁʁ

  18. CUDA ϓϩάϥϛϯάͷํ๏ • C Έ͍ͨͳݴޠͰΧʔωϧؔ਺Λ࣮૷ͯ͠
 nvcc ͱ͍͏ίϯύΠϥͰίϯύΠϧ͢Δ • μϧ͍ •

    GPU Λར༻ͨ͠ฒྻॲཧΛॻ͍ͯΈ͍͕ͨ
 C ͕ॻ͖͍ͨΘ͚Ͱ͸ͳ͍ • Python Ͱॻ͔ͤͯ͘Ε
  19. Numba • JIT ίϯύΠϧͯ͠
 Python Λߴ଎ԽͰ͖Δ΍ͭ • GPU ΋ར༻Ͱ͖Δ (Numba

    CUDA)
  20. Χʔωϧؔ਺ͷ ఆٛ σίϨʔλΛࢦఆ͢Δ͜ͱͰ Χʔωϧؔ਺ͱͯ͠ఆٛ ͜ͷΧʔωϧؔ਺͕ ฒྻ਺෼࣮ߦ͞ΕΔ ݱࡏͲͷҐஔ (ʁ) ͷεϨουͰ
 ࣮ߦ͍ͯ͠Δ͔औಘͰ͖Δ

    εϨουͷҐஔ৘ใ͔Β ॲཧ͢Δର৅ཁૉͷ࠲ඪΛܭࢉ͢Δ ߦྻͷର৅ཁૉʹରͯ͠ॲཧΛߦ͏
  21. Χʔωϧؔ਺ͷ࣮ߦ ฒྻ਺ (griddim, blockdim) Λࢦఆ͔ͯ͠Β࣮ߦ͢Δ

  22. ΋͏গ͠ෳࡶͳྫɿ ৞ΈࠐΈԋࢉ ग़యɿ http://tecmemo.wpblog.jp/category/machine-learning/deep-learning/page/2/

  23. ϥϓϥγΞϯϑΟϧλ • ৞ΈࠐΈԋࢉͰը૾ͷΤοδݕग़Λߦ͏ख๏ • ը૾ͷ৭ͷඍ෼ʹ૬౰͢Δ • ͜ͷߦྻΛϑΟϧλͱͯ͠
 ৞ΈࠐΈԋࢉΛߦ͏ 1 1

    1 1 -8 1 1 1 1
  24. ৞ΈࠐΈԋࢉΛߦ͏ Χʔωϧؔ਺Λ ࣮૷

  25. None
  26. ೖྗը૾ ϑΟϧλ݁Ռ

  27. ·ͱΊ • Python Ͱ΋ GPU ϓϩάϥϛϯά͸Ͱ͖Δ • GPU Ͱ༡Ϳͷ͸ͨͷ͍͠
 ✌('ω'✌

    )ࡾ✌('ω')✌ࡾ( ✌’ω')✌