Aggregate initialise numeric types, resolves #134

This commit is contained in:
Tom Lin 2023-10-07 09:41:18 +01:00
parent 9954b7d38c
commit e347d2ff6c
11 changed files with 17 additions and 17 deletions

View File

@ -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;

View File

@ -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];
@ -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];

View File

@ -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)
{

View File

@ -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;
@ -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;
@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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)
{

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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];
@ -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++)
{