From 0b601649ab6cf0326fb7b79fb3a3a14b1bb3c415 Mon Sep 17 00:00:00 2001 From: Duncan McBain Date: Wed, 22 Jan 2025 15:57:56 +0000 Subject: [PATCH 1/3] Fix old include style causing warnings We should be including the sycl.hpp header from the sycl/ folder. --- .gitignore | 3 +++ src/matrix_multiply_omp_compare/matrix-multiply.cpp | 3 ++- src/scan_parallel_inclusive/scan.cpp | 3 ++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 259148f..d634910 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,6 @@ *.exe *.out *.app + +# folders +*build*/ diff --git a/src/matrix_multiply_omp_compare/matrix-multiply.cpp b/src/matrix_multiply_omp_compare/matrix-multiply.cpp index e7e73a8..36015c9 100644 --- a/src/matrix_multiply_omp_compare/matrix-multiply.cpp +++ b/src/matrix_multiply_omp_compare/matrix-multiply.cpp @@ -24,7 +24,8 @@ * and differences between them. * See block_host for the OpenMP implementation. */ -#include +#include + #include #include #include diff --git a/src/scan_parallel_inclusive/scan.cpp b/src/scan_parallel_inclusive/scan.cpp index b099b3d..6a9f7b9 100644 --- a/src/scan_parallel_inclusive/scan.cpp +++ b/src/scan_parallel_inclusive/scan.cpp @@ -18,7 +18,8 @@ * **************************************************************************/ -#include +#include + #include #include #include From 6f9aa3f258d358c0c8d21ab0b2aeab1bbc284e67 Mon Sep 17 00:00:00 2001 From: Duncan McBain Date: Wed, 22 Jan 2025 18:50:55 +0000 Subject: [PATCH 2/3] Fix clang-formatting issues from header changes Changing from CL/sycl to sycl/sycl started forcing some header file reordering, which caused pre-commit failures in the CI. So I have changed the clang-format rules to better express what we want, which has then cause other formatting changes for files that were not already compliant to my dread will. * all "headers.hpp" * * * Other than that, changing the matmul header caused the `cl::` namespace to disappear, so was removed. Other formatting in the tuple_utils header started becoming a bit nasty so knowing that SYCL requires C++ 17, I changed to `decltype(auto)` for some of the function return types. --- .clang-format | 21 +++++++------------ src/fluid/fluid.h | 4 ++-- src/fluid/main.cpp | 4 ++-- src/game_of_life/main.cpp | 8 +++---- src/game_of_life/sim.hpp | 4 ++-- src/mandelbrot/main.cpp | 4 ++-- .../matrix-multiply.cpp | 11 +++++----- src/nbody/InteropGLBuffer.hpp | 2 ++ src/nbody/main.cpp | 12 +++++------ src/nbody/sim.hpp | 12 +++++------ src/nbody/sycl_bufs.hpp | 4 ++-- src/nbody/tuple_utils.hpp | 11 ++++------ 12 files changed, 45 insertions(+), 52 deletions(-) diff --git a/.clang-format b/.clang-format index aa68020..e7d2354 100644 --- a/.clang-format +++ b/.clang-format @@ -1,18 +1,13 @@ BasedOnStyle: Google +IncludeBlocks: Regroup IncludeCategories: - - Regex: '^$' - Priority: 3 - SortPriority: 0 - CaseSensitive: false - - Regex: '^<.*\.h>' + - Regex: '^".*"' Priority: 1 - SortPriority: 0 - CaseSensitive: false - - Regex: '^<.*' + - Regex: '^' + Priority: 3 + SortPriority: 2 + - Regex: '<^[.]+>' Priority: 4 - SortPriority: 0 - CaseSensitive: false diff --git a/src/fluid/fluid.h b/src/fluid/fluid.h index d6458d4..8195ea5 100644 --- a/src/fluid/fluid.h +++ b/src/fluid/fluid.h @@ -20,6 +20,8 @@ #pragma once +#include + #include // std::fill #include // std::round #include // std::size_t @@ -27,8 +29,6 @@ #include // std::cout, std::endl #include // std::vector -#include - // Kernel declarations. class fluid_boundary; class fluid_linear_solve; diff --git a/src/fluid/main.cpp b/src/fluid/main.cpp index 43fdc90..fdccf30 100644 --- a/src/fluid/main.cpp +++ b/src/fluid/main.cpp @@ -18,6 +18,8 @@ * **************************************************************************/ +#include "fluid.h" + #include #include #include @@ -33,8 +35,6 @@ #include -#include "fluid.h" - constexpr Magnum::PixelFormat PIXELFORMAT{Magnum::PixelFormat::RGBA8Unorm}; // Title bar text diff --git a/src/game_of_life/main.cpp b/src/game_of_life/main.cpp index 1764bb8..d2393f7 100644 --- a/src/game_of_life/main.cpp +++ b/src/game_of_life/main.cpp @@ -18,6 +18,8 @@ * **************************************************************************/ +#include "sim.hpp" + #include #include #include @@ -30,12 +32,10 @@ #include #include -#include -#include - #include -#include "sim.hpp" +#include +#include constexpr Magnum::PixelFormat PIXELFORMAT{Magnum::PixelFormat::RGBA8Unorm}; diff --git a/src/game_of_life/sim.hpp b/src/game_of_life/sim.hpp index 7f27c2e..862d309 100644 --- a/src/game_of_life/sim.hpp +++ b/src/game_of_life/sim.hpp @@ -20,11 +20,11 @@ #pragma once -#include +#include "../include/double_buf.hpp" #include -#include "../include/double_buf.hpp" +#include enum class CellState : unsigned int { LIVE = 1, diff --git a/src/mandelbrot/main.cpp b/src/mandelbrot/main.cpp index 0f3ecb8..9531df6 100644 --- a/src/mandelbrot/main.cpp +++ b/src/mandelbrot/main.cpp @@ -18,6 +18,8 @@ * **************************************************************************/ +#include "mandel.hpp" + #include #include #include @@ -32,8 +34,6 @@ #include -#include "mandel.hpp" - constexpr size_t WIDTH = 800; constexpr size_t HEIGHT = 600; constexpr Magnum::PixelFormat PIXELFORMAT{Magnum::PixelFormat::RGBA8Unorm}; diff --git a/src/matrix_multiply_omp_compare/matrix-multiply.cpp b/src/matrix_multiply_omp_compare/matrix-multiply.cpp index 36015c9..2c04e11 100644 --- a/src/matrix_multiply_omp_compare/matrix-multiply.cpp +++ b/src/matrix_multiply_omp_compare/matrix-multiply.cpp @@ -31,7 +31,7 @@ #include #include -using namespace cl::sycl; +using namespace sycl; class mxm_kernel; @@ -112,7 +112,7 @@ inline bool isPowerOfTwo(int x) { return (x & (x - 1)) == 0; } * Note that this example only works for powers of two. * */ template -bool local_mxm(cl::sycl::queue& q, T* MA, T* MB, T* MC, int matSize) { +bool local_mxm(sycl::queue& q, T* MA, T* MB, T* MC, int matSize) { // Make sure it is power of two before running if (!isPowerOfTwo(matSize)) { std::cout << " This example only works with power of two sizes " @@ -122,7 +122,7 @@ bool local_mxm(cl::sycl::queue& q, T* MA, T* MB, T* MC, int matSize) { auto device = q.get_device(); auto maxBlockSize = - device.get_info(); + device.get_info(); auto blockSize = prevPowerOfTwo(std::sqrt(maxBlockSize)); std::cout << " The Device Max Work Group Size is : " << maxBlockSize << std::endl; @@ -325,14 +325,13 @@ int main(int argc, char* argv[]) { * to capture potential asynchronous errors. This function will be * called every time there is an asynchronous error on the queue (i.e. * some error occurs while the queue is executing kernels) and one of - * cl::sycl::queue::throw() or cl::sycl::queue::wait_and_throw() is - * called. */ + * sycl::queue::throw() or sycl::queue::wait_and_throw() is called. */ queue q([&](exception_list eL) { try { for (auto& e : eL) { std::rethrow_exception(e); } - } catch (cl::sycl::exception e) { + } catch (sycl::exception e) { std::cout << " An exception has been thrown: " << e.what() << std::endl; } diff --git a/src/nbody/InteropGLBuffer.hpp b/src/nbody/InteropGLBuffer.hpp index 28db459..33bc60f 100644 --- a/src/nbody/InteropGLBuffer.hpp +++ b/src/nbody/InteropGLBuffer.hpp @@ -10,6 +10,8 @@ #define CUDA_GL_INTEROP_API_AVAILABLE 0 #endif +#include + /// @brief Magnum GL Buffer wrapper implementing backend-specific interop to /// work directly on OpenGL device buffers instead of using host memory. /// diff --git a/src/nbody/main.cpp b/src/nbody/main.cpp index e0622f7..f87a4b9 100644 --- a/src/nbody/main.cpp +++ b/src/nbody/main.cpp @@ -18,6 +18,9 @@ * **************************************************************************/ +#include "InteropGLBuffer.hpp" +#include "sim.hpp" + #include #include #include @@ -28,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -40,14 +44,10 @@ #include #include -#include -#include -#include - #include -#include "InteropGLBuffer.hpp" -#include "sim.hpp" +#include +#include using num_t = float; constexpr num_t PI{3.141592653589793238462643383279502884197169399}; diff --git a/src/nbody/sim.hpp b/src/nbody/sim.hpp index 5df3b79..61758f7 100644 --- a/src/nbody/sim.hpp +++ b/src/nbody/sim.hpp @@ -20,17 +20,17 @@ #pragma once -#include -#include -#include - -#include - #include "../include/double_buf.hpp" #include "integrator.hpp" #include "sycl_bufs.hpp" #include "tuple_utils.hpp" +#include + +#include +#include +#include + // Convenience types template using vec3 = sycl::vec; diff --git a/src/nbody/sycl_bufs.hpp b/src/nbody/sycl_bufs.hpp index 0b2207d..9dab42c 100644 --- a/src/nbody/sycl_bufs.hpp +++ b/src/nbody/sycl_bufs.hpp @@ -20,11 +20,11 @@ #pragma once -#include +#include "tuple_utils.hpp" #include -#include "tuple_utils.hpp" +#include // Template function object which transforms buffers to device read accessors struct BufToReadAccFunc { diff --git a/src/nbody/tuple_utils.hpp b/src/nbody/tuple_utils.hpp index 2128b54..74f9a04 100644 --- a/src/nbody/tuple_utils.hpp +++ b/src/nbody/tuple_utils.hpp @@ -111,7 +111,7 @@ namespace { template auto squash_tuple_help(Tuple && tpl, index_sequence) - ->decltype(std::make_tuple(std::get(std::forward(tpl))...)) { + -> decltype(std::make_tuple(std::get(std::forward(tpl))...)) { return std::make_tuple(std::get(std::forward(tpl))...); } } @@ -130,9 +130,8 @@ auto squash_tuple(Tuple&& tpl) // Adds tuples by calling operator+ elementwise. namespace { template -auto add_tuples_help(TupleA&& a, TupleB&& b, index_sequence) - -> decltype(std::make_tuple(std::get(std::forward(a)) + - std::get(std::forward(b))...)) { +auto add_tuples_help(TupleA&& a, TupleB&& b, + index_sequence) -> decltype(auto) { return std::make_tuple(std::get(std::forward(a)) + std::get(std::forward(b))...); } @@ -143,9 +142,7 @@ template < size_t SizeA = std::tuple_size::type>::value, size_t SizeB = std::tuple_size::type>::value, typename Ids = make_index_sequence> -auto add_tuples(TupleA&& a, TupleB&& b) - -> decltype(add_tuples_help(std::forward(a), - std::forward(b), Ids{})) { +auto add_tuples(TupleA&& a, TupleB&& b) -> decltype(auto) { static_assert(SizeA == SizeB, "Cannot add tuples of differing sizes."); return add_tuples_help(std::forward(a), std::forward(b), Ids{}); From 824f21411910a7e395d547d2064a89983cf52d89 Mon Sep 17 00:00:00 2001 From: Duncan McBain Date: Wed, 22 Jan 2025 19:56:45 +0000 Subject: [PATCH 3/3] Add clang-format v17 formatting --- src/nbody/tuple_utils.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nbody/tuple_utils.hpp b/src/nbody/tuple_utils.hpp index 74f9a04..2603fcc 100644 --- a/src/nbody/tuple_utils.hpp +++ b/src/nbody/tuple_utils.hpp @@ -111,7 +111,7 @@ namespace { template auto squash_tuple_help(Tuple && tpl, index_sequence) - -> decltype(std::make_tuple(std::get(std::forward(tpl))...)) { + ->decltype(std::make_tuple(std::get(std::forward(tpl))...)) { return std::make_tuple(std::get(std::forward(tpl))...); } } @@ -130,8 +130,8 @@ auto squash_tuple(Tuple&& tpl) // Adds tuples by calling operator+ elementwise. namespace { template -auto add_tuples_help(TupleA&& a, TupleB&& b, - index_sequence) -> decltype(auto) { +auto add_tuples_help(TupleA&& a, TupleB&& b, index_sequence) + -> decltype(auto) { return std::make_tuple(std::get(std::forward(a)) + std::get(std::forward(b))...); }