-
Notifications
You must be signed in to change notification settings - Fork 0
3. Programs and syntax
Nikita Shtengauer edited this page Oct 16, 2024
·
1 revision
To execute a program, it must be described. gpgpu-kt uses its own C-like language.
To compile the program you need to call the following function:
val program = context.compile("""
void main(int i){
// Hello world?
}
""".trimIndent())There is an alternative way with the access to AST:
val ast = GPAst.parse("""
void main(int i){
// Hello world?
}
""".trimIndent())
val program = context.compile(ast)The program itself does nothing. It should be launched with some parameters:
- Instances count
- Index offset (optional)
- Mapping for external buffers and variables (more details in Syntax/Externals)
program.execute(
instances = 100_000,
"myIntField" to 123,
"myFloatData" to memoryF
)The gpgpu-kt programs have some limitations and features.
To indicate that program is waiting memory from outside, the keyword extern is used.
It can be applied to regular fields and arrays.
These are the fields that are specified when the program is executed
extern int myIntField;
extern float[] myFloatData;
void main(int i){
myFloatData[i] = myIntField * i;
}