Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10....
Transcript of Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10....
![Page 1: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/1.jpg)
Fabric Engine and KLLLVM for 3D Digital Content Creation
Andrew MacPherson – Core Engineer, Fabric Software Inc.
![Page 2: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/2.jpg)
● Overview of Fabric Engine● Uses of LLVM within KL● Looking forward
The Plan
![Page 3: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/3.jpg)
● Digital Content Creation (DCC) framework● Standalone applications built on PySide
What is Fabric Engine?
![Page 4: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/4.jpg)
![Page 5: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/5.jpg)
● Digital Content Creation (DCC) framework● Standalone application built on PySide● Integration with existing DCC tools (Splice)
What is Fabric Engine?
![Page 6: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/6.jpg)
![Page 7: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/7.jpg)
● Digital Content Creation (DCC) framework● Standalone application built on PySide● Integration with existing DCC tools (Splice)● In use by production studios
What is Fabric Engine?
![Page 8: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/8.jpg)
● Many DCC tools are old● Closed and not configurable● Writing plugins is hard (C++) or slow (Python)● Development held back by software limitations
Why does Fabric Engine exist?
![Page 9: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/9.jpg)
● KL language + dependency graph
● Host language bindings (Python/C++)
● Simple multithreading (MapReduce/PEX)
● Fully cross-platform (Windows/Linux/OSX)
● Code portable among other DCC applications
![Page 10: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/10.jpg)
● Ease of Python with performance of threaded C++● Write once, use anywhere● Crash-free and updateable on the fly● Supports extensions for integration with existing libraries● Target selection at runtime (CPU or GPU)
How does KL help?
![Page 11: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/11.jpg)
![Page 12: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/12.jpg)
● In short: LLVM!● MCJIT-backed● Fabric Core compiler + scheduler● Let's look at some specifics...
So how does KL achieve this?
![Page 13: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/13.jpg)
● Ease of use● Fastest possible execution time● Minimal memory footprint● No significant startup delay
What's important for KL?
![Page 14: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/14.jpg)
● JIT languages slower to start than interpreted (ex. Python)● Want maximum performance from LLVM● Two-pass compilation
– First unoptimized compilation pass– Fully optimized code generated in background
KL – Compilation Passes
![Page 15: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/15.jpg)
● Sample case: CityAtNight.py● 37k lines KL● = 1.8M lines IR (pre-opt)
KL – Compilation Passes
Method Startup time
Upfront optimization 2m56s
Background optimization 0m37s
![Page 16: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/16.jpg)
● Using MCJIT ObjectCache since its introduction● Cache both IR and objects● Key based on hash of KL AST● Use of IR “stubs” with cached data
KL – Caching
![Page 17: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/17.jpg)
![Page 18: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/18.jpg)
● Sample case: CityAtNight.py● 37k lines KL● = 1.8M lines IR (pre-opt)
KL – Caching
Method Startup time
Upfront optimization 2m56s
Background optimization 0m37s
From cache 0m4s
![Page 19: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/19.jpg)
● Extensions export functions and methods● Core links swappable function pointer into KL● Same mechanism used in optimization pass● Allows updating linked runtime code● Explicit 'inline' modifier for extension functions
KL – Linking
![Page 20: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/20.jpg)
![Page 21: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/21.jpg)
● Sample case: SPHSimulation.py
KL – Linking
Method Startup time FPS
Inline everything 2m11s 26
Nothing inlined 0m34s 22
Selective use of 'inline' 0m35s 26
![Page 22: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/22.jpg)
● After compilation want minimal memory use● LLVM 3.4: delete Module after compile● Still need multiple ExecutionEngines
KL – Memory Use
![Page 23: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/23.jpg)
KL – Memory Use● Sample case: Crowd.py● With ObjectCache
Method RSS (MB)
Full IR + no removeModule 797
Stub IR + no removeModule 428
Full IR + removeModule 367
Stub IR + removeModule 356
Shared ExecutionEngine 296
![Page 24: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/24.jpg)
● KL code run without modification on CPU or GPU● AMD HSA hardware shared memory● Nvidia Cuda 6 “shared memory” via driver● Speedup varies by application and hardware but up to 10x faster● First release coming in May 2014
KL – GPU Compute
![Page 25: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/25.jpg)
● Sample case: Mandelbrot.py● Standard desktop hardware
KL – GPU Compute
Target FPS
Intel Core i7-3770k @ 3.50GHz 3.7
NVIDIA Quadro K5000 23.5
![Page 26: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/26.jpg)
![Page 27: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/27.jpg)
● Dwarf info via LLVM DIBuilder● LLDB JIT support● Breakpoints, threads, variable inspection, etc.● Python + PySide LLDB front-end
KL – Debugging
![Page 28: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/28.jpg)
![Page 29: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/29.jpg)
● Further reducing MCJIT memory footprint● Better error handling in out-of-memory scenarios● LLDB on Windows● Clang on Windows● GPU debugging?
Looking ahead
![Page 30: Fabric Engine and KL - LLVMllvm.org/devmtg/2014-04/PDFs/Talks/FabricEngine-LLVM.pdf · 2019. 10. 30. · Fabric Engine and KL LLVM for 3D Digital Content Creation Andrew MacPherson](https://reader035.fdocuments.in/reader035/viewer/2022071010/5fc7fdc9f6887426bd7d82ed/html5/thumbnails/30.jpg)
http://fabricengine.com/[email protected]