nikolaymetchev
12/30/2019, 6:27 PMfun main() {
memScoped {
val pointer = cValuesOf(0U).getPointer(memScope)
val result = clGetPlatformIDs(0, null, pointer)
if (CL_SUCCESS == result) {
println("Detected OpenCL platforms: ${pointer[0]}")
} else {
println("Error calling clGetPlatformIDs. Error code: $result");
}
}
}napperley
12/30/2019, 9:11 PMfun main() {
memScoped {
val numPlatformsPtr = alloc<UIntVar>()
val result = clGetPlatformIDs(num_entries = 0, platforms = null, num_platforms = pointer)
if (CL_SUCCESS == result) {
println("Detected OpenCL platforms: ${numPlatformsPtr?.pointed}")
} else {
println("Error calling clGetPlatformIDs. Error code: $result");
}
}
}napperley
12/30/2019, 9:17 PMalloc function. The pointer is passed as is to the clGetPlatformIDs function, which initialises the pointer with a value. If the call to ``clGetPlatformIDs`` is successful then the pointer's value is printed via the pointed extension property.nikolaymetchev
12/30/2019, 9:22 PMclGetPlatformIDs . The 3rd argument of that method is of type CValuesRef<cl_uintVar> . Whereas alloc<cl_uintVar> gives a cl_uintVar. It seems to work if we use allocArray<cl_uitVar> although I am little confused as to why.nikolaymetchev
12/30/2019, 9:22 PMfun main() {
memScoped {
val numPlatformsPtr = allocArray<cl_uintVar>(1)
val result = clGetPlatformIDs(0, null, numPlatformsPtr)
if (CL_SUCCESS == result) {
println("Detected OpenCL platforms: ${numPlatformsPtr[0]}")
} else {
println("Error calling clGetPlatformIDs. Error code: $result");
}
}
}Markus Böck
12/30/2019, 10:00 PMnikolaymetchev
12/31/2019, 12:29 AMMarkus Böck
12/31/2019, 1:11 AMnapperley
12/31/2019, 9:41 PMval result = clGetPlatformIDs(num_entries = 0, platforms = null, num_platforms = numPlatformsPtr) with val result = clGetPlatformIDs(num_entries = 0, platforms = null, num_platforms = numPlatformsPtr.ptr. The numPlatformsPtr should be renamed to numPlatforms to avoid confusion since it is a CPointerVar ( https://kotlinlang.org/api/latest/jvm/stdlib/kotlinx.cinterop/-c-pointer-var.html ), and not a CPointer. Can get a CPointer from CPointerVar via the ptr extension property. CValuesRef ( https://kotlinlang.org/api/latest/jvm/stdlib/kotlinx.cinterop/-c-values-ref/index.html ) can take a CPointer by itself ( https://github.com/JetBrains/kotlin-native/blob/master/INTEROP.md#passing-pointers-to-bindings ), "When passing CPointer<T> as the value of such a parameter, it is passed to the C function as is".nikolaymetchev
01/01/2020, 12:51 AM