gravitational wave data analysis using naked …all colors of physics gravitational wave data...

34
All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019 – Budapest

Upload: others

Post on 21-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

All colors of Physics

Gravitational Wave Data Analysis Using Naked OpenCL

Máté Ferenc Nagy-Egri

Wigner RCP of the HAS

GPU-Day 2019 – Budapest

Page 2: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

In this talk…

• Physical overview of gravitational waves

• Testing a hypothesis

– Motivation for OpenCL acceleration

– Challanges

– Results

• Future directions

– SYCL

– Machine learning

11/7/2019 GPU-Day, 2019 Budapest 2

Page 3: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

GRAVITATIONAL WAVES

What and how?

11/7/2019 GPU-Day, 2019 Budapest 3

Page 4: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

Mergers

11/7/2019 GPU-Day, 2019 Budapest 4

Continous

Sources of waves

Credits: ESO/L. Calçada (www.eso.org) Credits: W. Kastaun/T. Kawamura/B. Giacomazzo/R. Ciolfi/A. Endrizz(www.eso.org)

• Black holes and neutron stars

• Wide binary systems

• Non-axisymmetricobjects

Page 5: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

TESTING A HYPOTHESIS

Have we gone overboard?

11/7/2019 GPU-Day, 2019 Budapest 5

Page 6: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

Precise enough?

• Scientific computations default to double-precision floating-point (IEEE 754)

– Hardware accelerated

– Seldom have to fear rounding errors

• What do we sacrifice?

– Double the bandwidth

– Low-power architectures

• Low/mid-range dedicated/integrated GPUs

• ULV/mobile

11/7/2019 GPU-Day, 2019 Budapest 6

Page 7: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

