Your first IBM Spectrum Symphony C++ GPU service

For your first IBM® Spectrum Symphony C++ GPU service, use the sample applications provided.

Run a sample application

Refer to Synchronous IBM Spectrum Symphony C++ client tutorial to learn how to build, package and run a sample application.

Walk through the code

Review the sample service code to learn how you can create a service.

Locate the code samples

Refer to Synchronous IBM Spectrum Symphony C++ client tutorial to learn about the code and executable output locations.

What the sample does

The service receives two vectors containing float numbers, their sizes, and the target calculation method. The input is considered valid only if the vectors' sizes are equal. The target calculation method can be either cuda or opencl. The service verifies whether it was scheduled with a valid GPU device; if so, it calculates the sum of the vectors on the scheduled GPU device using the target calculation API. If the service was not scheduled with a valid GPU device, the calculation is performed on the CPU.
Input and output: define a service container
For a service to be managed by IBM Spectrum Symphony, it needs to be in a container object. This is the service container. For a service to have extended GPU functionality and advanced GPU-related API, it needs to inherit from the GpuServiceContainer class:
In SampleService.cpp, we inherited from the ServiceContainer class:
#include "GpuServiceContainer.h"

class MyServiceContainer : public GpuServiceContainer
Process the input
As opposed to a standard IBM Spectrum Symphony Service, the IBM Spectrum Symphony GPU Service calls GpuInvoke() on the GPU service container once per task. After you inherit from the GpuServiceContainer class, implement handlers so that the service can function properly. This is where the calculation is performed. The principles for input or output handling of the GPU service container are the same as for the standard IBM Spectrum Symphony service container.
Run the container and catch expressions
After processing the input, run the container and catch expressions.