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

Create mechanism instance struct in LLVM IR #507

Merged
merged 25 commits into from
Feb 1, 2021

Conversation

iomaganaris
Copy link
Contributor

@iomaganaris iomaganaris commented Jan 28, 2021

Create a stuct declaration in LLVM IR module similar to <mech>_Instance struct declared in cpp files.

An example of such struct declaration is:
test.mod (based on hh.mod)

NEURON {
    USEION na READ ena WRITE ina
    USEION k READ ek WRITE ik
    NONSPECIFIC_CURRENT il
    RANGE gnabar
    RANGE minf, hinf, ninf, mtau, htau, ntau
}

STATE {
    m h n
}

PARAMETER {
    gnabar = .12 (S/cm2)    <0,1e9>
}

ASSIGNED {
    v (mV)
    celsius (degC)

    minf hinf ninf
    mtau (ms) htau (ms) ntau (ms)
}

test.cpp

/** all mechanism instance variables */
    struct _Instance  {
        const double* __restrict__ gnabar;
        double* __restrict__ minf;
        double* __restrict__ hinf;
        double* __restrict__ ninf;
        double* __restrict__ mtau;
        double* __restrict__ htau;
        double* __restrict__ ntau;
        double* __restrict__ m;
        double* __restrict__ h;
        double* __restrict__ n;
        double* __restrict__ ena;
        double* __restrict__ ina;
        double* __restrict__ ek;
        double* __restrict__ ik;
        double* __restrict__ Dm;
        double* __restrict__ Dh;
        double* __restrict__ Dn;
        double* __restrict__ v_unused;
        const double* __restrict__ ion_ena;
        double* __restrict__ ion_ina;
        double* __restrict__ ion_dinadv;
        const double* __restrict__ ion_ek;
        double* __restrict__ ion_ik;
        double* __restrict__ ion_dikdv;
    };

In LLVM IR we generate the following:

%unknown_Instance = type { double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double*, double* }

The variables that are taken into account are:

88:  * Variable added to instance struct: gnabar
88:  * Variable added to instance struct: minf
88:  * Variable added to instance struct: hinf
88:  * Variable added to instance struct: ninf
88:  * Variable added to instance struct: mtau
88:  * Variable added to instance struct: htau
88:  * Variable added to instance struct: ntau
88:  * Variable added to instance struct: m
88:  * Variable added to instance struct: h
88:  * Variable added to instance struct: n
88:  * Variable added to instance struct: ena
88:  * Variable added to instance struct: ina
88:  * Variable added to instance struct: ek
88:  * Variable added to instance struct: ik
88:  * Variable added to instance struct: Dm
88:  * Variable added to instance struct: Dh
88:  * Variable added to instance struct: Dn
88:  * Variable added to instance struct: v_unused
88:  * Variable added to instance struct: ion_ena
88:  * Variable added to instance struct: ion_ina
88:  * Variable added to instance struct: ion_dinadv
88:  * Variable added to instance struct: ion_ek
88:  * Variable added to instance struct: ion_ik
88:  * Variable added to instance struct: ion_dikd

These variables include any float pointers or int pointers that are indexes to other vectors.

This PR also includes:

  • Refactoring CodegeCVisitor and moving some functions to CodegenInfo
  • Updating hpc-coding-conventions
  • Small fixes in breaking unit tests (Maybe this only happened to my machine? I am using LLVM 11 on Ubuntu 20.04)

TODO:
- Same should happen for codegen_int_variables, codegen_global_variables, codegen_shadow_variables
- Check especially codegen_global_variables
- Move small utility functions from CodegenCVisitor to codeged_utils
This reverts commit f522cb4.
- Removed non working blocks from procedure.mod
- Added unit test for global variable
- Add float and int variables
- Moved get_int_variables, get_shadow_variables and get_float_variables
  to codegen_info
- Removed debugging printf
- Added some comments
- Improved unit test
@iomaganaris iomaganaris requested a review from pramodk January 28, 2021 14:46
@georgemitenkov
Copy link
Collaborator

