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

Standalone binary #546

Merged
merged 10 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Full documentation for ROCm Compute Profiler is available at [https://rocm.docs.amd.com/projects/rocprofiler-compute/en/latest/](https://rocm.docs.amd.com/projects/rocprofiler-compute/en/latest/).

## Unreleased

* Add Docker files to package the application and dependencies into a single portable and executable standalone binary file

## (Unreleased) ROCm Compute Profiler 3.1.0 for ROCm 6.4.0

### Added
Expand Down
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,28 @@ add_custom_target(
"src/${PACKAGE_NAME},cmake/Dockerfile,cmake/rocm_install.sh,docker/docker-entrypoint.sh,src/rocprof_compute_analyze/convertor/mongodb/convert"
)

# Standalone binary creation
add_custom_target(
standalonebinary
# Change working directory to src
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src
# Check nuitka
COMMAND ${Python3_EXECUTABLE} -m pip list | grep -i nuitka > /dev/null 2>&1
Copy link
Contributor

Choose a reason for hiding this comment

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

You might want to add comments: this doesn't work on WIN.

# Check patchelf
COMMAND ${Python3_EXECUTABLE} -m pip list | grep -i patchelf > /dev/null 2>&1
# Build standalone binary
COMMAND
${Python3_EXECUTABLE} -m nuitka --mode=onefile
--include-data-files=${PROJECT_SOURCE_DIR}/VERSION*=./ --enable-plugin=no-qt
--include-package-data=dash_svg --include-package=dash_bootstrap_components
--include-package=plotly --include-package-data=kaleido
--include-package=rocprof_compute_soc --include-package-data=rocprof_compute_soc
--include-package-data=utils rocprof-compute
# Remove library rpath from executable
COMMAND patchelf --remove-rpath rocprof-compute.bin
# Move to build directory
COMMAND mv rocprof-compute.bin ${CMAKE_BINARY_DIR})

install(
FILES ${PROJECT_SOURCE_DIR}/LICENSE
DESTINATION ${CMAKE_INSTALL_DOCDIR}
Expand Down
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,22 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

This application uses the following dependencies and their usage is governed by their respective licenses
Python 3 standard library: PSFL
Nuitka specific runtime code: Apache 2.0 license
astunparse python library: PSFL
colorlover python library: MIT
dash python library: MIT
matplotlib python library: PSFL
numpy python library: BSD
pandas python library: BSD
pymongo python library: Apache 2.0 license
pyyaml python library: MIT
tabulate python library: MIT
tqdm python library: MIT
dash-svg python library: MIT
dash-bootstrap-components python library: MIT
kaleido python library: MIT
setuptools python library: MIT
plotille python library: MIT
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Users may checkout `amd-staging` to preview upcoming features.
## Testing

To quickly get the environment (bash shell) for building and testing, run the following commands:
* `cd utils/docker_env`
* `docker compose run app`
* `cd docker`
* `docker compose -f docker-compose.test.yml run test`

Inside the docker container, clean, build and install the project with tests enabled:
```
Expand All @@ -56,6 +56,27 @@ For manual testing, you can find the executable at `install/bin/rocprof-compute`

NOTE: This Dockerfile uses `rocm/dev-ubuntu-22.04` as the base image

## Standalone binary

To create a standalone binary, run the following commands:
* `cd docker`
* `docker compose -f docker-compose.standalone.yml run standalone`

You should find the rocprof-compute.bin standalone binary inside the `build` folder in the root directory of the project.

To build the binary we follow these steps:
* Use RHEL 8 image used to build ROCm as the base image
* Install python3.8
* Install dependencies for runtime and for making standalone binary
* Call the make target which uses Nuitka to build the standalone binary

NOTE: Since RHEL 8 ships with glibc version 2.28, this standalone binary can only be run on environment with glibc version greater than 2.28.
glibc version can be checked using `ldd --version` command.

NOTE: libnss3.so shared library is required when using --roof-only option which generates roofline data in PDF format

To test the standalone binary provide the `--call-binary` option to pytest.

## How to Cite

This software can be cited using a Zenodo
Expand Down
19 changes: 19 additions & 0 deletions docker/Dockerfile.standalone
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM redhat/ubi8:8.10-1184

WORKDIR /app

RUN yum install -y curl gcc cmake

RUN yum install -y python38 python38-devel && \
yum clean all && \
rm -rf /var/cache/yum && \
curl -sS https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \
python3.8 get-pip.py

CMD ["/bin/bash", "-c", "\
python3.8 -m pip install -r requirements.txt \
&& python3.8 -m pip install nuitka patchelf \
&& rm -rf build \
&& cmake -B build -S . \
&& make -C build standalonebinary \
"]
12 changes: 5 additions & 7 deletions utils/docker_env/Dockerfile → docker/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ RUN apt-get install -y python3.10 python3.10-venv python3.10-dev python3-pip
# Set Python 3.10 as the default python3
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1

# Copy your application code to the container
COPY . .

# Install any dependencies specified in requirements.txt
RUN pip3 install --no-cache-dir -r requirements.txt -r requirements-test.txt

# Command to run your application
CMD ["/bin/bash"]
# Run interactive bash shell
CMD ["/bin/bash", "-c", "\
python3.10 -m pip install -r requirements.txt -r requirements-test.txt \
&& exec /bin/bash \
"]
12 changes: 12 additions & 0 deletions docker/docker-compose.standalone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
standalone:
build:
context: ../
dockerfile: docker/Dockerfile.standalone
devices:
- /dev/kfd
- /dev/dri
security_opt:
- seccomp:unconfined
volumes:
- ../:/app
12 changes: 12 additions & 0 deletions docker/docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
services:
test:
build:
context: ../
dockerfile: docker/Dockerfile.test
devices:
- /dev/kfd
- /dev/dri
security_opt:
- seccomp:unconfined
volumes:
- ../:/app
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import pytest


def pytest_addoption(parser):
parser.addoption(
"--call-binary",
action="store_true",
default=False,
help="Call standalone binary instead of main function during tests",
)
Loading
Loading