Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
LLVMでHalideみたいな計算グラフ+JITを作りたい
Search
sonson
April 20, 2020
Programming
1.6k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
LLVMでHalideみたいな計算グラフ+JITを作りたい
sonson
April 20, 2020
More Decks by sonson
See All by sonson
計算グラフのJITコンパイラをLLVM on C++で作ろう
sonsongithub
2
630
LLVM Tutorial 02 - わいわいswiftc
sonsongithub
1
460
LLVM Tutorial - わいわいswiftc
sonsongithub
0
360
How to make and publish a Swift playground book for iPad
sonsongithub
5
19k
Swiftで実装するHTML特殊文字の高速処理
sonsongithub
3
8.1k
First step of 3D touch
sonsongithub
0
720
Getting started with 3D Touch
sonsongithub
0
820
SSLって必要ですか〜Let's Encryptを試してみよう
sonsongithub
3
610
Other Decks in Programming
See All in Programming
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
440
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.2k
AWSに止められる覚悟してますか?
morizo_1984
2
480
個人開発基盤をまるごとCloudflareに引っ越して爆速で総合的体験を向上させた話
tinykitten
0
210
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5.1k
モデルのリファクタリングが難しいと思ったら、そもそも複雑だったのはビジネス仕様だった ? / is-the-business-domain-the-real-complexity
hatsu38
0
420
GitHubハンズオン講座 — 実務レベルのチーム開発のフローを身につけよう
junhat6
0
110
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
210
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
460
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
340
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
240
Featured
See All Featured
Side Projects
sachag
456
43k
Highjacked: Video Game Concept Design
rkendrick25
PRO
1
460
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
440
Embracing the Ebb and Flow
colly
88
5.2k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
540
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
420
The untapped power of vector embeddings
frankvandijk
2
1.9k
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
2
290
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
590
Transcript
HalideͬΆ͍Կ͔Λ࡞ͬͯΈΔςετ Programming Yuichi Yoshida Chief engineer, DENSO IT Laboratory, Inc.
#Θ͍Θ͍swift @sonson_twit © 2014 DENSO IT Laboratory, Inc., All rights reserved. Redistribution or public display not permitted without written permission from DENSO IT Laboratory, Inc. LLVMͰܭࢉάϥϑΛJITίϯύΠϧ
αϯϓϧίʔυ • https://github.com/sonsongithub/llvm_jit_compile • https://github.com/sonsongithub/llvm-tutorial • Ϗϧυʹllvm͕ඞཁ • macOSͷ߹ brew
install llvm • ubuntuͷ߹ apt install llvm
ܭࢉάϥϑ
Computational Graph • ܭࢉΛάϥϑͱͯ͠อ࣋͢Δ • ී௨ͷίʔυͰɼ݁Ռ͔͠ಘΒΕͳ͍ • ͳͥɼͦΕ͕ඞཁʁ • ඍ͍͔ͨ͠Β
• ͳͥɼඍ͍ͨ͠ͷ͔ʁ
χϡʔϥϧωοτϫʔΫ f1 y W1 W2 W3 W4 f2 f3 x
ֶशɿ ͷΛௐ͍ͯ͘͠ ͜ͷͨΊʹ Ͱඍ͢Δඞཁ͕͋Δ ·ͨ ඍ͢Δඞཁ͕͋Δ Back propagationͰݕࡧʂ y Wi f
ඍ • χϡʔϥϧωοτϫʔΫΛ࣮͢Δ߹ • ϑΥϫʔυ • ग़ྗΛܭࢉ͢Δ࣮ • όοΫϫʔυ •
ௐ͢Δͱ͖ʹܭࢉ͢Δ࣮ • ࣮ɼϑΥϫʔυͷܭࢉͷඍ • ैདྷɼ͜ΕΒΛผʑʹ࣮͍ͯͨ͠ • ࣮͕ඇৗʹ໘ɾɾɾɾඍखܭࢉ • όάͷԹচ
ࣗಈඍ • ඍɼ࣮ࣗಈతʹͰ͖Δʢࡶʹݴ͏ͱʣ • ֶͷڭՊॻΈ͍ͯͩ͘͞ • ੵͦͷݶΓͰ͋Γ·ͤΜ
ී௨ʹ࣮͢Δͱ // x=10ͷͱ͖ͷdy/dwͷ͕ཉ͍͠ double w = 1; double x =
10; // ͜͜Ͱଈ࣌ʹܭࢉ͞ΕΔɽ double y = sin(w * x); double temp_x = 10; // खͰతʹܭࢉͨࣜ͠Λ // ιʔείʔυ্Ͱ࣮͢Δඞཁ͕͋Δ double dy_dw = cos(w * temp_x) * temp_x; std::cout << dy_dw << std::endl;
ܭࢉάϥϑ͕ར༻Ͱ͖Ε // ܭࢉάϥϑͷ߹ Param w; Var x,y; // ͜͜Ͱܭࢉ͞Εͳ͍ɽܭࢉάϥϑ͕ߏங͞ΕΔɽ //
“define by run”ͱݺΕΔ y = math.sin(w * x); double temp_x = 10; // ඍɼܭࢉάϥϑʹج͖ͮɼࣗಈతʹܭࢉ͞ΕΔɽ double dy_dw = y.diff(temp_x); std::cout << dy_dw << std::endl;
ฒྻԽ
ฒྻԽͷͨΊͷख๏ • SIMD sin(a) sin(a) sin(a) sin(a)
ฒྻԽͷͨΊͷख๏ • ϚϧνεϨου sin(a) sin(a)
ฒྻԽͷͨΊͷख๏ • ϚϧνεϨου+SIMD sin(a) sin(a) sin(a) sin(a) sin(a) sin(a) sin(a)
sin(a)
LLVMͷԠ༻ྫɾɾɾɾHalide • εϨου • SIMD • GPU • ͳͲͳͲɾɾɾ
Halideͷ߹ HalideͳΒɼ͜ͷίʔυͰશͯͷڥʹϙʔτͰ͖Δ [10] • εϨου • SIMD • GPU •
ͳͲͳͲɾɾɾ
[11]
Halideͷίʔυ C++ͰίϯύΠϧՄೳ
Halideͷ࣮ࡍ $ DPEF )BMJEF'VOD )BMJEF%4- #JOBSZ "45 ී௨ʹ ίϯύΠϧ Ϗϧυʹ
LLVMͱ Halide͕ඞཁ ੩తʹίϯύΠϧՄೳ
Halideͷ࣮ࡍ $ DPEF )BMJEF'VOD )BMJEF%4- #JOBSZ )BMJEF*3 --7.*3 #JOBSZ Halide::Funcͷ
AST͔ΒIRΛੜ Halide IR͔Β LLVM IRΛੜ LLVMͰ όΠφϦΛੜ "45 ࣮ߦڥΛηοτ
$ DPEF )BMJEF'VOD )BMJEF%4- Halideͷ࣮ࡍ #JOBSZ )BMJEF*3 --7.*3 #JOBSZ ࣮ߦ
Halide::Funcͷ AST͔ΒIRΛੜ Halide IR͔Β LLVM IRΛੜ LLVMͰ όΠφϦΛੜ "45 ࣮ߦڥΛηοτ ࠷ۙ͜ͷลͰ QPMZIFESBMPQUJNJ[BUJPOͷͨΊʹ ͏Ұஈ֊*3Λు͍ͯ࠷దԽ͢ΔΒ͍͠
$ DPEF )BMJEF'VOD )BMJEF%4- Halideͷ࣮ࡍ "45 #JOBSZ )BMJEF*3 --7.*3 #JOBSZ
࣮ߦ Halide::Funcͷ AST͔ΒIRΛੜ Halide IR͔Β LLVM IRΛੜ LLVMͰ όΠφϦΛੜ "45 ࣮ߦڥΛηοτ Ϗϧυʹ LLVMͱ Halide͕ඞཁ Polyhederal IR
ܭࢉάϥϑ·ͱΊ • ࣗಈඍ • TensoFlow, PyTorchɾɾɾɾɾ • χϡʔϥϧωοτϫʔΫͷֶशʹඞਢͷٕज़ • ฒྻԽͳͲʹ
• Halide • ͭ·Γ • ܭࢉΛఆ͓͍ٛͯͯ͠ɼϥϯλΠϜͰͳΜͧ͢Δ • ࣗಈతʹͳΜͧ͢Δͷָ͕ʹͳΔ
LLVMͰؔΛ࡞ͬͯΈΑ͏
llvm::JIT • Ͳ͏ΒJITʹ͍͔ͭ͘API/࣮͕͋ΔͬΆ͍ • MCJIT • depracatedΒ͍͠ɾɾɾ • ͰγϯϓϧͰݟ௨͕͍͍͠ •
ORC JIT • KaleidoscopeJIT.hʹ࣮͞Ε͍ͯΔͷ • ·ͩ͜ͷลɾɾɾશવௐࠪͰ͖ͯͳ͍ • http://llvm.1065342.n5.nabble.com/llvm-dev- Questions-about-moving-from-MCJIT-to-Orc-JIT- td129151.html
ࠓͷྲྀΕ • LLVM API for C++ͰίʔυΛॻ͘ • IRBuilder • ίʔυΛ֬ೝɼLLVM
IRΛు͘ɼ • MCJIT API • ExecutionEngine • ίϯύΠϧ • C++ͷؔͷϙΠϯλΛήοτ͢Δ
LLVM IRΛίʔυ͔Β࡞Δ LLVMͷAPIͰLLVM IRΛΈཱͯΔ --7.͕ཧ͢Δ$POUFYU
LLVM IRΛίʔυ͔Β࡞Δ LLVMͷAPIͰLLVM IRΛΈཱͯΔ --7.͕ཧ͢Δ$POUFYU .PEVMF
LLVM IRΛίʔυ͔Β࡞Δ LLVMͷAPIͰLLVM IRΛΈཱͯΔ --7.͕ཧ͢Δ$POUFYU .PEVMF 'VODUJPO 'VODUJPO
LLVM IRΛίʔυ͔Β࡞Δ LLVMͷAPIͰLLVM IRΛΈཱͯΔ --7.͕ཧ͢Δ$POUFYU .PEVMF 'VODUJPO #MPDL FOUSZ 'VODUJPO
#MPDL UIFO SFUVSO
͠ࢉ • add.cpp • ೋ߲ԋࢉAPI͕༻ҙ͞Ε͍ͯΔͷͰͦΕΛ͏ • CreateFAddͳͲ
ؔݺͼग़͠ • call.cpp • ͷcosΛݺͼग़͢ • ࣗͰϩʔΧϧͰ࣮ͨؔ͠Λݺͼग़͢ • Cͷ໊લ •
C++ͷmangled name • खॱ • ؔΛϞδϡʔϧʹՃ • module͔ΒؔΛऔಘ • ݺͼग़͢
ϙΠϯλ • pointer.cpp • વϙΠϯλॲཧͰ͖Δ • StoreͱLoadͰΛॻ͖ࠐΊΔ
ؔΛ࣮ߦ͢Δ // Get pointer to a function which is built
by EngineBuilder. // ؔͷϙΠϯλͰड͚Δ auto f = reinterpret_cast<double(*)(double*)>( engineBuilder->getFunctionAddress(name); if (f == NULL) { cout << "error" << endl; return 1; } // Execution // a + b double a = 10; cout << f(&a) << endl;
ܭࢉάϥϑ • graph.cpp • ೋมݻఆͷγϯϓϧͳྫ • ΫϥεͱԋࢉࢠͰߏจΛ࡞Δ • VarΫϥεͱVarΫϥεΛͯ͠ɼExpressionΛɾɾɾ •
LLVM Tutorial KaleidoscopeϕʔεͰ։ൃ
ܭࢉάϥϑ • graph.cpp • ೋมݻఆͷγϯϓϧͳྫ • ΫϥεͱԋࢉࢠͰߏจΛ࡞Δ • VarΫϥεͱVarΫϥεΛͯ͠ɼExpressionΛɾɾɾ •
LLVM Tutorial KaleidoscopeϕʔεͰ։ൃ • ՝ • C++ͷϙΠϯλͰड͚ΔgetFunctionAddress • ҾͱΓΛࣗ༝ʹઃܭͰ͖ͳ͍
ࢀߟจݙ • ͖ͭͶ͞ΜͰΘ͔ΔLLVM • llvm.org • LLVM Tutorial, C++൛Λಡ͏ •
swift.org • SwiftݴޠαΠτ • https://halide-lang.org • ݁ہɾɾɾίʔυಡΉͷ͕खͬऔΓૣ͠ɾɾɾɾɾ • Halideͷͬ͟ͱͨ͠આ໌ɾɾɾFixStars͕৺ʹ׆ಈ͍ͯ͠Δɼ͢Β͍͠ • https://www.slideshare.net/fixstars/halide-82788728 • https://qiita.com/fukushima1981/items/fa3537234e19baffc761 • Polyhedral Model • εέδϡʔϧΛઢܗʹؼண͠ɼܭըͰղ͘Έ͍ͨͳ • ·ͩɼΑʔ͔ΘΒ͔Μ • Darkroomͱ͍͏ٕज़ͷதͬΆ͍ • https://www.slideshare.net/fixstars/prelude-to-halidepublic-108059122