genericLayer
template<typename StateTypes> // e.g. thrust::tuple<float,float,float> class genericLayer
Generic layer wrapper holding neuron states and inputs.
-
StateTypes - Thrust tuple describing the per-neuron state variables.
Functions
| Name | Description |
|---|---|
| make_state_tuple | Helper to construct the tuple of state vectors on the device. |
| genericLayer | Constructs a layer with the given neuron count. |
| size | Returns the number of neurons in the layer. |
| state_vec | Access a specific state vector by index. |
| state_vec | Access a specific state vector by index (const overload). |
| make_zip_begin | Create a zip iterator over all state vectors (mutable). |
| make_zip_end | Create a zip iterator over all state vectors (mutable) - end. |
| make_zip_begin | Create a zip iterator over all state vectors (const). |
| make_zip_end | Create a zip iterator over all state vectors (const) - end. |
| full_zip_begin | Create a zip iterator over state and input (mutable). |
| full_zip_end | Create a zip iterator over state and input (mutable) - end. |
| step | Advance the layer state by one integration step using RK4. |
| input | Access the input buffer for modification. |
| input | Access the input buffer (read-only). |
| make_begin_tuple | Build a tuple of begin iterators for all state vectors. |
| make_end_tuple | Build a tuple of end iterators for all state vectors. |
| make_cbegin_tuple | Build a tuple of const begin iterators for all state vectors. |
| make_cend_tuple | Build a tuple of const end iterators for all state vectors. |
Function Details
full_zip_begin
auto full_zip_begin()
Create a zip iterator over state and input (mutable).
The iterator dereferences to a tuple of (state tuple iterator, input value).
- Return
- Iterator to the beginning of the zipped state+input range.
full_zip_end
auto full_zip_end()
Create a zip iterator over state and input (mutable) - end.
- Return
- Iterator to the end of the zipped state+input range.
genericLayer
explicit genericLayer(size_t N)
Constructs a layer with the given neuron count.
-
N - Number of neurons/states to allocate.
input
thrust::device_vector<float>& input() noexcept
Access the input buffer for modification.
- Return
- Reference to the device vector storing input currents.
const thrust::device_vector<float>& input() const noexcept
Access the input buffer (read-only).
- Return
- Const reference to the device vector storing input currents.
make_begin_tuple
template<size_t... I> auto make_begin_tuple(std::index_sequence<I...>)
Build a tuple of begin iterators for all state vectors.
-
I - Index pack over the elements of StateTypes.
- Return
- Thrust tuple of begin iterators.
make_cbegin_tuple
template<size_t... I> auto make_cbegin_tuple(std::index_sequence<I...>) const
Build a tuple of const begin iterators for all state vectors.
-
I - Index pack over the elements of StateTypes.
- Return
- Thrust tuple of const begin iterators.
make_cend_tuple
template<size_t... I> auto make_cend_tuple(std::index_sequence<I...>) const
Build a tuple of const end iterators for all state vectors.
-
I - Index pack over the elements of StateTypes.
- Return
- Thrust tuple of const end iterators.
make_end_tuple
template<size_t... I> auto make_end_tuple(std::index_sequence<I...>)
Build a tuple of end iterators for all state vectors.
-
I - Index pack over the elements of StateTypes.
- Return
- Thrust tuple of end iterators.
make_state_tuple
template<size_t... I> static auto make_state_tuple(size_t N, std::index_sequence<I...>)
Helper to construct the tuple of state vectors on the device.
For each element type in StateTypes, creates a corresponding
thrust::device_vector of size N initialized to zero.
-
I - Index pack over the elements of StateTypes.
-
N - Number of elements in each state vector.
- Return
- Tuple of device vectors matching StateTypes.
make_zip_begin
auto make_zip_begin()
Create a zip iterator over all state vectors (mutable).
Each element of the iterator is a thrust::tuple of references to the components of the neuron state.
- Return
- Iterator to the beginning of the zipped state range.
auto make_zip_begin() const
Create a zip iterator over all state vectors (const).
- Return
- Const iterator to the beginning of the zipped state range.
make_zip_end
auto make_zip_end()
Create a zip iterator over all state vectors (mutable) - end.
- Return
- Iterator to the end of the zipped state range.
auto make_zip_end() const
Create a zip iterator over all state vectors (const) - end.
- Return
- Const iterator to the end of the zipped state range.
size
size_t size() const noexcept
Returns the number of neurons in the layer.
state_vec
template<size_t I> auto& state_vec() noexcept
Access a specific state vector by index.
-
I - Index of the state component in the StateTypes tuple.
- Return
- Reference to the corresponding device vector.
template<size_t I> const auto& state_vec() const noexcept
Access a specific state vector by index (const overload).
-
I - Index of the state component in the StateTypes tuple.
- Return
- Const reference to the corresponding device vector.
step
template<typename RHS_Functor> void step(const RHS_Functor& rhs, float t, float dt, cudaStream_t stream = 0)
Advance the layer state by one integration step using RK4.
Applies the provided RHS functor on all neurons in parallel using Thrust on the given CUDA stream.
-
RHS_Functor - Functor type providing the right-hand side of the ODE. It must be callable from device code.
- See
- Solvers
-
rhs - Right-hand side functor.
-
t - Current time.
-
dt - Time step.
-
stream - CUDA stream to execute the operation on (default 0).