Skip to content

Commit

Permalink
Aggregate initialise numeric types, resolves #134
Browse files Browse the repository at this point in the history
  • Loading branch information
tom91136 committed Oct 7, 2023
1 parent 9954b7d commit e347d2f
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/acc/ACCStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void ACCStream<T>::nstream()
template <class T>
T ACCStream<T>::dot()
{
T sum = 0.0;
T sum{};

int array_size = this->array_size;
T * restrict a = this->a;
Expand Down
4 changes: 2 additions & 2 deletions src/hip/HIPStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ __global__ void dot_kernel(const T * a, const T * b, T * sum, int array_size)
const size_t local_i = threadIdx.x;
size_t i = blockDim.x * blockIdx.x + local_i;

tb_sum[local_i] = 0.0;
tb_sum[local_i]{};
for (; i < array_size; i += blockDim.x*gridDim.x)
tb_sum[local_i] += a[i] * b[i];

Expand All @@ -269,7 +269,7 @@ T HIPStream<T>::dot()
hipDeviceSynchronize();
check_error();

T sum = 0.0;
T sum{};
for (int i = 0; i < dot_num_blocks; i++)
sum += sums[i];

Expand Down
2 changes: 1 addition & 1 deletion src/kokkos/KokkosStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ T KokkosStream<T>::dot()
Kokkos::View<T*> a(*d_a);
Kokkos::View<T*> b(*d_b);

T sum = 0.0;
T sum{};

Kokkos::parallel_reduce(array_size, KOKKOS_LAMBDA (const long index, T &tmp)
{
Expand Down
10 changes: 5 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void run()
stream->init_arrays(startA, startB, startC);

// Result of the Dot kernel, if used.
T sum = 0.0;
T sum{};

std::vector<std::vector<double>> timings;

Expand Down Expand Up @@ -467,7 +467,7 @@ void check_solution(const unsigned int ntimes, std::vector<T>& a, std::vector<T>
T goldA = startA;
T goldB = startB;
T goldC = startC;
T goldSum = 0.0;
T goldSum{};

const T scalar = startScalar;

Expand All @@ -493,11 +493,11 @@ void check_solution(const unsigned int ntimes, std::vector<T>& a, std::vector<T>
goldSum = goldA * goldB * ARRAY_SIZE;

// Calculate the average error
long double errA = std::accumulate(a.begin(), a.end(), 0.0, [&](double sum, const T val){ return sum + std::fabs(val - goldA); });
long double errA = std::accumulate(a.begin(), a.end(), T{}, [&](double sum, const T val){ return sum + std::fabs(val - goldA); });
errA /= a.size();
long double errB = std::accumulate(b.begin(), b.end(), 0.0, [&](double sum, const T val){ return sum + std::fabs(val - goldB); });
long double errB = std::accumulate(b.begin(), b.end(), T{}, [&](double sum, const T val){ return sum + std::fabs(val - goldB); });
errB /= b.size();
long double errC = std::accumulate(c.begin(), c.end(), 0.0, [&](double sum, const T val){ return sum + std::fabs(val - goldC); });
long double errC = std::accumulate(c.begin(), c.end(), T{}, [&](double sum, const T val){ return sum + std::fabs(val - goldC); });
errC /= c.size();
long double errSum = std::fabs((sum - goldSum)/goldSum);

Expand Down
2 changes: 1 addition & 1 deletion src/ocl/OCLStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ T OCLStream<T>::dot()
);
cl::copy(queue, d_sum, sums.begin(), sums.end());

T sum = 0.0;
T sum{};
for (T val : sums)
sum += val;

Expand Down
2 changes: 1 addition & 1 deletion src/omp/OMPStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ void OMPStream<T>::nstream()
template <class T>
T OMPStream<T>::dot()
{
T sum = 0.0;
T sum{};

#ifdef OMP_TARGET_GPU
int array_size = this->array_size;
Expand Down
2 changes: 1 addition & 1 deletion src/raja/RAJAStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ T RAJAStream<T>::dot()
T* RAJA_RESTRICT a = d_a;
T* RAJA_RESTRICT b = d_b;

RAJA::ReduceSum<reduce_policy, T> sum(0.0);
RAJA::ReduceSum<reduce_policy, T> sum(T{});

forall<policy>(range, [=] RAJA_DEVICE (RAJA::Index_type index)
{
Expand Down
2 changes: 1 addition & 1 deletion src/std-data/STDDataStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ template <class T>
T STDDataStream<T>::dot()
{
// sum = 0; sum += a[i]*b[i]; return sum;
return std::transform_reduce(exe_policy, a, a + array_size, b, 0.0);
return std::transform_reduce(exe_policy, a, a + array_size, b, T{});
}

void listDevices(void)
Expand Down
2 changes: 1 addition & 1 deletion src/std-indices/STDIndicesStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ template <class T>
T STDIndicesStream<T>::dot()
{
// sum = 0; sum += a[i]*b[i]; return sum;
return std::transform_reduce(exe_policy, a, a + array_size, b, 0.0);
return std::transform_reduce(exe_policy, a, a + array_size, b, T{});
}

void listDevices(void)
Expand Down
2 changes: 1 addition & 1 deletion src/std-ranges/STDRangesStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ T STDRangesStream<T>::dot()
return
std::transform_reduce(
exe_policy,
a, a + array_size, b, 0.0);
a, a + array_size, b, T{});
}

void listDevices(void)
Expand Down
4 changes: 2 additions & 2 deletions src/sycl/SYCLStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ T SYCLStream<T>::dot()
size_t li = item.get_local_id(0);
size_t global_size = item.get_global_range()[0];

wg_sum[li] = 0.0;
wg_sum[li] = {};
for (; i < N; i += global_size)
wg_sum[li] += ka[i] * kb[i];

Expand All @@ -208,7 +208,7 @@ T SYCLStream<T>::dot()
});
});

T sum = 0.0;
T sum{};
auto h_sum = d_sum->template get_access<access::mode::read>();
for (int i = 0; i < dot_num_groups; i++)
{
Expand Down

0 comments on commit e347d2f

Please sign in to comment.