You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the new-pipeline, runQ should be re-implemented. This variant of runN allows compilation of Accelerate programs to happen at Haskell compile-time using Template Haskell, instead of Haskell run-time. It is implemented by converting (one of) the last AST(s) to Template Haskell expression.
For the new-pipeline, this will probably be the Linked language. However, we may want to split Linking in two phases, where phase 1 compiles the intra-kernel part of the program, and phase 2 actually loads the functions in memory using the system linker.
I have looked into this a bit and discussed with @ivogabe . Here are my notes. If I have made any mistakes, please let me know.
Context
With the other run functions, Accelerate programs are compiled at runtime. With runQ, Accelerate programs are instead compiled at compile-time, using Template Haskell. The runQ functions are not implemented in new-pipeline yet. The implementation from master is commented out in both the Native and PTX modules.
In master, Accelerate programs are implemented using monolithic programs. In new-pipeline, each Accelerate program is implemented using separate kernels that are composed together using intra-kernel "glue code." Currently, this "gluing" is done together with linking, but this needs to be split into separate phases in order to implement runQ. Compilation of kernels and intra-kernel "glue code" should be done using Template Haskell, invoking LLVM. Linking should be done separately, at Haskell runtime.
Execute
Type class Execute defines the interface for executing Accelerate programs, implemented by each backend (currently Interpreter, Native, and PTX). It currently has a single Linked data family and a few methods. We need to split this into two steps, using Linked and Glued data families. The methods must be refactored, likely adding a liftGlued method. Here is a draft of the new design:
With this design, we need to lift many more types, particularly UniformSchedule.
Native
The native (CPU) backend has a "gluing and linking" implementation. In the Execute instance in Native.Execute, method linkAfunSchedule is implemented using function linkSchedule. This function generates the intra-kernel "glue code" in function codegenSchedule, compiles it (see Native.Compile), and links it (see Native.Link). Kernels are compiled and linked by function compileKernel during schedule conversion, and they are referenced using function pointers (not symbols) in an imports data structure.
We currently build shared object files (in a user cache directory) and use dlopen to load shared object files by path. The interface is a single "entry point" function. We lookup that symbol and use the FunPtr directly. We also create a Lifetime for the shared object with a finalizer that calls dlclose. We would like to change this to embed the shared objects instead, like is done in master. Module Native.Embed implements object embedding, and function embed returns FFI declarations for getting the FunPtrs.
A GHC plugin implemented in Native.Plugin (and submodules) is used to help link everything, but I do not understand the details. It should still be working. We should look into this and see why/if it is needed. Perhaps there is a better way to do the same thing using TH?
It is recommended to get the native backend working before working on the PTX backend. This likely involves the following:
Refactor NativeKernel and split compileKernel
Split linkSchedule
Implement Glued type
Most lifting work should be done in accelerate, as it is not specific to the native backend.
Implement runQ
We should implement a new runQAt function in Data.Array.Accelerate.Backend and implement runQ using it.
Re-enable (or replace?) the plugin
Re-enable the test
PTX
The PTX (NVIDIA GPU) backend does not compile any "glue code." It interprets the schedule. With the lifting already done to get the native backend working, it should be easy. This likely involves the following:
Refactore the Execute instance to work with the new interface
Implement runQ (using runQAt)
Interpreter
The interpreter, used as a simple reference implementation, is not in a working state. It was used for experimentation and needs to be cleaned up, so there is no need to get it working as part of this issue.
Activity
TravisCardwell commentedon Sep 30, 2026
I have looked into this a bit and discussed with @ivogabe . Here are my notes. If I have made any mistakes, please let me know.
Context
With the other
runfunctions, Accelerate programs are compiled at runtime. WithrunQ, Accelerate programs are instead compiled at compile-time, using Template Haskell. TherunQfunctions are not implemented innew-pipelineyet. The implementation frommasteris commented out in both the Native and PTX modules.In
master, Accelerate programs are implemented using monolithic programs. Innew-pipeline, each Accelerate program is implemented using separate kernels that are composed together using intra-kernel "glue code." Currently, this "gluing" is done together with linking, but this needs to be split into separate phases in order to implementrunQ. Compilation of kernels and intra-kernel "glue code" should be done using Template Haskell, invoking LLVM. Linking should be done separately, at Haskell runtime.Execute
Type class
Executedefines the interface for executing Accelerate programs, implemented by each backend (currentlyInterpreter,Native, andPTX). It currently has a singleLinkeddata family and a few methods. We need to split this into two steps, usingLinkedandGlueddata families. The methods must be refactored, likely adding aliftGluedmethod. Here is a draft of the new design:With this design, we need to lift many more types, particularly
UniformSchedule.Native
The native (CPU) backend has a "gluing and linking" implementation. In the
Executeinstance in Native.Execute, methodlinkAfunScheduleis implemented using functionlinkSchedule. This function generates the intra-kernel "glue code" in functioncodegenSchedule, compiles it (see Native.Compile), and links it (see Native.Link). Kernels are compiled and linked by functioncompileKernelduring schedule conversion, and they are referenced using function pointers (not symbols) in animportsdata structure.We currently build shared object files (in a user cache directory) and use
dlopento load shared object files by path. The interface is a single "entry point" function. We lookup that symbol and use theFunPtrdirectly. We also create aLifetimefor the shared object with a finalizer that callsdlclose. We would like to change this to embed the shared objects instead, like is done inmaster. Module Native.Embed implements object embedding, and functionembedreturns FFI declarations for getting theFunPtrs.A GHC plugin implemented in Native.Plugin (and submodules) is used to help link everything, but I do not understand the details. It should still be working. We should look into this and see why/if it is needed. Perhaps there is a better way to do the same thing using TH?
It is recommended to get the native backend working before working on the PTX backend. This likely involves the following:
NativeKerneland splitcompileKernellinkScheduleGluedtypeaccelerate, as it is not specific to the native backend.runQrunQAtfunction inData.Array.Accelerate.Backendand implementrunQusing it.PTX
The PTX (NVIDIA GPU) backend does not compile any "glue code." It interprets the schedule. With the lifting already done to get the native backend working, it should be easy. This likely involves the following:
Executeinstance to work with the new interfacerunQ(usingrunQAt)Interpreter
The interpreter, used as a simple reference implementation, is not in a working state. It was used for experimentation and needs to be cleaned up, so there is no need to get it working as part of this issue.