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
640
LLVM Tutorial 02 - わいわいswiftc
sonsongithub
1
470
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
730
Getting started with 3D Touch
sonsongithub
0
820
SSLって必要ですか〜Let's Encryptを試してみよう
sonsongithub
3
610
Other Decks in Programming
See All in Programming
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.6k
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
950
月間100万人のサービス刷新で、 技術選定をHonoに振り切った話
yutobara
8
6.1k
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
7
13k
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
360
AWSに止められる覚悟してますか?
morizo_1984
2
520
すこし踏み込む CancellationToken
htkym
2
1.7k
Domain-Driven Transformation
hschwentner
2
2.3k
KiroのSpecで「五目並べ」を作ってみる
satoshi256kbyte
1
370
Simple Storage Service(S3) is not simple
iwatsukayura
0
250
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
200
Featured
See All Featured
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
720
How STYLIGHT went responsive
nonsquared
100
6.3k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
710
Fireside Chat
paigeccino
43
4.1k
Darren the Foodie - Storyboard
khoart
PRO
4
4k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
530
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
The Pragmatic Product Professional
lauravandoore
37
7.5k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
480
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.8k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
870
Color Theory Basics | Prateek | Gurzu
gurzu
1
480
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