Skip to content

Commit

Permalink
[update] tests (#1057)
Browse files Browse the repository at this point in the history
* small updates

* [ci/cd] run spack build in bwrap sandbox hiding $HOME (#1059)

---------

Co-authored-by: Simon Pintarelli <1237199+simonpintarelli@users.noreply.github.com>
  • Loading branch information
toxa81 and simonpintarelli authored Mar 7, 2025
1 parent fe2fe4b commit b7c671b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
3 changes: 2 additions & 1 deletion apps/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ test_mpi_grid;test_enu;test_eigen;test_gemm;test_wf_inner;test_memop;test_gvec_s
test_mem_pool;test_mem_alloc;test_examples;test_mpi_p2p_cyclic;test_pw_sph_exp;test_mpi_p2p;\
test_wf_ortho;test_mixer;test_davidson;test_lapw_xc;test_phase;test_fp;test_pppw_xc;\
test_atomic_orbital_index;test_sym;test_blacs;test_reduce;test_mpi_comm_split;test_wf_trans;\
test_wf_fft;test_potrf;test_lr_solver;test_radial_solver;test_radial_dirac;test_radial_schroed;test_iter_gvec")
test_wf_fft;test_potrf;test_lr_solver;test_radial_solver;test_radial_dirac;test_radial_schroed;test_iter_gvec;\
test_max_mem")

foreach(_test ${_tests})
add_executable(${_test} ${_test}.cpp)
Expand Down
3 changes: 2 additions & 1 deletion apps/tests/test_gemm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ test_gemm_impl(int M, int N, int K, int transa, la::lib_t la__, memory_t memA__,

c.zero(memC__);
if (!is_host_memory(memC__)) {
c.allocate(memory_t::host);
c.allocate(memory_t::host_pinned);
c.zero();
}

char TA[] = {'N', 'T', 'C'};
Expand Down
7 changes: 5 additions & 2 deletions apps/tests/test_hloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ test_hloc_impl(sirius::Simulation_context& ctx__, int num_bands__, int use_gpu__

sirius::Local_operator<T> hloc(ctx__, fft, gvec_fft);

wf::Wave_functions<T> phi(gvec, wf::num_mag_dims(0), wf::num_bands(4 * num_bands__), memory_t::host);
wf::Wave_functions<T> phi(gvec, wf::num_mag_dims(0), wf::num_bands(4 * num_bands__), memory_t::host_pinned);
#pragma omp patallel for
for (int i = 0; i < 4 * num_bands__; i++) {
for (int j = 0; j < phi.ld(); j++) {
phi.pw_coeffs(j, wf::spin_index(0), wf::band_index(i)) = random<std::complex<T>>();
}
phi.pw_coeffs(0, wf::spin_index(0), wf::band_index(i)) = 1.0;
}
wf::Wave_functions<T> hphi(gvec, wf::num_mag_dims(0), wf::num_bands(4 * num_bands__), memory_t::host);
wf::Wave_functions<T> hphi(gvec, wf::num_mag_dims(0), wf::num_bands(4 * num_bands__), memory_t::host_pinned);

{
auto mem_phi = (use_gpu__) ? memory_t::device : memory_t::host;
Expand All @@ -59,6 +60,7 @@ test_hloc_impl(sirius::Simulation_context& ctx__, int num_bands__, int use_gpu__
}

double diff{0};
#pragma omp parallel for reduction(+:diff)
for (int i = 0; i < 4 * num_bands__; i++) {
for (int j = 0; j < phi.ld(); j++) {
int ig = gvec->offset() + j;
Expand All @@ -69,6 +71,7 @@ test_hloc_impl(sirius::Simulation_context& ctx__, int num_bands__, int use_gpu__
2);
}
}

if (diff != diff) {
RTE_THROW("NaN");
}
Expand Down
49 changes: 49 additions & 0 deletions apps/tests/test_max_mem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* This file is part of SIRIUS electronic structure library.
*
* Copyright (c), ETH Zurich. All rights reserved.
*
* Please, refer to the LICENSE file in the root directory.
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <sirius.hpp>
#include "testing.hpp"

using namespace sirius;

int
test_max_mem(cmd_args const& args)
{
std::cout << "Free avaialble memory : " << (get_available_memory() >> 30) << " Gb" << std::endl;
auto M = get_memory_t(args.value<std::string>("memory_t", "host"));
size_t size = args.value<int>("size", 1);

//std::cout << "attempting to allocate " << size << " Gb" << std::endl;
//size *= (1 << 30);
//mdarray<char, 1> a({size}, M);
//a.zero(M);

std::vector<mdarray<char, 1>> v;
for (int i = 0; i < 100; i++) {
std::cout << "step : " << i << std::endl;
std::cout << "attempting to allocate " << size << " Gb" << std::endl;
v.push_back(mdarray<char, 1>({size * (1 << 30)}, M));
v.back().zero(M);
print_memory_usage(std::cout);
std::cout << std::flush;
}

return 0;
}

int
main(int argn, char** argv)
{
cmd_args args(argn, argv,
{{"memory_t=", "{string} type of the memory"}, {"size=", "{int} size of array in Gb"}});

sirius::initialize(1);
int result = call_test("test_max_mem", test_max_mem, args);
sirius::finalize();
return result;
}

0 comments on commit b7c671b

Please sign in to comment.