This is an archive of the discontinued LLVM Phabricator instance.

[libc] automemcpy - function generator
ClosedPublic

Authored by gchatelet on Oct 12 2021, 2:31 AM.

Details

Reviewers
courbet
Summary

"automemcpy: A framework for automatic generation of fundamental memory operations"
https://research.google/pubs/pub50338/

This patch implements the concepts presented in the paper, the overall approach is the following:

  • Makes use of constraint programming to model the implementation of a memory function (memcpy, memset, memcmp, bzero, bcmp).
  • Generate the code for all valid implementations
  • Compile the implementations and benchmark them on a set of machines. The benchmark makes use of representative distributions for the function's arguments.
  • Analyze the result and pick "the best" performing function according to the specific environement.

This patch in particular implements the constraint programming part that explores valid memory operations.

Diff Detail

Event Timeline

gchatelet created this revision.Oct 12 2021, 2:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 12 2021, 2:31 AM
gchatelet requested review of this revision.Oct 12 2021, 2:31 AM
gchatelet updated this revision to Diff 379690.Oct 14 2021, 6:11 AM
  • Move function generator to subdirectories
courbet added inline comments.Oct 15 2021, 2:20 AM
libc/benchmarks/automemcpy/include/automemcpy/RandomFunctionGenerator.h
35

This is not really a "disjunction", more like a disjuction of equality clauses. What about simply calling this addInSetConstraint or something like this ?

36

doc

37

doc

libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp
21

Can you please document these ?

56

Why not simply comment out bcmp int the type array above ?

59

This is not super clear. Maybe:

// Add constraints for span bounds.

The reader can then refer to addBoundsAndAnchors to understand what the specific constraints are.

65
// Fix endpoints: The minimum size that we want to copy is 0, and we always start with the `Contiguous` strategy. The max size is `kMaxSize`, and we always end with the `Accelerator` strategy, as it's typically more efficient for large sizes.
69
// We always consider strategies in this order: Contiguous <= Overlap <= Loop <= AlignedLoop <= Accelerator
74

Why ? Can you make this a kConstant ?

76

ditto

77

This needs a comment.

83

please get rid of the magic numbers and hoist them to constants at the top.

100

ditto: no need to add then remove, let's have fewer constraints instead.

gchatelet updated this revision to Diff 379983.Oct 15 2021, 6:41 AM
gchatelet marked 13 inline comments as done.
  • Address function generator comments
courbet accepted this revision.Oct 19 2021, 12:16 AM
courbet added inline comments.
libc/benchmarks/automemcpy/lib/RandomFunctionGenerator.cpp
24

[nit] maybe "limit" more than "prevent", this is still combinatorial :)

58

extra "the"

This revision is now accepted and ready to land.Oct 19 2021, 12:16 AM
gchatelet updated this revision to Diff 380648.Oct 19 2021, 4:36 AM
gchatelet marked 2 inline comments as done.
  • Fix comments
gchatelet closed this revision.Oct 28 2021, 4:32 AM

Submitted within D111801.