Tensors and n-d Arrays: A Mathematics of Arrays (MoA) and the - - PowerPoint PPT Presentation

tensors and n d arrays a mathematics of arrays moa and
SMART_READER_LITE
LIVE PREVIEW

Tensors and n-d Arrays: A Mathematics of Arrays (MoA) and the - - PowerPoint PPT Presentation

Tensors and n-d Arrays: A Mathematics of Arrays (MoA) and the -calculus Composition of Tensor and Array Operations Lenore M. Mullin and James E. Raynolds February 20, 2009 NSF Workshop on Future Directions in 0 Tensor-Based Computation


slide-1
SLIDE 1

Tensors and n-d Arrays: A Mathematics of Arrays (MoA) and the ψ-calculus

Composition of Tensor and Array Operations

Lenore M. Mullin and James E. Raynolds

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling

slide-2
SLIDE 2

Message of This Talk

February 20, 2009 1 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling

  • An algebra of multi-dimensional arrays (MoA) and

an index calculus (the ψ-calculus) allow a series

  • f operations to be composed so as to minimize

temporaries.

  • An array, and all operations on arrays are defined

using shapes, i.e. sizes of each dimension.

  • Scalars are 0-dimensional arrays. Their shape

is the empty vector.

  • Same algebra used to specify the algorithm as

well as to map to the architecture.

  • Composition of multiple Kronecker Products will

be discussed.

slide-3
SLIDE 3

Historical Background

  • Universal Algebra - Joseph Sylvester, late 19th Century
  • Matrix Mechanics - Werner Heisenberg, 1925
  • Basis of Dirac’s bra-ket notation
  • Algebra of Arrays - APL – Ken Iverson, 1957
  • Languages: Interpreters & Compilers
  • Phil Abrams: An APL Machine(1972) with Harold Stone
  • Indexing operations on shapes, open questions, not algebraic closed
  • system. Furthered by Hassett and Lyon, Guibas and Wyatt. Used in

Fortran.

  • Alan Perlis: Explored Abram’s optimizations in compilers for APL.

Furthered by Miller, Minter, Budd.

  • Susan Gerhart: Anomalies in APL algebra, can not verify correctness.
  • Alan Perlis with Tu: Array Calculator and Lambda Calculus 1986

February 20, 2009 2 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling

slide-4
SLIDE 4
  • MoA and Psi Calculus: Mullin (1988)
  • Full closure on Algebra of Arrays and Index Calculus based on

shapes.

  • Klaus Berkling: Augmented Lambda Calculus with MoA

– Werner Kluge and Sven-Bodo Scholz: SAC

  • Built prototype compilers: output C, F77, F90, HPF
  • Modified Portland Groups HPF, HPF Research Partner
  • Introduced Theory to Functional language Community

– Bird-Meertens, SAC, … – Applied to Hardware Design and Verification

  • Pottinger (ASICS), IBM (Patent, Sparse Arrays),

Savaria (Hierarchical Bus Parallel Machines)

  • Introduce Theory to OO Community (Sabbatical MIT Lincoln

Laboratory). – Expression Templates and C++ Optimizations for Scientific Libraries

Historical Background

February 20, 2009 3 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling

slide-5
SLIDE 5

Tensors and Language Issues

  • Minimizing materialization of array valued

temporaries… where A, B, C, and D are huge 3-d (or higher dimensional) arrays

  • How to generally map to processor/memory

hierarchies

  • Verification of both semantics and operation
  • Equivalence of programs
  • No language today has an array algebra and index

calculus without problems with boundary conditions.

D = ((A + B) ⊗ C)T

February 20, 2009 4 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling

slide-6
SLIDE 6

Notation

  • Dirac:

– Inner product: – Outer product: – Tensor-vector multiply:

  • Dirac notation unified Linear Algebra and Hilbert

Space: Tensors are ubiquitous across many disciplines: Quantum and Classical

a |b

a b

a b

( ) c = a

b c

( )

