@@ -57,15 +57,8 @@ namespace alpaka
5757 m_pMem(pMem),
5858 m_dev(dev),
5959 m_extentElements(extent::getExtentVecEnd<TDim>(extent)),
60- m_pitchBytes(Vec<TDim, TSize>::all(0 ))
61- {
62- // Calculate the pitches by hand.
63- m_pitchBytes[TDim::value - 1u ] = extent[TDim::value - 1u ] * sizeof (TElem);
64- for (TSize i = TDim::value - 1u ; i > static_cast <TSize>(0u ); --i)
65- {
66- m_pitchBytes[i-1 ] = extent[i-1 ] * m_pitchBytes[i];
67- }
68- }
60+ m_pitchBytes(calculatePitchesFromExtents(m_extentElements))
61+ {}
6962
7063 // -----------------------------------------------------------------------------
7164 // ! Constructor
@@ -116,11 +109,31 @@ namespace alpaka
116109 ALPAKA_NO_HOST_ACC_WARNING
117110 ALPAKA_FN_HOST_ACC ~ViewPlainPtr () = default ;
118111
112+ private:
113+ // -----------------------------------------------------------------------------
114+ // ! Calculate the pitches purely from the extents.
115+ // -----------------------------------------------------------------------------
116+ ALPAKA_NO_HOST_ACC_WARNING
117+ template <
118+ typename TExtent>
119+ ALPAKA_FN_HOST_ACC static auto calculatePitchesFromExtents (
120+ TExtent const & extent)
121+ -> Vec<TDim, TSize>
122+ {
123+ Vec<TDim, TSize> pitchBytes (Vec<TDim, TSize>::all (0 ));
124+ pitchBytes[TDim::value - 1u ] = extent[TDim::value - 1u ] * sizeof (TElem);
125+ for (TSize i = TDim::value - 1u ; i > static_cast <TSize>(0u ); --i)
126+ {
127+ pitchBytes[i-1 ] = extent[i-1 ] * pitchBytes[i];
128+ }
129+ return pitchBytes;
130+ }
131+
119132 public:
120- TElem * m_pMem;
121- TDev m_dev;
122- Vec<TDim, TSize> m_extentElements;
123- Vec<TDim, TSize> m_pitchBytes;
133+ TElem * const m_pMem;
134+ TDev const m_dev;
135+ Vec<TDim, TSize> const m_extentElements;
136+ Vec<TDim, TSize> const m_pitchBytes;
124137 };
125138 }
126139 }
0 commit comments