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

Can build with no render #30

Merged
merged 9 commits into from
Jan 11, 2024
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ log*
.vscode
nbody_dpcpp
nbody_cuda
nbody_cuda_d
nbody_dpcpp_d
56 changes: 56 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"configurations": [
{
"name": "DEBUG: (gdb-oneapi) nbody_dpcpp_d Launch",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "Debug C/C++: DPCPP Makefile",
"postDebugTask": "",
"program": "${workspaceFolder}/nbody_dpcpp_d",
"args": ["50", "4", "0.999998", "0.005", "1.0e-7", "2.0", "100000"],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [
{
"name": "ZET_ENABLE_PROGRAM_DEBUGGING",
"value": "1"
},
{
"name": "IGC_EnableGTLocationDebugging",
"value": "1"
}
],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "gdb-oneapi",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Disable target async",
"text": "set target-async off",
"ignoreFailures": true
},
{
"description": "Do not display function arguments when printing a stack frame",
"text": "set print frame-arguments none",
"ignoreFailures": true
}
]
},
{
"name": "DEBUG: (cuda-gdb) nbody_cuda_d Launch",
"type": "cuda-gdb",
"request": "launch",
"preLaunchTask": "Debug C/C++: CUDA Makefile",
"postDebugTask": "",
"program": "${workspaceFolder}/nbody_cuda_d",
"args": "50 4 0.999998 0.005 1.0e-7 2.0 100000",
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
}
]
}
69 changes: 69 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "Debug C/C++: CUDA Makefile",
"command": "make",
"args": [
"debug",
],
"options": {
"cwd": "${workspaceFolder}/build_cuda"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: INTEL oneapi icpx"
},
{
"type": "cppbuild",
"label": "Release C/C++: CUDA Makefile",
"command": "make",
"args": [
"release"
],
"options": {
"cwd": "${workspaceFolder}/build_cuda"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: INTEL oneapi icpx"
},
{
"type": "cppbuild",
"label": "Release C/C++: DPCPP Makefile",
"command": "make",
"args": [
"release"
],
"options": {
"cwd": "${workspaceFolder}build_dpcpp"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: INTEL oneapi icpx"
},
{
"type": "cppbuild",
"label": "Debug C/C++: DPCPP Makefile",
"command": "make",
"args": [
"debug"
],
"options": {
"cwd": "${workspaceFolder}/build_dpcpp"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: INTEL oneapi icpx"
}
]
}
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

set(BACKEND "CUDA" CACHE STRING "Which backend to build")
option(RENDER "Use openGl or not" ON)

if(BACKEND STREQUAL "CUDA")
set(BINARY_NAME "nbody_cuda" CACHE STRING "Binary name")
enable_language(CUDA)
add_subdirectory(src)
set(BINARY_NAME "nbody_cuda" CACHE STRING "Binary name")
enable_language(CUDA)
add_subdirectory(src)
elseif(BACKEND STREQUAL "DPCPP")
set(BINARY_NAME "nbody_dpcpp" CACHE STRING "Binary name")
add_subdirectory(src_sycl)
set(BINARY_NAME "nbody_dpcpp" CACHE STRING "Binary name")
add_subdirectory(src_sycl)
else()
message(FATAL_ERROR "Unrecognized BACKEND")
message(FATAL_ERROR "Unrecognized BACKEND")
endif()

if(RENDER)
add_subdirectory(libs/imgui)
endif()

add_subdirectory(libs/imgui)
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Source code for the CUDA version is in `./src/` while `./src_sycl/` contains the

### Graphics Dependencies

By default the build requieres OpenGL. See the **Building** section below to build without rendering.

The rendering components of this code are independent of the CUDA/SYCL backend, and depend on:
- GLM
- GLFW
Expand Down Expand Up @@ -49,6 +51,12 @@ The CMake option `-DBACKEND` allows to select which backend ("CUDA" or "DPCPP")

The DPC++ backend, in turn, supports both an OpenCL & CUDA backend, both of which are built by default. If you are building on a machine without CUDA support, you can switch off the DPC++ CUDA backend with the flag `-DDPCPP_CUDA_SUPPORT=off`.

The build scripts create a version that includes rendering. To build versions that do not require OpenGL, provide the argument **no_render** to the build scripts.

By default, a **release** target is built, for example, `nbody_cuda`. To build a debug version, navigate to the build directory and execute **make debug**. Running **make** will build both versions. The debug binary will share the same name as the **release** version with "_d" appended.

The provided `tasks.json` and `launch.json` configuration files for vscode serve as examples, demonstrating how to initiate a debug session directly from within vscode.

## Migrating CUDA to SYCL

The script `./scripts/run_dpct.sh` calls a containerized version of the Intel® DPC++ Compatibility Tool to automatically convert the CUDA components of this project into SYCL. A docker container was used because the dev machine has an incompatible version of the CUDA driver. This should be adapted based on your environment.
Expand Down
2 changes: 2 additions & 0 deletions libs/imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ target_link_libraries(imgui PRIVATE dl)
target_include_directories(imgui PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)

target_include_directories(${BINARY_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include)
target_include_directories(${BINARY_NAME}_d PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include)

# Link main project to imgui lib
target_link_libraries(${BINARY_NAME} PRIVATE imgui)
target_link_libraries(${BINARY_NAME}_d PRIVATE imgui)
13 changes: 12 additions & 1 deletion scripts/build_cuda.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@
# For a copy, see https://opensource.org/licenses/MIT.

BUILD_DIR="build_cuda"
render=on

if [ -n "$1" ]; then
if [ "$1" = "no_render" ]; then
render=off
else
echo "Unknown param $1"
exit
fi
fi

rm -rf $BUILD_DIR
mkdir $BUILD_DIR
cd $BUILD_DIR || exit

cmake ../ \
-DRENDER=${render} \
-DGLEW_LIBRARY=/usr/lib/x86_64-linux-gnu/libGLEW.so \
-DCMAKE_EXPORT_COMPILE_COMMANDS=on || exit

make
make release
19 changes: 16 additions & 3 deletions scripts/build_dpcpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,28 @@
# For a copy, see https://opensource.org/licenses/MIT.

BUILD_DIR="build_dpcpp"
render=on

if [ -n "$1" ]; then
if [ "$1" = "no_render" ]; then
render=off
else
echo "Unknown param $1"
exit
fi
fi

rm -rf $BUILD_DIR
mkdir $BUILD_DIR
cd $BUILD_DIR || exit

CXX=clang++ \
CC=clang \
#CXX=clang++ \
#CC=clang \
CXX=icpx \
CC=icpx \
cmake ../ \
-DRENDER=${render} \
-DGLEW_LIBRARY=/usr/lib/x86_64-linux-gnu/libGLEW.so \
-DBACKEND=DPCPP -DDPCPP_CUDA_SUPPORT=on || exit

make
make release
54 changes: 37 additions & 17 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,57 @@

find_package(PkgConfig REQUIRED)

pkg_check_modules(Glew REQUIRED IMPORTED_TARGET glew)
if (RENDER)
pkg_check_modules(Glew REQUIRED IMPORTED_TARGET glew)

find_package(glm REQUIRED)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
find_package(glm REQUIRED)
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
endif()

find_package(CUDA REQUIRED)

set(COMMON_SOURCE
nbody.cpp
camera.cpp
sim_param.cpp
gen.cpp
simulator.cu)

nbody.cpp
sim_param.cpp
simulator.cu)
set(OPENGL_SOURCE
renderer_gl.cpp
shader.cpp)
camera.cpp
gen.cpp
renderer_gl.cpp
shader.cpp)

