GpuKernelFunction¶
A procedure that runs on a GPU.
Declaration¶
Syntax¶
GpuKernelFunction(symbol_table symtab, identifier name,
ttype function_signature, identifier* dependencies, expr* args,
stmt* body, access access, location start_name, location end_name)
Arguments¶
Argument |
Description |
|---|---|
|
the symbol table of the kernel: its arguments and its local variables. |
|
the name of the kernel. |
|
a FunctionType with no |
|
the names of the symbols the body refers to. |
|
the arguments of the kernel, as |
|
the statements executed by every thread of the kernel. |
|
|
|
the source span of the name in the opening statement. |
|
the source span of the name in the closing statement. |
Return values¶
None.
Description¶
A GpuKernelFunction is separate from Function because it is not callable in the ordinary sense: it is launched, with an execution configuration, by GpuKernelLaunch, and it always returns nothing.
Inside the body, the position of the running thread is read with GpuThreadIndex, GpuBlockIndex and GpuBlockSize.
Examples¶
An ASR text document that uses it:
(TranslationUnit
:symtab (SymbolTable
:id 0
:symbols {
"m" (Module
:symtab (SymbolTable
:id 1
:symbols {
"scale" (GpuKernelFunction
:symtab (SymbolTable
:id 2
:symbols {
"a" (Variable
:parent_symtab 2
:name "a"
:dependencies []
:intent :InOut
:symbolic_value nil
:value nil
:storage :Default
:type (Array
:type (Real
:kind 4
)
:dims [
(dimension
:start (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:length (IntegerConstant
:n 256
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
)
]
:physical_type :FixedSizeArray
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
"i" (Variable
:parent_symtab 2
:name "i"
:dependencies []
:intent :Local
:symbolic_value nil
:value nil
:storage :Default
:type (Integer
:kind 4
)
:type_declaration nil
:abi :Source
:access :Public
:presence :Required
:value_attr false
:target_attr false
:contiguous_attr false
:bindc_name nil
:is_volatile false
:is_protected false
:pass_attr :NotMethod
:self_argument nil
:codims []
)
}
)
:name "scale"
:function_signature (FunctionType
:arg_types [
(Array
:type (Real
:kind 4
)
:dims [
(dimension
:start (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:length (IntegerConstant
:n 256
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
)
]
:physical_type :FixedSizeArray
)
]
:return_var_type nil
:abi :Source
:deftype :Implementation
:bindc_name nil
:elemental false
:pure false
:module false
:inline false
:static false
:restrictions []
:is_restriction false
)
:dependencies []
:args [
(Var
:v (SymbolRef 2 "a")
)
]
:body [
(Assignment
:target (Var
:v (SymbolRef 2 "i")
)
:value (IntegerBinOp
:left (GpuThreadIndex
:dim 0
:type (Integer
:kind 4
)
:value nil
)
:op :Add
:right (IntegerConstant
:n 1
:type (Integer
:kind 4
)
:intboz_type :Decimal
)
:type (Integer
:kind 4
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (Var
:v (SymbolRef 2 "i")
)
:value (IntegerBinOp
:left (GpuBlockIndex
:dim 0
:type (Integer
:kind 4
)
:value nil
)
:op :Mul
:right (GpuBlockSize
:dim 0
:type (Integer
:kind 4
)
:value nil
)
:type (Integer
:kind 4
)
:value nil
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
(Assignment
:target (ArrayItem
:v (Var
:v (SymbolRef 2 "a")
)
:args [
(array_index
:left nil
:right (Var
:v (SymbolRef 2 "i")
)
:step nil
)
]
:type (Real
:kind 4
)
:storage_format :ColMajor
:value nil
)
:value (RealConstant
:r 0.0
:type (Real
:kind 4
)
)
:overloaded nil
:realloc_lhs false
:move_allocation false
)
]
:access :Public
)
}
)
:name "m"
:parent_module nil
:dependencies []
:loaded_from_mod false
:intrinsic false
:has_submodules false
)
"main" (Program
:symtab (SymbolTable
:id 3
:symbols {}
)
:name "main"
:dependencies []
:body []
)
}
)
:items []
)