gbtl-cuda: graph algorithms and primitives for gpusgraphanalysis.org/ipdps2016-gabb/zhang.pdf ·...

27
GBTL-CUDA: Graph Algorithms and Primitives for GPUs Peter Zhang, Samantha Misurda, Marcin Zalewski, Scott McMillan, Andrew Lumsdaine

Upload: others

Post on 22-Jul-2020

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GBTL-CUDA: Graph Algorithms and Primitives for GPUs

Peter Zhang, Samantha Misurda, Marcin Zalewski, Scott McMillan, Andrew Lumsdaine

Page 2: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

What is this talk about?• Graph BLAS

– an emerging paradigm for graph computation– programs new graph algorithms in a highly abstract language of

linear algebra. – executes in a wide variety of programming environments

• Our implementation of Graph BLAS– Graph BLAS Template Library (GBTL) – High-level C++ frontend– Switchable backends: CUDA and sequential– Released at: https://github.com/cmu-sei/gbtl

2

Graph BLAS Forumhttp://www.graphblas.org

Software Engineering InstituteCarnegie Mellon University

CRESTIndiana University

Page 3: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

Graph algorithms meet hardware: love lost in translation?

Mitä ihmettä?!

Te quiero

3

Page 4: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

Current Graph Algorithms

CPU CUDA MPI

High Level Algorithm(BFS, MIS, MST, SSSP)

ImplementationConcerns

4

Sequential• for loops• contiguous

memory• …

Data Parallel• Parallel kernels• PCI Memory

transfer• …

Distributed• Message passing• Workload

balancing• …

Page 5: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

It’s the representation…

• Adjacency matrix representation of graphs in graph theory (Kőnig 1931)

• Matrices?!

5

6

4

3

21

57

A1

32

4567

4 5 6 7321

end

verte

x

start vertexT

Page 6: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

BLAS for Linear Algebra

X86 Architecture ARM Architecture PPC Architecture

X86-specific BLAS Optimization

ARM-specific BLAS Optimization

PPC-specific BLAS Optimization

Unified BLAS Interface

Application

6

Page 7: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

Graph BLAS

Unified Graph BLAS Interface

Application

CPU CUDA MPI

ArchitectureSpecificConcerns

SameInterfaceCrossPlatform

SameApplicationCrossPlatform

7

• OpenMP• Pthreads• Shared memory

• Asynchronous memory transfer

• Texture memory• Dynamic

Parallelism

• Memory coalescing

• Barrier control

Page 8: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

Graph BLAS

• A community effort to define a set of primitives used to describe graph algorithms using sparse linear algebra

• Rich data structures, algebraic abstraction– Sparse adjacency matrices represent graphs– Semirings to define specific behavior

8

Page 9: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

Graph BLAS: Semiring

• The standard arithmetic semiring:

• The “minPlus” semiring, for BFS with parents:

Domain D

Addition

Multiplication

Additive Identity

Multiplicative Identity

Domain D

“Addition”

“Multiplication”

Additive Identity

Multiplicative Identity

9

Page 10: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

Graph BLAS: BFS example

• Breadth-first Search (BFS): can be represented by matrix-vector multiplications in linear algebra

• Wavefront: vector• One multiplication operation results in the next

wave front

6

4

3

21

57

A1

32

4567

4 5 6 7321

star

t ver

tex

end vertexT

10

Page 11: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

Graph BLAS: BFS traversal

6

4

3

21

57

A1

32

4567

4 5 6 7321

end

verte

x

start vertexT

=

v A vT

Visited map4 5 6 7321

11

6

4

3

21

57

A1

32

4567

4 5 6 7321

end

verte

x

start vertexT

=

v A vT

Visited map4 5 6 7321

6

4

3

21

57

A1

32

4567

4 5 6 7321

end

verte

x

start vertexT

=

v A vT

Visited map4 5 6 7321

6

4

3

21

57

A1

32

4567

4 5 6 7321

end

verte

x

start vertexT

=

v A vT

Visited map4 5 6 7321

Page 12: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

Graph BLAS Template Library (GBTL)

• A C++ implementation of Graph BLAS– Allows for generic programming and metaprogramming

• A frontend-backend design– Uniform frontend for algorithm abstraction

• generic semantic checks• simplifies the templates

– Hardware-specific backend optimized for different architecture

Graph Analytic Applications

Hardware Architecture

Graph Primitives (tuned for hardware)

Graph Algorithms

GraphBLAS API (Separation of Concerns)

• A separation of concerns: render unto hardware experts hardware-specific optimizations

12

Page 13: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GBTL: Frontend and Backend

• Graph BLAS API: boundary between the algorithms and hardware-specific implementations

• Frontend forwards calls to backend namespace via C++ templates– performs generic semantic checks and implementation independent

operations– simplifies templates passed in by user for meta programming

13

Graph Analytic Applications

Hardware Architecture

Graph Primitives (tuned for hardware)

Graph Algorithms

GraphBLAS API (Separation of Concerns)

graphblas namespace

graphblas::backend namespace

Forward

Page 14: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GBTL: Algorithm Example

14

Page 15: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GBTL: Frontend Matrix• Frontend Matrix class: an opaque data

structure, uniform across backends

• User can provide hints to frontend Matrix at construction time through parameter pack, backend can make decisions based on hints

• Backend Matrix classes: specialized for hardware and implementation

Matrix <double, DenseMatrixTag, DirectedMatrixTag> matrix(...); 

Frontend Matrix Object Construction:

15

Page 16: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GBTL: Frontend Matrix Class

16

Page 17: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GBTL: Algorithm Example

17

Page 18: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GBTL: vXm, semiring overloading

18

template<typename AVectorT, typename BMatrixT, typename CVectorT, typename SemiringT = graphblas::ArithmeticSemiring<T>, typename AccumT = graphblas::math::Assign<T> > 

inline void vxm(AVectorT const &a,BMatrixT const &b, CVectorT &c, SemiringT s = SemiringT(), AccumT accum = AccumT())

{vector_multiply_dimension_check(a, b.get_shape());backend::vxm(a.m_vec, b.m_mat, c.m_vec, s, accum);

}

Domain D

Addition

Multiplication

Additive Identity

Multiplicative Identity

“Add1NotZero” Semiring:

T SelectAdd1(T first, T second) { return first == 0? 0: ++first; 

}

Page 19: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GBTL: Algorithm Example

19

wavefront =wavefront ⊗ visited

visited =wavefront ⊕ visited

Page 20: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GBTL: GPU Backend

• Implemented using CUSP: parallel algorithms and data structures for sparse linear algebra

• CUSP: built on top of the Thrust, a C++ library with GPU programming primitives

• Generalization meets performance

GBTL-CUDA Backend

Thrust Library (implements raw CUDA Kernels)

CUSP Library

GraphBLAS API (Separation of Concerns)

20

Page 21: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GPU Backend Data Type: Sparse Matrix

• We use sparse matrices to improve storage efficiency

• Sparse matrices have unstored elements called structural zeros

• Different sparse matrix formats: Compressed Sparse Row (CSR), Coordinate (COO), List Of Lists (LIL)

• Backend makes decision on format-of-choice, based on hardware layout

Blank space in matrix

21

Page 22: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

Sparse Matrix Example: COOA tale of three vectors

A1

32

4567

4 5 6 7321

star

t ver

tex

end vertexRow Indices

Column Indices

Values

1 1 2 2 3 4 4 5 6 7 7 7

2 4 5 7 6 1 3 6 3 3 4 5

1 1 1 1 1 1 1 1 1 1 1 1

22

• COO matrices: enables easy stream processing– Regularity in data layout

Page 23: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GPU Backend: mXm Scaling

0

50

100

150

200

250

300

350

400

MFLOPS

Scale

23

mXm scaling in Millions of Floating-point Operations Per Second (MFLOPS)

• Erdős–Rényi graphs• Average of 16 runs

Page 24: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GPU Backend: BFS Performance

24

• We test runtime of our BFS algorithm on several real world graphs

*MTEPS = Millions of Traversed Edges Per Second

Page 25: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

GBTL: API Overhead

25

Environment: • NVIDIA GPU• Overhead of API call compared against direct CUSP call

Methodology:• Average of 16 runs on Erdős–Rényi graphs generated using the same

dimension and sparsity

0

1

2

3

4

5

6

7

8

9

10

apply assign ewiseadd extract mxm tranpose

Overhea

d (%

)GraphBLAS Template Library Overhead

Page 26: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

Recap and Future Plans

• Graph BLAS:– Graph algorithms on sparse linear algebra primitives

• Graph BLAS Template Library (GBTL):– Extensibility meets performance– Abstraction layer: translator with low overhead penalty– Proof-of-concept: it works well!

• Future Plans– Multi-GPU backend– Distributed CPU/GPU backend– Participate in community discussion on future specifications

26

Page 27: GBTL-CUDA: Graph Algorithms and Primitives for GPUsgraphanalysis.org/IPDPS2016-GABB/Zhang.pdf · • Graph BLAS – an emerging paradigm for graph computation – programs new graph

Thank You

27

Questions?