Skip to content

NMODL LLVM Code Generation Project

Pramod Kumbhar edited this page Feb 28, 2021 · 31 revisions

This page summarises various resources to get started with the NEURON, CoreNEURON and NMODL ecosystem.

Introduction Computational Neuroscience [Background]

Before diving into the computational aspects of neurons, we could look at the following introductory videos. Go through as much as you like and skip as much as you want!

High Level!

Bit More Serious!

Some more detailed lectures from Neuronal Dynamics - Computational Neuroscience course. Don't need to get into all details but first 2-3 weeks give basic understanding:

A first simple neuron model

The Hodgkin-Huxley model and detailed ion-current based neuron models

This should give you sufficient vocabulary to get started!

Introduction to NEURON Simulator [Background]

To get an idea of how NEURON simulator is used, here are some video tutorials. Don't need to have thorough understanding of everything but to just get high level picture of NEURON simulator:

Here is another (old) NEURON tutorial by Andrew Gillies and David Sterratt. This is quite old with the HOC scripting interface but introduces some of the concepts step-by-step. It's sufficient to skim through the first two parts. If case you want to try example snippets (not necessary to do so), make sure to install NEURON via pip as:

pip3 install neuron #on linux and os x

Documentation

Building LLVM based compiler from scratch : Flex, Bison, AST and LLVM IR

Below from Loren Segal is simplest and complete tutorial I have seen that put together flex, bison, AST and LLVM code generation. It's based on ancient LLVM version but gives fairly good idea of what it requires to integrate LLVM. I "think" we will use similar approach in NMODL toolchain.

Language Frontend with LLVM Tutorial

Classic tutorial for any LLVM related work:

Introduction to NMODL (TODO/WIP)

This is where we start with the main relevant part of the project. We will update this section with better resources. To get some background, we can start with:

References for LLVM code generation

GitHub Projects

Here are some GitHub projects that could be useful (to search some implementation aspects)

Generating Efficient Code

Vectorisation related papers

How To

SIMD scatter add

NMODL to LLVM IR

NMODL kernels are of the form:

VOID nrn_state_hh(){
    INTEGER id
    for(id = 0; id<node_count; id = id+1) {
        INTEGER node_id, ena_id, ek_id
        DOUBLE v
        node_id = node_index[id]
        ena_id = ion_ena_index[id]
        ek_id = ion_ek_index[id]
        v = voltage[node_id]
        ena[id] = ion_ena[ena_id]
        ek[id] = ion_ek[ek_id]
        m[id] = m[id]+(1.0-exp(dt*((((-1.0)))/mtau[id])))*(-(((minf[id]))/mtau[id])/((((-1.0)))/mtau[id])-m[id])
        h[id] = h[id]+(1.0-exp(dt*((((-1.0)))/htau[id])))*(-(((hinf[id]))/htau[id])/((((-1.0)))/htau[id])-h[id])
        n[id] = n[id]+(1.0-exp(dt*((((-1.0)))/ntau[id])))*(-(((ninf[id]))/ntau[id])/((((-1.0)))/ntau[id])-n[id])
    }
}

Questions:

  • How this should be transformed to LLVM IR? esp. vector form?
  • Instead of creating serial code then vectorising, we can use vector types directly?