Developer’s Guide

Setup

You’ll probably want to install gtest for running and implementing your C++ unit tests.

In Ubuntu:

sudo apt-get install libgtest-dev
cd /usr/lib/gtest
sudo cmake .  sudo make
sudo mv libg* /usr/local/lib/

Mac OS X:

brew install cmake
git clone https://github.com/google/googletest.git
cd googletest
cmake .
make -j
make install

Custom data types

All data types must define three interfaces:

template <typename T>
class nervana::interface::extractor

Public Functions

virtual ~extractor()
virtual std::shared_ptr<T> extract(const char *, int) = 0
template <typename T, typename S>
class nervana::interface::transformer

Public Functions

virtual ~transformer()
virtual std::shared_ptr<T> transform(std::shared_ptr<S>, std::shared_ptr<T>) = 0
template <typename T>
class nervana::interface::loader

Public Functions

virtual ~loader()
virtual void load(const std::vector<void *>&, std::shared_ptr<T>) = 0

and a configuration class inheriting from:

class nervana::interface::config

Subclassed by nervana::audio::config, nervana::blob::config, nervana::boundingbox::config, nervana::char_map::config, nervana::image::config, nervana::label::config, nervana::label_map::config, nervana::loader_config, nervana::localization::config, nervana::multicrop::config, nervana::video::config

Public Functions

void add_shape_type(const std::vector<size_t> &sh, const std::string &output_type, const bool flatten_all_dims = false)
void add_shape_type(const std::vector<size_t> &sh, const nervana::output_type &ot, const bool flatten_all_dims = false)

The config should probably make use of the following three macros to define the entries that make up the configuration options.

ADD_SCALAR(var, mode, ...)
ADD_IGNORE(var)
ADD_DISTRIBUTION(var, mode, ...)

For example, in nervana::video::config, the following snippet adds the appropriate config options for frame and max_frame_count:

std::vector<std::shared_ptr<interface::config_info_interface>> config_list = {
    ADD_SCALAR(max_frame_count, mode::REQUIRED),
    ADD_IGNORE(frame)
};

Then in the config method, these attributes are then added using the add_shape_type method:

config(nlohmann::json js) :
frame(js["frame"])
{
    if(js.is_null()) {
        throw std::runtime_error("missing video config in json config");
    }

    for(auto& info : config_list) {
        info->parse(js);
    }
    verify_config("video", config_list, js);

    // channel major only
    add_shape_type({frame.channels, max_frame_count, frame.height, frame.width},
                    frame.type_string);
    }