Array Fire GPU Programming in C++
Array Fire GPU Programming in C++
A tutorial
by Chris McClanahan, GPU Engineer
Overview
Introduction to ArrayFire
Introduction to ArrayFire Graphics
Optical Flow
Optical Flow GFX Example / Demo
ArrayFire Introduction
Matrix Types
f64
f32 array b8
c32
c64
real double precision
boolean byte
container type
vectors
f32
matrices
b8
boolean byte
volumes
c32
c64
ND
A(1,1)
A(1,span)
A(span,span,2)
b8
f32
boolean byte
A(end,1)
A(end,span)
c32
c64
DEMO
GFX (C++)
Lua
Compute Thread
Render Thread
GFX (C++)
Lua
Lua
Port of OpenGL API to Lua
(independent AccelerEyes effort)
All graphics primitives / drawing logic
Wake and
Consumption
Of Draw Requests
At 35Hz
Render Thread
GFX (C++)
Lua
Wake and
Consumption
Of Draw Requests
At 35Hz
Render Thread
Graphics Commands
Available primitives (non-blocking)
DEMO
Graphics Commands
Utility Commands (blocking unless otherwise
stated)
keep_on / keep_off
subfigure
palette
clearfig
draw (blocking)
figure
title
close
DEMO
Horn-Schunck Background
Compute apparent motion between two
images
Minimize the following functional,
By solving,
Horn-Schunck Background
Can be accomplished with ArrayFire
Relatively small amount of code
Iterative Implementation on GPU via gradient
descent
Easily couple compute with visualization via basic
graphics commands
ArrayFire Implementation
Main algorithm loop:
array u = zeros(I1.dims()), v = zeros(I1.dims());
while (true) {
iter++;
array u_ = convolve(u, avg_kernel, afConvSame);
array v_ = convolve(v, avg_kernel, afConvSame);
ArrayFire Implementation
Main algorithm loop:
Initial flow field we are
for (on GPU)
ArrayFire Implementation
Main algorithm loop:
array u = zeros(I1.dims()), v = zeros(I1.dims());
while (true) {
iter++;
array u_ = convolve(u, avg_kernel, afConvSame);
array v_ = convolve(v, avg_kernel, afConvSame);
ArrayFire Implementation
Main algorithm loop:
array u = zeros(I1.dims()), v = zeros(I1.dims());
while (true) {
iter++;
array u_ = convolve(u, avg_kernel, afConvSame);
array v_ = convolve(v, avg_kernel, afConvSame);
ArrayFire Implementation
Main algorithm loop:
array u = zeros(I1.dims()), v = zeros(I1.dims());
while (true) {
iter++;
array u_ = convolve(u, avg_kernel, afConvSame);
array v_ = convolve(v, avg_kernel, afConvSame);
Graphics Integration
array u = zeros(I1.dims()), v = zeros(I1.dims());
while (true) {
iter++;
array u_ = convolve(u, avg_kernel, afConvSame);
array v_ = convolve(v, avg_kernel, afConvSame);
const float alphasq = 0.1f;
array num = mul(Ix, u_) + mul(Iy, v_) + It;
array den = alphasq + mul(Ix, Ix) + mul(Iy, Iy);
imgplot(I1);
imgplot(I2);
imgplot(u);
imgplot(v);
DEMO
Thank You