if(NOT TARGET glm::glm)
add_library(glm::glm IMPORTED INTERFACE)
target_include_directories(glm::glm INTERFACE ${GLM_INCLUDE_DIR})
endif()

add_executable(${BINARY_NAME} ${COMMON_SOURCE} ${OPENGL_SOURCE})
set(DEBUG_FLAGS -g -O0)

# COMPILER_NAME here is only used to print text overlay on simulation
target_compile_definitions(${BINARY_NAME} PRIVATE -DUSE_OPENGL COMPILER_NAME="CUDA")

target_compile_features(${BINARY_NAME} PRIVATE cxx_auto_type cxx_nullptr cxx_range_for)
if (RENDER)
set(RENDER_LIB glm::glm glfw PkgConfig::Glew OpenGL::OpenGL cuda)
set(RENDER_FLAG -DUSE_OPENGL)
set(SOURCE_FILES ${COMMON_SOURCE} ${OPENGL_SOURCE})
else()
set(RENDER_LIB cuda)
set(RENDER_FLAG DISABLE_GL)
set(SOURCE_FILES ${COMMON_SOURCE})
endif()

add_custom_target(release DEPENDS ${BINARY_NAME})
add_executable(${BINARY_NAME} ${SOURCE_FILES})
# COMPILER_NAME here is only used to print text overlay on simulation
target_compile_definitions(${BINARY_NAME} PRIVATE ${RENDER_FLAG} COMPILER_NAME="CUDA")
target_link_libraries(${BINARY_NAME} PRIVATE ${RENDER_LIB})
target_compile_features(${BINARY_NAME} PRIVATE cxx_auto_type cxx_nullptr cxx_range_for)
target_include_directories(${BINARY_NAME} PRIVATE ${CUDA_INCLUDE_DIRS})

target_link_libraries(${BINARY_NAME} PRIVATE glm::glm glfw PkgConfig::Glew OpenGL::OpenGL cuda)
add_custom_target(debug DEPENDS ${BINARY_NAME}_d)
add_executable(${BINARY_NAME}_d ${SOURCE_FILES})
# COMPILER_NAME here is only used to print text overlay on simulation
target_compile_definitions(${BINARY_NAME}_d PRIVATE ${RENDER_FLAG} COMPILER_NAME="CUDA")
target_link_libraries(${BINARY_NAME}_d PRIVATE ${RENDER_LIB})
target_compile_features(${BINARY_NAME}_d PRIVATE cxx_auto_type cxx_nullptr cxx_range_for)
target_include_directories(${BINARY_NAME}_d PRIVATE ${CUDA_INCLUDE_DIRS})
target_compile_options(${BINARY_NAME}_d PRIVATE ${DEBUG_FLAGS})
DuncanMcBain marked this conversation as resolved.
Show resolved Hide resolved
Loading