Cross-platform general-purpose computing Kotlin Multiplatform library
OpenCL | CUDA | Vulkan | Metal | WebGPU | JS | Bytecode | ||
---|---|---|---|---|---|---|---|---|
jvm | ✅ | ✅ | ❌ | ❌ | ✅ | |||
js | ✅ | |||||||
wasm | ❌ | ❌ | ||||||
ios | ✅ | |||||||
android | ✅ | ❌ | ❌ | ❌ | ||||
macos | ❌ | ✅ |
-
✅ - Fully implemented
-
⚠️ - Partially working -
❌ - Not implemented, but planned
-
* Doesn't support loops and Byte
- Add
sizeof()
function - Add array creation support
- Add Vulkan support
- Create GPDevice
val device = GPDevice.create()
- Compile a program
val program = device.compile("""
extern readonly float[] arr1, arr2;
extern float[] result;
extern float multiplier;
void main(const int i){
result[i] = arr1[i] + arr2[i] * multiplier;
}
""".trimIndent())
- Allocate buffers in GPU memory
val arr1 = device.wrapFloats(exampleArray())
val arr2 = device.wrapFloats(exampleArray())
val result = engine.allocFloats(arr1.length)
fun exampleArray() = FloatArray(1_000_000) { it.toFloat() }
- Execute the program with arguments
program.execute(
instances = 1_000_000,
"arr1" to arr1,
"arr2" to arr2,
"result" to result,
"multiplier" to 2
)
- Read the result from buffer
val modifiedResultArray = result.read()