Skip to content

Commit

Permalink
Merge branch 'add_init_value_to_reduce' into 'master'
Browse files Browse the repository at this point in the history
Add init value to reduce

See merge request npneq/inq!1153
  • Loading branch information
xavierandrade committed Oct 23, 2024
2 parents 4649d03 + 8638b17 commit c962fea
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 84 deletions.
147 changes: 73 additions & 74 deletions external_libs/gpurun/include/gpu/reduce.hpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ground_state/calculator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class calculator {
assert(el.occupations()[iphi].size() == normres[iphi].size());

auto func = state_conv_func<decltype(begin(el.occupations()[iphi])), decltype(begin(normres[iphi]))>{begin(el.occupations()[iphi]), begin(normres[iphi])};
state_conv += gpu::run(gpu::reduce(normres[iphi].size()), func);
state_conv += gpu::run(gpu::reduce(normres[iphi].size()), 0.0, func);
}

el.kpin_states_comm().all_reduce_n(&state_conv, 1);
Expand Down
2 changes: 1 addition & 1 deletion src/hamiltonian/energy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace hamiltonian {

assert(occupations.size() == array.size());
auto func = occ_sum_func<decltype(begin(occupations)), decltype(begin(array))>{begin(occupations), begin(array)};
return gpu::run(gpu::reduce(array.size()), func);
return gpu::run(gpu::reduce(array.size()), 0.0, func);
}

public:
Expand Down
2 changes: 1 addition & 1 deletion src/hamiltonian/ks_hamiltonian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ks_hamiltonian {

assert(occupations.size() == array.size());
auto func = occ_sum_func<decltype(begin(occupations)), decltype(begin(array))>{begin(occupations), begin(array)};
return gpu::run(gpu::reduce(array.size()), func);
return gpu::run(gpu::reduce(array.size()), 0.0, func);
}

public:
Expand Down
4 changes: 2 additions & 2 deletions src/hamiltonian/projector_all.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class projector_all {
phi.basis().comm().all_reduce_in_place_n(raw_pointer_cast(projections_all.data_elements()), projections_all.num_elements(), std::plus<>{});
}

auto en = gpu::run(gpu::reduce(phi.local_set_size()), gpu::reduce(max_nlm_), gpu::reduce(nprojs_),
auto en = gpu::run(gpu::reduce(phi.local_set_size()), gpu::reduce(max_nlm_), gpu::reduce(nprojs_), 0.0,
energy_reduction<decltype(begin(projections_all)), decltype(begin(coeff_)), decltype(begin(occupations))>
{begin(projections_all), begin(coeff_), begin(occupations), phi.local_spinor_set_size()});

Expand Down Expand Up @@ -399,7 +399,7 @@ class projector_all {
if(locally_empty_[iproj]) continue;

CALI_CXX_MARK_SCOPE("projector_force_sum");
force[iproj] = gpu::run(gpu::reduce(phi.local_set_size()), gpu::reduce(max_sphere_size_),
force[iproj] = gpu::run(gpu::reduce(phi.local_set_size()), gpu::reduce(max_sphere_size_), zero<vector3<double, covariant>>(),
force_term<decltype(begin(occs)), decltype(begin(sphere_phi_all[iproj])), decltype(begin(sphere_gphi_all[iproj]))>{begin(occs), begin(sphere_phi_all[iproj]), begin(sphere_gphi_all[iproj])});
}

Expand Down
2 changes: 1 addition & 1 deletion src/observables/forces_stress.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct forces_stress {
auto ionic_long_range = solvers::poisson::solve(electrons.atomic_pot().ionic_density(electrons.states_comm(), electrons.density_basis(), ions, iatom));
auto ionic_short_range = electrons.atomic_pot().local_potential(electrons.states_comm(), electrons.density_basis(), ions, iatom);

auto force_cov = -gpu::run(gpu::reduce(electrons.density_basis().local_size()),
auto force_cov = -gpu::run(gpu::reduce(electrons.density_basis().local_size()), zero<vector3<double, inq::covariant>>(),
loc_pot<decltype(begin(ionic_long_range.linear())), decltype(begin(ionic_short_range.linear())), decltype(begin(gdensity.linear()))>
{begin(ionic_long_range.linear()), begin(ionic_short_range.linear()), begin(gdensity.linear())});

Expand Down
4 changes: 2 additions & 2 deletions src/operations/overlap_diagonal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ gpu::array<typename PhiMatrix::element_type, 1> overlap_diagonal_impl(Basis cons
overlap_vector[0] = blas::dot(blas::C(phi1_matrix.rotated()[0]), phi2_matrix.rotated()[0]);
overlap_vector[0] *= basis.volume_element();
} else {
overlap_vector = gpu::run(nn, gpu::reduce(phi1_matrix.size()),
overlap_vector = gpu::run(nn, gpu::reduce(phi1_matrix.size()), zero<type>(),
overlap_diagonal_mult<decltype(begin(phi1_matrix))>{basis.volume_element(), begin(phi1_matrix), begin(phi2_matrix)});
}

Expand Down Expand Up @@ -152,7 +152,7 @@ auto overlap_diagonal_normalized_impl(Basis const & basis, PhiMatrix const & phi

using type = typename PhiMatrix::element_type;

auto overlap_and_norm = gpu::run(nn, gpu::reduce(phi1_matrix.size()),
auto overlap_and_norm = gpu::run(nn, gpu::reduce(phi1_matrix.size()), zero<value_and_norm<type>>(),
overlap_diagonal_normalized_mult<decltype(begin(phi1_matrix))>{begin(phi1_matrix), begin(phi2_matrix)});

if(basis.comm().size() > 1){
Expand Down
5 changes: 3 additions & 2 deletions src/operations/sum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ template <class array_type>
typename array_type::element sum(const array_type & phi){

CALI_CXX_MARK_SCOPE("sum(1arg)");
if(phi.size() == 0) return zero<typename array_type::element>();
return gpu::run(gpu::reduce(phi.size()), gpu::array_access<decltype(begin(phi))>{begin(phi)});
auto init = zero<typename array_type::element>();
if(phi.size() == 0) return init;
return gpu::run(gpu::reduce(phi.size()), init, gpu::array_access<decltype(begin(phi))>{begin(phi)});
}

template <class ArrayType, class UnaryOp>
Expand Down

0 comments on commit c962fea

Please sign in to comment.