technical architect ubisoft montreal michael lavaire technical lead ubisoft montreal remi quenin...
TRANSCRIPT
![Page 1: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/1.jpg)
Technical ArchitectUbisoft Montreal
Michael LAVAIRETechnical LeadUbisoft Montreal
Remi QUENIN
Squeeze the Juice out of CPUsPost Mortem of a Data-Driven Scheduler
![Page 2: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/2.jpg)
Table of Contents
1. Issues on common MT Archi.
2. “Shears” Solution
3. Tips and Tricks
![Page 3: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/3.jpg)
1. COMMON ARCHITECTURAL DESIGNS Usual multithreading patterns
![Page 4: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/4.jpg)
Folded loop
Gameplay
Engine Loop
Graphic
Smaller Engine Loop
Thread 1
Thread 2
Background LoadingThread 3
Frame NN+1N+2
![Page 5: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/5.jpg)
Sync point
Sync
Sync
Sync
Sync
Applying modifications
Applying modifications
Applying modifications
Gameplay
Graphic
Background Loading
Applying modifications
![Page 6: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/6.jpg)
Tasks SchedulingStage 1
Waiting
Stage 2 Stage 3
Gate
Task A
Task D
Task C
Task B
Task E
Task F
![Page 7: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/7.jpg)
2. « SHEARS » SOLUTION60 FPS for everyone
![Page 8: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/8.jpg)
Objectives
![Page 9: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/9.jpg)
2.1 DATA DRIVEN SCHEDULINGFocus on data, not on the code
![Page 10: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/10.jpg)
Task A
Task A
Task A
Data driven scheduling
Task A
Task A
Task A
Task A
Task B
Task A
Task A
Task A
Task C
Data D1
Data D0
Data D0
Data D1
![Page 11: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/11.jpg)
D0 D1
Data driven scheduling
Task A
Task A
Task A
Task A
Task A
Task A
Task A
Task B
Task A
Task A
Task A
Task C
Data D1
Data D0
![Page 12: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/12.jpg)
Data driven schedulingD0 D1
Task A
Task B
Task C
![Page 13: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/13.jpg)
Data driven scheduling
D0 D1Task
A
Task B
Task C
![Page 14: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/14.jpg)
Data driven scheduling
![Page 15: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/15.jpg)
Data driven scheduling
![Page 16: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/16.jpg)
Data driven scheduling
![Page 17: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/17.jpg)
2.2 WORKLOADSNo locks, be scalable
![Page 18: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/18.jpg)
Workload
![Page 19: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/19.jpg)
Lock-free : Internal
Container
State
Thread 2Container::Remove
()
State State
Thread 1Container::Add()
State StateState State
Test &Set Test &Set
SUCCESS ! FAILED !SUCCESS !
![Page 20: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/20.jpg)
Lock-free
![Page 21: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/21.jpg)
1 2 3 40
2000
4000
6000
8000
10000
12000
Lock-free - Op/msecCrit.Sec. - Op/msec
Lock-free : Comparison Q6600
Thread Count 1 2 3 4 Lock-free Mean Op Time (cycles) 233 678 2145 3278
Op/msec 10300 3540 1119 732Race count 0 9571 91205 161371
Crit.Sec. Mean Op Time (cycles) 771 24862 36835 49079
Op/msec 3113 97 65 49Idle % 57% 74% 83% 87%
Lock-free / Crit.Sec. ratio 3.31 36.67 17.17 14.97
![Page 22: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/22.jpg)
Lock-free : Comparison X360
Thread Count 1 2 3 4 5 6 Lock-free Mean Op Time (usec) 0.29 0.5 0.6 0.83 0.91 1.2
Op/msec 3448 2000 1667 1205 1099 833Race count 0 10447 72716 152283 218379 329422
Crit. Sec. Mean Op Time (usec) 0.96 10.06 13.76 19.16 24.66 29.88
Op/msec 1042 99 73 52 41 33Idle % 23% 75% 85% 89% 92% 93%
Lock-free / Crit.Sec. ratio 3.31 20.12 22.93 23.08 27.10 24.90
1 2 3 4 5 60
500
1000
1500
2000
2500
3000
3500
4000
Lock-free - Op/msec
Crit.Sec. - Op/msec
![Page 23: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/23.jpg)
1 20
500
1000
1500
2000
2500
3000
3500
4000
Lock-free - Op/msec
Crit.Sec. - Op/msec
Lock-free : Comparison PS3
Thread Count 1 2 Lock-free Mean Op Time (usec) 0.27 0.46
Op/msec 3704 2174Race count 0 253
Crit.Sec. Mean Op Time (usec) 1.15 5.15
Op/msec 870 194Idle % 25% 60%
Lock-free / Crit.Sec. ratio 4.26 11.20
![Page 24: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/24.jpg)
2.3 WORKING WITH SPUEasy cross-platforming, easy debugging
![Page 25: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/25.jpg)
Working with SPUCross Platform API
?
![Page 26: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/26.jpg)
Working with SPUCross Platform API
Main Memory Impl DMA Impl
Memory Access Interface
SatelliteTask
![Page 27: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/27.jpg)
Working with SPU Easy Debugging
Main Memory Impl DMA Impl
Memory Access Interface
SatelliteTask
![Page 28: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/28.jpg)
Working with SPUEasy Debugging
![Page 29: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/29.jpg)
Working with SPU Easy Debugging
Main Memory Impl DMA Impl
Memory Access Interface
SatelliteTask
Named Pipe
![Page 30: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/30.jpg)
![Page 31: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/31.jpg)
3. TIPS & TRICKSMultithreading & peace of mind
![Page 32: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/32.jpg)
Tip 1: Clever profiling
![Page 33: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/33.jpg)
Tip 2: Watchdog
![Page 34: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/34.jpg)
Tip 3: Unit Tests
![Page 35: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/35.jpg)
Trick 1: Perturbation
![Page 36: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/36.jpg)
Trick 1: Perturbation
Test A
Test C
Test B
Test D
Test A
Test C
Test B
Test D
Loop n Loop n+1
Thread A
Thread B
New thread synchronization
![Page 37: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/37.jpg)
Trick 2: State validation
![Page 38: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/38.jpg)
Trick 2: State validationSt
ate
1
Process A Process B Process C
Process X
Stat
e 2
Stat
e 3
Stat
e X
Assert !
![Page 39: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/39.jpg)
Trick 2: State validationclass StateChecker{public:
enum State { State1, State2, State3 };
StateChecker() { m_state = State1; }
bool SetState( State oldState, State newState ){
return Atomic::TestAndSet( &m_state, oldState, newState ) == oldState;
}
private:volatile State m_state;
};
![Page 40: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/40.jpg)
Trick 3: Access verification
![Page 41: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/41.jpg)
Trick 3: Access verificationclass AccessChecker{public:
AccessChecker() { m_access = 0; }
bool StartReadAccess() { return Atomic::Inc( &m_access ) > 0; }bool EndReadAccess() { return Atomic::Dec( &m_access ) >= 0; }
bool StartWriteAccess() { return Atomic::Dec( &m_access ) == -1; }bool EndWriteAccess() { return Atomic::Inc( &m_access ) == 0; }
private:volatile int m_access;
};
![Page 42: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/42.jpg)
Trick 4: Multithreaded Assert
![Page 43: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/43.jpg)
Trick 4: Multithreaded Assert
extern volatile bool g_waitOnAssert = false;
#define ASSERT( condition ) \while(g_waitOnAssert) {} \if( !(condition) ) \{ \
g_waitOnAssert = true; \DoAssert(); \g_waitOnAssert = false; \
}
![Page 44: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/44.jpg)
Squeeze the Juice !
![Page 45: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/45.jpg)
Inspiration• Game Programming Gems 6: Lock-free Algorithms
by Toby Jones• Design and Implementation of Multi-Threaded Games
by Bruce Dawson• Floodgate: Maximizing SPU parallelism without
sacrificing cross platform developmentby David Asbell & Michael Noland
• SPU Shadersby Mike Acton
![Page 47: Technical Architect Ubisoft Montreal Michael LAVAIRE Technical Lead Ubisoft Montreal Remi QUENIN Squeeze the Juice out of CPUs Post Mortem of a Data-Driven](https://reader035.vdocuments.mx/reader035/viewer/2022062417/5519bb2855034660578b4991/html5/thumbnails/47.jpg)
Ubisoft is recruiting!Come see us at the Ubisoft Booth in the Career
Pavilion (CP 2308, South Hall)
You can also check out: www.creatorsofemotions.com