Fast Machine Learning for Science Workshop 2023
09/26/2023
Ryan Forelli
Real-Time Instability Tracking with Deep Learning on FPGAs in Magnetic Confinement Fusion Devices
Goal: Begin solving the technical challenges facing fusion energy with fast machine learning on hardware.
Overview
2
Magnetic confinement fusion devices: the tokamak
3
The Problem: plasma instability in tokamak devices
4
The Solution: Active suppression of MHD instabilities
5
Tokamak
CNN
[
]
[
]
Controller
DAC
control outputs
actuators
control request
High-speed Camera Setup at the Tokamak
High-speed Camera view
6
CNN training results
7
n=1 : one toroidal wave period
How do CNNs compare to previous/alternative methods?
8
Hardware deployment
control request
Controller
DAC
control outputs
actuators
[
]
[
]
CNN
?
9
control request
Controller
DAC
control outputs
actuators
[
]
[
]
CNN
GPU
10
Hardware deployment
Frame grabber
PCIe hop 1
PCIe hop 2
Coaxial
control request
(RS422)
Controller
DAC
control outputs
host PC
actuators
[
]
[
]
CNN
Euresys CoaxLink Octo
Frame grabber
11
Hardware deployment
Framegrabber Model Integration: CustomLogic
CustomLogic
12
Design challenges and constraints
trigger
exposure
frame 0
readout
inference
writeout
t = 0us
t = 20us
Combinational
Logic
In
4ns
clk
xcku035-fbva676-2-e
Additional challenges and inefficiencies
0
1
2
3
4
5
6
7
0
1
2
3
4
5
6
7
Expected image
Received image
Hardware Optimizations
Optimization | Beneficiary |
Quantization aware training (32b → 7b) | Resources |
Pruning | Resources |
Strategy optimized by layer | Resources, Latency |
Reuse factor optimized by layer (see right) | Resources, Latency |
Dataflow pipelining (see below) | Latency |
Batched input streaming | Latency |
Target period, clock unc., & Vivado version scanned | Timing |
ReLUs merged | Latency |
Synthesis & routing strategies scanned | Timing |
Physical optimization looping | Timing |
15
Implementation results
100kfps
8.1us
Pipelining exposure/readout and inference
17
Exposure/readout pipelined with inference
Design verification|firmware
128
32
CNN
sine[10:0]
cosine[10:0]
Host PC
32
32
18
Final results and future work
Project summary
Future Work
19
Acknowledgements
Columbia University - HBT-EP Group
Fermilab - AI/RTPS Division
20
Supported by US DOE Grant DE-FG02-86ER53222, DE-SC0022234, and US DOE ASCR under the “Real-time Data Reduction Codesign at the Extreme Edge for Science” Project (DE-FOA-0002501).
Appendix A
DAC Input Timing Characteristics
Appendix B
Appendix C
Appendix D
Appendix E
2455 cycles (9.8us) → 1700 cycles (6.8us)
17
17
32
32
conv_0_0
conv_0_1
relu_0_0
relu_0_1
Rearrange
Split
450:450
to
480:420
pool_0_0
pool_0_1
32x17x1
Recombine
30x15x16
30x15x16
30x15x16
30x15x16
32x17x1
30x16x16
30x14x16
15x15x16
15x8x16
15x7x16
+---------------------------+------------------------+------+------+------+------+----------+
| | | Latency | Interval | Pipeline |
| Instance | Module | min | max | min | max | Type |
+---------------------------+------------------------+------+------+------+------+----------+
|conv_2d_cl_1_U0 |conv_2d_cl_1 | 434| 434| 434| 434| none |
|conv_2d_cl_2_U0 |conv_2d_cl_2 | 909| 909| 909| 909| none |
|dense_2_U0 |dense_2 | 61| 62| 61| 62| none |
|relu_U0 |relu | 2| 2| 1| 1| function |
|dense_U0 |dense | 103| 103| 103| 103| none |
|dense_1_U0 |dense_1 | 88| 89| 88| 89| none |
|conv_2d_cl_U0 |conv_2d_cl | 1034| 1034| 1034| 1034| none |
|relu_1_U0 |relu_1 | 2| 2| 1| 1| function |
|relu_2_U0 |relu_2 | 20| 20| 20| 20| none |
|pooling2d_avg_cl_par_7_U0 |pooling2d_avg_cl_par_7 | 521| 521| 521| 521| none |
|pooling2d_cl_U0 |pooling2d_cl | 21| 21| 21| 21| none |
|relu_4_U0 |relu_4 | 904| 904| 904| 904| none |
|relu_3_U0 |relu_3 | 173| 173| 173| 173| none |
|pooling2d_cl_2_U0 |pooling2d_cl_2 | 905| 905| 905| 905| none |
|pooling2d_cl_1_U0 |pooling2d_cl_1 | 174| 174| 174| 174| none |
|myproject_Loop_INPUT_U0 |myproject_Loop_INPUT | 258| 258| 258| 258| none |
|myproject_Loop_POOL_U0 |myproject_Loop_POOL_s | 1026| 1026| 1026| 1026| none |
+---------------------------+------------------------+------+------+------+------+----------+
Appendix F: Extra parallelization: streaming
26
conv2d_0
conv2d_1
conv2d_2
dense_0
dense_1
dense_2
poolings
activations
other (streaming, etc.)
Camera protocol
Appendix G: Logic placement
8.1us
1.6us
Model Serial Readout
sclk
cs
Appendix H: Oscilloscope traces
28
old
Appendix I: Camera Readout Fix
29
Raw readout
Naturally ordered image
CNN
CustomLogic Model Integration
void myproject_axi(hls::stream<video_if_t> &VideoIn, hls::stream<video_if_t> &VideoOut,� Metadata_t* MetaIn, Metadata_t* MetaOut, ctrl_req_pack_t &Request) {�� #pragma HLS INTERFACE ap_vld register port=Request�� // Set proper interface for CustomLogic� #pragma HLS INTERFACE ap_none port=MetaOut� #pragma HLS INTERFACE ap_vld register port=MetaIn� // Meta Data valid signal needs to be connect on VideoIn AXI-Stream valid signal� #pragma HLS INTERFACE axis depth=0 port=VideoIn� #pragma HLS INTERFACE axis port=VideoOut�� (*MetaOut) = meta_data_proc((*MetaIn));�� hls::stream<ctrl_req_pack_t> request_out("request_out");� #pragma HLS STREAM variable=request_out depth=1�� // Call neural network� myproject(VideoIn, VideoOut, request_out);�� // Read control request� ctrl_req_pack_t request_v = request_out.read();� Request = request_v;�}
VideoOut
VideoIn
MetaIn
Control Request
MetaOut
HLS top-level function
typedef ap_uint<60> ctrl_req_pack_t;
typedef struct video_struct{� DataMono12 Data;� ap_uint<4> User;�} video_if_t;
Control Request Pack
Data Stream Struct
typedef nnet::array<ap_fixed<11,1>, 2*1> layer21_t;
Prediction Result
Generating a control request
Coaxial
Pos1 request
[
]
[
]
CNN
Pos2 request
Pos3 request
Pos4 request
Pos5 request
IO Extension Module
op amp
op amp
op amp
op amp
op amp
DIN
V
Control Request
SCLK
CS
Control Request (uint_12)
31
Design verification|C/RTL testbench
Cropped Input Frame:
195 195 195 195 195 195 195 195 195 195 ...
Normalized Model Input:
0.764648 0.764648 0.764648 0.764648 0.764648 0.764648 ...
Normalized Reordered Model Input:
0.638672 0.638672 0.638672 0.638672 0.638672 0.638672 ...
Model Predictions:
-0.291992 0.140625
Control Request:
coil1 = 0.481445 | coil2 = 0.416016 | coil3 = 0.1875 | coil4 = -0.110352 | coil5 = -0.368164 |
Control Request Mapped to DAC (0-4095):
coil1 = 3034 = 101111011010 | coil2 = 2900 = 101101010100 | coil3 = 2432 = 100110000000 | coil4 = 1822 = 011100011110 | coil5 = 1294 = 010100001110 |
Request Unsigned Binaary Packed
010100001110 011100011110 100110000000 101101010100 101111011010
Received Image:
192 192 192 192 192 192 192 192 192 192 192 192 ...
METADATA:
StreamId = 0x00
SourceTag = 0x0000
Xsize = 0x000080
Xoffs = 0x000000
Ysize = 0x000020
Yoffs = 0x000000
DsizeL = 0x000020
PixelF = 0x0101
TapG = 0x0000
Flags = 0x00
Timestamp = 0x00000001
PixProcFlgs = 0x00
Status = 0x00000000
PAYLOAD:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 ...
32