Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using std::integral_constant for model_detail::forEachInTuple #129

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions RTNeural/ModelT.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ namespace modelt_detail

/** Functions to do a function for each element in the tuple */
template <typename Fn, typename Tuple, size_t... Ix>
constexpr void forEachInTuple(Fn&& fn, Tuple&& tuple, std::index_sequence<Ix...>) noexcept(noexcept(std::initializer_list<int> { (fn(std::get<Ix>(tuple), Ix), 0)... }))
constexpr void forEachInTuple(Fn&& fn, Tuple&& tuple, std::index_sequence<Ix...>) noexcept(noexcept(std::initializer_list<int> { (fn(std::get<Ix>(tuple), std::integral_constant<size_t, Ix>()), 0)... }))
{
(void)std::initializer_list<int> { ((void)fn(std::get<Ix>(tuple), Ix), 0)... };
(void)std::initializer_list<int> { ((void)fn(std::get<Ix>(tuple), std::integral_constant<size_t, Ix>()), 0)... };
}

template <typename T>
Expand Down
2 changes: 1 addition & 1 deletion RTNeural/RTNeural.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <limits>

// RTNeural includes:
#include "config.h"
#include "Model.h"
#include "ModelT.h"
#include "config.h"
#include "model_loader.h"
#include "torch_helpers.h"
4 changes: 2 additions & 2 deletions RTNeural/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
for which instructions may be found in the RADSan repository above.
*/
#ifdef RTNEURAL_RADSAN_ENABLED
#define RTNEURAL_REALTIME [[clang::realtime]]
#define RTNEURAL_REALTIME [[clang::realtime]]
#else
#define RTNEURAL_REALTIME
#define RTNEURAL_REALTIME
#endif
6 changes: 3 additions & 3 deletions RTNeural/conv1d/conv1d.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Conv1D final : public Layer<T>
// set state pointers to particular columns of the buffer
setStatePointers();

if (groups == 1)
if(groups == 1)
{
// copy selected columns to a helper variable
for(int k = 0; k < kernel_size; ++k)
Expand Down Expand Up @@ -198,7 +198,7 @@ class Conv1DT
/** Resets the layer state. */
RTNEURAL_REALTIME void reset();

template<int _groups = groups, std::enable_if_t<_groups == 1, bool> = true>
template <int _groups = groups, std::enable_if_t<_groups == 1, bool> = true>
/** Performs forward propagation for this layer. */
RTNEURAL_REALTIME inline void forward(const T (&ins)[in_size]) noexcept
{
Expand Down Expand Up @@ -230,7 +230,7 @@ class Conv1DT
state_ptr = (state_ptr == state_size - 1 ? 0 : state_ptr + 1); // iterate state pointer forwards
}

template<int _groups = groups, std::enable_if_t<_groups != 1, bool> = true>
template <int _groups = groups, std::enable_if_t<_groups != 1, bool> = true>
/** Performs forward propagation for this layer. */
inline void forward(const T (&ins)[in_size]) noexcept
{
Expand Down
6 changes: 3 additions & 3 deletions RTNeural/conv1d/conv1d_eigen.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Conv1D : public Layer<T>
// set state pointers to the particular columns of the buffer
setStatePointers();

if (groups == 1)
if(groups == 1)
{
// copy selected columns to a helper variable
for(int k = 0; k < kernel_size; ++k)
Expand Down Expand Up @@ -175,7 +175,7 @@ class Conv1DT
RTNEURAL_REALTIME void reset();

/** Performs forward propagation for this layer. */
template<int _groups = groups, std::enable_if_t<_groups == 1, bool> = true>
template <int _groups = groups, std::enable_if_t<_groups == 1, bool> = true>
RTNEURAL_REALTIME inline void forward(const Eigen::Matrix<T, in_size, 1>& ins) noexcept
{
// insert input into a circular buffer
Expand All @@ -196,7 +196,7 @@ class Conv1DT
}

/** Performs forward propagation for this layer (groups > 1). */
template<int _groups = groups, std::enable_if_t<_groups != 1, bool> = true>
template <int _groups = groups, std::enable_if_t<_groups != 1, bool> = true>
RTNEURAL_REALTIME inline void forward(const Eigen::Matrix<T, in_size, 1>& ins) noexcept
{
// insert input into a circular buffer
Expand Down
8 changes: 4 additions & 4 deletions RTNeural/conv1d/conv1d_xsimd.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include "../Layer.h"
#include "../common.h"
#include "../config.h"
#include <iostream>
#include <numeric>
#include <vector>
#include <iostream>

namespace RTNEURAL_NAMESPACE
{
Expand Down Expand Up @@ -54,7 +54,7 @@ class Conv1D : public Layer<T>
// set state pointers to particular columns of the buffer
setStatePointers();

if (groups == 1)
if(groups == 1)
{
// copy selected columns to a helper variable
for(int k = 0; k < kernel_size; ++k)
Expand Down Expand Up @@ -220,10 +220,10 @@ class Conv1DT
{
// copy selected columns to a helper variable
// @TODO: I'm not sure the reinterpret_casts are 100% safe here, but they seem to work in testing!
const auto& column = reinterpret_cast<std::array<T, in_size>&> (state[state_ptrs[j]]);
const auto& column = reinterpret_cast<std::array<T, in_size>&>(state[state_ptrs[j]]);
const auto column_begin = column.begin() + ii;
const auto column_end = column_begin + filters_per_group;
std::copy(column_begin, column_end, reinterpret_cast<std::array<T, filters_per_group>&> (state_cols[j]).begin());
std::copy(column_begin, column_end, reinterpret_cast<std::array<T, filters_per_group>&>(state_cols[j]).begin());

accum += std::inner_product(
subWeights[j].begin(),
Expand Down
2 changes: 1 addition & 1 deletion RTNeural/dense/dense_xsimd.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ class DenseT<T, 1, out_sizet>
for(int i = 0; i < v_out_size; ++i)
outs[i] = bias[i];

const auto in = ins[0].get (0);
const auto in = ins[0].get(0);
for(int i = 0; i < v_out_size; ++i)
outs[i] += in * weights[i];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/torch_conv1d_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void testTorchConv1DModel()
}

std::ifstream modelOutputsFile { std::string { RTNEURAL_ROOT_DIR } + "test_data/conv1d_torch_y_python.csv" };
const auto expected_y = RTNeural::torch_helpers::detail::transpose(load_csv::loadFile2d<T> (modelOutputsFile));
const auto expected_y = RTNeural::torch_helpers::detail::transpose(load_csv::loadFile2d<T>(modelOutputsFile));

for(size_t n = 0; n < expected_y.size(); ++n)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/torch_microtcn_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "RTNeural/RTNeural.h"
#include "load_csv.hpp"

#if ! (RTNEURAL_USE_EIGEN || RTNEURAL_USE_XSIMD)
#if !(RTNEURAL_USE_EIGEN || RTNEURAL_USE_XSIMD)

namespace
{
Expand Down