Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .cookiecutterrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@

default_context:

_output_dir: '/home/iavarone/repos'
_output_dir: '/home/lmoyasans/repos'
_template: 'gh:ITISFoundation/cookiecutter-osparc-service'
author_affiliation: "IT'IS Foundation"
author_email: 'iavarone@itis.swiss'
author_name: 'Elisabetta Iavarone'
contact_email: 'iavarone@itis.swiss'
author_email: 'moyasans@itis.swiss'
author_name: 'Lucia Moya-Sans'
contact_email: 'moyasans@itis.swiss'
default_docker_registry: 'itisfoundation'
docker_base: 'custom:special-image'
git_repo: 'github'
git_username: 'elisabettai'
git_username: 'lmoyasans'
number_of_inputs: '1'
number_of_outputs: '1'
project_name: 'k-Wave'
Expand All @@ -35,4 +35,4 @@ default_context:
project_slug: 'k-wave'
project_type: 'computational'
release_date: '2023'
version: '1.0.0'
version: '2.0.0'
7 changes: 4 additions & 3 deletions .osparc/docker-compose.overwrite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
build:
dockerfile: docker/custom/Dockerfile
target: production
args:
- KWAVE_LOGIN
- KWAVE_PASSWORD
# KWAVE_LOGIN / KWAVE_PASSWORD removed in v2.0.0:
# the binary is now built from open-source source code
# (https://github.com/klepo/k-Wave-Fluid-CUDA) using CUDA 12.2,
# so no k-wave.org credentials are required at build time.
Comment thread
GitHK marked this conversation as resolved.
Outdated
9 changes: 6 additions & 3 deletions .osparc/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ name: k-Wave
key: simcore/services/comp/k-wave
type: computational
integration-version: 1.0.0
version: 1.0.0
description: k-Wave is a MATLAB toolbox for the time-domain simulation of acoustic wave fields. This service uses the kspaceFirstOrder-CUDA function to run 3D time-domain simulation of wave propagation on a GPU using C++ CUDA code (k-Wave version 1.3). <br><br> Have an issue? Create one at https://github.com/ITISFoundation/k-wave/issues
contact: iavarone@itis.swiss
version: 2.0.0
Comment thread
GitHK marked this conversation as resolved.
description: k-Wave is a MATLAB toolbox for the time-domain simulation of acoustic wave fields. This service uses the kspaceFirstOrder-CUDA function to run 3D time-domain simulation of wave propagation on a GPU using C++ CUDA code. Built with CUDA 12.2; supports Turing (sm_75) through Ada Lovelace (sm_89, RTX 4070) and Hopper (sm_90). <br><br> Have an issue? Create one at https://github.com/ITISFoundation/k-wave/issues
contact: moyasans@itis.swiss
thumbnail: https://pbs.twimg.com/media/ER4wiXEWkAAY-GD.jpg
authors:
- name: Elisabetta Iavarone
email: iavarone@itis.swiss
affiliation: IT'IS Foundation
- name: Lucia Moya-Sans
email: moyasans@itis.swiss
affiliation: IT'IS Foundation
inputs:
input_1:
displayOrder: 1
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Author: Elisabetta Iavarone
# Lucia Moya-Sans

