Skip to content
This repository has been archived by the owner on Mar 20, 2023. It is now read-only.

Fixes for NVHPC 22.5 #842

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions coreneuron/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,9 @@ if(CORENRN_ENABLE_GPU)
endif()

# =============================================================================
# eion.cpp depends on CORENRN_USE_LEGACY_UNITS
# CORENEURON_USE_LEGACY_UNITS is used in membfunc.hpp so define it everywhere
# =============================================================================
set(LegacyFR_FILES
${CMAKE_CURRENT_SOURCE_DIR}/mechanism/eion.cpp ${CMAKE_CURRENT_SOURCE_DIR}/apps/main1.cpp
${CMAKE_CURRENT_SOURCE_DIR}/io/global_vars.cpp)

set_property(
SOURCE ${LegacyFR_FILES}
APPEND
PROPERTY COMPILE_DEFINITIONS "CORENRN_USE_LEGACY_UNITS=${CORENRN_USE_LEGACY_UNITS}")
add_compile_definitions(CORENEURON_USE_LEGACY_UNITS=${CORENRN_USE_LEGACY_UNITS})

# =============================================================================
# create libraries
Expand Down
9 changes: 4 additions & 5 deletions coreneuron/apps/main1.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
# =============================================================================
# Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
# Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
#
# See top-level LICENSE file for details.
# =============================================================================.
Expand Down Expand Up @@ -51,9 +51,9 @@ const char* corenrn_version() {
return coreneuron::bbcore_write_version;
}

// the CORENRN_USE_LEGACY_UNITS determined by CORENRN_ENABLE_LEGACY_UNITS
// the CORENEURON_USE_LEGACY_UNITS determined by CORENRN_ENABLE_LEGACY_UNITS
bool corenrn_units_use_legacy() {
return CORENRN_USE_LEGACY_UNITS;
return CORENEURON_USE_LEGACY_UNITS;
}

void (*nrn2core_part2_clean_)();
Expand Down Expand Up @@ -562,8 +562,7 @@ extern "C" int run_solve_core(int argc, char** argv) {
}
#endif
bool compute_gpu = corenrn_param.gpu;

