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
Jakarta EE meets AI
ivargrimstad
0
230
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
930
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
rails stats で紐解く ANDPAD のイマを支える技術たち
andpad
1
290
create_tableをしただけなのに〜囚われのuuid編〜
daisukeshinoku
0
240
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
670
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
250
From Translations to Multi Dimension Entities
alexanderschranz
2
130
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
14 Years of iOS: Lessons and Key Points
seyfoyun
1
770
Refactor your code - refactor yourself
xosofox
1
260
プロダクトの品質に コミットする / Commit to Product Quality
pekepek
2
770
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Building an army of robots
kneath
302
44k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.1k
How to Ace a Technical Interview
jacobian
276
23k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Fireside Chat
paigeccino
34
3.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Automating Front-end Workflow
addyosmani
1366
200k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Building a Scalable Design System with Sketch
lauravandoore
460
33k
A designer walks into a library…
pauljervisheath
204
24k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
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