Carnegie Mellon Performance An Algorithmic Specific Code Generator for GEMM-Like Operations Applications Richard Michael Veras Platforms
Carnegie Mellon Want Automatic High Performance Model Driven GEMM-Like approach for Operations generating DGEMM: High Perf. Compiler Techniques: Richard Veras (rveras@cmu.edu) 2
Carnegie Mellon GEMM Like Operations Clustering : ~π©π© πΌ π© Centrality : ~π© πΌ π© (triangle) [betweeness] (π, β, +, π, π) (π, +, π΅π±πΆ, π, π) Community Detection : ~π© π³ Check out GraphBLAS Richard Veras (rveras@cmu.edu) 3
Carnegie Mellon High Performance Micro-Kernels Cast micro kernel as outer product: Use Models to Select from Design Space: Aggressively Schedule Enumerate all possible tilings and Optimize: given ISA Veras, R. , Smith T., Low T.M., Franchetti, F. van de Geijn, R. [CGO 2017 Submitted] Richard Veras (rveras@cmu.edu) 4
Carnegie Mellon High Performance Micro-Kernels OpenBLAS Our Generated ATLAS Veras, R. , Smith T., Low T.M., Franchetti, F. van de Geijn, R. [CGO 2017 Submitted] Richard Veras (rveras@cmu.edu) 5
Carnegie Mellon Automating with Compiler Techniques Subtle Semiring Changes Cast as ILP Problem Impact Performance: [extremetech.com] Minimizing Stalls [cs.duke.edu] [massey.ac.nz] Richard Veras (rveras@cmu.edu) 6
Carnegie Mellon A Generator for GEMM-Like Kernels Input: Ouput: Kernel Algorithm from Betweeness Centrality our design space: (Floyd-Warshall) Kernel Sustains High Throughput: GEMM Like: π« π©πͺ + π« π« ππ π π Initialize π« ππ π π ππ πΌ Compute Tuned to the Target π(π« ππ π ) Accumulate π« Architecture Semiring (π, +, π΅π±πΆ, π, π) Richard Veras (rveras@cmu.edu) 7
Carnegie Mellon Our GEMM Generator Pipeline Find Efficient Instructions Mix (Algo) Turn Mix into Efficient Code (Implementation) Template Template Enumerate User defines Top Candidate transformed into Created for algorithm space block size, ISA selected optimized and Candidate and semiring scheduled code Richard Veras (rveras@cmu.edu) 8
Carnegie Mellon From Math to Tiling Identify Small Outer Products from ISA π« π©πͺ + π« π« ππ π π Initialize π« ππ π π ππ πΌ Compute π(π« ππ π ) Accumulate π« A High Throughput Mix Enumerate Space of Outer Products Start with ISA Select Best Mix with Queueing Model Richard Veras (rveras@cmu.edu) 9
Carnegie Mellon From Tiling to Template Selected Outer Product: π« ππ π π for( i = 0; i < m_r; i++ ) for( j = 0; j < n_r; j++ ) init(c_reg, ii,jj ) ππ πΌ π« ππ π π for( pp = 0; pp < k_b; pp++ ) /* perform the outer products */ for( i = 0; i < m_r; i+=m_s ) for( j = 0; j < n_r; j+=n_s ) for( ii = i; ii < i+m_s; ii++ ) Embedding Function (get_b): get_a_elem(a_reg, ii,j ); for( jj = j; jj < j+n_s; jj++ ) get_b_elem(b_reg, ii,jj ); apply(c_reg,a_reg,b_reg,ii,jj,pp); def get_b_element ( var array b_reg[][], ptr B, ii, jj ) opts = { π« π(π« ππ π ) 0: assign( b_reg[jj], vload(B,jj )), 1: assign( b_reg[jj], shuffle(b_reg[jj-1]) ), for( i = 0; i < m_r; i++ ) 2: assign( b_reg[jj], permute(b_reg[jj-1]) ), for( j = 0; j < n_r; j++ ) 3: assign( b_reg[jj], shuffle(b_reg[jj-1]) )} accumulate(C, c_reg, ii, jj ); if ii mod v = 0 return opts[jj] Richard Veras (rveras@cmu.edu) 10
Carnegie Mellon Floyd-Warshall Embedded in GEMM DGEMM Floyd-Warshall Semiring: (πΊ,β, +, π, π) (π, +, π΅π±πΆ, π, β) Initialize: assign( c_reg[ii,jj], 0) assign( c_reg[ii,jj], π« ππ π π (ii==jj)? 0 : INFINITY) Compute: assign( c_reg[ii,jj], assign( c_reg[ii,jj], π« ππ π π ππ πΌ a_reg[ii,pp]* MIN(a_reg[ii,pp]+ b_reg[pp,jj], b_reg[pp,jj], +c_reg[ii,jj])) c_reg[ii,jj])) Accumulate: assign( C[(ii,jj)], assign( C[(ii,jj)], π« π(π« ππ π ) MIN(c_reg[ii,jj], c_reg[ii,jj]+ C[(ii,jj)] ) C[(ii,jj)] Richard Veras (rveras@cmu.edu) 11
Carnegie Mellon Scheduling the Problem Pipeline for Scheduling: We have built the kernel code, Built Kernel + Now we need to schedule: Embedding Func. Express as Decision Vars Static Scheduling still matters on OOO Processors: Formulate Constraints over Vars Minimize with ILP Solver Scheduled Kernel Code Richard Veras (rveras@cmu.edu) 12
Carnegie Mellon OASIC approach for ILP Scheduling Expressing Constraints in Representing Design Space as terms of X: Polytope: Every instruction n is executed once π = π π π ππ π At any timestep t, functional unit k is used no more than it can π π π ππ β€ πΊ π Decision Variable: instruction n is executed on functional unit k at time step t If π π depends on π π , then π π will not execute until l cycles after π π π π π π π ππ π + π π ππ π β€ π π ππ Functional unit π π cycle But wait, thereβs more! Instruction label Richard Veras (rveras@cmu.edu) 13
Carnegie Mellon Emitting The Code Code is emitted: for( pp = 0; pp < k_b; pp+=KUNR ) Code is now Scheduled /* STEADY STATE CODE */ VLOAD_IA(GET_A_ADDR(0),GET_A_REG(0)) VLOAD_IA(GET_A_ADDR(1),GET_A_REG(1)) VLOAD_IA(GET_B_ADDR(0),GET_B_REG(0)) VSHUFFLE_IA(GET_B_REG(0),GET_B_REG(1)) VFMA(GET_A_REG(0), GET_B_REG(0),GET_C_REG(0,0)) VFMA(GET_A_REG(0),GET_B_REG(1),GET_C_REG(0,1)) VPERM2F128_IA(0x01,GET_B_REG(1),GET_B_REG(2)) VSHUFFLE_IA(0x05,GET_B_REG(2),GET_B_REG(3)) VFMA(GET_A_REG(1),GET_B_REG(0),GET_C_REG(0,0)) VFMA(GET_A_REG(1),GET_B_REG(1),GET_C_REG(0,1)) Need Custom ANSI C compliant SIMD Is this necessary? wrappers to schedule in Compiler: #define VADD(srca,srcb,dest) asm volatile( "vaddpd %[vsrca],%[vsrcb], %[vdest]" : [vdest] "=x"(dest) : [vsrca] "x"(srca), [vsrcb] "x"(srcb)); Richard Veras (rveras@cmu.edu) 14
Carnegie Mellon Putting it All Together Have Operation that we can express like GEMM: π« π©πͺ + π« π« ππ π π Initialize π« ππ π π ππ πΌ Compute π(π« ππ π ) Accumulate π« Run through our Pipeline: Richard Veras (rveras@cmu.edu) 15
Carnegie Mellon Moving Forward Clustering : ~π©π© πΌ π© Centrality : ~π© πΌ π© (triangle) (betweeness) Community Detection : ~π© π³ Richard Veras (rveras@cmu.edu) 16
Carnegie Mellon Summary ο’ There exists a large class of GEMM-like Operations ο’ Obtaining DGEMM level performance for each of these operations requires automation ο’ We have a systematic approach for automatically generating DGEMM ο’ We are extending it by allowing the user to define a semi-ring with an initialize and accumulate function Richard Veras (rveras@cmu.edu) 17
Recommend
More recommend