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

Go言語でMac GPUプログラミング

Go言語でMac GPUプログラミング

2023.12.18 Fukuoka.go#19 Reboot
https://fukuokago.connpass.com/event/302717/

monochromegane

December 18, 2023
Tweet

More Decks by monochromegane

Other Decks in Programming

Transcript

  1. Lightning Talks ࡾ୐༔հ / Pepabo R&D Institute, GMO Pepabo, Inc.

    2023.12.18 Fukuoka.go#19 Reboot GoݴޠͰMac GPUϓϩάϥϛϯά
  2. • ଟมྔਖ਼ن෼෍ ʹै͏ཚ਺ੜ੒ʹ͕͔͔࣌ؒΔ • ͜ͷཚ਺ੜ੒ͷखॱʢͷҰͭʣ͸ҎԼͷ௨Γ 1. ֤ཁૉ͕ඪ४ਖ਼ن෼෍ʹै͏ཚ਺ ΛಘΔ 2. ڞ෼ࢄߦྻ

    ΛίϨεΩʔ෼ղʢ ʣͯ͠ࡾ֯ߦྻ ΛಘΔ 3. ΛٻΊΔ • ಛʹɺ֬཰෼෍ͷύϥϝʔλʢ ͱ ʣ͕౎౓ҟͳͬͨΓɺ࣍ݩ਺ ͕େ͖͍ ৔߹ʹɺཚ਺ੜ੒ʹ͕͔͔࣌ؒͬͯ͠·͏ y ∼ 𝒩 (μ, Σ), μ ∈ ℝD, Σ ∈ ℝD×D z = {zi }1≤i≤D , zi ∼ 𝒩 (0,1) Σ Σ = LL⊤ L y = μ + Lz μ Σ D 3 ͸͡Ίʹ
  3. 6 Metal: MacͰGPUϓϩάϥϛϯά • جຊతͳྲྀΕ͸ɺσόΠεʢGPUʣͷίϚϯυΩϡʔʹର͠ɺίϚϯυόο ϑΝͱ͍͏୯ҐͰγΣʔμʔؔ਺Λొ࿥͠ɺ݁ՌΛड͚औΔͱ͍͏΋ͷ • ͳ͓ɺCPUͱGPUͷ஋ͷ΍ΓऔΓʹ͸ઐ༻ͷόοϑΝ͕༻ҙ͞Ε͍ͯΔ ίϚϯυΩϡʔ ͷ४උ

    ΍ΓऔΓ༻ͷ όοϑΝͷ४උ όοϑΝͷσʔλ͔Β ߦྻΠϯελϯεੜ੒ .14ͷγΣʔμʔؔ਺ ΛॳظԽɺίϚϯυ όοϑΝͱͯ͠Τϯ ίʔυɺΩϡʔʹొ࿥ όοϑΝ͔Β݁Ռͷड ͚औΓ 0CKFDUJW$Ͱͷ ࣮૷ྫ
  4. • Goݴޠ্ͰͷGPUΛ༻͍ͨଟมྔਖ਼ن෼෍ʹै͏ཚ਺ੜ੒ • Goͷίʔυ͔Β ΛcgoΛܦ༝ͯ͠Objective-Cͷؔ਺ʹ౉͢ • MPSͷMPSMatrixDecompositionCholeskyΛ༻͍ͯίϨεΩʔ෼ղ • ࣗલγΣʔμʔؔ਺Λ༻͍ͯԼࡾ֯ߦྻҎ֎Λ0ʹຒΊΔ •

    MPSͷMPSMatrixVectorMultiplicationΛ༻͍ͯ Λܭࢉ • MPSͷMPSMatrixSumΛ༻͍ͯ Λܭࢉ • GoͷίʔυͰ݁ՌΛड͚औΔ z, μ, Σ Lz μ + Lz 9 Cgo: GoݴޠͰMac GPUϓϩάϥϛϯά
  5. • GonumͱMetal࣮૷ͷ࣮ߦ଎౓Λൺֱʢ1000࣍ݩʣ 10 ඪ४ਖ਼ن෼෍ཚ਺ͷม׵଎౓ͷൺֱ BenchmarkTransformNormMetal-8 9 117668310 ns/op BenchmarkTransformNormGonumBLAS-8 55

    21494668 ns/op BenchmarkTransformNormGonum-8 21 54288034 ns/op BenchmarkTransformNormCholMetal-8 1140 1070094 ns/op BenchmarkTransformNormCholGonumBLAS-8 15124 78960 ns/op BenchmarkTransformNormCholGonum-8 6712 177368 ns/op • ίϨεΩʔ෼ղͷ݁ՌΛผ్౉͢Α͏ʹͨ͠৔߹ͷൺֱ • MPSͷίϨεΩʔ෼ղ͸গ͠஗͍͔΋͠Εͳ͍͕ɺͦͷଞͷࠩ͸Կ͔
  6. • ߦྻʢ1000x1000ʣͱߦྻʢ1000x1000ʣͷ৐ࢉ଎౓Λൺֱ 11 ߦྻ৐ࢉ଎౓ͷൺֱ BenchmarkMatrixMultipicationMetal-8 494 2222134 ns/op BenchmarkMatrixMultipicationGonumBLAS-8 60

    22063894 ns/op BenchmarkMatrixMultipicationGonum-8 19 59507228 ns/op BenchmarkMatrixVectorMultipicationMetal-8 1497 792244 ns/op BenchmarkMatrixVectorMultipicationGonumBLAS-8 10000 114843 ns/op BenchmarkMatrixVectorMultipicationGonum-8 972 1239177 ns/op • ߦྻʢ1000x1000ʣͱϕΫτϧʢ1000x1ʣͷ৐ࢉ଎౓Λൺֱ • ߦྻಉ࢜ͷΑ͏ͳܭࢉྔͰ͸GPUͷํ͕ߴ଎ɻ ͷΑ͏ͳߦྻͱϕΫτϧͷ৐ࢉͰ͸͜ ͷ࣍ݩ਺ʹ͓͍ͯ͸GPUҠৡͷΦʔόʔϔουͷํ͕େ͖͔ͬͨͱߟ͑ΒΕΔ Lz