Skip to content

Commit

Permalink
optimized
Browse files Browse the repository at this point in the history
  • Loading branch information
aghaeifar committed Aug 1, 2024
1 parent d97d18c commit 0061f3c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 41 deletions.
61 changes: 33 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,63 +1,68 @@
cmake_minimum_required(VERSION 3.18)
message(STATUS "CMake version: ${CMAKE_VERSION}")
include(CheckLanguage)

project(spinwalk LANGUAGES CUDA CXX)
set(project "SpinWalk")
project(${project})

# Find HDF5
find_package(HDF5 REQUIRED COMPONENTS CXX)

# Find OpenMP
find_package(OpenMP REQUIRED)

# Find TBB
find_package(TBB REQUIRED)

# Boost
if(CMAKE_VERSION VERSION_GREATER "3.30")
cmake_policy(SET CMP0167 NEW)
endif()
find_package(Boost COMPONENTS program_options log log_setup REQUIRED)

# FindCUDA module
if(POLICY CMP0146)
cmake_policy(SET CMP0146 OLD)
endif()
find_package(CUDA)
# find_package(CUDAToolkit)
# Find TBB
find_package(TBB REQUIRED)

check_language(CUDA)
# Check for CUDA-capable GPU
if(CUDA_FOUND)
# Check for GPU device
cuda_select_nvcc_arch_flags(ARCH_FLAGS Auto)
if(NOT ARCH_FLAGS)
message("No CUDA-capable GPU found")
endif()
# Set CUDA architecture (change according to your GPU)
# set(CUDA_ARCH "-arch=sm_75" CACHE STRING "CUDA architecture")
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
# set_property(TARGET ${target} PROPERTY CUDA_ARCHITECTURES native)
set(CMAKE_CUDA_ARCHITECTURES 75 86 89)
# Add CUDA and OpenMP flags
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${CUDA_ARCH} -Xcompiler=${OpenMP_CXX_FLAGS}")
else()
message("CUDA not found")
message("CUDA not found. Compiling without GPU support.")
endif()

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS "-lboost_program_options")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
# set(Boost_USE_STATIC_LIBS OFF)

# Add Boost and CUDA include directories
include_directories(${Boost_INCLUDE_DIRS} ${HDF5_INCLUDE_DIRS} ./include ./src ./src/shapes)
# Add the executable
add_executable(spinwalk ./src/spinwalk.cu ./src/kernels.cu ./src/file_utils.cpp ./src/shapes/shape_base.cu ./src/shapes/cylinder.cu ./src/shapes/sphere.cu)
set(SOURCES ./src/spinwalk.cu ./src/kernels.cu ./src/file_utils.cpp ./src/shapes/shape_base.cu ./src/shapes/cylinder.cu ./src/shapes/sphere.cu)

# Link CUDA and OpenMP libraries
if(CMAKE_CUDA_COMPILER)
add_executable(${project} ${SOURCES})
target_link_libraries(${project} ${CUDA_LIBRARIES} ${Boost_LIBRARIES} ${HDF5_CXX_LIBRARIES} TBB::tbb)
else()
set(RENAMED_SOURCES)
foreach(OLD_FILE ${SOURCES})
# Get the file name without extension
get_filename_component(DIR ${OLD_FILE} DIRECTORY)
get_filename_component(FILE_NAME_WE ${OLD_FILE} NAME_WE)
# Define the new file name
set(NEW_FILE ${DIR}/${FILE_NAME_WE}.cpp)
# Copy and rename the file
file(COPY_FILE ${OLD_FILE} ${NEW_FILE})
list(APPEND RENAMED_SOURCES ${NEW_FILE})
endforeach()
add_executable(${project} ${RENAMED_SOURCES})
target_link_libraries(${project} ${Boost_LIBRARIES} ${HDF5_CXX_LIBRARIES} TBB::tbb)
endif()

target_link_libraries(spinwalk ${CUDA_LIBRARIES} ${OpenMP_CXX_LIBRARIES} ${Boost_LIBRARIES} ${HDF5_CXX_LIBRARIES} TBB::tbb)
set_target_properties(${project} PROPERTIES OUTPUT_NAME "spinwalk")

if (UNIX)
install(TARGETS spinwalk DESTINATION bin)
install(TARGETS ${project} DESTINATION bin)
endif()

# cmake ..
Expand Down
15 changes: 2 additions & 13 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ USER root

# needed for add-apt-repository
RUN apt-get update && apt install -y software-properties-common && apt-get update && apt-get clean && apt-get -y autoremove && rm -rf /var/lib/apt/lists/*
# needed for gcc 11
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && apt-get clean && apt-get -y autoremove && rm -rf /var/lib/apt/lists/*

# Install the necessary dependencies for TBB and GCC 11
RUN apt-get update && apt-get install -y --no-install-recommends \
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
libtbb-dev \
Expand All @@ -22,25 +21,15 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
git \
libboost-all-dev \
libhdf5-dev \
# python3.10 \
# python3-pip \
# python-is-python3 \
# python3-venv \
&& apt-get clean && apt-get -y autoremove && rm -rf /var/lib/apt/lists/*

# RUN apt-get install nvidia-cuda-toolkit

# Set the default GCC version to 11
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 \
&& update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100

RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11 && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 11

# RUN pip install --no-cache-dir --upgrade pip && \
# pip install --no-cache-dir numpy torch scipy nibabel ipython jupyter matplotlib tqdm h5py scikit-image scikit-learn seaborn virtualenv && rm -rf /root/.cache

COPY . /opt/SpinWalk/
# Clone the Git repository
# RUN git clone --depth 1 https://github.com/aghaeifar/SpinWalk.git /opt/SpinWalk
WORKDIR /opt/SpinWalk
RUN cmake -B ./build && cmake --build ./build --config Release && cmake --install ./build
Expand Down
34 changes: 34 additions & 0 deletions Dockerfile_CPU
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

FROM ubuntu:24.04
USER root

# needed for add-apt-repository
RUN apt-get update && apt install -y software-properties-common && apt-get update && apt-get clean && apt-get -y autoremove && rm -rf /var/lib/apt/lists/*

# Install the necessary dependencies for TBB and GCC 11
RUN add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
apt-get update && apt-get install -y --no-install-recommends \
build-essential \
cmake \
libtbb-dev \
gcc-11 \
g++-11 \
libboost-all-dev \
libhdf5-dev \
&& apt-get clean && apt-get -y autoremove && rm -rf /var/lib/apt/lists/*

# Set the default GCC version to 11
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 \
&& update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 100

RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11 && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 11

COPY . /opt/SpinWalk/
WORKDIR /opt/SpinWalk
RUN cmake -B ./build && cmake --build ./build --config Release && cmake --install ./build

LABEL org.opencontainers.image.authors="Ali Aghaeifar"

# docker build -t spinwalk .
# docker run --gpus all --rm -it --runtime=nvidia spinwalk bash
# clear && rm -rf ./build && cmake -B ./build && cmake --build ./build --config Release

0 comments on commit 0061f3c

Please sign in to comment.