Opened 3 years ago

Last modified 20 months ago

#5369 new bug

Reinstate VECTORISE pragmas with expressions as right-hand sides

Reported by: simonpj Owned by: chak
Priority: normal Milestone: 7.6.2
Component: Data Parallel Haskell Version: 7.0.4
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

The current vectoriser depends in a very fragile way on the order in which the constraint solver generates constraints. This ticket is just to track this known problem.

Manifestation:

*** Vectorisation error ***
    Type mismatch in vectorisation pragma for Data.Array.Parallel.unzipP
        Expected type forall a_a1SF b_a1SG.
                      (Data.Array.Parallel.PArray.PRepr.PA a_a1SF,
                       Data.Array.Parallel.PArray.PRepr.PA b_a1SG) =>
                      Data.Array.Parallel.PArray.Base.PArray (a_a1SF, b_a1SG)
                      Data.Array.Parallel.Lifted.Closure.:-> (Data.Array.Parallel.PArray.Base.PArray
                                                                a_a1SF,
                                                              Data.Array.Parallel.PArray.Base.PArray
                                                                b_a1SG)
        Inferred type forall a_a21g b_a21h.
                      (Data.Array.Parallel.PArray.PRepr.PA b_a21h,
                       Data.Array.Parallel.PArray.PRepr.PA a_a21g) =>
                      Data.Array.Parallel.PArray.Base.PArray (a_a21g, b_a21h)
                      Data.Array.Parallel.Lifted.Closure.:-> (Data.Array.Parallel.PArray.Base.PArray
                                                                a_a21g,
                                                              Data.Array.Parallel.PArray.Base.PArray
                                                                b_a21h)

Reason: the compilation of VECTORISE pragmas depends on the order of constraints in an inferred type. This isn't trivial to fix. As Manuel writes, the problem here is that we do not know what wrapper w we need *until* the vectoriser runs. Why is that? Given

  f :: ty
  f = e
  {-# VECTORISE f = e_v #-}

where the type *inferred* for e_v is ty_v, we need to mediate between ty_v and V[[ty]]. (Here V[[ty]] is the transformation that maps a regular type to a vectorised type.)

It is V[[ty]] that we cannot determine until the vectoriser runs. If we could compute V[ty]] in the type checker, we could use it together with ty_v to compute a wrapper w as you propose.

Alas, given the current implementation of V[[..]] in the vectoriser (it is implemented in Vectorise.Type.vectType), we cannot call it in the type checker, because it runs in the VM monad, which is a variant of the 'DsM' monad. In particular, 'VM' uses some tables of names of types and functions defined in the DPH library that are not available during type checking. (I briefly considered duplicating the code for vectType as a stop gap measure in TcM, but that didn't seem to be so easy.)

I believe that the Right Thing to do is to change the 'VM' monad and the implementation of vectType, so that it is more flexible and can be called from TcM. The changes that I am making at the moment (i.e., cutting down these tables of magic, built-in things) will make it easier to improve vectType.

Change History (8)

comment:1 Changed 3 years ago by chak

  • Owner set to chak

We agreed to handle this problem in two stages:

  1. For the moment, the pragmas will be restricted to be of the form {-# VECTORISE f = g #-}, where g is an identifier. Then, we need no type inference for the right-hand side of the pragma.
  2. Once the vectoriser got to a point, where we can call Vectorise.Type.vectType from the type checker, we will reinstate the more general form of the pragma again in a more robust form (where the type checker generates a suitable wrapper.)

comment:2 Changed 3 years ago by chak

I did the first stage:

commit ae6161ec6f2466ca2d04f098f350ce06090003b1
Author: Manuel M T Chakravarty <chak@cse.unsw.edu.au>
Date:   Sat Aug 20 23:08:10 2011 +1000

   Until the type checker can use vectorised signatures, we restrict the RHS of VECTORISE pragmas to be a single identifier only.

   - This removes the need to be careful about the order of dictionaries during type inference. A property that is too fragile to try to maintain in the type checker.

comment:3 Changed 2 years ago by igloo

  • Milestone set to 7.4.1

comment:4 Changed 2 years ago by chak

@igloo The remaining work is not affecting users, but is just a convenience for us (the implementors). I'd suggest to set the milestone to 7.6.1.

comment:5 Changed 2 years ago by chak

  • Summary changed from Vectoriser depends in too-fragile a way on the type constraint solver to Reinstate VECTORISE pragmas with expressions as right-hand sides

comment:6 Changed 2 years ago by chak

  • Component changed from Compiler to Data Parallel Haskell

comment:7 Changed 2 years ago by igloo

  • Milestone changed from 7.4.1 to 7.6.1

comment:8 Changed 20 months ago by igloo

  • Milestone changed from 7.6.1 to 7.6.2
Note: See TracTickets for help on using tickets.