nrn_pragma_acc(update device(celsius, secondorder, pi) if (compute_gpu))
nrn_pragma_acc(data copyin(celsius, secondorder, pi) if (compute_gpu))
nrn_pragma_omp(target update to(celsius, secondorder, pi) if (compute_gpu))
{
double v = corenrn_param.voltage;
Expand Down
2 changes: 1 addition & 1 deletion coreneuron/io/global_vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void set_globals(const char* path, bool cli_global_seed, int cli_global_seed_val
} else if (strcmp(name, "Random123_globalindex") == 0) {
nrnran123_set_globalindex((uint32_t) n);
} else if (strcmp(name, "_nrnunit_use_legacy_") == 0) {
if (n != CORENRN_USE_LEGACY_UNITS) {
if (n != CORENEURON_USE_LEGACY_UNITS) {
hoc_execerror(
"CORENRN_ENABLE_LEGACY_UNITS not"
" consistent with NEURON value of"
Expand Down
48 changes: 10 additions & 38 deletions coreneuron/mechanism/eion.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
# =============================================================================
# Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
# Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
#
# See top-level LICENSE file for details.
# =============================================================================.
Expand Down Expand Up @@ -154,23 +154,9 @@ the USEION statement of any model using this ion\n",
}
}

#ifndef CORENRN_USE_LEGACY_UNITS
#define CORENRN_USE_LEGACY_UNITS 0
#endif

#if CORENRN_USE_LEGACY_UNITS == 1
#define FARADAY 96485.309
#define gasconstant 8.3134
#else
#include "coreneuron/nrnoc/nrnunits_modern.h"
#define FARADAY _faraday_codata2018
#define gasconstant _gasconstant_codata2018
#endif

#define ktf (1000. * gasconstant * (celsius + 273.15) / FARADAY)

double nrn_nernst(double ci, double co, double z, double celsius) {
/*printf("nrn_nernst %g %g %g\n", ci, co, z);*/
// std::log isn't constexpr, but there are argument values for which nrn_nernst
// is a constant expression
constexpr double nrn_nernst(double ci, double co, double z, double celsius) {
if (z == 0) {
return 0.;
}
Expand All @@ -179,7 +165,7 @@ double nrn_nernst(double ci, double co, double z, double celsius) {
} else if (co <= 0.) {
return -1e6;
} else {
return ktf / z * log(co / ci);
return ktf(celsius) / z * std::log(co / ci);
}
}

Expand All @@ -200,24 +186,8 @@ void nrn_wrote_conc(int type,
pe[0] = nrn_nernst(pe[1 * _STRIDE], pe[2 * _STRIDE], gimap[type][2], celsius);
}
}

static double efun(double x) {
if (fabs(x) < 1e-4) {
return 1. - x / 2.;
} else {
return x / (exp(x) - 1);
}
}

nrn_pragma_omp(end declare target)

double nrn_ghk(double v, double ci, double co, double z) {
double temp = z * v / ktf;
double eco = co * efun(temp);
double eci = ci * efun(-temp);
return (.001) * z * FARADAY * (eci - eco);
}

#if VECTORIZE
#define erev pd[0 * _STRIDE] /* From Eion */
#define conci pd[1 * _STRIDE]
Expand Down Expand Up @@ -257,7 +227,7 @@ ion_style("name_ion", [c_style, e_style, einit, eadvance, cinit])

double nrn_nernst_coef(int type) {
/* for computing jacobian element dconc'/dconc */
return ktf / charge;
return ktf(celsius) / charge;
}

/* Must be called prior to any channels which update the currents */
Expand All @@ -271,7 +241,8 @@ void nrn_cur_ion(NrnThread* nt, Memb_list* ml, int type) {
pd = ml->data;
ppd = ml->pdata;
// clang-format off
nrn_pragma_acc(parallel loop present(pd[0:_cntml_padded * 5],
nrn_pragma_acc(parallel loop present(celsius,
pd[0:_cntml_padded * 5],
ppd[0:_cntml_actual],
nrn_ion_global_map[0:nrn_ion_global_map_size]
[0:ion_global_map_member_size])
Expand Down Expand Up @@ -311,7 +282,8 @@ void nrn_init_ion(NrnThread* nt, Memb_list* ml, int type) {
// verify if this can be made asynchronous or if there is a strong reason it
// needs to be like this.
// clang-format off
nrn_pragma_acc(parallel loop present(pd[0:_cntml_padded * 5],
nrn_pragma_acc(parallel loop present(celsius,
pd[0:_cntml_padded * 5],
ppd[0:_cntml_actual],
nrn_ion_global_map[0:nrn_ion_global_map_size]
[0:ion_global_map_member_size])
Expand Down
36 changes: 27 additions & 9 deletions coreneuron/mechanism/membfunc.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/*
# =============================================================================
# Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
# Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
#
# See top-level LICENSE file for details.
# =============================================================================.
*/

#pragma once

#include <vector>

#include "coreneuron/mechanism/mechanism.hpp"
#include "coreneuron/utils/offload.hpp"
#include "coreneuron/utils/units.hpp"

#include <cmath>
#include <vector>

namespace coreneuron {

using Pfrpdat = Datum* (*) (void);
Expand Down Expand Up @@ -112,12 +114,28 @@ extern void nrn_jacob_capacitance(NrnThread*, Memb_list*, int);
extern void nrn_writes_conc(int, int);
nrn_pragma_omp(declare target)
nrn_pragma_acc(routine seq)
extern void nrn_wrote_conc(int, double*, int, int, double**, double, int);
nrn_pragma_acc(routine seq)
double nrn_nernst(double ci, double co, double z, double celsius);
nrn_pragma_acc(routine seq)
extern double nrn_ghk(double v, double ci, double co, double z);
void nrn_wrote_conc(int, double*, int, int, double**, double, int);
nrn_pragma_omp(end declare target)
constexpr double ktf(double celsius) {
return 1000. * units::gasconstant * (celsius + 273.15) / units::faraday;
}
inline double nrn_ghk(double v, double ci, double co, double z, double celsius) {
auto const efun = [](double x) {
if (std::abs(x) < 1e-4) {
return 1. - x / 2.;
} else {
return x / (std::exp(x) - 1.);
}
};
double const temp{z * v / ktf(celsius)};
double const eco{co * efun(+temp)};
double const eci{ci * efun(-temp)};
return .001 * z * units::faraday * (eci - eco);
}
// Overload using the global celsius variable
inline double nrn_ghk(double v, double ci, double co, double z) {
return nrn_ghk(v, ci, co, z, celsius);
}
extern void hoc_register_prop_size(int, int, int);
extern void hoc_register_dparam_semantics(int type, int, const char* name);
extern void hoc_reg_ba(int, mod_f_t, int);
Expand Down
10 changes: 2 additions & 8 deletions coreneuron/nrnconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,10 @@ using Symbol = char;
#define VEC_AREA(i) (_nt->_actual_area[(i)])
#define VECTORIZE 1

// extern variables require acc declare
// Defined in register_mech.cpp
nrn_pragma_omp(declare target)
extern double celsius;
nrn_pragma_acc(declare create(celsius))

extern double pi;
nrn_pragma_acc(declare create(pi))

extern double celsius, pi;
extern int secondorder;
nrn_pragma_acc(declare create(secondorder))
nrn_pragma_omp(end declare target)

extern double t, dt;
Expand Down
36 changes: 0 additions & 36 deletions coreneuron/nrnoc/nrnunits_modern.h

This file was deleted.

Loading