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
390
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
150
多様かつ継続的に変化する環境に適応する情報システム/thesis-defense-presentation
monochromegane
1
530
Online Nonstationary and Nonlinear Bandits with Recursive Weighted Gaussian Process
monochromegane
0
280
AIを前提とした体験の実現に向けて/toward_ai_based_experiences
monochromegane
1
640
Contextual and Nonstationary Multi-armed Bandits Using the Linear Gaussian State Space Model for the Meta-Recommender System
monochromegane
1
840
迅速な学習機構を用いて逐次適応性を損なうことなく非線形性を扱う文脈付き多腕バンディット手法/extreme_neural_linear_bandits
monochromegane
0
1.9k
再帰化への認知的転回/the-turn-to-recursive-system
monochromegane
0
720
仮想的な探索を用いて文脈や時間の経過による番狂わせにも迅速に追従する多腕バンディット手法/wi2_lkf_bandits
monochromegane
0
660
Synapse: 文脈と時間経過に応じて推薦手法の選択を最適化するメタ推薦システム/smash21-synapse
monochromegane
0
560
Other Decks in Programming
See All in Programming
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
Amazon Qを使ってIaCを触ろう!
maruto
0
400
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
1.9k
役立つログに取り組もう
irof
28
9.6k
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
Compose 1.7のTextFieldはPOBox Plusで日本語変換できない
tomoya0x00
0
190
みんなでプロポーザルを書いてみた
yuriko1211
0
260
as(型アサーション)を書く前にできること
marokanatani
9
2.6k
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
Six Lessons from altMBA
skipperchong
27
3.5k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
How GitHub (no longer) Works
holman
310
140k
RailsConf 2023
tenderlove
29
900
How to Ace a Technical Interview
jacobian
276
23k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
126
18k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Writing Fast Ruby
sferik
627
61k
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