#pragma once #include "constant_integral.hip.hpp" #include "functional.hip.hpp" template struct Sequence { using Type = Sequence; static constexpr index_t nDim = sizeof...(Is); const index_t mData[nDim] = {Is...}; template __host__ __device__ constexpr index_t Get(Number) const { return mData[I]; } __host__ __device__ index_t operator[](index_t i) const { return mData[i]; } // this is ugly, only for nDIm = 4 template __host__ __device__ constexpr auto ReorderByGetNewFromOld(Sequence) const { static_assert(nDim == 4, "nDim != 4"); constexpr auto old_sequence = Type{}; constexpr index_t NR0 = old_sequence.mData[I0]; constexpr index_t NR1 = old_sequence.mData[I1]; constexpr index_t NR2 = old_sequence.mData[I2]; constexpr index_t NR3 = old_sequence.mData[I3]; return Sequence{}; } template __host__ __device__ constexpr auto ReorderByPutOldToNew(Sequence) const { // don't know how to implement this printf("Sequence::ReorderByPutOldToNew not implemented"); assert(false); } template __host__ __device__ constexpr auto PushBack(Number) const { return Sequence{}; } __host__ __device__ constexpr auto PopBack() const; template __host__ __device__ constexpr auto Transform(F f) const { return Sequence{}; } }; template __host__ __device__ constexpr auto sequence_pop_back(Sequence) { static_assert(sizeof...(Is) >= 1, "empty Sequence!"); return Sequence{}; } template __host__ __device__ constexpr auto sequence_sequence_op(Sequence, Sequence, F f) { static_assert(Sequence::nDim == Sequence::nDim, "Dim not the same"); return Sequence{}; } template __host__ __device__ constexpr auto sequence_sequence_add(Sequence, Sequence) { struct add { __host__ __device__ constexpr index_t operator()(index_t x, index_t y) const { return x + y; } }; return sequence_sequence_op(Sequence{}, Sequence{}, add{}); } template __host__ __device__ constexpr auto Sequence::PopBack() const { return sequence_pop_back(Type{}); } template struct accumulate_on_sequence_f { template __host__ __device__ constexpr index_t operator()(IDim) const { return Seq{}.Get(IDim{}); } }; template __host__ __device__ constexpr index_t accumulate_on_sequence(Seq, Reduce, Number) { constexpr index_t a = static_const_reduce_n{}(accumulate_on_sequence_f{}, Reduce{}); return Reduce{}(a, I); }