From 3cd6267aa3e9dfe8c12757ca109b307d51a8916c Mon Sep 17 00:00:00 2001 From: Tobias Hienzsch Date: Thu, 19 Sep 2024 06:43:13 +0200 Subject: [PATCH] [cpp] Move engines to library --- src/cpp/CMakeLists.txt | 10 +++++++++- src/cpp/main_2d/CMakeLists.txt | 12 +----------- src/cpp/main_2d/main.cpp | 12 +++++------- src/cpp/main_3d/main.cpp | 8 ++++---- .../engine_2d_native.cpp} | 2 +- .../engine_2d_native.hpp} | 0 .../engine_sycl.cpp => pffdtd/engine_2d_sycl.cpp} | 2 +- .../engine_sycl.hpp => pffdtd/engine_2d_sycl.hpp} | 0 8 files changed, 21 insertions(+), 25 deletions(-) rename src/cpp/{main_2d/engine_native.cpp => pffdtd/engine_2d_native.cpp} (99%) rename src/cpp/{main_2d/engine_native.hpp => pffdtd/engine_2d_native.hpp} (100%) rename src/cpp/{main_2d/engine_sycl.cpp => pffdtd/engine_2d_sycl.cpp} (99%) rename src/cpp/{main_2d/engine_sycl.hpp => pffdtd/engine_2d_sycl.hpp} (100%) diff --git a/src/cpp/CMakeLists.txt b/src/cpp/CMakeLists.txt index 50a2642..a86442b 100644 --- a/src/cpp/CMakeLists.txt +++ b/src/cpp/CMakeLists.txt @@ -19,6 +19,8 @@ target_link_libraries(pffdtd target_sources(pffdtd PRIVATE pffdtd/config.hpp + pffdtd/engine_2d_native.cpp + pffdtd/engine_2d_native.hpp pffdtd/engine_openmp.cpp pffdtd/engine_openmp.hpp pffdtd/exception.hpp @@ -40,7 +42,14 @@ target_sources(pffdtd target_compile_definitions(pffdtd PUBLIC _CRT_SECURE_NO_WARNINGS=1) if(PFFDTD_HAS_SYCL) + target_sources(pffdtd PRIVATE pffdtd/engine_2d_sycl.cpp pffdtd/engine_2d_sycl.hpp) + add_sycl_to_target(TARGET pffdtd SOURCES pffdtd/engine_2d_sycl.cpp) target_compile_definitions(pffdtd PUBLIC PFFDTD_HAS_SYCL=1) + + if(PFFDTD_ENABLE_SYCL_ONEAPI) + set_source_files_properties(pffdtd/engine_2d_sycl.cpp PROPERTIES COMPILE_FLAGS "-fsycl-targets=nvptx64-nvidia-cuda") + target_link_libraries(pffdtd PRIVATE "-fsycl-targets=nvptx64-nvidia-cuda") + endif() endif() if(PFFDTD_ENABLE_CUDA) @@ -50,7 +59,6 @@ else() target_compile_definitions(pffdtd PUBLIC PFFDTD_HAS_CUDA=0) endif() - if((CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") OR (CMAKE_CXX_COMPILER_FRONTEND_VARIANT STREQUAL "MSVC")) target_compile_options(pffdtd PUBLIC /W3) else () diff --git a/src/cpp/main_2d/CMakeLists.txt b/src/cpp/main_2d/CMakeLists.txt index 0ec3a0a..6063c32 100644 --- a/src/cpp/main_2d/CMakeLists.txt +++ b/src/cpp/main_2d/CMakeLists.txt @@ -3,15 +3,5 @@ project(pffdtd_2d) -add_executable(pffdtd_2d main.cpp engine_native.cpp) +add_executable(pffdtd_2d main.cpp) target_link_libraries(pffdtd_2d PRIVATE CLI11::CLI11 pffdtd::pffdtd) - -if(PFFDTD_HAS_SYCL) - target_sources(pffdtd_2d PRIVATE engine_sycl.cpp) - add_sycl_to_target(TARGET pffdtd_2d SOURCES engine_sycl.cpp) -endif() - -if(PFFDTD_ENABLE_SYCL_ONEAPI) - set_source_files_properties(engine_sycl.cpp PROPERTIES COMPILE_FLAGS "-fsycl-targets=nvptx64-nvidia-cuda") - target_link_libraries(pffdtd_2d PRIVATE "-fsycl-targets=nvptx64-nvidia-cuda") -endif() diff --git a/src/cpp/main_2d/main.cpp b/src/cpp/main_2d/main.cpp index 8c87240..b571e53 100644 --- a/src/cpp/main_2d/main.cpp +++ b/src/cpp/main_2d/main.cpp @@ -1,19 +1,17 @@ // SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: 2024 Tobias Hienzsch -#include "engine_native.hpp" - -#if defined(PFFDTD_HAS_SYCL) - #include "engine_sycl.hpp" -#endif - +#include "pffdtd/engine_2d_native.hpp" #include "pffdtd/exception.hpp" #include "pffdtd/hdf.hpp" #include "pffdtd/simulation_2d.hpp" #include "pffdtd/time.hpp" -#include +#if defined(PFFDTD_HAS_SYCL) + #include "pffdtd/engine_2d_sycl.hpp" +#endif +#include #include #include diff --git a/src/cpp/main_3d/main.cpp b/src/cpp/main_3d/main.cpp index 1eea9ce..c55a4d2 100644 --- a/src/cpp/main_3d/main.cpp +++ b/src/cpp/main_3d/main.cpp @@ -2,14 +2,14 @@ // SPDX-FileCopyrightText: 2021 Brian Hamilton // Main entry point of the CPU/GPU PFFDTD engines. -#include "pffdtd/simulation_3d.hpp" -#include "pffdtd/time.hpp" -#include "pffdtd/utility.hpp" - #ifndef PFFDTD_HAS_CUDA #error "forgot to define PFFDTD_HAS_CUDA" #endif +#include "pffdtd/simulation_3d.hpp" +#include "pffdtd/time.hpp" +#include "pffdtd/utility.hpp" + #if PFFDTD_HAS_CUDA #include "pffdtd/engine_cuda.hpp" #else diff --git a/src/cpp/main_2d/engine_native.cpp b/src/cpp/pffdtd/engine_2d_native.cpp similarity index 99% rename from src/cpp/main_2d/engine_native.cpp rename to src/cpp/pffdtd/engine_2d_native.cpp index 9a71b8a..84a467c 100644 --- a/src/cpp/main_2d/engine_native.cpp +++ b/src/cpp/pffdtd/engine_2d_native.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: 2024 Tobias Hienzsch -#include "engine_native.hpp" +#include "engine_2d_native.hpp" #include diff --git a/src/cpp/main_2d/engine_native.hpp b/src/cpp/pffdtd/engine_2d_native.hpp similarity index 100% rename from src/cpp/main_2d/engine_native.hpp rename to src/cpp/pffdtd/engine_2d_native.hpp diff --git a/src/cpp/main_2d/engine_sycl.cpp b/src/cpp/pffdtd/engine_2d_sycl.cpp similarity index 99% rename from src/cpp/main_2d/engine_sycl.cpp rename to src/cpp/pffdtd/engine_2d_sycl.cpp index 36d4b6a..c0815ad 100644 --- a/src/cpp/main_2d/engine_sycl.cpp +++ b/src/cpp/pffdtd/engine_2d_sycl.cpp @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: 2024 Tobias Hienzsch -#include "engine_sycl.hpp" +#include "engine_2d_sycl.hpp" #include "pffdtd/sycl.hpp" diff --git a/src/cpp/main_2d/engine_sycl.hpp b/src/cpp/pffdtd/engine_2d_sycl.hpp similarity index 100% rename from src/cpp/main_2d/engine_sycl.hpp rename to src/cpp/pffdtd/engine_2d_sycl.hpp