Vulpes is C++ STL compute library for Metal Programming on iOS and Mac OS X GPUs
Vulpes is a C++ STL compute library for Metal Programming on iOS and Mac OS X GPUs. Metal is a low-level, low-overhead hardware accelerated graphics, compute programming API specific to Apple devices. Being low-level and low-overhead means Metal supports pre-compiled shaders and efficient multi-threading. Metal is supported on Mac from OS X 10.11 (El Capitan) and on mobile devices from iOS 8. Vulpes is an abstraction on top of Obj-C and Metal. As most of the iOS and Mac devices are equipped with one GPU, the library is optimised for single GPU systems.
Metal is a huge leap for gaming on iOS and dawn on Macs. Metal is supported for Obj-C and Swift which turns good for mobile devices as most of the apps are built using them. With most of the game engines written in C++, using Metal on iMacs or Macbooks makes the game developer to spend resources, money and development time on porting existing code not only to Metal but also interfacing it with the current base code. Bringing a C++ based wrapper or abstractor to Metal, removes these contraints and help the developer to write the code seemlessly. With applications using GPUs increasing, bringing Metal to C++ helps programmers to leverage the compute power more easily than need to learn a new programming language or new API
#include <iostream>
#include <vector>
#include "vulpes.hpp"
int main(){
   // Allocating Host memory
   float a[] = {1, 2, 3, 4, 5, 6};
   float b[] = {2, 3, 4, 5, 6, 7};
   // Allocating aligned memory for output vector
   std::vector<float, aligned_allocator<float>> c(6);
   // Allocating GPU memory. Copy is done here too!
   vulpes::vector<float> ad(a, a+6);
   vulpes::vector<float> bd(b, b+6);
   vulpes::vector<float> cd(c);
   // Executing operation addition on GPU using vulpes::transform
   vulpes::transform(ad.begin(), ad.end(),
     bd.begin(),
     cd.begin(),
     vulpes::plus<float>());
   // Printing out the result
   std::cout<< c[3] <<std::endl;
   return 0;
}
As Vulpes code is written in headers, no libraries are genereated. Including the header files into a standard XCode project with Metal libraries loaded works just fine. Download the source from Vulpes git repository.
After downloading the package, import vulpes.hpp
and /include
into existing project then include Metal.framework
.
1. Device supporting Metal API.
2. Xcode version 7.0
Vulpes is created by Aditya Atluri (@adityaatluri). Feel free to try the code. Any testers to the code are welcome, especially in a dual-GPU environment. Any suggestions or feedback would be most welcome.
Any questions regarding implementation or usage or contacting me can be done by creating issue on the issue tracker for the Vulpes repository.