Changes between Version 43 and Version 44 of DataParallel/VectPragma
- Timestamp:
- 08/19/12 19:48:09 (10 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DataParallel/VectPragma
v43 v44 49 49 The type constructor `T` must be in scope, but it may be imported. 'PData' and 'PRepr' instances are automatically generated by the vectoriser. 50 50 51 Examples are the vectorisation of types, such as ` Ordering` and `[]`, defined in the `Prelude`.51 Examples are the vectorisation of types, such as `Maybe` and `[]`, defined in the `Prelude`. 52 52 53 53 === With right-hand side === … … 57 57 {-# VECTORISE type T = T' #-} 58 58 }}} 59 directs the vectoriser to replace `T` by `T'` in vectorised code and to use the corresponding data constructors of `T'` instead of those of `T`. This implies that the two type constructors must be of the same kind and that the data constructors of `T` and `T'` need to be of the same number and type.59 directs the vectoriser to replace `T` by `T'` in vectorised code. Vectorisation of `T` is abstract in that constructors of `T` may not occur in vectorised code. 60 60 61 61 The type constructor `T` must be in scope, but it may be imported. 'PData' and 'PRepr' instances must be explicitly defined — they are not automatically generated. 62 62 63 An example is the handling of `Bool`, where we represent `Bool` by itself in vectorised code, but want to use the custom instances of 'PData' and 'PRepr' defined in the DPH libraries.63 An example is the vectorisation of parallel arrays, where `[::]` is replaced by `PArray` during vectorisation, but the vectoriser never looks at the representation of `[::]`. 64 64 65 65 == The VECTORISE SCALAR pragma for type constructors == 66 67 All types imported from modules that have not been vectorised are regarded to be scalar types, and they can be used in encapsulated scalar code. If custom instances for the `PData` and `PRepr` classes are provided, these types can also be used in vectorisation code. The types represent themselves (as they are scalar) and are abstract; i.e., there constructors cannot be used in vectorised code. An example is the treatment of `Int`. `Int`s can be used in vectorised code and remain unchanged by vectorisation. However, the representation of `Int` by the `I#` data constructor wrapping an `Int#` is not exposed in vectorised code. Instead, computations involving the representation need to be confined to scalar code. 66 68 67 69 === Without right-hand side === … … 71 73 {-# VECTORISE SCALAR type T #-} 72 74 }}} 73 indicates that the type is scalar; i.e., it has no embedded arrays and its constructors can '''only''' be used in scalar code. This is the default for all data types imported from non-vectorised modules.75 indicates that the type `T` is scalar; i.e., it cannot have any embedded arrays. Hence, the `T` represents itself in vectorised code. (No special vectorised version needs to be generated.) 74 76 75 `T` that may be used in vectorised code, where `T` represents itself. However, the representation of `T` is opaque in vectorised code. An example is the treatment of `Int`. `Int`s can be used in vectorised code and remain unchanged by vectorisation. However, the representation of `Int` by the `I#` data constructor wrapping an `Int#` is not exposed in vectorised code. Instead, computations involving the representation need to be confined to scalar code. 77 The type constructor `T` must be in scope, but it may be imported. `PData` and `PRepr` instances for `T` need to be manually defined if needed at all. (This is the fundamental difference to types for which the vectoriser determines automatically that they don't need a vectorised version: for the latter, the vectoriser automatically generates instances for `PData` and `PRepr`.) 76 78 77 The type constructor `T` must be in scope, but it may be imported. `PData` and `PRepr` instances for `T` need to be manually defined if needed at all. (For types that the vectoriser automatically determines that they don't need a vectorised version, instances for `PData` and `PRepr` are still generated automatically.) 78 79 NB: The crucial difference between `{-# VECTORISE SCALAR type T1 #-}` and `{-# VECTORISE type T2 #-}`, where `T2` embeds no parallel arrays, is that the *representation* (i.e., the constructors) of the former can only be used in scalar code. However, neither the representation of `T1` nor `T2` does get vectorised — so, both types are suitable for code that does not get vectorised due to vectorisation avoidance. 80 79 An example is the handling of `Bool`, which is scalar and represents itself in vectorised code, but we want to use the custom instances of 'PData' and 'PRepr' defined in the DPH libraries. 81 80 82 81 === With right-hand side === … … 86 85 {-# VECTORISE SCALAR type T = T' #-} 87 86 }}} 88 directs the vectoriser to replace `T` by `T'` in vectorised code, but its constructors can '''only''' be used inscalar code.87 directs the vectoriser to replace `T` by `T'` in vectorised code, but the type is abstract — i.e., its constructors cannot be used in vectorised code. Although, the representation of the types changes during vectorisation, it is still regarded as scalar, and hence, can be used in encapsulated scalar code. 89 88 90 89 The type constructor `T` must be in scope, but it may be imported. The `PData` and `PRepr` instances for `T` need to be manually defined. 91 90 92 An example is the handling of `[::]`, which the vectoriser maps to `PArray`, but it never looks at the implementation of `[::]`. 93 94 '''TODO:''' 95 * Maybe `VECTORISE ABSTRACT` would be a better name as it doesn't guarantee that the type constructor can be used in scalar code that doesn't need to be vectorised. It just means that the data constructors can '''only''' be used in scalar code — i.e., the vectoriser treats it as an abstract type. 91 An example is the handling of `(->)`, which the vectoriser maps to `(:->)`, but it never looks at the implementation of `(->)` and allows its use in encapsulated scalar code. 96 92 97 93 == The NOVECTORISE pragma for types ==
