Reputation: 1044
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?
Upvotes: 7
Views: 1910
Reputation: 1490
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?
Upvotes: 6
Reputation: 31782
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.
Upvotes: 11