Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code generation issue with inlining #809

Closed
iomaganaris opened this issue Feb 21, 2022 · 6 comments · Fixed by #845 or #980
Closed

Code generation issue with inlining #809

iomaganaris opened this issue Feb 21, 2022 · 6 comments · Fixed by #845 or #980
Labels
bug Something isn't working codegen Code generation backend

Comments

@iomaganaris
Copy link
Contributor

iomaganaris commented Feb 21, 2022

Installing NEURON with NMODL on Apple Macbook Air with M1 processor generated the following issue when compiling the na3n.mod file from the reduced_dentate repo:

arm64/corenrn/mod2c/na3n.cpp:544:32: error: use of undeclared identifier 'bets_in_0'
                exptrap_in_4 = bets_in_0;

Seems like there is some issue with the code generated in

exptrap_in_4 = bets_in_0;

which should be:

if (x_in_4 >= 700.0) {
    exptrap_in_4 = exp(700.0);
} else {
    exptrap_in_4 = exp(x_in_4);
}

after the inline pass.
Unfortunately I couldn't reproduce the issue when I installed NEURON with CoreNEURON and NMODL using the following commands:

git clone --recursive https://github.com/neuronsimulator/nrn.git
cd nrn
mkdir build_nmodl
python3 -v venv venv
. venv/bin/activate
pip3 install -r nrn_requirements.txt
pip3 install -U pip setuptools scikit-build Jinja2 PyYAML pytest 'sympy>=1.3,<1.9' 'cmake-format==0.6.13'  # NMODL requirements
brew install flex bison
export PATH="/opt/homebrew/opt/bison/bin:/opt/homebrew/opt/flex/bin:$PATH"
export PYTHONPATH="$(pwd)/build_nmodl/install/lib/python:$PYTHONPATH"
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
cmake .. -DCMAKE_INSTALL_PREFIX=./install -DNRN_ENABLE_CORENEURON=ON -DCORENRN_ENABLE_NMODL=ON -DNRN_ENABLE_RX3D=OFF -DNRN_ENABLE_INTERVIEWS=OFF -DNRN_ENABLE_TESTS=ON
cmake --build . --target install --parallel 1
ctest -R reduced_dentate
@iomaganaris iomaganaris added bug Something isn't working codegen Code generation backend labels Feb 21, 2022
@iomaganaris
Copy link
Contributor Author

I got a similar issue again when building NEURON with NMODL enabled in M1 but this time in a different mod file:

