[PATCH] D49024: [Polly] [WIP] Introduce ShapeInfo into polly for sizes and strides.

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 31 19:21:25 PDT 2018


Meinersbur added a comment.

As mentioned in the last phone call, I think we should not use 'Stride' as an alternative to row-major indexing. The primary reason is that there are no unique coordinates for a single memory location which means we cannot accurately compute dependencies. Indeed, the delinearization stuff is all about ensuring that there is no unpredictable aliasing.

If offsets are required, this can be added as padding between rows. The default row-major address computation for a 4-dimensional tensor of size n1×n2×n3×n4 at index (i1,i2,i3,i4) is:

  address = base + ((i1*n2 + i2)*n3 + i3)*n4 + i4 = i1*n2*n3*n4 + i2*n3*n4 + i3*n4 + i4*1
                                                       ^~~~~~~^      ^~~~^      ^^      ^ 
                                                       These coefficients are what I interpret as 'strides'

(note that if the strides are precomputed, both representations have the same number of operations)
or

  address = base + (((i1*n2 + i2)*n3 + i3)*n4 + i4)*sizeof(*address)

when we compute in byte units.

With padding of p1,p2,p3,p4 bytes between elements (i.e. `p4` is the number of bytes we insert after every element) we get an expression such as

  address = base + (sizeof(*address) + p4)*i4;
                   ^~~~~~~~~~~~~~~~~~~~~~^
                   size per element incl padding

in one dimension.

  address = base + ((sizeof(*address) + p4)*n4 + p3)*i3 + (sizeof(*address) + p4)*i4;
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~^            ^~~~~~~~~~~~~~~~~~~~~~~~~^
                   size of lower-dim line                 Index in that line

in two dimensions.

  address = base + (((sizeof(*address) + p4)*n4 + p3)*n3 + p2)*i2 + ((sizeof(*address) + p4)*n4 + p3)*i3 + (sizeof(*address) + p4)*i4;

in three dimensions.

  address = base + ((((p4 + sizeof(*address))*n4 + p3)*n3 + p2)*n2 + p1)*i1 + (((p4 + sizeof(*address))*n4 + p3)*n3 + p2)*i2 + ((p4 + sizeof(*address))*n4 + p3)*i3 + (p4 + sizeof(*address))*i4;

in four dimensions. Note that `p1` unused (it would be added just once at the end of the tensor; it could be used if we add padding before each element/line/row/column in which case it would represent a constant offset of the first element to the base pointer).

Padding/dimension sizes should be known by higher level languages. If we only have the strides were are back to the delinerization problem.



================
Comment at: include/polly/CodeGen/IslExprBuilder.h:280-281
+
+  // Provide a uniform interface to lookup replacements of the old value
+  // in the various maps we provide.
+  llvm::Value *getLatestValue(llvm::Value *Old);
----------------
Please use doxygen comments for member documentation (triple slashes `////`)


https://reviews.llvm.org/D49024





More information about the llvm-commits mailing list