abstract-par-offchip-0.3

Safe HaskellSafe-Infered

Control.Monad.Par.OffChip

Contents

Description

This module is conceptually part of Control.Monad.Par.Class, but is factored into a separate package because it depends on ConstraintKinds, available only in GHC 7.4 and later.

Synopsis

The Class

class ParFuture ivar m => ParOffChip con ivar m where

A generic interface for operations that happen outside of the CPU.

Associated Types

type OffChipConstraint a :: Constraint

A constraint on types that must be sent off of the CPU. This typically includes, but is not limited to, serializability.

Methods

runOffChip :: OffChipConstraint a => (con a -> a) -> con a -> m a

Run an computation off of the CPU and wait for its result. A common example is invoking a GPU computation.

 runOffChip runner foreignComp 

From the type of this function you can see that, runner already has the capability to execute the foreign computations. The purpose of using runOffChip is to inform the Par CPU scheduler that a blocking operation is about to occur.

This can result in better performance by enabling the CPU to do other work while waiting for the off-chip computation to complete.

spawnOffChip :: OffChipConstraint a => (con a -> a) -> con a -> m (ivar a)

Non-blocking variant of runOffChip.

unsafeHybrid :: OffChipConstraint b => (con b -> b) -> (b -> a) -> (m a, con b) -> m (ivar a)

Spawn an computation which may execute either on the CPU or off-chip based on runtime load. The CPU and off-chip implementations may employ completely different algorithms. Therefore, this is an UNSAFE operation which will not guarantee determinism unless the user ensures that the two algorithms are equivalent.

Usage is:

 unsafeHybrid runner conversion (cpuVer, offChipVer)

As with runOffChip, the runner invokes the actual off-chip computation. The new parameter, conversion, converts results from the off-chip computation to be of the same type as the CPU version of the function. Finally, the pair argument contains two complete computations, only one of which is invoked at runtime.

Example applications of unsafeHybrid