MIPP: a Portable C++ SIMD Wrapper and its use for

0 downloads 0 Views 2MB Size Report
Instruction set selection based on preprocessor definitions .... Same code can work on various data types and instruction sets ... In the AVX-512 instruction set:.
MIPP: a Portable C++ SIMD Wrapper and its use for Error Correction Coding in 5G Standard Adrien Cassagne1,2 Olivier Aumage1 Denis Barthou1 Camille Leroux2 Christophe Jégo2 1 Inria,

Bordeaux Institute of Technology, U. of Bordeaux, LaBRI/CNRS, Bordeaux, France 2 IMS/CNRS,

Bordeaux, France

WPMVP, February 2018

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 1 / 19

Context: Error Correction Codes (ECC) Algorithms that enable reliable delivery of digital data Redundancy for error correction

Usually, hardware implementation Growing interest for software implementation End-user utilization (low power consumption processors) Algorithm validation (Monte-Carlo simulations) Requires performance

Source

Encoder

Transmitter

Channel

Decoder

Comm. Chan.

Sink

Receiver

The communication chain

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 2 / 19

Context: 5G Standard Many devices connected to Internet via wireless interfaces Large zoo of devices: Flexibility Varied, complex ECC algorithms: Expensive testing and validation

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 3 / 19

Context: 5G Standard Many devices connected to Internet via wireless interfaces Large zoo of devices: Flexibility Varied, complex ECC algorithms: Expensive testing and validation ⇒ Portable SIMD library

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 3 / 19

Proposal: MyIntrinsics++ (MIPP) SIMD C++ wrapper Maximizes code portability Improves expressiveness over intrinsics No dependencies to other libraries

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 4 / 19

Proposal: MyIntrinsics++ (MIPP) SIMD C++ wrapper Maximizes code portability Improves expressiveness over intrinsics No dependencies to other libraries

Programming model close to intrinsics Whenever possible, one statement = one intrinsic One variable = one register allocation

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 4 / 19

Proposal: MyIntrinsics++ (MIPP) SIMD C++ wrapper Maximizes code portability Improves expressiveness over intrinsics No dependencies to other libraries

Programming model close to intrinsics Whenever possible, one statement = one intrinsic One variable = one register allocation

MIPP MIPP!

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 4 / 19

MIPP: Programming Interfaces

The Low-Level MIPP Interface (low) Similar to SIMD intrinsics: Untyped registers, typed operations Portability through template specialization and function inlining

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 5 / 19

MIPP: Programming Interfaces

The Low-Level MIPP Interface (low) Similar to SIMD intrinsics: Untyped registers, typed operations Portability through template specialization and function inlining

The Medium-Level MIPP Interface (med.) Typed registers, polymorphic operations Based on MIPP Low Level Interface Typing through object encapsulation and operator overloading

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 5 / 19

MIPP: Low Level Interface (low) Similar to SIMD intrinsics: Untyped registers, typed operations Abstract SIMD data register (mipp::reg) The number of elements in a register: mipp::N()

Abstract SIMD mask register (mipp::msk) Intrinsic functions wrapped into MIPP functions 1 2 3 4 5 6 7 8

template < > mipp :: reg { return ( mipp :: reg ) } template < > mipp :: reg { return ( mipp :: reg ) }

mipp :: add < float >( mipp :: reg a , mipp :: reg b ) _mm256_add_ps(( __mm256 ) a , ( __mm256 ) b ) ; mipp :: add < double >( mipp :: reg a , mipp :: reg b ) _mm256_add_pd(( __mm256d ) a , ( __mm256d ) b ) ;

C++ template specialization technique

Instruction set selection based on preprocessor definitions A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 6 / 19

MIPP: Low Level Interface (low) Similar to SIMD intrinsics: Untyped registers, typed operations Abstract SIMD data register (mipp::reg) The number of elements in a register: mipp::N()

Abstract SIMD mask register (mipp::msk) Intrinsic functions wrapped into MIPP functions 1 2 3 4 5 6 7 8

template < > mipp :: reg { return ( mipp :: reg ) } template < > mipp :: reg { return ( mipp :: reg ) }