@iomaganaris A quick question about the Mech struct. The pointers point to the arrays of these variables that define current, conductivity, etc, across different points on the membrane. (By that I mean that NEURON user can define segments within the model that have their own properties). Do we know the sizes of the arrays they point to at compile time?

@iomaganaris
Copy link
Contributor Author

@iomaganaris A quick question about the Mech struct. The pointers point to the arrays of these variables that define current, conductivity, etc, across different points on the membrane. (By that I mean that NEURON user can define segments within the model that have their own properties). Do we know the sizes of the arrays they point to at compile time?

@georgemitenkov As far as I know the sizes of the arrays are defined during run time according to the number of cells and segments per cell. @pramodk can correct me if I am wrong.

@pramodk
Copy link
Contributor

pramodk commented Jan 29, 2021

What Ioannis mentioned is correct! we will know the trip count at runtime unless we do JIT (but that's different topic for now).

@pramodk pramodk marked this pull request as ready for review February 1, 2021 20:57
@pramodk pramodk merged commit ccbca85 into llvm Feb 1, 2021
@pramodk pramodk deleted the magkanar/llvm_mech_instance branch February 1, 2021 21:01
pramodk pushed a commit that referenced this pull request Feb 23, 2021
* Moved info related function to codegen_info
  - Moved get_float_variables, codegen_int_variables,
     codegen_global_variables, codegen_shadow_variables
     into CodegenHelper
  - Move small utility functions from CodegenCVisitor to codeged_utils
* Add proper variables to the mech_Instance
* Adding LLVMStructBlock
* Added test and visitor
* Fix llvm codegen tests with x[0-9].*
pramodk pushed a commit that referenced this pull request May 8, 2021
* Moved info related function to codegen_info
  - Moved get_float_variables, codegen_int_variables,
     codegen_global_variables, codegen_shadow_variables
     into CodegenHelper
  - Move small utility functions from CodegenCVisitor to codeged_utils
* Add proper variables to the mech_Instance
* Adding LLVMStructBlock
* Added test and visitor
* Fix llvm codegen tests with x[0-9].*
pramodk pushed a commit that referenced this pull request Mar 8, 2022
* Moved info related function to codegen_info
  - Moved get_float_variables, codegen_int_variables,
     codegen_global_variables, codegen_shadow_variables
     into CodegenHelper
  - Move small utility functions from CodegenCVisitor to codeged_utils
* Add proper variables to the mech_Instance
* Adding LLVMStructBlock
* Added test and visitor
* Fix llvm codegen tests with x[0-9].*
iomaganaris added a commit that referenced this pull request May 10, 2022
* Moved info related function to codegen_info
  - Moved get_float_variables, codegen_int_variables,
     codegen_global_variables, codegen_shadow_variables
     into CodegenHelper
  - Move small utility functions from CodegenCVisitor to codeged_utils
* Add proper variables to the mech_Instance
* Adding LLVMStructBlock
* Added test and visitor
* Fix llvm codegen tests with x[0-9].*
iomaganaris added a commit that referenced this pull request May 12, 2022
* Moved info related function to codegen_info
  - Moved get_float_variables, codegen_int_variables,
     codegen_global_variables, codegen_shadow_variables
     into CodegenHelper
  - Move small utility functions from CodegenCVisitor to codeged_utils
* Add proper variables to the mech_Instance
* Adding LLVMStructBlock
* Added test and visitor
* Fix llvm codegen tests with x[0-9].*
iomaganaris added a commit that referenced this pull request Sep 15, 2022
* Moved info related function to codegen_info
  - Moved get_float_variables, codegen_int_variables,
     codegen_global_variables, codegen_shadow_variables
     into CodegenHelper
  - Move small utility functions from CodegenCVisitor to codeged_utils
* Add proper variables to the mech_Instance
* Adding LLVMStructBlock
* Added test and visitor
* Fix llvm codegen tests with x[0-9].*
* Fixes after rebasing llvm branch on master (15.9.2022)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants