[GHC] #14003: Allow more worker arguments in SpecConstr

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

[GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
           Reporter:  choenerzs      |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  normal         |         Milestone:  8.2.2
          Component:  Compiler       |           Version:  8.2.1-rc3
           Keywords:  JoinPoints,    |  Operating System:  Unknown/Multiple
  Fusion                             |
       Architecture:                 |   Type of failure:  Runtime
  Unknown/Multiple                   |  performance bug
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Starting with GHC 8.2 (rc1 -- head) I noticed that the SpecConstr pass
 does not always optimize completely with SpecConstr-heavy code.
 Setting ```-fmax-worker-args=100``` leads to complete specialization
 again.

 However, given that code annotated with ```SPEC``` should be optimized
 until no more ```SPEC``` arguments are alive, shouldn't
 ```callToNewPats``` in ```compiler/specialise/SpecConstr.hs``` specialize
 *irrespective* of the size of the worker argument list?

 Code that actually fails to specialize is fairly large, hence no test case
 -- though I have some files with core output showing insufficient
 specialization.

 (I'd be willing to write a patch for this)

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  choenerzs         |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.2.2
       Component:  Compiler          |              Version:  8.2.1-rc3
      Resolution:                    |             Keywords:  JoinPoints,
                                     |  Fusion
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by bgamari):

 In general your code will perform pretty poorly with or without
 worker/wrapper if you have >100 arguments as this is well beyond what we
 can accommodate in physical registers. Of course, I'm happy to be proven
 wrong: do you have a concrete example of a program with this many
 arguments which you think should optimize well?

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  choenerzs         |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.2.2
       Component:  Compiler          |              Version:  8.2.1-rc3
      Resolution:                    |             Keywords:  JoinPoints,
                                     |  Fusion
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by choenerzs):

 I'm using a lot of intermediate data constructors for control flow which
 are all eliminated if SpecConstr runs to completion.

 The ```100``` for W/W was only to provide a ceiling I'm not likely to bump
 against. However, this is part of the problem, in that the user of the
 library now needs to think about which value to give W/W.

 The function wstream_Strng2_V_1 becomes more than x10 faster if specconstr
 runs to completion and allocates *a lot* less (in my allocation benchmark
 it is 48 bytes versus ~ 600 Kilo-bytes . It has arity 18 after full
 SpecConstr.

 In GHC 8.0.2 and earlier, I did not have to change the maximal number of
 W/W arguments for SpecConstr.

 The core output for v1-slow (W/W = 10) and v1-fast (W/W = 100) is given as
 attachments.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  choenerzs         |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.2.2
       Component:  Compiler          |              Version:  8.2.1-rc3
      Resolution:                    |             Keywords:  JoinPoints,
                                     |  Fusion
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by choenerzs):

 * Attachment "v1-slow.dump-simpl" added.

 core output with default W/W 10

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  choenerzs         |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.2.2
       Component:  Compiler          |              Version:  8.2.1-rc3
      Resolution:                    |             Keywords:  JoinPoints,
                                     |  Fusion
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by choenerzs):

 * Attachment "v1-fast.dump-simpl" added.

 core output with W/W 100

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  choenerzs         |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.2.2
       Component:  Compiler          |              Version:  8.2.1-rc3
      Resolution:                    |             Keywords:  JoinPoints,
                                     |  Fusion
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 I'm confused.

 * I think `-fmax-worker-args` applies to the demand analyser, not
 `SpecConstr`.  So I'm not sure how it is affecting things.

 * Are you getting the same code with 8.0.2 and 8.2 after `SpecConstr`?

 Overall it's going to be hard to help without a test case.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003#comment:3>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  choenerzs         |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.2.2
       Component:  Compiler          |              Version:  8.2.1-rc3
      Resolution:                    |             Keywords:  JoinPoints,
                                     |  Fusion
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by choenerzs):

 SpecConstr checks via ```isWorkerSmallEnough``` in ```callsToNewPats``` if
 the pattern to be specialised is small enough. This is controlled by
 ```-fmax-worker-args```. Line 1913 in SpecConstr.hs.

 And no, 8.0.2 fully specialises irrespective of the number of worker
 arguments. Specialisation in 8.2 depends on the number of arguments the
 pattern to be specialised has.

 I'll try to construct a test case.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  choenerzs         |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.2.2
       Component:  Compiler          |              Version:  8.2.1-rc3
      Resolution:                    |             Keywords:  JoinPoints,
                                     |  Fusion
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #11565            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by bgamari):

 * related:   => #11565