mipp :: add < float >( mipp :: reg a , mipp :: reg b ) _mm256_add_ps(( __mm256 ) a , ( __mm256 ) b ) ; mipp :: add < double >( mipp :: reg a , mipp :: reg b ) _mm256_add_pd(( __mm256d ) a , ( __mm256d ) b ) ;

C++ template specialization technique

Instruction set selection based on preprocessor definitions A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 6 / 19

MIPP: Medium Level Interface (med.) Typed registers, polymorphic operations Typed, portable SIMD data register (mipp::Reg) Contains a MIPP low data register (mipp::reg)

Typed, portable SIMD mask register (mipp::Msk) Contains a MIPP low mask register (mipp::msk)

Supports operator overloading mipp::Reg a = 1.f, b = 2.f; auto c = a + b;

Eases the register initializations (broadcasts, sets and loads) mipp::Reg a = 1, b = {1, 2, 3, 4}, c = ptr;

Defines an aligned memory allocator for the std::vector class (mipp::vector)

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 7 / 19

MIPP: Hello World! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

template < typename T > void vecAdd ( const std :: vector &A , const std :: vector &B , std :: vector & C ) { // N elements per SIMD register constexpr int N = mipp :: N () ; // sizes verifications assert ( A . size () == B . size () ) ; assert ( A . size () == C . size () ) ; assert (( A . size () % N ) == 0) ; for ( auto i = 0; i < A . size () ; i += N ) { mipp :: Reg rA = & A [ i ]; // SIMD load mipp :: Reg rB = & B [ i ]; // SIMD load mipp :: Reg rC = rA + rB ; // SIMD addition rC . store (& C [ i ]) ; // SIMD store } }

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 8 / 19

MIPP: Hello World! 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23

template < typename T > void vecAdd ( const std :: vector &A , const std :: vector &B , std :: vector & C ) { // N elements per SIMD register constexpr int N = mipp :: N () ; // sizes verifications assert ( A . size () == B . size () ) ; assert ( A . size () == C . size () ) ; assert (( A . size () % N ) == 0) ; for ( auto i = 0; i < A . size () ; i += N ) { mipp :: Reg rA = & A [ i ]; // SIMD load mipp :: Reg rB = & B [ i ]; // SIMD load mipp :: Reg rC = rA + rB ; // SIMD addition rC . store (& C [ i ]) ; // SIMD store } }

MIPP operates at register level Same code can work on various data types and instruction sets A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 8 / 19

MIPP: Masking Support In the AVX-512 instruction set: Height dedicated hardware mask registers (k0, k1, ..., k7) Some operations can be masked

Picture from colfaxresearch.com

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 9 / 19

MIPP: Masking Support In the AVX-512 instruction set: Height dedicated hardware mask registers (k0, k1, ..., k7) Some operations can be masked

Picture from colfaxresearch.com

MIPP takes advantage of the masked operations with a dedicated function: mipp::mask(m, src, r1, r2) A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 9 / 19

MIPP: Masking Support (example)

1 2 3 4 5 6 7 8

mipp :: Reg < float > ZMM1 = { 40 , -30, 60 , 80}; mipp :: Reg < float > ZMM2 = 0.1; // broadcast mipp :: Msk < mipp :: N < float >() > k1 = { false , true, false , false }; // ZMM3 = k1 ? ZMM1 * ZMM2 : ZMM1 ; auto ZMM3 = mipp :: mask < float , mipp :: mul >( k1 , ZMM1 , ZMM1 , ZMM2 ) ; std :: cout ZMM2 = 0.1; // broadcast mipp :: Msk < mipp :: N < float >() > k1 = { false , true, false , false }; // ZMM3 = k1 ? ZMM1 * ZMM2 : ZMM1 ; auto ZMM3 = mipp :: mask < float , mipp :: mul >( k1 , ZMM1 , ZMM1 , ZMM2 ) ; std :: cout mipp : : Msk h_SIMD ( c o n s t mipp : : Msk& sa , c o n s t mipp : : Msk& sb )

{ }

Sink

Same code for various data types (double, float, int16_t, int8_t) Decodes frame per frame (SIMD intra-frame strategy)

SIMD size Seq. T/P (Mb/s) MIPP T/P (Mb/s) Speedup

NEON 16 48.0 148.7 ×3.1

SSE 16 120.1 528.3 ×4.4

AVX 32 127.1 483.0 ×3.8

r e t u r n sa ^ sb ;

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 15 / 19

Related works: SIMD Wrappers Two main strategies: 1

operator overloading (used in MIPP)

2

expression templates, can automatically match instructions like Fused Multiply–Add (FMA, d = a × b + c)

General Information

Library

Name MIPP VCL simdpp T-SIMD Vc xsimd Boost.SIMD bSIMD

Instruction Set SSE 128-bit 3 3 3 3 3 3 3 3

AVX 256-bit 3 3 3 3 3 3 7 3

AVX-512 512-bit 3 3 3 7 7 7 7 3

Data Type NEON 128-bit 3 7 3 3 7 7 7 3

Float 64 32 3 3 3 3 3 3 7 3 3 3 3 3 3 3 3 3

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

64 3 3 3 7 3 3 3 3

Integer 32 16 3 3 3 3 3 3 3 3 3 3 3 7 3 3 3 3

Features 8 3 3 3 3 7 7 3 3

Math Func. 3 3 7 7 3 3 3 3

C++ Technique Op. overload. Op. overload. Expr. templ. Op. overload. Op. overload. Op. overload. Expr. templ. Expr. templ.

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 16 / 19

Related works: Comparison on the Mandelbrot Set Computational intensive kernel Need to manage an early termination C++ code is freely available1

1

Full code is available online: https://gitlab.inria.fr/acassagn/mandelbrot

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 17 / 19

Related works: Comparison on the Mandelbrot Set Computational intensive kernel Need to manage an early termination C++ code is freely available1 Float 32-bit 14

NEON SSE AVX AVX-512

Speedup

12 10 8 6 4 2 0

D IM t.S os Bo

d im xs

Vc

D M SI T-

p dp sim

L VC . ed m P IP M w lo P IP M ics ns tri In

1

Full code is available online: https://gitlab.inria.fr/acassagn/mandelbrot

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 17 / 19

Conclusion and Future Works Conclusion: 1

SIMD wrapper dedicated to digital communication algorithms

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 18 / 19

Conclusion and Future Works Conclusion: 1

SIMD wrapper dedicated to digital communication algorithms

2

Matches both simulation and embedded software constraints

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 18 / 19

Conclusion and Future Works Conclusion: 1

SIMD wrapper dedicated to digital communication algorithms

2

Matches both simulation and embedded software constraints

3

Outperforms most ECC software solutions on CPUs

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 18 / 19

Conclusion and Future Works Conclusion: 1

SIMD wrapper dedicated to digital communication algorithms

2

Matches both simulation and embedded software constraints

3

Outperforms most ECC software solutions on CPUs

4

Used by hardware designers in academic and industrial research2

2

AFF3CT Open-source toolbox: http://aff3ct.github.io

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 18 / 19

Conclusion and Future Works Conclusion: 1

SIMD wrapper dedicated to digital communication algorithms

2

Matches both simulation and embedded software constraints

3

Outperforms most ECC software solutions on CPUs

4

Used by hardware designers in academic and industrial research2

Future works: Wraps the new ARM Scalable Vector Extension (SVE) Predicate registers would likely map on MIPP masks Main challenge will be to deal with agnostic vector sizes

2

AFF3CT Open-source toolbox: http://aff3ct.github.io

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 18 / 19

Thank you! MIPP code: https://github.com/aff3ct/MIPP AFF3CT toolbox: https://github.com/aff3ct/aff3ct

A. Cassagne, O. Aumage, D. Barthou, C. Leroux, C. Jégo MIPP: a Portable C++ SIMD Wrapper and its use for ECC in 5G Standard

Inria, IMS, U. of Bordeaux, LaBRI/CNRS 19 / 19

Suggest Documents