February 20, 2009 5 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling

slide-7
SLIDE 7

Tensors and Multi-Particle States

“The Hilbert space describing the n-particle system is that spanned by all n-th rank tensors of the form:

|ψ > = |ψ1 > |ψ2 >K |ψn >

The zero-particle states (i.e. n = 0 ) are tensors of rank zero, that is, scalars (complex numbers).” Quote: Richard Feynman, “Statistical Mechanics” pp. 168- 170

February 20, 2009 6 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling

slide-8
SLIDE 8

Manipulation of an Array

  • Given a 3 by 5 by 4 array:
  • Shape vector:
  • Index vector:
  • Used to select:

A = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ , 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ,

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 ⎡ ⎣ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎤ ⎦ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥

ρA =< 3 5 4 >

r i =< 21 3 > r i ψA =< 21 3 >ψA = 47

February 20, 2009 7 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling

slide-9
SLIDE 9

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 8

Is defined by: Kronecker Product of A and B The Kronecker Product:

slide-10
SLIDE 10

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 9

Kronecker Product of A and B

(A ⊗ B)I,J = Ai, jBl,m

where

I ≡< i l >

J ≡< j m >

MoA would write:

< i j l m >ψ (A opx B) = (< i j >ψA) × (< l m >ψB)

slide-11
SLIDE 11

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 10

Kronecker Product flattened using row-major layout MoA Outer Product flattened using row-major layout

MoA Outer Product of A and B

slide-12
SLIDE 12

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 11

Multiple Kronecker Products

  • Large temporaries:

;

  • Complicated index calculations
  • Processor/memory optimizations difficult

TEMP = B ⊗ C

A ⊗ TEMP

Standard approach suffers from:

A ⊗ B ⊗ C

( )

slide-13
SLIDE 13

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 12

Shapes and the Outer Product

Note: The general definition takes an array of indicies as its left argument.

slide-14
SLIDE 14

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 13

slide-15
SLIDE 15

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 14

Multiple Kronecker Products

  • We want:

with:

C = A ⊗ B

E = A ⊗ B

( )⊗ A

A = B =

slide-16
SLIDE 16

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 15

Multiple Kronecker Products

  • We want:

with:

C = A ⊗ B

Shape of C is < 6 6 > because we are combining a < 2 2 > array with a < 3 3 >

Typo: +ed instead of Xed

E = A ⊗ B

( )⊗ A

C =

Note the use of the generalized binary

  • peration + rather than

* (times) in this “product”

slide-17
SLIDE 17

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 16

E = C ⊗ A ⊗A

E = E =

slide-18
SLIDE 18

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 17

Multiple Outer Products

C = A opx B C =

Typo: +ed instead of Xed

slide-19
SLIDE 19

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 18

Multiple Outer Products

Notice the shape. The shape is <2 2 3 3>. From this shape we can easily index each 3 by 3. <0 0> ψgets the first one. Notice how easily we can use these indicies to map to processors. Now perform the outer product of C with A. Now the shape is <2 2 3 3 2 2>. With the shape we can perform index compositions.

slide-20
SLIDE 20

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 19

  • This is the Denotational Normal Form (DNF) expressed

in terms of Cartesian coordinates.

slide-21
SLIDE 21

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 20

  • Convert to the Operational Normal Form (ONF) expressed

in terms of start, stop and stride, the ideal machine abstraction

  • Break up over 4 processors…need to restructure the array

shape from to

  • Thus for

2 2 3 3 2 2

4 3 3 2 2

0 ≤ p < 4

A

slide-22
SLIDE 22

February 20, 2009 NSF Workshop on Future Directions in Tensor-Based Computation and Modeling 21

Conclusions

  • We’ve discussed how an algebra can describe an

algorithm, its decomposition, and its mapping to processors.

  • We’ve discussed how to compose array operations
  • We’ve built prototype compilers and hardware
  • What is next? How can the applications drive the

research?

  • How can the research drive the funding?
  • How do we continue to have fun either way?