Skip to content

Commit 2e4bff0

Browse files
authored
Merge pull request #227 from BenjaminW3/topic-constification
constification
2 parents afbc552 + 6b047f2 commit 2e4bff0

File tree

16 files changed

+52
-47
lines changed

16 files changed

+52
-47
lines changed

example/bufferCopy/src/bufferCopy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ auto main()
169169
/***************************************************************************
170170
* Get the first device
171171
**************************************************************************/
172-
DevAcc devAcc(alpaka::pltf::getDevByIdx<PltfAcc>(0u));
173-
DevHost devHost(alpaka::pltf::getDevByIdx<PltfHost>(0u));
172+
DevAcc const devAcc(alpaka::pltf::getDevByIdx<PltfAcc>(0u));
173+
DevHost const devHost(alpaka::pltf::getDevByIdx<PltfHost>(0u));
174174

175175
/***************************************************************************
176176
* Create sync stream

example/helloWorld/src/helloWorld.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ auto main()
117117
* can also retrieve all devices in a vector (getDevs()).
118118
* In this example the first devices is choosen.
119119
*/
120-
DevAcc devAcc(alpaka::pltf::getDevByIdx<PltfAcc>(0u));
121-
DevHost devHost(alpaka::pltf::getDevByIdx<PltfHost>(0u));
120+
DevAcc const devAcc(alpaka::pltf::getDevByIdx<PltfAcc>(0u));
121+
DevHost const devHost(alpaka::pltf::getDevByIdx<PltfHost>(0u));
122122

123123
/**
124124
* Create a stream to the accelerator device

example/vectorAdd/src/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@ auto main()
9999
VectorAddKernel kernel;
100100

101101
// Get the host device.
102-
auto devHost(
102+
auto const devHost(
103103
alpaka::pltf::getDevByIdx<PltfHost>(0u));
104104

105105
// Select a device to execute on.
106-
auto devAcc(
106+
auto const devAcc(
107107
alpaka::pltf::getDevByIdx<PltfAcc>(0));
108108

109109
// Get a stream on this device.

include/alpaka/mem/view/Traits.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include <alpaka/stream/Traits.hpp> // stream::enqueue
3030

3131
#include <alpaka/vec/Vec.hpp> // Vec
32-
3332
#include <alpaka/meta/Fold.hpp> // meta::foldr
3433
#include <alpaka/core/Common.hpp> // ALPAKA_FN_HOST
3534

@@ -566,13 +565,7 @@ namespace alpaka
566565
rowPrefix,
567566
rowSuffix);
568567
}
569-
}
570-
}
571568

572-
namespace mem
573-
{
574-
namespace view
575-
{
576569
namespace detail
577570
{
578571
//#############################################################################

include/alpaka/mem/view/ViewPlainPtr.hpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

include/alpaka/mem/view/ViewSubView.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ namespace alpaka
5454
using Dev = TDev;
5555
using Elem = TElem;
5656
using Dim = TDim;
57-
using ViewParentView = mem::view::ViewPlainPtr<TDev, TElem, TDim, TSize>;
5857

5958
public:
6059
//-----------------------------------------------------------------------------
@@ -175,7 +174,7 @@ namespace alpaka
175174
}
176175

177176
public:
178-
ViewParentView m_viewParentView; // This wraps the parent view.
177+
mem::view::ViewPlainPtr<TDev, TElem, TDim, TSize> m_viewParentView; // This wraps the parent view.
179178
Vec<TDim, TSize> m_extentElements; // The extent of this view.
180179
Vec<TDim, TSize> m_offsetsElements; // The offset relative to the parent view.
181180
};

include/alpaka/stream/StreamCpuAsync.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ namespace alpaka
7676
//! Constructor.
7777
//-----------------------------------------------------------------------------
7878
ALPAKA_FN_HOST StreamCpuAsyncImpl(
79-
dev::DevCpu & dev) :
79+
dev::DevCpu const & dev) :
8080
m_uuid(boost::uuids::random_generator()()),
8181
m_dev(dev),
8282
m_workerThread(1u, 128u)
@@ -123,7 +123,7 @@ namespace alpaka
123123
//! Constructor.
124124
//-----------------------------------------------------------------------------
125125
ALPAKA_FN_HOST StreamCpuAsync(
126-
dev::DevCpu & dev) :
126+
dev::DevCpu const & dev) :
127127
m_spAsyncStreamCpu(std::make_shared<cpu::detail::StreamCpuAsyncImpl>(dev))
128128
{
129129
dev.m_spDevCpuImpl->RegisterAsyncStream(m_spAsyncStreamCpu);

include/alpaka/stream/StreamCpuSync.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ namespace alpaka
5858
//! Constructor.
5959
//-----------------------------------------------------------------------------
6060
ALPAKA_FN_HOST StreamCpuSyncImpl(
61-
dev::DevCpu & dev) :
61+
dev::DevCpu const & dev) :
6262
m_uuid(boost::uuids::random_generator()()),
6363
m_dev(dev)
6464
{}
@@ -100,7 +100,7 @@ namespace alpaka
100100
//! Constructor.
101101
//-----------------------------------------------------------------------------
102102
ALPAKA_FN_HOST StreamCpuSync(
103-
dev::DevCpu & dev) :
103+
dev::DevCpu const & dev) :
104104
m_spSyncStreamCpu(std::make_shared<cpu::detail::StreamCpuSyncImpl>(dev))
105105
{}
106106
//-----------------------------------------------------------------------------

include/alpaka/stream/StreamCudaRtAsync.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ namespace alpaka
141141
//! Constructor.
142142
//-----------------------------------------------------------------------------
143143
ALPAKA_FN_HOST StreamCudaRtAsync(
144-
dev::DevCudaRt & dev) :
144+
dev::DevCudaRt const & dev) :
145145
m_spStreamCudaRtAsyncImpl(std::make_shared<cuda::detail::StreamCudaRtAsyncImpl>(dev))
146146
{}
147147
//-----------------------------------------------------------------------------

include/alpaka/stream/StreamCudaRtSync.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ namespace alpaka
141141
//! Constructor.
142142
//-----------------------------------------------------------------------------
143143
ALPAKA_FN_HOST StreamCudaRtSync(
144-
dev::DevCudaRt & dev) :
144+
dev::DevCudaRt const & dev) :
145145
m_spStreamCudaRtSyncImpl(std::make_shared<cuda::detail::StreamCudaRtSyncImpl>(dev))
146146
{}
147147
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)