Skip to content

Commit deb491c

Browse files
committed
fortran Coarray Fortran Kernl on Backend.AI
1 parent d04ab4f commit deb491c

File tree

10 files changed

+497
-0
lines changed

10 files changed

+497
-0
lines changed

fortran/Dockerfile.caf

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
FROM ubuntu:18.04
2+
MAINTAINER Mario Cho "[email protected]"
3+
4+
ENV PATH=/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH \
5+
LANG=C.UTF-8
6+
# DEBIAN_FRONTEND=noninteractive
7+
8+
ARG OPENCOARRAYS_VERSION=2.8.0
9+
ENV GCC_VERSION 8.2.0
10+
11+
RUN DEBIAN_FRONTEND=noninteractive transientBuildDeps="file" && \
12+
set -v && \
13+
cat /etc/issue && \
14+
uname -a && \
15+
echo "${DEBIAN_FRONTEND}" && \
16+
apt-get update -y && \
17+
apt-get install -y \
18+
software-properties-common && \
19+
add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
20+
apt-get update -y && \
21+
apt-get install -y \
22+
python3 python3-pip \
23+
gfortran \
24+
libssl-dev \
25+
make \
26+
curl \
27+
wget \
28+
gcc-8 \
29+
gfortran-8 \
30+
g++-8 \
31+
mpich \
32+
${transientBuildDeps} && \
33+
update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 60 --slave /usr/bin/gfortran gfortran /usr/bin/gfortran-8 && \
34+
update-alternatives --set gcc "/usr/bin/gcc-8" && \
35+
gcc --version && \
36+
gfortran --version && \
37+
mpiexec --version && \
38+
mpifort --version && \
39+
mpicc --version && \
40+
apt-get clean && \
41+
apt-get purge -y --auto-remove ${transientBuildDeps} && \
42+
rm -rf /var/lib/apt/lists/* /var/log/* /tmp/*
43+
44+
# Install commonly-used wheels
45+
RUN curl https://bootstrap.pypa.io/get-pip.py | python3 && \
46+
python3 -m pip install --no-cache-dir -U setuptools && \
47+
python3 -m pip install --no-cache-dir pyzmq && \
48+
python3 -m pip install --no-cache-dir ipython && \
49+
python3 -m pip install --no-cache-dir jupyter && \
50+
python3 -m pip install --no-cache-dir jupyterlab
51+
52+
# Build-time metadata as defined at http://label-schema.org
53+
ARG BUILD_DATE
54+
ARG VCS_REF
55+
ARG VCS_URL
56+
ARG VCS_VERSION=latest
57+
LABEL org.label-schema.schema-version="1.0" \
58+
org.label-schema.build-date="${BUILD_DATE}" \
59+
org.label-schema.name="jupyter-CAF-kernel" \
60+
org.label-schema.description="Fortran Jupyter kernel with OpenCoarrays and MPICH backend on Basckend.AI" \
61+
org.label-schema.url="https://github.com/sourceryinstitute/jupyter-CAF-kernel/" \
62+
org.label-schema.vcs-ref="${VCS_REF}" \
63+
org.label-schema.vcs-url="${VCS_URL}" \
64+
org.label-schema.version="${VCS_VERSION}" \
65+
org.label-schema.vendor="SourceryInstitute" \
66+
org.label-schema.license="MIT"
67+
68+
COPY ./jupyter-caf-kernel /opt/jupyter/jupyter-caf-kernel
69+
70+
RUN update-alternatives --install /usr/bin/python python /usr/bin/python3 2
71+
72+
WORKDIR /tmp
73+
RUN DEBIAN_FRONTEND=noninteractive transientBuildDeps="cmake git" && \
74+
set -v && \
75+
echo "${DEBIAN_FRONTEND}" && \
76+
apt-get update && \
77+
apt-get install -y ${transientBuildDeps} && \
78+
cmake --version && \
79+
wget -nv -t 3 https://github.com/sourceryinstitute/opencoarrays/releases/download/${OPENCOARRAYS_VERSION}/OpenCoarrays-${OPENCOARRAYS_VERSION}.tar.gz && \
80+
wget -nv -t 3 https://github.com/sourceryinstitute/opencoarrays/releases/download/${OPENCOARRAYS_VERSION}/opencoarrays-${OPENCOARRAYS_VERSION}-SHA256.txt && \
81+
sha256sum -c opencoarrays-${OPENCOARRAYS_VERSION}-SHA256.txt && \
82+
echo "sha" && \
83+
tar xzf OpenCoarrays-${OPENCOARRAYS_VERSION}.tar.gz && \
84+
cd OpenCoarrays-${OPENCOARRAYS_VERSION} && \
85+
echo "Installing OpenCoarrays using CMake in $(pwd)" && \
86+
mkdir build && \
87+
cd build && \
88+
gcc --version && \
89+
gfortran --version && \
90+
FC="`which gfortran`" CC="`which gcc`" cmake .. && \
91+
make -j "$(nproc)" install && \
92+
if [ "${RUN_TESTS}" = "true" ] ; then ctest --output-on-failure; fi && \
93+
cd && \
94+
rm -rf OpenCoarrays* opencoarrays* && \
95+
caf --version && \
96+
python3 -m pip install --no-cache-dir notebook==5.* && \
97+
python3 -m pip install -e /opt/jupyter/jupyter-caf-kernel && \
98+
jupyter-kernelspec install /opt/jupyter/jupyter-caf-kernel/Coarray-Fortran/ && \
99+
jupyter-kernelspec list && \
100+
rm -rf jupyter-caf-kernel && \
101+
apt-get clean && \
102+
apt-get purge -y --auto-remove ${transientBuildDeps} && \
103+
rm -rf /var/lib/apt/lists/* /var/log/* /tmp/*
104+
# chown -R ${NB_USER} /home/${NB_USER&& }
105+
106+
# Install ipython kernelspec
107+
RUN python3 -m ipykernel install --display-name "gFrotran 8.3 on Backend.AI" && \
108+
cat /usr/local/share/jupyter/kernels/python3/kernel.json
109+
110+
LABEL ai.backend.kernelspec="1" \
111+
ai.backend.envs.corecount="OPENBLAS_NUM_THREADS,OMP_NUM_THREADS,NPROC" \
112+
ai.backend.features="batch query uid-match user-input" \
113+
ai.backend.resource.min.cpu="1" \
114+
ai.backend.resource.min.mem="256m" \
115+
ai.backend.base-distro="ubuntu16.04" \
116+
ai.backend.runtime-type="python" \
117+
ai.backend.runtime-path="/usr/bin/python3" \
118+
ai.backend.service-ports="jupyter:http:8080,jupyterlab:http:8090"
119+
120+
COPY policy.yml /etc/backend.ai/jail/policy.yml
121+
122+
# vim: ft=dockerfile
123+
124+
# build-essential \
125+
126+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"argv": [
3+
"python3",
4+
"-m",
5+
"jupyter_caf_kernel",
6+
"-f",
7+
"{connection_file}"
8+
],
9+
"display_name": "Coarray Fortran",
10+
"language": "Fortran"
11+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 Sourcery Institute
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include LICENSE.txt

fortran/jupyter-caf-kernel/README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<div align="center">
2+
3+
# Fortran kernel for Jupyter with Coarray support
4+
5+
[![Binder](http://mybinder.org/badge.svg)](https://beta.mybinder.org/v2/gh/sourceryinstitute/jupyter-CAF-kernel/master)
6+
[![](https://images.microbadger.com/badges/image/sourceryinstitute/jupyter-caf-kernel.svg)](https://microbadger.com/images/sourceryinstitute/jupyter-caf-kernel)
7+
[![](https://images.microbadger.com/badges/version/sourceryinstitute/jupyter-caf-kernel.svg)](https://hub.docker.com/r/sourceryinstitute/jupyter-caf-kernel/)
8+
[![](https://images.microbadger.com/badges/commit/sourceryinstitute/jupyter-caf-kernel.svg)](https://github.com/sourceryinstitute/jupyter-CAF-kernel#readme)
9+
[![](https://images.microbadger.com/badges/license/sourceryinstitute/jupyter-caf-kernel.svg)][license]
10+
11+
</div>
12+
13+
----
14+
15+
## Quick start
16+
17+
* [Try][try CAF] Coarray Fortran in the cloud with [GFortran] and [OpenCoarrays]
18+
using [Binder]: __http://bit.ly/TryCoarrays__
19+
This will open the [`index.ipynb`] file in an interactive
20+
environment using [Binder].
21+
* Launch a full JupyterHub [Binder] Fortran environment in the cloud with [OpenCoarrays]: __http://bit.ly/CAF-Binder__
22+
23+
## Run locally
24+
25+
```bash
26+
docker pull sourceryinstitute/jupyter-caf-kernel:latest
27+
docker run -i -t -p 8888:8888 sourceryinstitute/jupyter-caf-kernel:latest
28+
```
29+
30+
You should see output similar to the following which will instruct you
31+
to point your web browser to `http://localhost:8888/?token=...`
32+
33+
```
34+
[I 19:29:08.089 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
35+
[W 19:29:08.188 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
36+
[I 19:29:08.221 NotebookApp] JupyterLab alpha preview extension loaded from /opt/conda/lib/python3.5/site-packages/jupyterlab
37+
[I 19:29:08.233 NotebookApp] Serving notebooks from local directory: /home/jovyan
38+
[I 19:29:08.233 NotebookApp] 0 active kernels
39+
[I 19:29:08.233 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=67e0bf26a40f863c8af93c030de57b4802cd7b3d9f10ae17
40+
[I 19:29:08.233 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
41+
[C 19:29:08.234 NotebookApp]
42+
43+
Copy/paste this URL into your browser when you connect for the first time,
44+
to login with a token:
45+
http://localhost:8888/?token=67e0bf26a40f863c8af93c030de57b4802cd7b3d9f10ae17
46+
```
47+
48+
When running locally (this way) you won't have access to the examples
49+
folder or [`index.ipynb`].
50+
51+
## About
52+
53+
This Coarray Fortran kernel is still a bit rough around the edges. It
54+
is a shameless fork of the [jupyter-c-kernel], quickly thrown
55+
together. This is [licensed under the MIT license][license], as is
56+
[jupyter-c-kernel]. I also drew inspiration from the
57+
[jupyter-fortran-kernel].
58+
59+
### Whats up with the `prebuild` directory?
60+
61+
The `prebuild` directory is there so that the docker image used to
62+
launch the Coarray Fortran kernel on [Binder] can be built
63+
automatically on Docker Hub. The `Dockerfile` at the project root then
64+
wraps the one located in `prebuild`. This is because we must compile
65+
GCC from source to get a new enough version and this takes a very long
66+
time. We don't want users to have to wait forever to spawn a new
67+
notebook on [Binder], so we ensure that the base image is built ahead
68+
of time, locally, or through the Docker Hub automated build process.
69+
70+
## Manual local installation
71+
72+
The recommended usage of this kernel is through [Binder] in the cloud,
73+
or [via Docker, as described above](#Run-locally). If you decide to
74+
install this kernel locally on your system you will need the following
75+
software packages installed:
76+
77+
* GCC and [GFortran] >= 8.2
78+
* [MPICH] >= 3.2
79+
* [OpenCoarrays]
80+
* [Jupyter]
81+
* Python 3
82+
* pip
83+
84+
### Step-by-step
85+
86+
1. `git clone https://github.com/sourceryinstitute/jupyter-CAF-kernel`
87+
1. `cd jupyter-CAF-kernel`
88+
1. `pip install -e prebuild/jupyter-caf-kernel`
89+
1. `jupyter-kernelspec install prebuild/jupyter-caf-kernel/Coarray-Fortran/`
90+
1. `jupyter-notebook .`
91+
92+
## Contributing
93+
94+
Contributions are most welcome!
95+
96+
### ToDo
97+
98+
* [ ] Use proper Python OOP class extension & better understand base class
99+
* [ ] Improve I/O
100+
* [ ] Improve exception handling and error reporting
101+
* [x] Improve magics
102+
* [ ] Use [MetaKernel] to build the kernel and magics
103+
* [ ] Allow use of all aplicable [MetaKernel magics]
104+
* [ ] Don't attempt to compile code when only magics are present
105+
* [ ] Different flavors of Docker images (so that less space is
106+
used). See [jupyter/docker-stacks][jupyter-stacks]
107+
108+
### Version control
109+
110+
1. [Fork]
111+
1. Create branches named `issue-X` where `X` is the number of the
112+
issue.
113+
1. Commit changes
114+
1. [Pull Request]
115+
116+
## License
117+
118+
[MIT][license]
119+
120+
[Binder]: https://beta.mybinder.org
121+
[try CAF]: http://bit.ly/TryCoarrays
122+
[GFortran]: https://gcc.gnu.org/wiki/GFortran
123+
[OpenCoarrays]: https://github.com/sourceryinstitute/OpenCoarrays#readme
124+
[`index.ipynb`]: https://nbviewer.jupyter.org/github/sourceryinstitute/jupyter-CAF-kernel/blob/master/index.ipynb
125+
[jupyter-c-kernel]: https://github.com/brendan-rius/jupyter-c-kernel#readme
126+
[jupyter-fortran-kernel]: https://github.com/ZedThree/jupyter-fortran-kernel
127+
[MPICH]: https://www.mpich.org
128+
[license]: https://github.com/sourceryinstitute/jupyter-CAF-kernel/blob/master/LICENSE
129+
[Fork]: https://github.com/sourceryinstitute/jupyter-CAF-kernel/fork
130+
[Pull Request]: https://github.com/sourceryinstitute/jupyter-CAF-kernel/compare?expand=1
131+
[MetaKernel]: https://github.com/Calysto/metakernel#readme
132+
[MetaKernel magics]: https://github.com/Calysto/metakernel/blob/master/metakernel/magics/README.md
133+
[jupyter-stacks]: https://github.com/jupyter/docker-stacks#readme
134+
[Jupyter]: https://jupyter.org

fortran/jupyter-caf-kernel/jupyter_caf_kernel/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from ipykernel.kernelapp import IPKernelApp
2+
from .kernel import CafKernel
3+
IPKernelApp.launch_instance(kernel_class=CafKernel)

0 commit comments

Comments
 (0)