| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Futhark.Pass.AddGlobalParams
Description
Add explicit parameters for global names used in device functions.
The purpose of this pass is to ensure that no functions called from within a
parallel section (identified by SegMap, SegRed, `SegScan, SegHist, or
GPUBody) reference a global name directly. We call these functions "device
functions". A global name is a name bound by a statement outside of any
defunction definition. This is done by:
- Identifying which global names are referenced by each device function. Since device functions can call each other, this must be determined transitively, using a call graph.
- Adding new parameters to each device function corresponding to each of the global names used by that function.
- Updating each application of a device function to include these new names.
The main complication is that it is not allowed for a device function to have parameter names that are the same as global names - shadowing is not allowed. However, it is legal for different device functions to have the same parameter names. Hence, once it has been determined which global names are used in device functions, we compute a map that associates the global names to parameter names, and use these. This implies that these names must also be substituted into the device function bodies. Note that when modifying the application of the outermost device function call with additional function arguments, we must use the original global names.