Skip to content

Cross-platform general-purpose computing Kotlin Multiplatform library

Notifications You must be signed in to change notification settings

husker-dev/gpgpu-kt

Repository files navigation

gpgpu-kt

Cross-platform general-purpose computing Kotlin Multiplatform library

Available accelerations:

OpenCL CUDA Vulkan Metal WebGPU JS OpenGL Bytecode
jvm ⚠️
js ⚠️*
wasm
ios
android
macos
  • ✅ - Fully implemented

  • ⚠️ - Partially working

  • ❌ - Not implemented, but planned

  • * Doesn't support loops and Byte

TODO List:

  • Add sizeof() function
  • Add array creation support
  • Add Vulkan support

Simple example

  1. Create GPDevice
val device = GPDevice.create()
  1. 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())
  1. 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() }
  1. Execute the program with arguments
program.execute(
    instances = 1_000_000,
    "arr1" to arr1,
    "arr2" to arr2,
    "result" to result,
    "multiplier" to 2
)
  1. Read the result from buffer
val modifiedResultArray = result.read()

About

Cross-platform general-purpose computing Kotlin Multiplatform library

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published