Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Go言語でMac GPUプログラミング
Search
monochromegane
December 18, 2023
Programming
1
430
Go言語でMac GPUプログラミング
2023.12.18 Fukuoka.go#19 Reboot
https://fukuokago.connpass.com/event/302717/
monochromegane
December 18, 2023
Tweet
Share
More Decks by monochromegane
See All by monochromegane
Go言語でターミナルフレンドリーなAIコマンド、afaを作った/fukuokago20_afa
monochromegane
2
170
多様かつ継続的に変化する環境に適応する情報システム/thesis-defense-presentation
monochromegane
1
590
Online Nonstationary and Nonlinear Bandits with Recursive Weighted Gaussian Process
monochromegane
0
330
AIを前提とした体験の実現に向けて/toward_ai_based_experiences
monochromegane
1
680
Contextual and Nonstationary Multi-armed Bandits Using the Linear Gaussian State Space Model for the Meta-Recommender System
monochromegane
1
860
迅速な学習機構を用いて逐次適応性を損なうことなく非線形性を扱う文脈付き多腕バンディット手法/extreme_neural_linear_bandits
monochromegane
0
2k
再帰化への認知的転回/the-turn-to-recursive-system
monochromegane
0
730
仮想的な探索を用いて文脈や時間の経過による番狂わせにも迅速に追従する多腕バンディット手法/wi2_lkf_bandits
monochromegane
0
670
Synapse: 文脈と時間経過に応じて推薦手法の選択を最適化するメタ推薦システム/smash21-synapse
monochromegane
0
570
Other Decks in Programming
See All in Programming
Semantic Kernelのネイティブプラグインで知識拡張をしてみる
tomokusaba
0
180
menu基盤チームによるGoogle Cloudの活用事例~Application Integration, Cloud Tasks編~
yoshifumi_ishikura
0
110
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
선언형 UI에서의 상태관리
l2hyunwoo
0
150
Haze - Real time background blurring
chrisbanes
1
510
return文におけるstd::moveについて
onihusube
1
1k
プロダクトの品質に コミットする / Commit to Product Quality
pekepek
2
770
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
3
120
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
540
StarlingMonkeyを触ってみた話 - 2024冬
syumai
3
270
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
Symfony Mapper Component
soyuka
2
730
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
YesSQL, Process and Tooling at Scale
rocio
169
14k
For a Future-Friendly Web
brad_frost
175
9.4k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
247
1.3M
Facilitating Awesome Meetings
lara
50
6.1k
Mobile First: as difficult as doing things right
swwweet
222
9k
KATA
mclloyd
29
14k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Testing 201, or: Great Expectations
jmmastey
40
7.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Fireside Chat
paigeccino
34
3.1k
Transcript
Lightning Talks ࡾ༔հ / Pepabo R&D Institute, GMO Pepabo, Inc.
2023.12.18 Fukuoka.go#19 Reboot GoݴޠͰMac GPUϓϩάϥϛϯά
ϓϦϯγύϧΤϯδχΞ ࡾ ༔հ / @monochromegane 2 https://blog.monochromegane.com Yusuke Miyake ϖύϘݚڀॴ
ݚڀһ
• ଟมྔਖ਼ن ʹै͏ཚੜʹ͕͔͔࣌ؒΔ • ͜ͷཚੜͷखॱʢͷҰͭʣҎԼͷ௨Γ 1. ֤ཁૉ͕ඪ४ਖ਼نʹै͏ཚ ΛಘΔ 2. ڞࢄߦྻ
ΛίϨεΩʔղʢ ʣͯ͠ࡾ֯ߦྻ ΛಘΔ 3. ΛٻΊΔ • ಛʹɺ֬ͷύϥϝʔλʢ ͱ ʣ͕ҟͳͬͨΓɺ࣍ݩ ͕େ͖͍ ߹ʹɺཚੜʹ͕͔͔࣌ؒͬͯ͠·͏ y ∼ 𝒩 (μ, Σ), μ ∈ ℝD, Σ ∈ ℝD×D z = {zi }1≤i≤D , zi ∼ 𝒩 (0,1) Σ Σ = LL⊤ L y = μ + Lz μ Σ D 3 ͡Ίʹ
• ߦྻܭࢉಠཱ͔ͭฒߦͨ͠λεΫΛଟؚ͘ΉͨΊɺߴԽʹฒྻԽ͕༗ޮ • ͢ͳΘͪɺSIMDɺCPUͷϚϧνίΞɺGPUͳͲʹΑΔฒྻԽ • CPUόϯυͰλεΫཻখ͍͞ͷͰgoroutine͔ͳ͍ʢͱࢥ͏ʣ • GoݴޠͰͷߦྻܭࢉϥΠϒϥϦGonumCPUͷϚϧνίΞΛαϙʔτ͢Δ BLASͷόΠϯσΟϯάΛఏڙ͍ͯ͠Δ •
Apple silicon (M1) ʹGPU͕ࡌ͞Ε͍ͯΔͷͰɺͦͪΒ׆༻͍ͨ͠ 4 ͡Ίʹ
• GPUͷΞΫηεΛఏڙ͢ΔOSඪ४ࡌͷϑϨʔϜϫʔΫ • άϥϑΟοΫεॲཧҎ֎ʹɺGPU্Ͱͷฒྻܭࢉॲཧѻ͑Δ • Objective-C·ͨSwift͔ΒɺGPU্ͷॲཧΛهड़ͨ͠γΣʔμʔؔΛݺͿ • γΣʔμʔؔC++ϕʔεͷMetal Shader Language
(MSL) Ͱهड़ • Metal Performance Shaders (MPS) ͱ͍͏γΣʔμʔؔ܈ఏڙ͞ΕΔ 5 Metal: MacͰGPUϓϩάϥϛϯά
6 Metal: MacͰGPUϓϩάϥϛϯά • جຊతͳྲྀΕɺσόΠεʢGPUʣͷίϚϯυΩϡʔʹର͠ɺίϚϯυόο ϑΝͱ͍͏୯ҐͰγΣʔμʔؔΛొ͠ɺ݁ՌΛड͚औΔͱ͍͏ͷ • ͳ͓ɺCPUͱGPUͷͷΓऔΓʹઐ༻ͷόοϑΝ͕༻ҙ͞Ε͍ͯΔ ίϚϯυΩϡʔ ͷ४උ
ΓऔΓ༻ͷ όοϑΝͷ४උ όοϑΝͷσʔλ͔Β ߦྻΠϯελϯεੜ .14ͷγΣʔμʔؔ ΛॳظԽɺίϚϯυ όοϑΝͱͯ͠Τϯ ίʔυɺΩϡʔʹొ όοϑΝ͔Β݁Ռͷड ͚औΓ 0CKFDUJW$Ͱͷ ࣮ྫ
• Goݴޠ͔ΒcgoΛ͑͜ΕΒͷObjective-CͷίʔυΛݺΔ༷ࢠ • https://github.com/a-h/gpu ϥΠϒϥϦͱͯ͠ར༻Ͱ͖Δ͕MPSʹରԠ͍ͯ͠ͳ͍ • https://github.com/mikecvet/go-mm MPSͷݺͼग़͠Λ࣮͍ͯ͠Δ͕ϕϯνϚʔΫͷίʔυͷΈ • ্هΛࢀߟʹͭͭ͠ɺGoݴޠ্ͰͷGPUΛ༻͍ͨଟมྔਖ਼نʹै͏ཚ
ੜ͕Ͱ͖ͦ͏ 7 Cgo: GoݴޠͰMac GPUϓϩάϥϛϯά
1. Objective-CͷϔομϑΝΠϧΛinclude͠ɺLDFLAGSʹMetalϑϨʔϜϫʔΫΛࢦఆ͢Δ 2. ʢඞཁʹԠͯ͡ʣࣗલͷγΣʔμʔؔΛgo:embedͰΈࠐΜͰ͓͘ 3. C.xxͱͯ͠Objective-CͰهड़ͨ͠ॳظԽγΣʔμʔؔΛ࣮ߦ͢ΔؔΛݺͿɻ࣮ߦ࣌ ͷύϥϝʔλ݁ՌunsafeύοέʔδΛͬͯΞΫηεɻ 8 Cgo: GoݴޠͰMac
GPUϓϩάϥϛϯά (PͰͷ࣮ྫ
• Goݴޠ্ͰͷGPUΛ༻͍ͨଟมྔਖ਼نʹै͏ཚੜ • Goͷίʔυ͔Β ΛcgoΛܦ༝ͯ͠Objective-Cͷؔʹ͢ • MPSͷMPSMatrixDecompositionCholeskyΛ༻͍ͯίϨεΩʔղ • ࣗલγΣʔμʔؔΛ༻͍ͯԼࡾ֯ߦྻҎ֎Λ0ʹຒΊΔ •
MPSͷMPSMatrixVectorMultiplicationΛ༻͍ͯ Λܭࢉ • MPSͷMPSMatrixSumΛ༻͍ͯ Λܭࢉ • GoͷίʔυͰ݁ՌΛड͚औΔ z, μ, Σ Lz μ + Lz 9 Cgo: GoݴޠͰMac GPUϓϩάϥϛϯά
• 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ͷίϨεΩʔղগ͍͔͠͠Εͳ͍͕ɺͦͷଞͷࠩԿ͔
• ߦྻʢ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
• GoݴޠͰMac GPUϓϩάϥϛϯά͢Δํ๏Λհͨ͠ • ؆қతͳͷൺֱධՁΛ௨ͯ͠ɺ͍ॴͷഽײΛಘΔ͜ͱ͕Ͱ͖ͨ • MPSͷϚχϡΞϧΛಡΉͱχϡʔϥϧωοτϫʔΫͷαϙʔτ͋ΓɺΞΠ σΟΞ࣍ୈͰ໘ന͍͜ͱ͕Ͱ͖ͦ͏ • MPSͷݺͼग़͠ՄೳͳϥΠϒϥϦΛ࡞ͬͯΈ͍ͨ
• Ͳ͏ϝϞϦϦʔΫͯͦ͠͏ͳͷͰͦͷลΓվળ͍ͨ͠ • ࡾGo 12 ·ͱΊ
None