Skip to content

Support for translating mod files to cpp using nrnivmodl#397

Closed
pramodk wants to merge 2 commits into
masterfrom
pramodk/nmodl-cpp
Closed

Support for translating mod files to cpp using nrnivmodl#397
pramodk wants to merge 2 commits into
masterfrom
pramodk/nmodl-cpp

Conversation

@pramodk

@pramodk pramodk commented Jan 5, 2020

Copy link
Copy Markdown
Member

Based on discussion in #384 I was playing with nrnivmodl and relevant files to support C++ code generation. Current implementation allows to choose C++ or C output after installation which will be helpful for debugging/developing. Once we verify that all models work without any issue with C++, we can remove current logic and make out C++ only.

Idea of this PR is to :

  • keep old behaviour or existing workflow i.e. nrnivmodl
  • add command line option in nrnivmodl so that user can choose to translate mod files to C++

Here is summary of changes:

  • nrnivmodl accept extra option -cpp by which all mod files
    are translated to .cpp instead of .c (i.e. nrnivmodl -cpp .
  • all files are then compiled with CXX and relevant compiler
    flags to build special
  • keep everything backward compatible i.e. if -cpp flag is not
    provided then keep old behaviour
  • nocmodl accepts extra comamnd line argument ext=cpp (last argument)
    by which .mod file is translated to .cpp
  • nrnivmodl and relevant makefiles are updated to accept -cpp flag

For example,

  • Default behaviour (C code)
$ /Users/kumbhar/workarena/repos/bbp/nn/build/install/bin/nrnivmodl .
Creating x86_64 directory for .o files.

/Users/kumbhar/workarena/repos/bbp/ringtest/mod
ls: ./*.inc: No such file or directory
./halfgap.mod
halfgap.mod
mkdir -p x86_64
 -> Compiling mod_func.c
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -g  -O0    -I. -I..   -I/Users/kumbhar/workarena/repos/bbp/nn/build/install/include   -fPIC -c mod_func.c -o mod_func.o
 -> MOD2C halfgap.mod
MODLUNIT=/Users/kumbhar/workarena/repos/bbp/nn/build/install/share/nrn/lib/nrnunits.lib \
	  /Users/kumbhar/workarena/repos/bbp/nn/build/install/bin/nocmodl halfgap.mod ext=c
Translating halfgap.mod into halfgap.c
Thread Safe
 -> Compiling x86_64/halfgap.c
(cd .. ; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -g  -O0    -I. -I..   -I/Users/kumbhar/workarena/repos/bbp/nn/build/install/include   -fPIC -c x86_64/halfgap.c -o x86_64/halfgap.o)
 => LINKING library x86_64/libnrnmech.0.0.dylib Mod files: halfgap.mod
(cd .. ; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g  -O0   -std=c++11 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -fPIC -L/usr/local/opt/ruby/lib -I /Users/kumbhar/workarena/repos/bbp/nn/build/install/include -o x86_64/libnrnmech.0.0.dylib -Wl,-install_name,@rpath/libnrnmech.0.0.dylib \
	  x86_64/mod_func.o x86_64/halfgap.o -L/Users/kumbhar/workarena/repos/bbp/nn/build/install/lib -lnrniv -Wl,-rpath,/Users/kumbhar/workarena/repos/bbp/nn/build/install/lib    -lreadline /Library/Frameworks/Python.framework/Versions/3.6/lib/libpython3.6m.dylib)
(cd .. ; rm -f x86_64/.libs/libnrnmech.so ; mkdir -p x86_64/.libs ; ln -s ../../x86_64/libnrnmech.0.0.dylib x86_64/.libs/libnrnmech.so)
Successfully created x86_64/special
  • New option (CPP code):
$ /Users/kumbhar/workarena/repos/bbp/nn/build/install/bin/nrnivmodl -cpp .
Creating x86_64 directory for .o files.

/Users/kumbhar/workarena/repos/bbp/ringtest/mod
halfgap.mod
halfgap.mod
mkdir -p x86_64
 -> Compiling mod_func.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g  -O0   -std=c++11  -I. -I..   -I/Users/kumbhar/workarena/repos/bbp/nn/build/install/include   -fPIC -c mod_func.cpp -o mod_func.o
 -> MOD2C halfgap.mod
MODLUNIT=/Users/kumbhar/workarena/repos/bbp/nn/build/install/share/nrn/lib/nrnunits.lib \
	  /Users/kumbhar/workarena/repos/bbp/nn/build/install/bin/nocmodl halfgap.mod ext=cpp
Translating halfgap.mod into halfgap.cpp
Thread Safe
 -> Compiling x86_64/halfgap.cpp
(cd .. ; /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g  -O0   -std=c++11  -I. -I..   -I/Users/kumbhar/workarena/repos/bbp/nn/build/install/include   -fPIC -c x86_64/halfgap.cpp -o x86_64/halfgap.o)
In file included from x86_64/halfgap.cpp:12:
/Users/kumbhar/workarena/repos/bbp/nn/build/install/include/nrniv_mf.h:77:12: error:
      conflicting types for 'derivimplicit_thread'
extern int derivimplicit_thread(int, int*, int*, double*, int(*)(double*, union D...
           ^
/Users/kumbhar/workarena/repos/bbp/nn/build/install/include/scoplib_ansi.h:72:5: note:
      previous declaration is here
int derivimplicit_thread();
    ^
x86_64/halfgap.cpp:88:31: error: unknown type name '_ho'
 static void* _hoc_create_pnt(_ho) Object* _ho; { void* create_point_process();

As shown above, compilation is failing. I now remember some fixes we did in MOD2C as well with generated code to compiler with CXX. I think it won't take much efforts to fix compilation issues / generated code (e.g. mismatch with function prototypes/definitions, K&R function declarations).

fixes #384

@nrnhines nrnhines left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't the modfunc.cpp and translated .cpp files need an
extern "C" {
}
more or less from beginning to end (but not around the #include as they have their own). Or is that
an old habit I have that no longer applies?

@pramodk

pramodk commented Jan 5, 2020

Copy link
Copy Markdown
Member Author

Most likely yes! I think we will see link time errors but before that I have to resolve all those compilation errors.

@ramcdougal

ramcdougal commented Jan 5, 2020

Copy link
Copy Markdown
Member

As is, this won't work in a regular Windows cmd or PowerShell window. In that context, nrnivmodl is provided by the src/mswin/bin/nrnivmodl.bat script, which would need to be modified to pass the relevant flag to mknrndll.sh.

@pramodk

pramodk commented May 8, 2020

Copy link
Copy Markdown
Member Author

I will close this for now as this requires (quite) some work.

@pramodk pramodk closed this May 8, 2020
@pramodk pramodk reopened this Aug 15, 2020
  - nrnivmodl accept extra option -cpp by which all mod files
    are translated to .cpp instead of .c
  - all files are then compiled with CXX and relevant compiler
    flags to build special
  - keep everything backward compatible i.e. if -cpp flag is not
    provided then keep old behaviour
  - nocmodl accepts extra comamnd line argument ext=cpp (last argument)
    by which .mod file is translated to .cpp
  - nrnivmodl and relevant makefiles are updated to accept -cpp flag

fixes #384
@alexsavulescu

Copy link
Copy Markdown
Member

superseded by #1597

@alexsavulescu alexsavulescu deleted the pramodk/nmodl-cpp branch July 20, 2022 15:13
olupton pushed a commit that referenced this pull request Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can we rename nocmodl generated file to .cpp instead of .c?

4 participants