Class SpikingNetwork

Class Documentation

class SpikingNetwork

Spiking Neural Network (SNN) composed of layers of spiking neurons. Layers have to be successively added from input to outputs. SpikingNetwork uses the JITCompiler to compile and load custom source files containing kernel callbacks.

Public Types

using iterator = std::vector<std::shared_ptr<Layer>>::iterator

Type definition of the Layer iterator

Public Functions

SpikingNetwork(const std::string &compile_path = default_compile_path)

Constructs an empty SNN.

Parameters

compile_path – Compilation path for custom kernel callback sources.

~SpikingNetwork()

Destructor. Deletes layer, unload custom kernel callback dynamic libraries and delete JITCompiler.

template<class LayerType, typename ...Args>
inline std::shared_ptr<LayerType> add_layer(Args... args)

Adds a layer of type LayerType with the given arguments to the network. The added layer uses the default kernel during inference.

Template Parameters
  • LayerType – Type of layer to add. Must inherit from Layer.

  • Args – Types of arguments passed to the new layer constructor.

Parameters

args – Arguments passed to the new layer constructor.

Returns

Shared pointer on the new layer.

template<class LayerType, typename ...Args>
inline std::shared_ptr<LayerType> add_layer_from_source(const std::string &src_path, Args... args)

Adds a layer of type LayerType with a custom kernel callbacks source. If not already used, the given source file is compiled and loaded by the JITCompiler.

Template Parameters
  • LayerType – Type of layer to add. Must inherit from Layer.

  • Args – Types of arguments passed to the new layer constructor.

Parameters
  • src_path – Path to the kernel callbacks source file.

  • args – Arguments passed to the new layer constructor.

Throws
  • std::runtime_error – if the given source file failed to compile.

  • std::runtime_error – with the result of dlerror() if the compiled dynamic library could not be loaded.

Returns

Shared pointer on the new layer.

const SpikeArray &infer(const SpikeArray &pre_spikes)

Infer the entire SNN using the given sorteed input spike array.

Parameters

pre_spikes – Sorted input spikes.

Throws

std::runtime_error – if pre_spikes are not sorted.

Returns

Constant reference on the output spike array.

template<class IndicesType, class TimesType>
inline const SpikeArray &infer(const IndicesType &indices, const TimesType &times)

Infer the entire SNN using the given input spike indices and times.

Template Parameters
  • IndicesType – Type of spike indices

  • TimesType – Type of spike times

Parameters
  • indices – Input spike indices.

  • times – Input spike times.

Returns

Constant reference on the output spike array.

iterator begin()

Gets an iterator on the first layer.

Returns

An iterator on the first layer.

iterator end()

Gets the end iterator of layers.

Returns

The end iterator of layers.

template<typename T>
inline std::shared_ptr<Layer> operator[](T idx)

Gets the layer at the specified index.

Template Parameters

T – Type of index.

Parameters

idx – The index of the layer.

Returns

A shared pointer on the requested layer.

std::shared_ptr<Layer> get_output_layer()

Gets the output layer.

Returns

A shared pointer on the last layer.

unsigned int get_n_layers() const

Gets the number of layers.

Returns

The number of layers.

Public Static Attributes

static constexpr char default_compile_path[] = "/tmp/evspikesim"

Default compilation path for custom kernel callback sources.