Skip to content

Commit

Permalink
Update clang-format include order rules (#38)
Browse files Browse the repository at this point in the history
We should be including the sycl.hpp header from the sycl/ folder.
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 caused other formatting changes for files that were not already
compliant to my dread will.

* all "headers.hpp"
* <third_party/includes.h>
* <sycl/sycl.hpp>
* <cppstdlibheaders>

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.
This is a bit more terse and functions exactly the same as the previous
version.
  • Loading branch information
DuncanMcBain authored Jan 24, 2025
1 parent 356abe1 commit 28f993e
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 52 deletions.
21 changes: 8 additions & 13 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
BasedOnStyle: Google
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<sycl/.*>$'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*\.h>'
- Regex: '^".*"'
Priority: 1
SortPriority: 0
CaseSensitive: false
- Regex: '^<.*'
- Regex: '^<sycl/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
SortPriority: 3
- Regex: '<[[:alnum:]_/]+\.(h|hpp)>'
Priority: 3
SortPriority: 2
- Regex: '<^[.]+>'
Priority: 4
SortPriority: 0
CaseSensitive: false
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@
*.exe
*.out
*.app

# folders
*build*/
4 changes: 2 additions & 2 deletions src/fluid/fluid.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@

#pragma once

#include <sycl/sycl.hpp>

#include <algorithm> // std::fill
#include <cmath> // std::round
#include <cstdlib> // std::size_t
#include <exception> // std::exception_ptr
#include <iostream> // std::cout, std::endl
#include <vector> // std::vector

#include <sycl/sycl.hpp>

// Kernel declarations.
class fluid_boundary;
class fluid_linear_solve;
Expand Down
4 changes: 2 additions & 2 deletions src/fluid/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*
**************************************************************************/

#include "fluid.h"

#include <Corrade/Containers/StringStlView.h>
#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Mesh.h>
Expand All @@ -33,8 +35,6 @@

#include <sycl/sycl.hpp>

#include "fluid.h"

constexpr Magnum::PixelFormat PIXELFORMAT{Magnum::PixelFormat::RGBA8Unorm};

// Title bar text
Expand Down
8 changes: 4 additions & 4 deletions src/game_of_life/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*
**************************************************************************/

#include "sim.hpp"

#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Mesh.h>
#include <Magnum/GL/Texture.h>
Expand All @@ -30,12 +32,10 @@
#include <Magnum/Shaders/FlatGL.h>
#include <Magnum/Trade/MeshData.h>

#include <chrono>
#include <thread>

#include <sycl/sycl.hpp>

#include "sim.hpp"
#include <chrono>
#include <thread>

constexpr Magnum::PixelFormat PIXELFORMAT{Magnum::PixelFormat::RGBA8Unorm};

Expand Down
4 changes: 2 additions & 2 deletions src/game_of_life/sim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

#pragma once

#include <random>
#include "../include/double_buf.hpp"

#include <sycl/sycl.hpp>

#include "../include/double_buf.hpp"
#include <random>

enum class CellState : unsigned int {
LIVE = 1,
Expand Down
4 changes: 2 additions & 2 deletions src/mandelbrot/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*
**************************************************************************/

#include "mandel.hpp"

#include <Magnum/GL/DefaultFramebuffer.h>
#include <Magnum/GL/Mesh.h>
#include <Magnum/GL/Texture.h>
Expand All @@ -32,8 +34,6 @@

#include <sycl/sycl.hpp>

#include "mandel.hpp"

constexpr size_t WIDTH = 800;
constexpr size_t HEIGHT = 600;
constexpr Magnum::PixelFormat PIXELFORMAT{Magnum::PixelFormat::RGBA8Unorm};
Expand Down
14 changes: 7 additions & 7 deletions src/matrix_multiply_omp_compare/matrix-multiply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
* and differences between them.
* See block_host for the OpenMP implementation. */

#include <CL/sycl.hpp>
#include <sycl/sycl.hpp>

#include <chrono>
#include <cmath>
#include <ctime>
#include <iostream>

using namespace cl::sycl;
using namespace sycl;

class mxm_kernel;

Expand Down Expand Up @@ -111,7 +112,7 @@ inline bool isPowerOfTwo(int x) { return (x & (x - 1)) == 0; }
* Note that this example only works for powers of two.
* */
template <typename T>
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 "
Expand All @@ -121,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<cl::sycl::info::device::max_work_group_size>();
device.get_info<sycl::info::device::max_work_group_size>();
auto blockSize = prevPowerOfTwo(std::sqrt(maxBlockSize));
std::cout << " The Device Max Work Group Size is : " << maxBlockSize
<< std::endl;
Expand Down Expand Up @@ -324,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;
}
Expand Down
2 changes: 2 additions & 0 deletions src/nbody/InteropGLBuffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define CUDA_GL_INTEROP_API_AVAILABLE 0
#endif

#include <iostream>

/// @brief Magnum GL Buffer wrapper implementing backend-specific interop to
/// work directly on OpenGL device buffers instead of using host memory.
///
Expand Down
12 changes: 6 additions & 6 deletions src/nbody/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*
**************************************************************************/

#include "InteropGLBuffer.hpp"
#include "sim.hpp"

#include <Corrade/PluginManager/Manager.h>
#include <Corrade/Utility/Resource.h>
#include <Magnum/GL/AbstractShaderProgram.h>
Expand All @@ -28,6 +31,7 @@
#include <Magnum/GL/Texture.h>
#include <Magnum/GL/TextureFormat.h>
#include <Magnum/GL/Version.h>
#include <Magnum/ImGuiIntegration/Context.hpp>
#include <Magnum/ImageView.h>
#include <Magnum/Magnum.h>
#include <Magnum/Math/Angle.h>
Expand All @@ -40,14 +44,10 @@
#include <Magnum/Trade/ImageData.h>
#include <Magnum/Trade/MeshData.h>

#include <Magnum/ImGuiIntegration/Context.hpp>
#include <chrono>
#include <fstream>

#include <sycl/sycl.hpp>

#include "InteropGLBuffer.hpp"
#include "sim.hpp"
#include <chrono>
#include <fstream>

using num_t = float;
constexpr num_t PI{3.141592653589793238462643383279502884197169399};
Expand Down
12 changes: 6 additions & 6 deletions src/nbody/sim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@

#pragma once

#include <iostream>
#include <memory>
#include <random>

#include <sycl/sycl.hpp>

#include "../include/double_buf.hpp"
#include "integrator.hpp"
#include "sycl_bufs.hpp"
#include "tuple_utils.hpp"

#include <sycl/sycl.hpp>

#include <iostream>
#include <memory>
#include <random>

// Convenience types
template <typename num_t>
using vec3 = sycl::vec<num_t, 3>;
Expand Down
4 changes: 2 additions & 2 deletions src/nbody/sycl_bufs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

#pragma once

#include <type_traits>
#include "tuple_utils.hpp"

#include <sycl/sycl.hpp>

#include "tuple_utils.hpp"
#include <type_traits>

// Template function object which transforms buffers to device read accessors
struct BufToReadAccFunc {
Expand Down
7 changes: 2 additions & 5 deletions src/nbody/tuple_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ auto squash_tuple(Tuple&& tpl)
namespace {
template <typename TupleA, typename TupleB, size_t... Ids>
auto add_tuples_help(TupleA&& a, TupleB&& b, index_sequence<Ids...>)
-> decltype(std::make_tuple(std::get<Ids>(std::forward<TupleA>(a)) +
std::get<Ids>(std::forward<TupleB>(b))...)) {
-> decltype(auto) {
return std::make_tuple(std::get<Ids>(std::forward<TupleA>(a)) +
std::get<Ids>(std::forward<TupleB>(b))...);
}
Expand All @@ -143,9 +142,7 @@ template <
size_t SizeA = std::tuple_size<typename std::decay<TupleA>::type>::value,
size_t SizeB = std::tuple_size<typename std::decay<TupleB>::type>::value,
typename Ids = make_index_sequence<SizeA>>
auto add_tuples(TupleA&& a, TupleB&& b)
-> decltype(add_tuples_help(std::forward<TupleA>(a),
std::forward<TupleB>(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<TupleA>(a), std::forward<TupleB>(b),
Ids{});
Expand Down
3 changes: 2 additions & 1 deletion src/scan_parallel_inclusive/scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*
**************************************************************************/

#include <CL/sycl.hpp>
#include <sycl/sycl.hpp>

#include <algorithm>
#include <iostream>
#include <numeric>
Expand Down

0 comments on commit 28f993e

Please sign in to comment.