5. Example code and usage

5.1. Linking

When compiling your program, you will need to add the libraries used by the linker. The Poplar SDK contains the shared library file for GCL named libgcl.so and after activating the Poplar SDK, it will be available for linking after specifying -lgcl. For example:

$ g++ -std=c++11 my-program.cpp -lpoplar -lpopops -lgcl

5.2. Example code

A full example of an invocation of the AllReduce operation on two replicas using GCL is available. The graph creation code is shown in Listing 5.1.

Listing 5.1 gcl_allreduce_example.cpp

  // Main program
  program::Sequence prog;
  prog.add(program::Copy(inStream, data));
  gcl::allReduceInPlaceCrossReplica(graph, data, gcl::CollectiveOperator::ADD,
                                    prog);

You can download the complete code and compile it with the command:

$ g++ gcl_allreduce_example.cpp -lpoplar -lpopops -lgcl \
      -o gcl_allreduce_example

Download gcl_allreduce_example.cpp