Skip to content

Commit

Permalink
CMake MUSIC setup from #2092
Browse files Browse the repository at this point in the history
  • Loading branch information
alexsavulescu committed Feb 8, 2023
1 parent 06ce9c7 commit d5df041
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 16 deletions.
4 changes: 4 additions & 0 deletions cmake/NeuronFileLists.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ set(IVOS_FILES_LIST listimpl.cpp string.cpp observe.cpp regexp.cpp resource.cpp)

set(MPI_DYNAMIC_INCLUDE nrnmpi_dynam.h nrnmpi_dynam_cinc nrnmpi_dynam_wrappers.inc)

set(NRN_MUSIC_FILES_LIST nrnmusic.cpp)

# =============================================================================
# Top level directories under src
# =============================================================================
Expand All @@ -538,6 +540,7 @@ set(NRN_NRNIV_SRC_DIR ${PROJECT_SOURCE_DIR}/src/nrniv)
set(NRN_MODLUNIT_SRC_DIR ${PROJECT_SOURCE_DIR}/src/modlunit)
set(NRN_NMODL_SRC_DIR ${PROJECT_SOURCE_DIR}/src/nmodl)
set(NRN_IVOS_SRC_DIR ${PROJECT_SOURCE_DIR}/src/ivos)
set(NRN_MUSIC_SRC_DIR ${PROJECT_SOURCE_DIR}/src/neuronmusic)

