Skip to content
Snippets Groups Projects
Commit d9839df0 authored by Ben Cumming's avatar Ben Cumming Committed by Sam Yates
Browse files

remove small cudaMemcpys (#175)

This patch removes the many small `cudaMemcpy` calls for single values, except for those from calling `net_receive` in event delivery.

The small copies during initialization were from when the upper diagonal and time invariant component of the diagonal were computed on the host. There were many small reads/writes to device memory accessing the `p` and `u` vectors.

* Remove many small device copies in matrix setup by copying required data to host, computing, and then copying back in one copy.
* Add `constexpr` test `is_debug_mode()` for having been compiled in debug mode (tests `NDEBUG`).
* Only perform `is_physical_solution` test if `is_debug_mode()` is true. (The `is_physical_solution` test triggers a single copy from device to host on each time step to test whether the voltage has exceeded some "reasonable" physical bounds.)
parent 0e0bcd8f
No related branches found
No related tags found
No related merge requests found
......@@ -118,17 +118,20 @@ struct backend {
{
auto n = d.size();
host_array invariant_d_tmp(n, 0);
host_array u_tmp(n, 0);
// make a copy of the conductance on the host
host_array face_conductance_tmp = face_conductance;
auto p_tmp = memory::on_host(p);
for(auto i: util::make_span(1u, n)) {
auto gij = face_conductance_tmp[i];
u[i] = -gij;
u_tmp[i] = -gij;
invariant_d_tmp[i] += gij;
invariant_d_tmp[p[i]] += gij;
invariant_d_tmp[p_tmp[i]] += gij;
}
invariant_d = invariant_d_tmp;
memory::copy(u_tmp, u);
params = {
d.data(), u.data(), rhs.data(),
......
......@@ -106,7 +106,7 @@ public:
time_type tnext = next ? next->time: tstep;
cell_.advance(tnext - cell_.time());
if (!cell_.is_physical_solution()) {
if (util::is_debug_mode() && !cell_.is_physical_solution()) {
std::cerr << "warning: solution out of bounds for cell "
<< gid_base_ << " at t " << cell_.time() << " ms\n";
}
......
......@@ -11,6 +11,13 @@ namespace nest {
namespace mc {
namespace util {
constexpr inline bool is_debug_mode() {
#ifndef NDEBUG
return true;
#else
return false;
#endif
}
using failed_assertion_handler_t =
bool (*)(const char* assertion, const char* file, int line, const char* func);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment