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

JIT invocation from python for benchmarks #832

Merged
merged 13 commits into from
Apr 27, 2022
Merged

JIT invocation from python for benchmarks #832

merged 13 commits into from
Apr 27, 2022

Conversation

ohm314
Copy link
Contributor

@ohm314 ohm314 commented Mar 23, 2022

  • Created CodegenDriver class to factor out ast preparation
  • Created pybind wrappers for Jit and Codegen configuration options
  • misc small changes to simplify code

Here's a little test for this:

import sys
sys.path.pop(0)
print(sys.path)

import nmodl.dsl as nmodl

driver = nmodl.NmodlDriver()

cfg = nmodl.CodeGenConfig()
cfg.llvm_vector_width = 4
cfg.llvm_opt_level_ir = 2

with open('test/benchmark/kernels/hh.mod') as f:
    hh = f.read()
    ast = driver.parse_string(hh)
    jit = nmodl.Jit(cfg)

    res = jit.run(ast, "hh", 1000, 10000)
    print(res)

(updated example)

- Created CodegenDriver class to factor out ast preparation
- Created pybind wrappers for Jit and Codegen configuration options
- misc small changes to simplify code
@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #43947 (:no_entry:) have been uploaded here!

Status and direct links:

Copy link
Contributor

@iomaganaris iomaganaris left a comment

Choose a reason for hiding this comment

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

Overall LGTM. I just skimmed through the PR and left some comments/suggestions on its current state since it's still draft

src/codegen/codegen_driver.hpp Outdated Show resolved Hide resolved
src/main.cpp Show resolved Hide resolved
src/main.cpp Show resolved Hide resolved
src/main.cpp Show resolved Hide resolved
src/pybind/pynmodl.cpp Outdated Show resolved Hide resolved
- Updated benchmark runner to return runtime stats
- Updated python module to reflect this change and return results to
  python
- Addressed @iomaganaris' comments.
@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #47934 (:no_entry:) have been uploaded here!

Status and direct links:

@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #48066 (:no_entry:) have been uploaded here!

Status and direct links:

@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #48065 (:no_entry:) have been uploaded here!

Status and direct links:

Copy link
Contributor

@iomaganaris iomaganaris left a comment

Choose a reason for hiding this comment

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

Some minor suggestions and comments.
Overall LGTM. I would just like to add an integration test that runs a small python example.
Also the python jit needs to have -DNMODL_PYTHON_BINDINGS_ENABLED to work but when I enable it with clang 13.0.0 I get issues like the following:

/usr/bin/ld: ../codegen/libcodegen.a(codegen_driver.cpp.o): relocation R_X86_64_32S against hidden symbol `_ZTVN5nmodl7visitor10AstVisitorE' can not be used when making a shared object
/usr/bin/ld: ../codegen/libcodegen.a(codegen_compatibility_visitor.cpp.o): relocation R_X86_64_32 against hidden symbol `_ZTIN5nmodl3ast3AstE' can not be used when making a shared object
/usr/bin/ld: ../../test/benchmark/libllvm_benchmark.a(llvm_benchmark.cpp.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ../../test/benchmark/libllvm_benchmark.a(jit_driver.cpp.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: ../../test/unit/libbenchmark_data.a(codegen_data_helper.cpp.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC

Compiling NMODL with -DCMAKE_CXX_FLAGS="-fPIC" fixes the compilation but then I get the following error when I run the example provided:

➜  build_pyjit git:(ohm314/pyjit) python test_pyjit.py                                                                                                                                                                                                 
['/home/magkanar/bbp_repos/nmodl/build_pyjit', '/home/magkanar/bbp_repos/nmodl/build_pyjit/install/lib/python', '/home/magkanar/bbp_repos/nmodl/build_pyjit/install/lib#', '/home/magkanar/bbp_repos/nmodl/build_pyjit/install/lib', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/magkanar/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages']
[NMODL] [warning] :: Python bindings are not available
Traceback (most recent call last):
  File "test_pyjit.py", line 5, in <module>
    import nmodl.dsl as nmodl
  File "/home/magkanar/bbp_repos/nmodl/build_pyjit/install/lib/nmodl/dsl.py", line 4, in <module>
    from ._nmodl import *
ImportError: /home/magkanar/bbp_repos/nmodl/build_pyjit/install/lib/nmodl/_nmodl.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZTVN5nmodl7codegen20CodegenHelperVisitorE

Am I missing something? How did you build/test this?

test/benchmark/llvm_benchmark.cpp Outdated Show resolved Hide resolved
src/main.cpp Show resolved Hide resolved
@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #48181 (:no_entry:) have been uploaded here!

Status and direct links:

@ohm314 ohm314 marked this pull request as ready for review April 12, 2022 19:48
Omar Awile added 4 commits April 20, 2022 15:30
- Move fmt::literals namespace using into the nmodl namespace (where it should be).
- Remove also logger.hpp header inclusion from places where it is unnecessary.
@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #49638 (:no_entry:) have been uploaded here!

Status and direct links:

Passing the dereferenced node and constructing new shared_ptrs when needed causes all kinds of grief.
@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #49989 (:no_entry:) have been uploaded here!

Status and direct links:

@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #50460 (:white_check_mark:) have been uploaded here!

Status and direct links:

Copy link
Contributor

@pramodk pramodk left a comment

Choose a reason for hiding this comment

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

really nice! was able to run this locally!

$ PYTHONPATH=`pwd`/lib/ python3 test.py
...
[NMODL] [info] :: Created LLVM IR module from NMODL AST in 1.9729e-05 sec
[NMODL] [info] :: CPU: icelake-client
[NMODL] [info] :: Benchmarking kernel 'nrn_state_hh' with 2.708770751953125 MBs dataset
[NMODL] [info] :: Average compute time = 0.000038
[NMODL] [info] :: Compute time standard deviation = 0.000000
[NMODL] [info] :: Minimum compute time = 0.000025
[NMODL] [info] :: Maximum compute time = 0.003346

{'nrn_state_hh': (3.821874700000001e-05, 1.229097320882649e-07, 2.4908e-05, 0.003346102)}

All looks good to me! If you ask me, I would have two questions/wishes:

  • as python bindings are required for running all meaningful tests, I wonder if we should turn ON bindings now (we turned off in the llvm branch during initial development):
 option(NMODL_ENABLE_PYTHON_BINDINGS "Enable pybind11 based python bindings" OFF)
  • to avoid this getting broken, it will be helpful to add a minimal test (like the one shown in the description) here.

src/pybind/CMakeLists.txt Outdated Show resolved Hide resolved
src/main.cpp Show resolved Hide resolved
src/codegen/llvm/target_platform.hpp Show resolved Hide resolved
src/codegen/codegen_driver.hpp Outdated Show resolved Hide resolved
Copy link
Contributor

@iomaganaris iomaganaris left a comment

Choose a reason for hiding this comment

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

LGTM apart from the existing comments.
Regarding enabling NMODL_ENABLE_PYTHON_BINDINGS I think we can still keep it off by default to accelerate local development when the python bindings are not needed however we can enable them on the CI.
I'm also in favour of adding a test that uses the python JIT.
In https://github.com/BlueBrain/nmodl/pull/829/files#diff-037ea159eb0a7cb0ac23b851e66bee30fb838ee8d0d99fa331a1ba65283d37f7R93 I've added tests for running the JIT on the gitlab ci in allocations on BB5 so we can use the same configuration here to run the tests

@ohm314
Copy link
Contributor Author

ohm314 commented Apr 26, 2022

I will add a test. @iomaganaris already suggested it too and you are absolutely right.

@ohm314 ohm314 changed the title Proof of Concept jit invocation from python JIT invocation from python for benchmarks Apr 27, 2022
@bbpbuildbot
Copy link
Collaborator

Logfiles from GitLab pipeline #51014 (:white_check_mark:) have been uploaded here!

Status and direct links:

Copy link
Contributor

@iomaganaris iomaganaris left a comment

Choose a reason for hiding this comment

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

LGTM

@ohm314 ohm314 merged commit c154efb into llvm Apr 27, 2022
@ohm314 ohm314 deleted the ohm314/pyjit branch April 27, 2022 12:32
iomaganaris pushed a commit that referenced this pull request May 10, 2022
- Created CodegenDriver class to factor out ast preparation
- Created pybind wrappers for Jit and Codegen configuration options
- Updated benchmark runner to return runtime stats
- Return benchmark results to python
- Addressed @iomaganaris' comments.
- Add a PyJIT integration test
* Re-enable python bindings by default
iomaganaris pushed a commit that referenced this pull request May 12, 2022
- Created CodegenDriver class to factor out ast preparation
- Created pybind wrappers for Jit and Codegen configuration options
- Updated benchmark runner to return runtime stats
- Return benchmark results to python
- Addressed @iomaganaris' comments.
- Add a PyJIT integration test
* Re-enable python bindings by default
iomaganaris pushed a commit that referenced this pull request Sep 15, 2022
- Created CodegenDriver class to factor out ast preparation
- Created pybind wrappers for Jit and Codegen configuration options
- Updated benchmark runner to return runtime stats
- Return benchmark results to python
- Addressed @iomaganaris' comments.
- Add a PyJIT integration test
* Re-enable python bindings by default
iomaganaris pushed a commit that referenced this pull request Sep 15, 2022
- Created CodegenDriver class to factor out ast preparation
- Created pybind wrappers for Jit and Codegen configuration options
- Updated benchmark runner to return runtime stats
- Return benchmark results to python
- Addressed @iomaganaris' comments.
- Add a PyJIT integration test
* Re-enable python bindings by default
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.

4 participants