In case it helps anyone, I translated this from Apple's Objective-C example Selecting Device Objects For Compute Processing. I pared it down quite a bit too, because I ran into trouble with it and decided to ask for help on StackOverflow. For which, many thanks to Tyler for his brilliant help.
I think it's more-or-less self-explanatory, or maybe I'm just too busy to write a nice, useful description of it, or maybe just too lazy. Anyway, build and run, it's fun to watch.