Interfacing with the FSCL compiler
Once you have coded your FSCL kernels, the next step is to compile them to OpenCL. Valid OpenCL C99 source code is not the only output produced by the FSCL Compiler. Instead, the compiler produces a lot of useful information about the kernel structure, the data-types used and the way parameters are accessed from withing the kernel body. In this page we provide an overview on how to compile FSCL kernels and on the information produced by the compilation itself.
Default compilation
Most of the time, to compile a kernel you simply create an instance of the FSCL Compiler
and you pass the quoted kernel
call or kernel reference to its Compile
method. From the compilation point of view, there is no much difference between passing the kernel
and passing a call to the kernel. The compilation process is exactly the same as like as the OpenCL source produced.
The only difference is that in case of a call the result contains the expressions of the actual arguments. Those expressions
are currently required only if you Run the kernel, which is a task performed by the FSCL Runtime.
Nonetheless, future developments may introduce compiler steps whose behavior is driven by the actual arguments of a kernel call (for example, merging two kernels into one
when the argument of a kernel call is the result of another kernel call). In such a case, the compiler itself would produce different results
depending on whether you pass a kernel reference of a kernel call.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: |
|
The compiler data-structure: IKernelModule
The Compile
signature declares that the method is returning an instance of Object
. The runtime type of the returned value
depends on the configuration of the compiler pipeline (see Compiler Customisation Tutorial).
The default pipeline is composed of built-in (on native ) steps and generates an instance of IKernelModule
.
Among the other information, this instance contains the OpenCL source code produced.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: |
|
The kernel data structure: IKernelInfo
One of the most interesting data in the kernel module is provided by the Kernel
property (of type `IKernelInfo). Among the other information,
the other information, this property holds the result of access analysis relative to each kernel parameter.
Access analysis is performed on the kernel body for each vector (array) parameter to detect the way the parameter is accessed (ReadOnly, WriteOnly, ReadWrite, NoAccess).
This analysis is particularly useful for the FSCL Runtime to optimise buffer allocation prior to kernel execution.
1: 2: |
|
Compiler options
The Compile
method is overloaded to enable the programmer to specify some compilation options using an insteance
of Dictionary<string, obj>
.
The FSCL compiler library is currently declaring two built-in options, heavily used by the FSCL Runtime to speed-up kernel compilation: "ParsOnly"
and "NoCodegen"
. The first stops the native
pipeline after the parsing step, the second right before the latest two steps (function and module codegen).
Compiler options are thought to be completely extensible. Programmer can define additional options to drive the behavior of custom compiler steps.
1: 2: 3: 4: 5: 6: 7: |
|
type ReflectedDefinitionAttribute =
inherit Attribute
new : unit -> ReflectedDefinitionAttribute
Full name: Microsoft.FSharp.Core.ReflectedDefinitionAttribute
--------------------
new : unit -> ReflectedDefinitionAttribute
Full name: CompilerInterfaceTutorial.VectorAdd
val float32 : value:'T -> float32 (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.float32
--------------------
type float32 = System.Single
Full name: Microsoft.FSharp.Core.float32
--------------------
type float32<'Measure> = float32
Full name: Microsoft.FSharp.Core.float32<_>
Full name: CompilerInterfaceTutorial.compiler
Full name: CompilerInterfaceTutorial.compilationResultFromRef
Full name: CompilerInterfaceTutorial.a
from Microsoft.FSharp.Collections
Full name: Microsoft.FSharp.Collections.Array.create
Full name: CompilerInterfaceTutorial.b
Full name: CompilerInterfaceTutorial.c
Full name: Microsoft.FSharp.Collections.Array.zeroCreate
Full name: CompilerInterfaceTutorial.size
Full name: CompilerInterfaceTutorial.compilationResultFromCall
Full name: CompilerInterfaceTutorial.compilationResult
Full name: CompilerInterfaceTutorial.callArgs
Full name: CompilerInterfaceTutorial.code
Full name: CompilerInterfaceTutorial.defines
Full name: CompilerInterfaceTutorial.directives
Full name: CompilerInterfaceTutorial.globalTypes
Full name: CompilerInterfaceTutorial.utilityFunctions
Full name: CompilerInterfaceTutorial.kernel
Full name: CompilerInterfaceTutorial.firstKernelPar
Full name: CompilerInterfaceTutorial.accessAnalysis
Full name: CompilerInterfaceTutorial.myCustomOptions
type Dictionary<'TKey,'TValue> =
new : unit -> Dictionary<'TKey, 'TValue> + 5 overloads
member Add : key:'TKey * value:'TValue -> unit
member Clear : unit -> unit
member Comparer : IEqualityComparer<'TKey>
member ContainsKey : key:'TKey -> bool
member ContainsValue : value:'TValue -> bool
member Count : int
member GetEnumerator : unit -> Enumerator<'TKey, 'TValue>
member GetObjectData : info:SerializationInfo * context:StreamingContext -> unit
member Item : 'TKey -> 'TValue with get, set
...
nested type Enumerator
nested type KeyCollection
nested type ValueCollection
Full name: System.Collections.Generic.Dictionary<_,_>
--------------------
Dictionary() : unit
Dictionary(capacity: int) : unit
Dictionary(comparer: IEqualityComparer<'TKey>) : unit
Dictionary(dictionary: IDictionary<'TKey,'TValue>) : unit
Dictionary(capacity: int, comparer: IEqualityComparer<'TKey>) : unit
Dictionary(dictionary: IDictionary<'TKey,'TValue>, comparer: IEqualityComparer<'TKey>) : unit
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
Full name: Microsoft.FSharp.Core.obj
Full name: CompilerInterfaceTutorial.compilationResultOnlyParsing