# =============================================================================
# Create source file lists by gathering from various directories
Expand Down Expand Up @@ -569,6 +572,7 @@ nrn_create_file_list(NRN_MODLUNIT_SRC_FILES ${NRN_MODLUNIT_SRC_DIR} ${MODLUNIT_F
nrn_create_file_list(NRN_NMODL_SRC_FILES ${NRN_NMODL_SRC_DIR} ${NMODL_FILES_LIST})
nrn_create_file_list(NRNMPI_DYNAMIC_INCLUDE_FILE ${PROJECT_SOURCE_DIR}/src/nrnmpi
${MPI_DYNAMIC_INCLUDE})
nrn_create_file_list(NRN_MUSIC_SRC_FILES ${NRN_MUSIC_SRC_DIR} ${NRN_MUSIC_FILES_LIST})
nrn_create_file_list(NRN_IVOS_SRC_FILES ${NRN_IVOS_SRC_DIR} ${IVOS_FILES_LIST})
list(APPEND NRN_OC_SRC_FILES ${PROJECT_BINARY_DIR}/src/oc/hocusr.h)

Expand Down
32 changes: 22 additions & 10 deletions src/nrniv/nrnmusic.cpp → src/neuronmusic/nrnmusic.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#include <../../nrnconf.h>
#define NO_PYTHON_H 1
#include <../neuronmusic/nrnmusic.h>
#define IN_NRNMUSIC_CPP
#include "nrnmusicapi.h"
#include "hocdec.h"
#include "nrn_ansi.h"
#include "netcon.h"
#include "cvodeobj.h"
#include "netcvode.h"
#include "multicore.h"
#include "nrnmusic.h"
#include "netpar.h"
#include <unordered_map>

extern int nrnmusic;
Expand All @@ -15,6 +25,7 @@ void nrnmusic_spikehandle(void* vport, double tt, int gindex);
extern Object* nrnpy_po2ho(PyObject*);
extern PyObject* nrnpy_ho2po(Object*);
extern Object* hoc_new_object(Symbol*, void*);
extern NetCvode* net_cvode_instance;

MUSIC::Setup* nrnmusic_setup;
MUSIC::Runtime* nrnmusic_runtime;
Expand Down Expand Up @@ -73,7 +84,7 @@ static PortTable* music_output_ports;
NetParMusicEvent::NetParMusicEvent() {}
NetParMusicEvent::~NetParMusicEvent() {}
void NetParMusicEvent::send(double t, NetCvode* nc, NrnThread* nt) {
nc->event(t + usable_mindelay_, this, nt);
nc->event(t + nrn_usable_mindelay(), this, nt);
}
void NetParMusicEvent::deliver(double t, NetCvode* nc, NrnThread* nt) {
nrnmusic_runtime->tick();
Expand Down Expand Up @@ -127,8 +138,8 @@ void NRNMUSIC::EventOutputPort::gid2index(int gid, int gi) {
// except pc.cell(gid, nc) has already been called and this
// will add this to the PreSyn.music_out_ list.
alloc_music_space();
auto iter = gid2out_.find(gid);
if (iter == gid2out_.end()) {
auto iter = nrn_gid2out().find(gid);
if (iter == nrn_gid2out().end()) {
return;
}
PreSyn* ps = iter->second;
Expand Down Expand Up @@ -179,7 +190,7 @@ PyObject* NRNMUSIC::EventInputPort::index2target(int gi, PyObject* ptarget) {
ps = (*gi_table)[gi];
}
NetCon* nc = new NetCon(ps, target);
Object* o = hoc_new_object(netcon_sym_, nc);
Object* o = hoc_new_object(nrn_netcon_sym(), nc);
nc->obj_ = o;
PyObject* po = nrnpy_ho2po(o);
// printf("index2target %d %s\n", gi, hoc_object_name(target));
Expand All @@ -198,6 +209,7 @@ void nrnmusic_init(int* pargc, char*** pargv) {
nrnmusic = 1;
}
}

if (getenv("_MUSIC_CONFIG_"))
nrnmusic = 1; // temporary kludge
if (nrnmusic) {
Expand All @@ -216,7 +228,7 @@ void nrnmusic_terminate() {

// Called from nrn_spike_exchange_init so usable_mindelay is ready to use
// For now, can only be called once.
static void nrnmusic_runtime_phase() {
void nrnmusic_runtime_phase() {
static int called = 0;
assert(!called);
called = 1;
Expand All @@ -237,7 +249,7 @@ static void nrnmusic_runtime_phase() {
}
eh->filltable(eip, cnt);
MUSIC::PermutationIndex indices(&gindices.front(), gindices.size());
eip->map(&indices, eh, usable_mindelay_ / 1000.0);
eip->map(&indices, eh, nrn_usable_mindelay() / 1000.0);
delete eip->gi_table;
}
delete music_input_ports;
Expand All @@ -260,8 +272,8 @@ static void nrnmusic_runtime_phase() {
delete music_output_ports;

// switch to the runtime phase
// printf("usable_mindelay = %g\n", usable_mindelay_);
nrnmusic_runtime = new MUSIC::Runtime(nrnmusic_setup, usable_mindelay_ / 1000.0);
// printf("usable_mindelay = %g\n", nrn_usable_mindelay());
nrnmusic_runtime = new MUSIC::Runtime(nrnmusic_setup, nrn_usable_mindelay() / 1000.0);
npme = new NetParMusicEvent();
npme->send(0, net_cvode_instance, nrn_threads);
}
}
14 changes: 14 additions & 0 deletions src/neuronmusic/nrnmusicapi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

extern int nrnmusic;

extern "C" {

// Note: MPI_Comm nrnmusic_comm; in nrnmpi.cpp and nrnmusic.cpp

extern void nrnmusic_runtime_phase();
extern void nrnmusic_injectlist(void*, double);
extern void nrnmusic_init(int* parg, char*** pargv);
extern void nrnmusic_terminate();

} // end of extern "C"
2 changes: 1 addition & 1 deletion src/nrncvode/netcvode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ extern "C" void nrnthread_trajectory_return(int tid,
double t);
bool nrn_trajectory_request_per_time_step_ = false;
#if NRN_MUSIC
extern void nrnmusic_injectlist(void*, double);
#include "nrnmusicapi.h"
#endif

extern int hoc_return_type_code;
Expand Down
9 changes: 8 additions & 1 deletion src/nrniv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ if(NOT NRN_ENABLE_INTERVIEWS)
list(APPEND NRN_NRNIV_LIB_SRC_FILES ${NRN_IVOS_SRC_FILES})
endif()

if(NRN_ENABLE_MUSIC)
list(APPEND NRN_NRNIV_LIB_SRC_FILES ${NRN_MUSIC_SRC_FILES})
endif()

# =============================================================================
# Include directories for #include <../../nrnconf.h>
# =============================================================================
Expand Down Expand Up @@ -199,6 +203,9 @@ set(NRN_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}/src/sundials/cvodes
${PROJECT_SOURCE_DIR}/src/sundials/ida
${PROJECT_SOURCE_DIR}/src/sundials/shared)
if(NRN_ENABLE_MUSIC)
list(APPEND NRN_INCLUDE_DIRS ${NRN_MUSIC_SRC_DIR})
endif()
set(NRN_INCLUDE_DIRS
${NRN_INCLUDE_DIRS}
PARENT_SCOPE)
Expand Down Expand Up @@ -335,7 +342,7 @@ if(NRN_ENABLE_MPI_DYNAMIC)
endif()

if(NRN_ENABLE_MUSIC)
set_source_files_properties(${PROJECT_SOURCE_DIR}/src/nrniv/netpar.cpp
set_source_files_properties(${PROJECT_SOURCE_DIR}/src/neuronmusic/nrnmusic.cpp
PROPERTIES INCLUDE_DIRECTORIES ${MUSIC_INCDIR})
endif()

Expand Down
13 changes: 12 additions & 1 deletion src/nrniv/netpar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,20 @@ static NrnThread* last_nt_;
#endif

#if NRN_MUSIC
#include "nrnmusic.cpp"
#include "nrnmusicapi.h"
int nrnmusic;
#endif

double nrn_usable_mindelay() {
return usable_mindelay_;
}
Symbol* nrn_netcon_sym() {
return netcon_sym_;
}
Gid2PreSyn& nrn_gid2out() {
return gid2out_;
}

NetParEvent::NetParEvent() {
wx_ = ws_ = 0.;
ithread_ = -1;
Expand Down
13 changes: 13 additions & 0 deletions src/nrniv/netpar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

// Some things in netpar.cpp that were static but needed by nrnmusic.cpp

#include "netcon.h"
#include <unordered_map>
struct Symbol;

using Gid2PreSyn = std::unordered_map<int, PreSyn*>;

double nrn_usable_mindelay();
Symbol* nrn_netcon_sym();
Gid2PreSyn& nrn_gid2out();
9 changes: 6 additions & 3 deletions src/nrnmpi/nrnmpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ extern double nrn_timeus();
#include <libhpm.h>
#endif

int nrnmusic;
#if NRN_MUSIC
MPI_Comm nrnmusic_comm;
extern void nrnmusic_init(int* parg, char*** pargv);
extern void nrnmusic_terminate();
#include "nrnmusicapi.h"
extern int nrnmusic;
#endif

MPI_Comm nrnmpi_world_comm;
Expand Down Expand Up @@ -98,9 +97,11 @@ for (i=0; i < *pargc; ++i) {
b = 1;
nrnmpi_under_nrncontrol_ = 1;
}
#if NRN_MUSIC
if (nrnmusic) {
b = 1;
}
#endif
if (!b) {
nrnmpi_under_nrncontrol_ = 0;
return;
Expand All @@ -121,7 +122,9 @@ for (i=0; i < *pargc; ++i) {
asrt(MPI_Init(pargc, pargv));
#endif
nrnmpi_under_nrncontrol_ = 1;
#if NRN_MUSIC
} else if (!nrnmusic) {
#endif
nrnmpi_under_nrncontrol_ = 0;
}

Expand Down

0 comments on commit d5df041

Please sign in to comment.