deploying deep learning networks to embedded gpus and …...deep neural networks deep learning,...
TRANSCRIPT
![Page 1: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/1.jpg)
1© 2015 The MathWorks, Inc.
Deploying Deep Learning Networks
to Embedded GPUs and CPUs
Daniel Aronsson
![Page 2: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/2.jpg)
2
Agenda
▪ What is CUDA code?
▪ What is GPU Coder?
▪ Why use GPU Coder?
▪ How to use GPU Coder?
▪ How fast is GPU Coder?
▪ Key takeaways
![Page 3: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/3.jpg)
3
Algorithm Design to Embedded Deployment Workflow
MATLAB algorithm
(functional reference)
C++
Embedded GPU
?
![Page 4: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/4.jpg)
4
GPUs and CUDA
CUDA
kernelsC/C++
ARM
Cortex
GPU
CUDA Cores
C/C++
CUDA Kernel
C/C++
CUDA Kernel
GPU Memory
Space
CPU Memory
Space
![Page 5: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/5.jpg)
5
What is CUDA code?
GPU
GPU
CUDA
Cores
ARM
Cortex
CUDA KernelC/C++
C/C++
CUDA Kernel
CUDA extends C/C++ code with constructs for parallel computing
![Page 6: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/6.jpg)
6
What does CUDA code look like?
void foo(const real_T A[100000000], const real_T B[100000000],
real_T C[100000000])
{
real_T *gpu_B;
real_T *gpu_A;
real_T *gpu_C;
cudaMalloc(&gpu_C, 800000000ULL);
cudaMalloc(&gpu_A, 800000000ULL);
cudaMalloc(&gpu_B, 800000000ULL);
cudaMemcpy((void *)gpu_B, (void *)&B[0], 800000000ULL,
cudaMemcpyHostToDevice);
cudaMemcpy((void *)gpu_A, (void *)&A[0], 800000000ULL,
cudaMemcpyHostToDevice);
foo_kernel1<<<dim3(313U, 313U, 1U), dim3(32U, 32U,
1U)>>>(gpu_B, gpu_A, gpu_C);
cudaMemcpy((void *)&C[0], (void *)gpu_C, 800000000ULL,
cudaMemcpyDeviceToHost);
cudaFree(gpu_B);
cudaFree(gpu_A);
cudaFree(gpu_C);
}
static __global__ __launch_bounds__(1024, 1)
void foo_kernel1(const real_T *B,
const real_T *A, real_T *C)
{
uint32_T threadId;
int32_T i0;
threadId = (uint32_T)mwGetGlobalThreadIndex();
i0 = (int32_T)threadId;
if (!(i0 >= 100000000)) {
C[i0] = A[i0] * B[i0];
}
}
function C = foo(A,B)
C = A*B;
![Page 7: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/7.jpg)
7
Challenges for the CUDA programmer
▪ Learning to program in CUDA
– Need to rewrite algorithms for parallel processing paradigm
▪ Creating CUDA kernels
– Need to analyze algorithms to create CUDA kernels that maximize parallel processing
▪ Allocating memory
– Need to deal with memory allocation on both CPU and GPU memory spaces
▪ Minimizing data transfers
– Need to minimize while ensuring required data transfers are done at the appropriate
parts of your algorithm
![Page 8: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/8.jpg)
8
What is GPU Coder?
▪ Generates CUDA code for NVIDIA GPUs
▪ Also generates code for Deep Neural Networks for Intel CPUs and ARM
Cortex-A platforms.
![Page 9: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/9.jpg)
9
GPU Coder Helps You Deploy to GPUs Faster
GPU Coder
CUDA Kernel creation
Memory allocation
Data transfer minimization
• Library function mapping
• Loop optimizations
• Dependence analysis
• Data locality analysis
• GPU memory allocation
• Data-dependence analysis
• Dynamic memcpy reduction
![Page 10: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/10.jpg)
10
Scalarized MATLAB
GPU Coder Generates CUDA from MATLAB: saxpy
CUDA kernel for GPU parallelization
CUDA
Vectorized MATLAB
Loops and matrix operations are
directly compiled into kernels
![Page 11: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/11.jpg)
11
Generated CUDA Optimized for Memory Performance
Mandelbrot space
CUDA kernel for GPU parallelization
… …
… …
CUDA
Kernel data allocation is
automatically optimized
![Page 12: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/12.jpg)
12
Algorithm Design to Embedded Deployment Workflow
MATLAB algorithm
(functional reference)
Functional test1 Deployment
unit-test
2
Desktop
GPU
C++
Deployment
integration-test
3
Desktop
GPU
C++
Real-time test4
Embedded GPU
.mex .lib Cross-compiled
.lib
Build type
Call CUDA
from MATLAB
directly
Call CUDA from
(C++) hand-
coded main()
Call CUDA from (C++)
hand-coded main().
![Page 13: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/13.jpg)
13
Demo: Alexnet Deployment with ‘mex’ Code Generation
![Page 14: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/14.jpg)
14
Algorithm Design to Embedded Deployment on Tegra GPU
MATLAB algorithm
(functional reference)
Functional test1
(Test in MATLAB on host)
Deployment
unit-test
2
(Test generated code in
MATLAB on host + GPU)
Tesla
GPU
C++
Deployment
integration-test
3
(Test generated code within
C/C++ app on host + GPU)
Tesla
GPU
C++
Real-time test4
(Test generated code within
C/C++ app on Tegra target)
Tegra GPU
.mex .lib Cross-compiled
.lib
Build type
Call CUDA
from MATLAB
directly
Call CUDA from
(C++) hand-
coded main()
Call CUDA from (C++)
hand-coded main().
Cross-compiled on host
with Linaro toolchain
![Page 15: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/15.jpg)
15
Alexnet Deployment to Tegra: Cross-Compiled with ‘lib’
Two small changes
1. Change build-type to ‘lib’
2. Select cross-compile toolchain
![Page 16: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/16.jpg)
16
End-to-End Application: Lane Detection
Transfer Learning
Alexnet
Lane detection
CNN
Post-processing
(find left/right lane
points)Image
Image with
marked lanes
Left lane coefficients
Right lane coefficients
Output of CNN is lane parabola coefficients according to: y = ax^2 + bx + c
GPU coder generates code for whole application
![Page 17: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/17.jpg)
17
GPU Coder for Deployment
Deep Neural Networks
Deep Learning, machine learning
Image Processing and
Computer Vision
Image filtering, feature detection/extraction
Signal Processing and
Communications FFT, filtering, cross correlation,
5x faster than TensorFlow
2x faster than MXNet
60x faster than CPUs
for stereo disparity
20x faster than
CPUs for FFTs
GPU CoderAccelerated implementation of
parallel algorithms on GPUs & CPUs
ARM Compute
Library
Intel
MKL-DNN
Library
![Page 18: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/18.jpg)
18
Deep Learning Network Support (with Neural Network Toolbox)
SeriesNetwork DAGNetwork
GPU Coder: R2017b
Networks: MNist
Alexnet
YOLO
VGG
Lane detection
Pedestrian detection
GPU Coder: R2018a
Networks: GoogLeNet
ResNet
SegNet
DeconvNetSemantic
segmentation
Object
detection
![Page 19: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/19.jpg)
19
Semantic Segmentation
Running in MATLAB Generated Code from GPU Coder
![Page 20: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/20.jpg)
20
Deploying to CPUs
GPU
Coder
Deep Learning
Networks
NVIDIA
TensorRT &
cuDNN
Libraries
ARM
Compute
Library
Intel
MKL-DNN
Library
![Page 21: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/21.jpg)
21
Desktop CPU
Raspberry Pi board
Deploying to CPUs
GPU
Coder
Deep Learning
Networks
NVIDIA
TensorRT &
cuDNN
Libraries
![Page 22: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/22.jpg)
22
How Good is Generated Code Performance
▪ Performance of image processing and computer vision
▪ Performance of CNN inference (Alexnet) on Titan XP GPU
▪ Performance of CNN inference (Alexnet) on Jetson (Tegra) TX2
![Page 23: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/23.jpg)
23
GPU Coder for Image Processing and Computer Vision
8x speedup
Distance
transform
5x speedup
Fog removal
700x speedup
SURF feature
extraction
18x speedup
Ray tracing
3x speedup
Frangi filter
![Page 24: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/24.jpg)
24
Alexnet Inference on NVIDIA Titan Xp
GPU Coder +
TensorRT (3.0.1)
GPU Coder +
cuDNN
Fra
mes p
er
second
Batch Size
CPU Intel(R) Xeon(R) CPU E5-1650 v4 @ 3.60GHz
GPU Pascal Titan Xp
cuDNN v7
Testing platform
MXNet (1.1.0)
GPU Coder +
TensorRT (3.0.1, int8)
TensorFlow (1.6.0)
![Page 25: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/25.jpg)
25
VGG-16 Inference on NVIDIA Titan Xp
GPU Coder +
TensorRT (3.0.1)
GPU Coder +
cuDNN
Fra
mes p
er
second
Batch Size
CPU Intel(R) Xeon(R) CPU E5-1650 v4 @ 3.60GHz
GPU Pascal Titan Xp
cuDNN v7
Testing platform
MXNet (1.1.0)
GPU Coder +
TensorRT (3.0.1, int8)
TensorFlow (1.6.0)
![Page 26: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/26.jpg)
26
Alexnet Inference on Jetson TX2: Frame-Rate Performance
MATLAB GPU Coder (R2017b)
Batch Size
C++ Caffe (1.0.0-rc5)
TensorRT (2.1)
2x
1.15x
Fra
mes p
er
second
![Page 27: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/27.jpg)
27
Alexnet Inference on Jetson TX2: Memory Performance
MATLAB GPU Coder (R2017b)
C++ Caffe (1.0.0-rc5)
TensorRT 2.1
(using giexec wrapper)
Peak M
em
ory
(M
B)
Batch Size
![Page 28: Deploying Deep Learning Networks to Embedded GPUs and …...Deep Neural Networks Deep Learning, machine learning Image Processing and Computer Vision Image filtering, feature detection/extraction](https://reader036.vdocument.in/reader036/viewer/2022062602/5f01d11c7e708231d4012e48/html5/thumbnails/28.jpg)
28
Key Takeaways
▪ GPU Coder automates the process of writing CUDA code for general
algorithms – not only Deep Learning
▪ GPU Coder generates code for DNN for multiple platforms
▪ GPU Coder performs in most times better than other common Deep
Learning platforms