I'm using the Minimum Edit Distance algorithm to determine how closely two strings are related. I've implemented it to run on the CPU and it works great when you have hundreds of strings, but it is a source of slow down when you are comparing thousands of strings, multiple times. So I thought it might be useful to off load on to the GPU since it could perform multiple comparisons at once.
Is this possible? The Metal resources I've come across are mainly for graphics which aren't helpful. Or maybe they are?
Metal is Apple's API for programming the GPU (graphics processor unit). While often ignored by non-game developers, Metal can be a computational powerhouse with little effort.
Build your own low-level game engine in Metal! Metal is a unified application programming interface (API) for the graphics processing unit, or GPU. It's unified because it applies to both 3D graphics and data-parallel computation paradigms.
Optimize graphics and compute performance with kernels that are fine-tuned for the unique characteristics of each Metal GPU family.
The Metal framework gives your app direct access to a device's graphics processing unit (GPU). With Metal, apps can leverage a GPU to quickly render complex scenes and run computational tasks in parallel.
What you want to do is possible, at least for certain problem sizes, but it's not particularly straightforward. What you'll need to do is express the algorithm in a way that can be run on the GPU, and on iOS, that probably means using Metal. Specifically, you'll need to write one or more compute kernels in the Metal shading language that implement the minimum edit distance algorithm, then dispatch them using a Metal compute command encoder. There are several resources on compute programming with Metal around the Web.
I'm not aware of an existing Metal implementation of MED, but there is at least one CUDA implementation, and you can read a longer explanation of MED on the GPU here.
In addition to @warrenm answer, you need to write kernel function or couple of them. there is cool metal tutorial website: http://metalbyexample.com, also Apple documentation has something about it: https://developer.apple.com/library/content/documentation/Miscellaneous/Conceptual/MetalProgrammingGuide/Compute-Ctx/Compute-Ctx.html
and also there are couple of tutorials on https://www.raywenderlich.com but they are mostly graphic-oriented. You can also check GPUImage library for iOS, that is a cool wrapper around OpenGL with nice interface. Maybe there is also an option to write custom functions that will be executed using OpenGL?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With