Source: Marco Verch (https://flic.kr/p/CTUznS)

11/7/2019 GPU-Day, 2019 Budapest 7

Nail & hammer

Page 8: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

Source: Marcin Wichary (https://flic.kr/p/4MEakL)

11/7/2019 GPU-Day, 2019 Budapest 8

Nail & minigun

Page 9: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

Why OpenCL?

• OpenCL is a Khronos standard for dataparallel computations

• It’s portable

– Not 100% performance portable (see later)

– Cross-platform, cross-vendor

– Target non-existing architectures

• ~Future proof? (Intel 2020)

• Generic GPGPU optimizations result in decent multi-core CPU code

11/7/2019 GPU-Day, 2019 Budapest 9

Page 10: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 10

Algorithmic overview

Amplitude and phase modulation.Resampling (FFT)

Establish sky position

Read data, detector ephemeris & grid generating matrix

Spindown demodulation

FFT interpolation

ℱ-statistic calculation (FFT)

Signals above thethreshold registered

Spindown loop

Sky loop

Sky position

Next spindown

Next skyposition

~3000

~200

Page 11: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

Challanges

• GNU C to ISO C11

– Portable warning free compilation is a nightmare

– The secure extensions to the C runtime isn’t a success story

– POSIX extensions to the CRT are ubiquitous

– Complex numbers with MSVC still remain a dream

11/7/2019 GPU-Day, 2019 Budapest 11

Page 12: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

Challanges

• Isolating state

– Remove all global state

– Remove c-style stateful functions

– Const correctness

• Adding parallelism

– Coarse grain

• Need an efficient thread-pool implementation

– OpenMP to the rescue!

– Fine grain

• OpenCL

11/7/2019 GPU-Day, 2019 Budapest 12

Page 13: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

Challanges

• OpenCL

– Buggy runtimes

• Nvidia kernel cache bug (4 years old!)

– Disenchantingly neglected on some platforms

• AMD + Windows (3-4 years without update)

• Apple (deprecated)

– Most common libraries are on life-support

• Bug fixes only, no new features

• clBLAS and clFFT share non-standard API usage in their kernel cache mechanism

11/7/2019 GPU-Day, 2019 Budapest 13

Page 14: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 14

• When numQueuesAndEvents != 0– CLFFT_NOTIMPLEMENTED

• Documentation reads:

Challanges

CLFFTAPI clfftStatusclfftEnqueueTransform(

clfftPlanHandle plHandle,clfftDirection dir,cl_uint numQueuesAndEvents,cl_command_queue* commQueues,cl_uint numWaitEvents,const cl_event* waitEvents,cl_event* outEvents,cl_mem* inputBuffers,cl_mem* outputBuffers,cl_mem tmpBuffer)

„Currently, you must manage the multi-device operation. You can create OpenCL contexts that are associated with multiple devices, but clFFT only uses

a single device from that context to transform the data. You can manage a multi-device operation by creating multiple contexts, in which each context

contains a different device; you are responsible for scheduling and partitioning the work across multiple

devices and contexts.”

• What happens if you use only 1 device from a multi-devicecontext?– AMD: It works as expected

– Others: Stack corruption

Page 15: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 15

• Type generic code?

– #ifdef around actual types

– Buffers erase stored type

Challanges

Page 16: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 16

• Type generic code?

– #ifdef around actual types

– Buffers erase stored type

• Host code involvingcomplex becomes nasty

– This means OpenCL devicecode too

Challanges

void spline(const fft_complex* y,

int n,

spline_complex* y2,

spline_complex* u) {

#ifndef _WIN32

// Linux code

#else

#if SPLINE_DOUBLE

#if FFT_DOUBLE

#else

#endif

#else

#if FFT_DOUBLE

#else

#endif

#endif

}

Page 17: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 17

• Type generic code?

– #ifdef around actual types

– Buffers erase stored type

• Host code involvingcomplex becomes nasty

– This means OpenCL devicecode too

• Complex numbers?

– OpenCL C still onlyreserves the complexkeyword, but does notdefine it• OpenCL C 2.2 spec, p.11

Challanges

„6.1.4. Reserved Data Types

The data type names described in the following table are reserved and cannot be used byapplications as type names. The vector data type names defined in Built-in Vector Data Types, butwhere n is any value other than 2, 3, 4, 8 and 16, are also reserved.

boolnhalfnquad, quadncomplex half, complex halfnimaginary half, imaginary halfncomplex float, complex floatn…floatnxm…”

Page 18: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 18

• Being „chatty” over PCI-E is not good

• Issue as manycommands up front as possible

• Allow the runtime toschedule as it sees fit

Pipelining

typedef struct _pipeline

{

cl_event *modvir_events,

*tshift_pmod_events;

cl_event **fft_interpolate_fw_fft_events,

**fft_interpolate_resample_copy_events,

**fft_interpolate_resample_fill_events,

**fft_interpolate_inv_fft_events,

**spline_map_events,

**spline_unmap_events,

**spline_blas_events,

**blas_dot_events;

cl_event *mxx_fill_events,

*axpy_events,

*phase_mod_events,

*zero_pad_events,

*fw2_fft_events;

cl_event compute_Fstat_event,

normalize_Fstat_event,

peak_map_event,

peak_unmap_event;

} Pipeline;

Page 19: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 19

Results

Page 20: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

Preliminary results on the effect of floating-point precision on the search pipeline

11/7/2019 GPU-Day, 2019 Budapest 20

Results

0,000

0,002

0,004

0,006

0,008

0,010

6,0 6,5 7,0 7,5 8,0 8,5 9,0 9,5 10,0 10,5 11,0

Rel

ativ

e d

evia

tio

n f

rom

ref

eren

ce [

1]

Signal to noise ratio [1]

Measure of precision

calc float calc double all double

Page 21: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 21

• Code runs mostly asexpected

– AMD runtime onWindows is terriblyslow

• No linux run

– A great deal of perf is lost on datamovement

• Using both the CPU & GPU is a win

Results

0

1000

2000

3000

4000

5000

6000

7000

8000

9000

10000

ISO C11 CPU device GPU device CPU + GPU

Exec

uti

on

tim

e [s

]

ASUS ROG STRIX GL702ZC laptopRX 580 + Ryzen 7 1700

all double calc double calc float

Page 22: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 22

• On a beefier linuxnode

– 2X Radeon Vega56

– Higher quality runtime

• Using the GPU deviceis a clear win

• Using both CPU & GPU is a net loss

– The idle time of theGPUs are notcompensated

Results

0

1000

2000

3000

4000

5000

6000

7000

ISO C11 CPU device GPU device CPU + GPU

Exec

uti

on

tim

e[s

]

ASUS P9X79 WS workstation2*RX Vega56 + Core-i7

all double calc double calc float

Page 23: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 23

Results

0

2000

4000

6000

8000

10000

12000

ISO C11 CPU device GPU device CPU + GPU

Exec

uti

on

tim

e[s

]

ASUS P9X79 WS workstation2*RX Vega56 + Core-i7

all double calc double calc float

0

2000

4000

6000

8000

10000

12000

ISO C11 CPU device GPU device CPU + GPU

Exec

uti

on

tim

e [s

]

ASUS ESC4000FDR/G2 server4*GTX 1080Ti + 2*Intel Xeon

all double calc double calc float

Page 24: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 24

• Running serial CPU code on a MIC is a terrible idea

– As expected

• OpenCL codeperforms slower thananticipated

– Requires a deep diveto find out why

Results

0

5000

10000

15000

20000

25000

30000

35000

40000

45000

ISO C11 CPU device

Exec

uti

on

tim

e [s

]

Intel Xeon Phi Server Compute Module

all double calc double calc float

Page 25: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

FUTURE DIRECTIONS

„Et maintenant, on va ou?”

11/7/2019 GPU-Day, 2019 Budapest 25

Page 26: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 26

OpenCL to SYCL

Page 27: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

What else do we gain?

• Say no to macros, say hello to templates

• Two high-quality libraries ML libraries

– SYCL-ML, SYCL-DNN

• Not limited to built-in FFT types

– half? double_float?

• Portable complex numbers

– std::complex FTW

• More robust, readable, maintainable code

11/7/2019 GPU-Day, 2019 Budapest 27

Page 28: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 28

What else do we gain?

typedef struct _pipeline

{

cl_event *modvir_events,

*tshift_pmod_events;

cl_event **fft_interpolate_fw_fft_events,

**fft_interpolate_resample_copy_events,

**fft_interpolate_resample_fill_events,

**fft_interpolate_inv_fft_events,

**spline_map_events,

**spline_unmap_events,

**spline_blas_events,

**blas_dot_events;

cl_event *mxx_fill_events,

*axpy_events,

*phase_mod_events,

*zero_pad_events,

*fw2_fft_events;

cl_event compute_Fstat_event,

normalize_Fstat_event,

peak_map_event,

peak_unmap_event;

} Pipeline;

Page 29: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 29

What else do we gain?

typedef struct _pipeline

{

cl_event *modvir_events,

*tshift_pmod_events;

cl_event **fft_interpolate_fw_fft_events,

**fft_interpolate_resample_copy_events,

**fft_interpolate_resample_fill_events,

**fft_interpolate_inv_fft_events,

**spline_map_events,

**spline_unmap_events,

**spline_blas_events,

**blas_dot_events;

cl_event *mxx_fill_events,

*axpy_events,

*phase_mod_events,

*zero_pad_events,

*fw2_fft_events;

cl_event compute_Fstat_event,

normalize_Fstat_event,

peak_map_event,

peak_unmap_event;

} Pipeline;

Page 30: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

11/7/2019 GPU-Day, 2019 Budapest 30

What else do we gain?

typedef struct _pipeline

{

cl_event *modvir_events,

*tshift_pmod_events;

cl_event **fft_interpolate_fw_fft_events,

**fft_interpolate_resample_copy_events,

**fft_interpolate_resample_fill_events,

**fft_interpolate_inv_fft_events,

**spline_map_events,

**spline_unmap_events,

**spline_blas_events,

**blas_dot_events;

cl_event *mxx_fill_events,

*axpy_events,

*phase_mod_events,

*zero_pad_events,

*fw2_fft_events;

cl_event compute_Fstat_event,

normalize_Fstat_event,

peak_map_event,

peak_unmap_event;

} Pipeline;

Page 31: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

Machine Learning

• The search pipeline outputs too manycandidates to investigate individually.

• Filter output by a classifier

– Teach on synthetic data (?)

– Data can be generated ON the GPU

– Feed immediately to a training algorithm

11/7/2019 GPU-Day, 2019 Budapest 31

Page 32: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

AMMENDMENT

To those whom it may concern

11/7/2019 GPU-Day, 2019 Budapest 32

Page 33: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

SYCL-PRNG

• Open-source

• Initially supports two PRNGs

– MWC64X (MultiplyWithCarry), Tiny-Mersenne Twister

• STL compatible

– Satisfies the UniformRandomBitGenerator concept

• SYCL compatible

– Satisfies StandardLayoutType concept

• It is in alpha-beta stage

– Should you wish to help push it through the finishline, don’t hesitate to submit a PR

11/7/2019 GPU-Day, 2019 Budapest 33

Page 34: Gravitational Wave Data Analysis Using Naked …All colors of Physics Gravitational Wave Data Analysis Using Naked OpenCL Máté Ferenc Nagy-Egri Wigner RCP of the HAS GPU-Day 2019

THANK YOU FOR YOUR ATTENTION

11/7/2019 GPU-Day, 2019 Budapest 34