SHELL = /bin/sh
.DEFAULT_GOAL := help
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ $ make help
$ make build
$ make publish-local
```
**Note**: to build the image, you need an account [to download k-Wave](http://www.k-wave.org/download.php). In version 1.0.0 the pre-compiled executables are used.

### How to test
Use as input the file `validation/input/input.h5`. Running the service should generate an `output.h5` file.
Expand Down
156 changes: 86 additions & 70 deletions docker/custom/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,96 +1,112 @@
FROM nvidia/cudagl:11.2.2-runtime-ubuntu20.04 as base
#
# USAGE:
# cd services/k-wave
# docker build -f Dockerfile -t k-wave:prod --target production ../../
# docker run k-wave:prod
#

LABEL maintainer=elisabettai

# simcore-user uid=8004(${SC_USER_NAME}) gid=8004(${SC_USER_NAME}) groups=8004(${SC_USER_NAME})
ENV SC_USER_ID 8004
ENV SC_USER_NAME scu
RUN adduser --uid ${SC_USER_ID} --disabled-password --gecos "" --shell /bin/sh --home /home/${SC_USER_NAME} ${SC_USER_NAME}
# v2.0.0 builds kspaceFirstOrder-CUDA from source
# (https://github.com/klepo/k-Wave-Fluid-CUDA) using CUDA 12.2 and targets
# sm_75 (Turing) through sm_90 (Hopper), covering all current consumer and
# data-centre NVIDIA GPUs.

RUN apt-get update \
&& apt-get -y install --no-install-recommends \
jq \
&& rm --recursive --force /var/lib/apt/lists/*

# -------------------------- Build stage -------------------
# Installs build/package management tools and third party dependencies
#
# + /build WORKDIR
#
# ======================== Build stage ========================
FROM nvidia/cuda:12.2.2-devel-ubuntu22.04 AS build

FROM base as build
LABEL maintainer=lmoyasans

ENV SC_BUILD_TARGET build
ENV SC_BUILD_TARGET=build

ARG KWAVE_PASSWORD
ARG KWAVE_LOGIN
# ------------------------------------------------------------------------------------
# build dependencies shall be installed
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
unzip \
gcc \
curl \
&& rm -rf /var/lib/apt/lists/*

# ------------------------------------------------------------------------------------
# Download binaries (get authentication cookie to login to http://www.k-wave.org/download.php and download the file with the cookie)
# Note, you need to have a valid login and export credentials as env. variables

WORKDIR /build
git \
make \
g++ \
libhdf5-dev \
zlib1g-dev \
libaec-dev \
&& rm -rf /var/lib/apt/lists/*

# Create the HDF5 prefix layout expected by the k-Wave Makefile:
# $(HDF5_DIR)/include and $(HDF5_DIR)/lib
# Ubuntu 22.04 puts the serial-variant files in non-standard sub-directories.
RUN mkdir -p /opt/hdf5 \
&& ln -s /usr/include/hdf5/serial /opt/hdf5/include \
&& ln -s /usr/lib/x86_64-linux-gnu/hdf5/serial /opt/hdf5/lib

RUN curl --cookie-jar cookie.txt --form password=$KWAVE_PASSWORD --form user_login=$KWAVE_LOGIN http://www.k-wave.org/forum/bb-login.php && \
curl -L -b cookie.txt http://www.k-wave.org/getfile.php?id=117 -o kwave.zip && \
unzip kwave.zip && \
rm kwave.zip cookie.txt
# ------------------------------------------------------------------------------------
# libaec-dev provides SZIP compatibility; ensure libsz.a is reachable.
RUN ls /usr/lib/x86_64-linux-gnu/libsz.a 2>/dev/null \
|| ln -s /usr/lib/x86_64-linux-gnu/libaec.a \
/usr/lib/x86_64-linux-gnu/libsz.a

WORKDIR /build

# defines the output of the build
RUN mkdir --parents /build/bin
# copy src code: There's none for the moment
#COPY --chown=${SC_USER_NAME}:${SC_USER_NAME} src/k_wave src/k_wave
# ------------------------------------------------------------------------------------
#TODO:
# uncomment and adapt if build steps are necessary. For now, we use the compiled executable
RUN cp -R /build/kspaceFirstOrder-CUDA /build/bin
# ------------------------------------------------------------------------------------
# Clone the open-source k-Wave CUDA fluid solver.
RUN git clone --depth 1 https://github.com/klepo/k-Wave-Fluid-CUDA.git .
Comment thread
GitHK marked this conversation as resolved.
Outdated

# --------------------------Production stage -------------------
# Final cleanup up to reduce image size and startup setup
# Runs as ${SC_USER_NAME} (non-root user)
# Patch source to fix compilation issues in the feat_q_computing branch:
#
# + /home/${SC_USER_NAME} $HOME = WORKDIR
# + k_wave [${SC_USER_NAME}:${SC_USER_NAME}]
# + docker [${SC_USER_NAME}:${SC_USER_NAME}]
# + service.cli [${SC_USER_NAME}:${SC_USER_NAME}]
#
FROM base as production
# 1. Case mismatch: sources include <KSpaceSolver/SolverCUDAKernels.cuh> (all-caps)
# but the actual file is SolverCudaKernels.cuh — create a symlink.
# 2. KSpaceFirstOrderSolver.cpp uses std::ifstream (<fstream>), strcmp (<cstring>),
# sysconf/_SC_PHYS_PAGES/_SC_PAGE_SIZE (<unistd.h>/<sys/sysinfo.h>),
# and _mm_malloc/_mm_free (<xmmintrin.h>) without including the required headers.
# 3. IndexMatrix.cpp uses ceilf() without #include <cmath>.
# 4. CompressHelper.cpp uses std::numeric_limits without #include <limits>.
RUN ln -s SolverCudaKernels.cuh KSpaceSolver/SolverCUDAKernels.cuh && \
sed -i 's|^#include <ctime>|#include <ctime>\n#include <fstream>\n#include <cstring>\n#include <unistd.h>\n#include <xmmintrin.h>|' \
KSpaceSolver/KSpaceFirstOrderSolver.cpp && \
sed -i '1s|^|#include <cmath>\n|' MatrixClasses/IndexMatrix.cpp && \
sed -i '1s|^|#include <limits>\n|' Compression/CompressHelper.cpp

# Build with CUDA 12.2.
# SEMI linking: HDF5 + zlib + szip linked statically, cuFFT dynamically
# (avoids the static-cuFFT relocation bug noted in the upstream Makefile).
# CUDA_ARCH: cover Turing (sm_75) → Ada Lovelace (sm_89) → Hopper (sm_90).
# LIBS is passed on the command line to override the ifeq(LINKING,SEMI) block,
# since Ubuntu 22.04 places static libs in /usr/lib/x86_64-linux-gnu/ not /usr/lib/.
RUN make -f Makefiles/Release/Makefile -j"$(nproc)" \
HDF5_DIR=/opt/hdf5 \
CUDA_DIR=/usr/local/cuda \
LINKING=SEMI \
LIBS="/opt/hdf5/lib/libhdf5_hl.a \
/opt/hdf5/lib/libhdf5.a \
/usr/lib/x86_64-linux-gnu/libz.a \
/usr/lib/x86_64-linux-gnu/libsz.a \
/usr/lib/x86_64-linux-gnu/libaec.a \
-lcufft -ldl" \
CUDA_ARCH="--generate-code arch=compute_75,code=sm_75 \
--generate-code arch=compute_80,code=sm_80 \
--generate-code arch=compute_86,code=sm_86 \
--generate-code arch=compute_89,code=sm_89 \
--generate-code arch=compute_90,code=sm_90"

RUN mkdir -p /build/bin \
&& cp kspaceFirstOrder-CUDA /build/bin/

# ======================== Production stage ========================
# simcore-user uid=8004(${SC_USER_NAME}) gid=8004(${SC_USER_NAME}) groups=8004(${SC_USER_NAME})
FROM nvidia/cuda:12.2.2-runtime-ubuntu22.04 AS production

ENV SC_BUILD_TARGET production
ENV SC_BOOT_MODE production
ENV SC_USER_ID=8004 \
SC_USER_NAME=scu

RUN adduser --uid ${SC_USER_ID} --disabled-password --gecos "" \
--shell /bin/sh --home /home/${SC_USER_NAME} ${SC_USER_NAME}

ENV SC_BUILD_TARGET=production \
SC_BOOT_MODE=production

ENV INPUT_FOLDER="/input" \
OUTPUT_FOLDER="/output"

# GPU access: all modern NVIDIA GPUs are visible.
# Ada Lovelace (sm_89) and Hopper (sm_90) are fully supported.
# Requires CUDA-capable driver ≥ 525 (ships CUDA 12.0 user-space ABI).
ENV NVIDIA_VISIBLE_DEVICES=all \
NVIDIA_DRIVER_CAPABILITIES=compute,utility \
NVIDIA_REQUIRE_CUDA="cuda>=12.0 driver>=525"

WORKDIR /home/${SC_USER_NAME}

# ------------------------------------------------------------------------------------
# uncomment and adapt to install runtime dependencies
RUN apt-get update \
&& apt-get -y install --no-install-recommends \
jq \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# ------------------------------------------------------------------------------------

# copy docker bootup scripts
COPY --chown=${SC_USER_NAME}:${SC_USER_NAME} docker/custom/*.sh docker/
Expand All @@ -99,9 +115,9 @@ COPY --chown=${SC_USER_NAME}:${SC_USER_NAME} service.cli/ service.cli/
# necessary to be able to call run directly without sh in front
ENV PATH="/home/${SC_USER_NAME}/service.cli:${PATH}"

# copy binaries from build
# copy binary from build stage
COPY --from=build --chown=${SC_USER_NAME}:${SC_USER_NAME} /build/bin k_wave
RUN chmod +x k_wave/*

ENTRYPOINT [ "/bin/sh", "docker/entrypoint.sh", "/bin/sh", "-c" ]
ENTRYPOINT [ "/bin/sh", "docker/entrypoint.sh" ]
CMD ["run"]
6 changes: 6 additions & 0 deletions service.cli/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
# oSPARC service entry point — called by entrypoint.sh via CMD ["run"]
# Delegates to execute.sh which reads INPUT_* env vars and launches
# kspaceFirstOrder-CUDA.

exec "$(dirname "$0")/execute.sh"
Comment thread
GitHK marked this conversation as resolved.
Outdated
Loading