Comment:

 >  The function `wstream_Strng2_V_1` becomes more than x10 faster if
 specconstr runs to completion and allocates *a lot* less (in my allocation
 benchmark it is 48 bytes versus ~ 600 Kilo-bytes . It has arity 18 after
 full SpecConstr.

 Where is this `wstream_Strng2_V_1` function that you refer to? It would be
 helpful to see a concrete example.

 > And no, 8.0.2 fully specialises irrespective of the number of worker
 arguments. Specialisation in 8.2 depends on the number of arguments the
 pattern to be specialised has.

 This change is due to two causes:
  * a48de37dcca98e7d477040b0ed298bcd1b3ab303, which fixes #11565 where
 `-fmax-worker-args` was simply ignored
  * f93c363fab1ac8ce6f0b474f5967b0b097995827, which extended the reach of
 `-fmax-worker-args` to include SpecConstr in order to improve compiler
 performance.

 Perhaps you want the SpecConstr limit to be independent from the
 worker/wrapper limit?

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  choenerzs         |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.2.2
       Component:  Compiler          |              Version:  8.2.1-rc3
      Resolution:                    |             Keywords:  JoinPoints,
                                     |  Fusion
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #11565            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by choenerzs):

 The core output of the ```wstream_Strng2_V_1``` function is in the two
 attached files. I still need to prepare a test case that doesn't depend on
 a lot of dependencies.

 What I want is SpecConstr to continue specialising functions that have a
 ```SPEC``` argument irrespective of the number of arguments.

 That is, those where sc_force is set, I think?

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003#comment:6>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  choenerzs         |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.2.2
       Component:  Compiler          |              Version:  8.2.1-rc3
      Resolution:                    |             Keywords:  JoinPoints,
                                     |  Fusion
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #11565            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 That seems plausible. We could not call `isWorkerSmallEnough` if
 `sc_force` is true.  Would you like to try that?

 If so, we should update this comnent
 {{{
 ForceSpecConstr arguments are spotted in scExpr' and scTopBinds which then
 set
 sc_force to True when calling specLoop. This flag does four things:
   * Ignore specConstrThreshold, to specialise functions of arbitrary size
         (see scTopBind)
   * Ignore specConstrCount, to make arbitrary numbers of specialisations
         (see specialise)
   * Specialise even for arguments that are not scrutinised in the loop
         (see argToPat; Trac #4488)
   * Only specialise on recursive types a finite number of times
         (see is_too_recursive; Trac #5550; Note [Limit recursive
 specialisation])
 }}}
 Now there'd be five things!

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003#comment:7>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  choenerzs         |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.2.2
       Component:  Compiler          |              Version:  8.2.1-rc3
      Resolution:                    |             Keywords:  JoinPoints,
                                     |  Fusion
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #11565            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by choenerzs):

 Ok!
 I've HEAD prepared, and will start with simplified example code.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003#comment:8>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  choenerzs         |                Owner:  choenerzs
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.4.1
       Component:  Compiler          |              Version:  8.2.1-rc3
      Resolution:                    |             Keywords:  JoinPoints,
                                     |  Fusion
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #11565            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by bgamari):

 * owner:  (none) => choenerzs
 * milestone:  8.2.2 => 8.4.1


Comment:

 Any progress on this, choenerzs?

 Bumping off to 8.4.1 as there is a workaround for the regression (e.g.
 increase `-fmax-worker-args`).

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003#comment:9>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets
Reply | Threaded
Open this post in threaded view
|

Re: [GHC] #14003: Allow more worker arguments in SpecConstr

GHC - devs mailing list
In reply to this post by GHC - devs mailing list
#14003: Allow more worker arguments in SpecConstr
-------------------------------------+-------------------------------------
        Reporter:  choenerzs         |                Owner:  choenerzs
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:  8.4.1
       Component:  Compiler          |              Version:  8.2.1-rc3
      Resolution:                    |             Keywords:  JoinPoints,
                                     |  Fusion
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #11565            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by choenerzs):

 Hi Ben,

 sorry for the delay. Work caught up with me. I think, this month should
 work out.

 Best,
 Christian

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14003#comment:10>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler

_______________________________________________
ghc-tickets mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-tickets