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
Metal Acceleratedかどうかを調べる方法〜あなたのアプリのどこでMetalが暗躍...
Search
shu223
February 22, 2018
Programming
1.7k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Metal Acceleratedかどうかを調べる方法〜あなたのアプリのどこでMetalが暗躍しているのか #potatotips
potatotips #48 (iOS/Android開発Tips共有会)での発表資料です。
https://potatotips.connpass.com/event/77702/
shu223
February 22, 2018
More Decks by shu223
See All by shu223
slidify-sample
shu223
1
1.6k
機械学習のブルーオーシャン Core ML by 堤 修一 #iOSDC Japan 2020
shu223
12
5.9k
エンジニアのための発信講座 #4 登壇しよう
shu223
0
160
エンジニアのための発信講座 #3
shu223
0
150
エンジニアのための発信講座 #2
shu223
2
270
エンジニアのための発信講座 #1
shu223
1
1k
今こそwatchOS #iosdc
shu223
5
11k
Depth in Depth #iOSDC
shu223
4
31k
技術書のジレンマとPEAKS + 書評ブログを書くTips #iOS11book
shu223
18
6k
Other Decks in Programming
See All in Programming
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
370
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
520
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.6k
Google Apps Script で Ruby を動かす
kawahara
0
150
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
470
仕様駆動開発の消費期限
watany
20
7.7k
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
18k
S3 を使うアプリケーションをローカル完結で動かすことに全力を注いでみた / Running S3 Apps Offline
contour_gara
0
420
Android CLI
fornewid
0
220
プロポーザルを書いてもらう
pvcresin
0
300
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.5k
2年かけて Deno に DOMMatrix を実装した話 / How I implemented DOMMatrix in Deno over two years
petamoriken
0
210
Featured
See All Featured
sira's awesome portfolio website redesign presentation
elsirapls
0
320
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
790
The World Runs on Bad Software
bkeepers
PRO
72
12k
Docker and Python
trallard
47
4.1k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
390
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Why Our Code Smells
bkeepers
PRO
340
58k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Design in an AI World
tapps
1
280
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.8k
Designing for humans not robots
tammielis
254
26k
Transcript
Metal Accelerated͔Ͳ͏͔ΛௐΔํ๏ ͋ͳͨͷΞϓϦͷͲ͜ͰMetal͕҉༂͍ͯ͠Δͷ͔ Shuichi Tsutsumi @shu223
None
WWDC17ͷ͜ͷਤͰɺUIKitΛؚΉ ଟ͘ͷϑϨʔϜϫʔΫ͕෦Ͱ MetalΛ༻͍͍ͯΔ͜ͱ͕Θ͔ͬͨ
͕ɺ
ࡉ͔͍͜ͱ·Ͱ৭ʑͱΘ͔Βͳ͍ • UIKitͷԼճΓ͍͔ͭΒMetalʹͳͬͨͷ͔ʁ • UIKitͷͲͷॲཧ͕Metal AcceleratedͰɺͲͷॲཧ͕ͦ͏͡Όͳ͍ͷ͔ʁ • OpenGLʢiOSͰʣࠓMetalͷ্ʹ࣮͞Ε͍ͯΔͱAppleͷਓ͕WWDC ͷϥϘͰݴ͚ͬͯͨͲɺެࣜใͳ͍ •
2014ͷWWDCͰCore AnimationͷϨΠϠʹ͍ͭͯղઆ͕͋Δ͚Ͳɺ͜ ΕͬͯͲ͔͜ΒͲ͜·Ͱ͕ࠓ༗ޮͳใͳͷ͔ʁ • etc.
AppleͷެࣜใཔΈ • API Reference • Programming Guide • Forum •
WWDC Session • ʮWWDC LabͰதͷਓ͕ݴͬͯͨʯ ͔͠ɾɾɾ ͕࣌ؒܦͭͱɺެࣜใͰϝϯς͞Ε͍ͯͳ͍ͷূڌͱͯ͠ෆेʹͳΔ
ʮཪऔΓʯେมˍ͍͠
ʮMetal Accelerated͔Ͳ͏͔ʯ ΛࣗͰௐΒΕͳ͍͔ʁ
Metal Accelerated͔Ͳ͏͔ΛͳͥΓ͍ͨͷ͔ʁ • தͷਓʹΑͬͯϝϯς͞Ε͍ͯͯɺ࠷దԽ͞Ε͍ͯΔ͜ͱ͕Θ͔Δ • ࣗͷ࠷దԽख๏͕ద͔Ͳ͏͔ͷஅࡐྉʹͳΔ • ϨΠϠʹ౿ΈࠐΜͰࣗલ࣮͢Δ͔Ͳ͏͔ͷஅࡐྉʹͳΔ
XcodeͷGPU Reportʁ
MetalΛ໌ࣔతʹར༻͍ͯ͠ͳ͍ͱɺ XcodeͷGPU Reportग़ͯ͜ͳ͍
ͦ͜ͰInstruments
Metal System Trace
UIKit͔ͬͯ͠ͳ͍ʢʹMetalͬͯͳ͍ʣ ΞϓϦͰࢼͯ͠ΈΔ
τϨʔεͰ͖ͯΔʂ
UIKitͷԼͰʮ҉తʹʯΘΕ͍ͯΔ MetalͷଉਧΛײ͡Δ͜ͱ͕Ͱ͖Δʂ
࣌ܥྻํʹ֦େͯ͠ΈΔ
ͬ͘͟Γͨ͠ݟํ GPUͰ࣮ߦ͢ΔίϚϯυͷ࡞ʢonCPUʣ GPUίϚϯυΛૹ৴ʢon CPUʣ γΣʔμͷ࣮ߦʢon GPUʣ σΟεϓϨΠͷඳը CPUͰͷॲཧ → GPUͰͷॲཧ
→ ը໘දࣔ ͷҰ࿈ͷྲྀΕͱෛՙ͕ՄࢹԽ͞Ε͍ͯΔ
“Launching” Comand Buffer (SpringBoard) ͦͷޙඳըλεΫͳ͠ ʢUIKitඞཁ͕ͳ͚Εߋ৽ॲཧΛ͠ͳ͍ʣ “Foreground” ͜ͷ͋ͨΓΞϓϦىಈ࣌ͷඳը ॲཧͬΆ͍
ϘλϯΛԡͨ͠ΒUIImageViewͰը૾Λදࣔ͢Δ ʢͪΖΜMetalΘͳ͍ʣ
ΞϓϦىಈ࣌ͷॾʑ ϘλϯԡԼʙ UIImageViewͷը૾දࣔ
࣌ܥྻํʹ֦େ
ʮMetal Accelerated͔Ͳ͏͔ʯ ΛࣗͰௐΒΕͳ͍͔ʁ → InstrumentsͰௐΒΕͦ͏
ϦΞϧλΠϜʹݟΕͳ͍ ʮͲͷάϥϑ͕ͲͷॲཧΛද͍ͯ͠Δͷ͔ʁʯ ͕Θ͔ΓͮΒ͍
MetalͷlabelػೳΛར༻ͯ͠Ͳ͏͔ʁ private func pushLabel(_ label: String) { let commandBuffer =
commandQueue.makeCommandBuffer()! commandBuffer.label = label commandBuffer.commit() } ʮԿ͠ͳ͍MetalͷίϚϯυόοϑΝʯΛGPUʹϓογϡ͢Δ ϝιουΛ͓͍ͭͬͯͯ͘ɺ @IBAction func btnTapped(_ sender: UIButton) { pushLabel(“start”) imageView.image = UIImage(named: "highsierra") pushLabel(“end”) } ͜Μͳײ͡ͰݺͿͱɾɾɾ label͚͍ͩ࣋ͬͯΔ
Instruments্Ͱͦͷlabel͕දࣔ͞Εɾɾɾ ͳ͔ͬͨɾɾɾ
ʮۭͷίϚϯυόοϑΝʯ InstrumentsͰݟ͑ͳ͍ ࣮ߦ࣌ʹGPUʹૹΒΕͳ͍ͷ͔ɺ ͦͦϏϧυஈ֊Ͱ࠷దԽ͞ΕΔͷ͔ɺetc… ʢͲ͔͜ʹ༷ͱͯ͠ॻ͍ͯ͋Δ͔ʣ
தͷ͋ΔίϚϯυʹ͢Δ private func pushLabel(_ label: String) { let textureLoader =
MTKTextureLoader(device: device) let srcTex = try! textureLoader.newTexture(name: “hoge”, scaleFactor: 2.0, bundle: nil) let descriptor = MTLTextureDescriptor.texture2DDescriptor( pixelFormat: srcTex.pixelFormat, width: srcTex.width, height: srcTex.height, mipmapped: false) let destTex = device.makeTexture(descriptor: descriptor)! let commandBuffer = commandQueue.makeCommandBuffer()! commandBuffer.label = label let blitEncoder = commandBuffer.makeBlitCommandEncoder()! blitEncoder.copy( from: srcTex, sourceSlice: 0, sourceLevel: 0, sourceOrigin: MTLOriginMake(0, 0, 0), sourceSize: MTLSizeMake(srcTex.width, srcTex.height, srcTex.depth), to: destTex, destinationSlice: 0, destinationLevel: 0, destinationOrigin: MTLOriginMake(0, 0, 0)) blitEncoder.endEncoding() commandBuffer.commit() } ຊʹཉ͍͠ͷ͚ͩ͜͜
ޭʂ ηοτͨ͠label͕ݟ͍͑ͯΔ
·ͱΊ • ͍··ͰɺMetal Accelerated͔Ͳ͏͔Λ֬ೝ͢ΔʹɺެࣜใཔΈͩͬͨ - Guide, API Reference, Forum, WWDC
Session, WWDC LabͰݴͬͯͨ, etc…ʮཪऔΓʯ ͕͔ͬͨ͠ - MetalΛ໌ࣔతʹ༻͍͍ͯͳ͚ΕɺXcodeͷGPU ReportԠ͠ͳ͍ • InstrumentsͷMetal System TraceΛ༻͍ΔͱɺMetalΛ໌ࣔతʹ༻͍͍ͯͳ ͍߹ʹɺMetalͷಈ͖ΛΔ͜ͱ͕Ͱ͖Δ • ϦΞϧλΠϜʹτϨʔεͰ͖ͳ͍ͷͰɺҹͱͯ͠labelΛషΔํ๏ݕ౼ - ҰԠ͏·͍ͬͨ͘ - ͕ɺखʹMetalΛ͏ख๏ʹͳͬͯ͠·ͬͨͷͰɺ͓͢͢Ί͠ͳ͍