[NMODL] [warning] :: Python bindings are not available
arm64/corenrn/mod2c/tca.cpp:283:17: error: use of undeclared identifier 'exptrap_in_5'; did you mean 'exptrap_in_4'?
            if (exptrap_in_5 < 1e-4) {
                ^~~~~~~~~~~~
                exptrap_in_4
arm64/corenrn/mod2c/tca.cpp:262:33: note: 'exptrap_in_4' declared here
        double nu, f, KTF_in_0, exptrap_in_4, efun_in_0;
                                ^
1 error generated.
make: *** [arm64/corenrn/build/tca.o] Error 1

@iomaganaris
Copy link
Contributor Author

iomaganaris commented Apr 14, 2022

Seems like after 2109df6 this issue is somehow fixed

Edit: After this commit the mod files included in NEURON integrated tests pass however I still go the error in another mod file with current NMODL master

@iomaganaris
Copy link
Contributor Author

@alkino Have you maybe tested whether this fixes the issue in an M1 machine?

@iomaganaris
Copy link
Contributor Author

iomaganaris commented Jun 16, 2022

It seems like the issue is still not resolved. nmodl still creates wrong output in inlined variables

@iomaganaris iomaganaris reopened this Jun 16, 2022
@iomaganaris
Copy link
Contributor Author

iomaganaris commented Jun 16, 2022

Some more instructions to reproduce the issue in M1 processors:

python3 -v venv venv
. venv/bin/activate
pip3 install -U pip setuptools scikit-build Jinja2 PyYAML pytest 'sympy>=1.3,<1.9' 'cmake-format==0.6.13'  # NMODL requirements
brew install flex bison
export PATH="/opt/homebrew/opt/bison/bin:/opt/homebrew/opt/flex/bin:$PATH"
export SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
export BASE_DIR=$(pwd)
git clone https://github.com/neuronsimulator/reduced_dentate.git
git clone https://github.com/BlueBrain/nmodl.git
cd nmodl
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=./install
cmake --build . --target install --parallel
cd ../..
git clone https://github.com/BlueBrain/CoreNeuron.git
cd CoreNeuron
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=./install -DCORENRN_NMODL_DIR=${BASE_DIR}/nmodl/build/install -DCORENRN_ENABLE_NMODL=ON
cmake --build . --target install --parallel
cd ..
for i in {0..19}; do rm -rf arm64 && build/install/bin/nrnivmodl-core ${BASE_DIR}/reduced_dentate/mechanisms || break; done

Above script is installing NMODL and CoreNEURON and compiles the mod files from reduced dentate that showcase this issue multiple times until there is a failure.
With the above workflow it's easy to do some change in NMODL, then rebuild and install it and nrnivmodl-core will then use the updated NMODL executable

@pramodk
Copy link
Contributor

pramodk commented Nov 28, 2022

I don't think this happens on Apple M1 only! today on my Intel MacBook I saw:

[NMODL] [info] :: Running cnexp visitor
[NMODL] [info] :: Running C backend code generator
x86_64/corenrn/mod2c/Aradi_Ca.cpp:560:36: error: use of undeclared identifier 'exponential_in_2'; did you mean 'exptrap_in_2'?
                    exptrap_in_2 = exponential_in_2;
                                   ^~~~~~~~~~~~~~~~
                                   exptrap_in_2
x86_64/corenrn/mod2c/Aradi_Ca.cpp:550:20: note: 'exptrap_in_2' declared here
            double exptrap_in_2, A_in_7, k_in_7, v_in_20, D_in_7;
                   ^
x86_64/corenrn/mod2c/Aradi_Ca.cpp:1482:48: error: use of undeclared identifier 'exponential_in_2'; did you mean 'exptrap_in_2'?
                                exptrap_in_2 = exponential_in_2;
                                               ^~~~~~~~~~~~~~~~
                                               exptrap_in_2
x86_64/corenrn/mod2c/Aradi_Ca.cpp:1472:32: note: 'exptrap_in_2' declared here
                        double exptrap_in_2, A_in_7, k_in_7, v_in_20, D_in_7;
                               ^
2 errors generated.
make[3]: *** [x86_64/corenrn/build/Aradi_Ca.o] Error 1
make[3]: *** Waiting for unfinished jobs....

The NMODL version:

✗ ./bin/nmodl --help
NMODL : Source-to-Source Code Generation Framework [0.4 14359293 2022-10-28 08:35:35 +0200]

And CMake command I used:

cmake .. -DNRN_ENABLE_INTERVIEWS=OFF -DNRN_ENABLE_RX3D=OFF -DCMAKE_INSTALL_PREFIX=`pwd`/install -DNRN_ENABLE_CORENEURON=ON -DCORENRN_ENABLE_LEGACY_UNITS=ON -DNRN_DYNAMIC_UNITS_USE_LEGACY=ON -DCORENRN_ENABLE_NMODL=ON -DCORENRN_ENABLE_OPENMP=OFF -DNRN_ENABLE_TESTS=ON

Tried to build again and I see:

[NMODL] [info] :: Running C backend code generator
x86_64/corenrn/mod2c/Aradi_Ca.cpp:400:36: error: use of undeclared identifier 'alphaa_in_1'
                    exptrap_in_1 = alphaa_in_1;
                                   ^
x86_64/corenrn/mod2c/Aradi_Ca.cpp:1262:48: error: use of undeclared identifier 'alphaa_in_1'
                                exptrap_in_1 = alphaa_in_1;
                                               ^

@pramodk pramodk changed the title Code generation issue on Apple M1 Code generation issue with inlining Dec 15, 2022
pramodk added a commit that referenced this issue Dec 15, 2022
* when we inline AST nodes, we keep the track
  of which nodes being replaced by using a map containing
  address of those nodes.
* when inlining of a particular node is finished, we were
  not removing that node address from the map.
* if we get a situation where AST node with same address is
  created (dynamic allocation) during inlining pass, it might
  end-up replacing wrong node just because it has the same
  address as previously inlined node.
* to avoid this, make sure to clear map entry when inlining is done!

Fixes #809
pramodk added a commit that referenced this issue Dec 15, 2022
* when we inline AST nodes, we keep the track
  of which nodes being replaced by using a map containing
  address of those nodes.
* when inlining of a particular node is finished, we were
  not removing that node address from the map.
* if we get a situation where AST node with same address is
  created (dynamic allocation) during inlining pass, it might
  end-up replacing wrong node just because it has the same
  address as previously inlined node.
* to avoid this, make sure to clear map entry when inlining is done!

Fixes #809
pramodk added a commit that referenced this issue Dec 15, 2022
* when we inline AST nodes, we keep the track
  of which nodes being replaced by using a map containing
  address of those nodes.
* when inlining of a particular node is finished, we were
  not removing that node address from the map.
* if we get a situation where AST node with same address is
  created (dynamic allocation) during inlining pass, it might
  end-up replacing wrong node just because it has the same
  address as previously inlined node.
* to avoid this, make sure to clear map entry when inlining is done!

Fixes #809
pramodk added a commit that referenced this issue Dec 15, 2022
* when we inline AST nodes, we keep the track
  of which nodes being replaced by using a map containing
  address of those nodes.
* when inlining of a particular node is finished, we were
  not removing that node address from the map.
* if we get a situation where AST node with same address is
  created (dynamic allocation) during inlining pass, it might
  end-up replacing wrong node just because it has the same
  address as previously inlined node.
* to avoid this, make sure to clear map entry when inlining is done!

Fixes #809
pramodk added a commit that referenced this issue Dec 19, 2022
* when we inline AST nodes, we keep the track
  of which nodes being replaced by using a map containing
  address of those nodes.
* when inlining of a particular node is finished, we were
  not removing that node address from the map.
* if we get a situation where AST node with same address is
  created (dynamic allocation) during inlining pass, it might
  end-up replacing wrong node just because it has the same
  address as previously inlined node.
* to avoid this, make sure to clear map entry when inlining is done!

Fixes #809
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working codegen Code generation backend
Projects
None yet
2 participants