Advanced CPP Buildsystem Override

Advanced CPP Buildsystem Override

In this example we will show how we can wrap a complex CPP project by extending the buildsystem defaults provided, which will give us flexibility to configure the required bindings.

If you are looking for a basic implementation of the C++ wrapper, you can get started with the "Single file C++ Example".

You can read about how to configure your environment in the CPP Wrapper documentation page.

Naming Conventions

In this example we will have full control on naming conventions.

More specifically there are a few key naming conventions that we need to consider:

  • Python Module name

  • Python Wrapper Class name

  • C++ Library Name

As long as we keep these three key naming conventions in mind, we will have full flexibility on the entire build system.

For this project we will choose the following naming conventions:

  • Python Module Name: CustomSeldonPackage

  • Python Wrapper Class: MyModelClass

  • C++ Library Name: CustomSeldonPackage

As you can see, the name of the Python Module and C++ Library can be the same.

Wrapper Class

We will first start with the wrapper code of our example. We'll first create our file Main.cpp and we'll explain in detail each section below.

In this file we basically have to note the following key points:

  • We import "seldon/SeldonModel.hpp" which is from the Seldon package

  • We use our custom class name "MyModelClass"

  • We extend the SeldonModelBase class which processes the protos for us

  • We override the predict() function which provides the raw protos

  • We register our class as SELDON_BIND_MODULE passing the package name and class name

Buildsystem CMakeLists.txt

For the build system we have integrated with CMake, as this provides quite a lot of flexibility, and easy integration with external projects.

In this case below are the minimal configurations required in order for everything to work smoothly. The key components to note are:

  • We fetch the seldon and pybind11 packages

  • We register our C++ library with the name CustomSeldonMessage

  • We bind the package with the seldon library

You are able to extend the points below as required.

Environment Variables

The final component is to specify the environment variables.

FOr this we can either pass the env variable as a parameter to the s2i command below, or in this example we'll approach it by the other option which is creating an environment file in the .s2i/environment file.

The environment variable is MODEL_NAME, which should contain the name of your package and model.

In our case it is CustomSeldonPackage.MyModelClass as follows:

(Optional) Extend CMake Config via Setup.py

In our case we won't have to pass any custom CMAKE parameters as we can configure everything through the CMakeLists.txt, but if you wish to modify how your C++ wrapper is packaged you can extend the setup.py file by following the details in the CPP Wrapper documentation page.

Build Seldon Microservice

We can now build our seldon microservice using s2i:

Test our model locally by running docker

Send request (which should return the same value)

Clean up

Deploy to seldon

Last updated

Was this helpful?