diff --git a/CLAUDE.md b/CLAUDE.md index b90f102..843d61d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -205,8 +205,28 @@ pushpull's fully-static order×bound compile is nightly which category a dependency is in, not about lookup. `tools/normalise-include-delimiters.py --check` enforces it, and also checks the converse: every quoted include must resolve beside its includer. +- **`#pragma once` on line 1 of every header — no `#ifndef` include guards.** + Line 1 with no exception, licence and provenance comments included; they keep + their text and sit one line lower. **`include/fastfields/core/dlpack.h` is + the one exception and must keep its upstream `DLPACK_DLPACK_H_` guard** — it + is a verbatim vendored copy, and that macro is what lets it and a *system* + DLPack header carrying the same guard collapse into one inclusion, which + `#pragma once` cannot do for two distinct files. Do not "finish the job" on + it. The seven other headers with third-party provenance (`impl/kernels/`'s + `atomic.h`, `parallel{,_impl}.h`, `threadpool.{h,inl}`, `distance/mesh.h`, + and `impl/cuda/utils.h`) are adaptations, not drop-in copies: each is + re-namespaced into `ff::` and none carries an upstream guard macro, so there + is nothing for a guard to interoperate with and the pragma applies to them. + A partial-file `#ifndef` is *not* a header guard and this rule leaves it + alone — `FF_LIB_BOUND_SPLINE_T` (eight `api/*.h` headers share it so they + co-include; `fastfields-dlpack`'s `ext.cpp` depends on that and says so) and + the `FF_*_MAX_NBATCH` / `FF_AUTOCAST_PINNED_HOST` build knobs all stay. + Enforced by `tools/normalise-header-guards.py --check`, which also applies + the convention and audits that no guard macro is tested from another file — + the one way deleting a `#define` could change what compiles. - `include/fastfields/core/dlpack.h` is vendored upstream code: do not edit it, - and it is skipped by `codespell` (see `.codespellrc`). + and it is skipped by `codespell` (see `.codespellrc`). It is the only + verbatim third-party file in the tree. ## Pointers diff --git a/include/fastfields/api/checks.h b/include/fastfields/api/checks.h index 6b41d68..f4f417a 100644 --- a/include/fastfields/api/checks.h +++ b/include/fastfields/api/checks.h @@ -1,5 +1,4 @@ -#ifndef FF_LIB_CHECKS -#define FF_LIB_CHECKS +#pragma once #include #include #include @@ -56,5 +55,3 @@ inline void require_same_device(const DLTensor & ref, const DLTensor & t, const } FF_NAMESPACE_END(FF_NS) - -#endif // FF_LIB_CHECKS diff --git a/include/fastfields/api/cpu/distance.h b/include/fastfields/api/cpu/distance.h index 9382753..ff9da0c 100644 --- a/include/fastfields/api/cpu/distance.h +++ b/include/fastfields/api/cpu/distance.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_DISTANCE -#define FF_CPU_DISTANCE +#pragma once #include #include @@ -62,5 +61,3 @@ void dt_mesh( } // namespace cpu } // namespace ff - -#endif // FF_CPU_DISTANCE diff --git a/include/fastfields/api/cpu/posdef.h b/include/fastfields/api/cpu/posdef.h index 74452e5..8f95b1e 100644 --- a/include/fastfields/api/cpu/posdef.h +++ b/include/fastfields/api/cpu/posdef.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_POSDEF -#define FF_CPU_POSDEF +#pragma once #include #include @@ -80,5 +79,3 @@ void sym_invert_( } // namespace cpu } // namespace ff - -#endif // FF_CPU_POSDEF diff --git a/include/fastfields/api/cpu/pushpull.h b/include/fastfields/api/cpu/pushpull.h index 6a33df3..7141233 100644 --- a/include/fastfields/api/cpu/pushpull.h +++ b/include/fastfields/api/cpu/pushpull.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_PUSHPULL -#define FF_CPU_PUSHPULL +#pragma once #include #include @@ -199,5 +198,3 @@ void grad_backward( } // namespace cpu } // namespace ff - -#endif // FF_CPU_PUSHPULL diff --git a/include/fastfields/api/cpu/pushpull_dispatch.h b/include/fastfields/api/cpu/pushpull_dispatch.h index a05e64c..a6383b4 100644 --- a/include/fastfields/api/cpu/pushpull_dispatch.h +++ b/include/fastfields/api/cpu/pushpull_dispatch.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_PUSHPULL_DISPATCH -#define FF_CPU_PUSHPULL_DISPATCH +#pragma once /** * Private (not installed) header: the argument-marshalling helpers, the * argument checks and the ndim x order x bound x dtype dispatch matrix @@ -103,5 +102,3 @@ typedef double reduce_t; FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_CPU_PUSHPULL_DISPATCH diff --git a/include/fastfields/api/cpu/reg_field.h b/include/fastfields/api/cpu/reg_field.h index ed3abb5..6d5e005 100644 --- a/include/fastfields/api/cpu/reg_field.h +++ b/include/fastfields/api/cpu/reg_field.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_REG_FIELD -#define FF_CPU_REG_FIELD +#pragma once #include #include @@ -368,5 +367,3 @@ void field_relax_rls( } // namespace cpu } // namespace ff - -#endif // FF_CPU_REG_FIELD diff --git a/include/fastfields/api/cpu/reg_flow.h b/include/fastfields/api/cpu/reg_flow.h index e19c798..cbf300c 100644 --- a/include/fastfields/api/cpu/reg_flow.h +++ b/include/fastfields/api/cpu/reg_flow.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_REG_FLOW -#define FF_CPU_REG_FLOW +#pragma once #include #include @@ -404,5 +403,3 @@ void flow_relax_rls( } // namespace cpu } // namespace ff - -#endif // FF_CPU_REG_FLOW diff --git a/include/fastfields/api/cpu/resize.h b/include/fastfields/api/cpu/resize.h index e67ef75..8734d0e 100644 --- a/include/fastfields/api/cpu/resize.h +++ b/include/fastfields/api/cpu/resize.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_RESIZE -#define FF_CPU_RESIZE +#pragma once #include #include @@ -38,5 +37,3 @@ void resample( } // namespace cpu } // namespace ff - -#endif // FF_CPU_RESIZE diff --git a/include/fastfields/api/cpu/restrict.h b/include/fastfields/api/cpu/restrict.h index a1c0c95..cab6c1d 100644 --- a/include/fastfields/api/cpu/restrict.h +++ b/include/fastfields/api/cpu/restrict.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_RESTRICT -#define FF_CPU_RESTRICT +#pragma once #include #include @@ -40,5 +39,3 @@ void restriction( } // namespace cpu } // namespace ff - -#endif // FF_CPU_RESTRICT diff --git a/include/fastfields/api/cpu/solve_field.h b/include/fastfields/api/cpu/solve_field.h index 31d4ec3..3e7367e 100644 --- a/include/fastfields/api/cpu/solve_field.h +++ b/include/fastfields/api/cpu/solve_field.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_SOLVE_FIELD -#define FF_CPU_SOLVE_FIELD +#pragma once #include #include @@ -66,5 +65,3 @@ void field_cg( } // namespace cpu } // namespace ff - -#endif // FF_CPU_SOLVE_FIELD diff --git a/include/fastfields/api/cpu/splinc.h b/include/fastfields/api/cpu/splinc.h index f2acc00..751a369 100644 --- a/include/fastfields/api/cpu/splinc.h +++ b/include/fastfields/api/cpu/splinc.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_SPLINC -#define FF_CPU_SPLINC +#pragma once #include #include @@ -28,5 +27,3 @@ void spline_coeff( } // namespace cpu } // namespace ff - -#endif // FF_CPU_SPLINC diff --git a/include/fastfields/api/cuda/distance.h b/include/fastfields/api/cuda/distance.h index 70b8350..42aa97e 100644 --- a/include/fastfields/api/cuda/distance.h +++ b/include/fastfields/api/cuda/distance.h @@ -1,5 +1,4 @@ -#ifndef FF_CUDA_DISTANCE -#define FF_CUDA_DISTANCE +#pragma once #include #include @@ -62,5 +61,3 @@ void dt_mesh( } // namespace cuda } // namespace ff - -#endif // FF_CUDA_DISTANCE diff --git a/include/fastfields/api/cuda/posdef.h b/include/fastfields/api/cuda/posdef.h index 7f3cab6..339f8fc 100644 --- a/include/fastfields/api/cuda/posdef.h +++ b/include/fastfields/api/cuda/posdef.h @@ -1,5 +1,4 @@ -#ifndef FF_CUDA_POSDEF -#define FF_CUDA_POSDEF +#pragma once #include #include @@ -80,5 +79,3 @@ void sym_invert_( } // namespace cuda } // namespace ff - -#endif // FF_CUDA_POSDEF diff --git a/include/fastfields/api/cuda/pushpull.h b/include/fastfields/api/cuda/pushpull.h index 4f64e26..732c16f 100644 --- a/include/fastfields/api/cuda/pushpull.h +++ b/include/fastfields/api/cuda/pushpull.h @@ -1,5 +1,4 @@ -#ifndef FF_CUDA_PUSHPULL -#define FF_CUDA_PUSHPULL +#pragma once #include #include @@ -199,5 +198,3 @@ void grad_backward( } // namespace cuda } // namespace ff - -#endif // FF_CUDA_PUSHPULL diff --git a/include/fastfields/api/cuda/pushpull_dispatch.h b/include/fastfields/api/cuda/pushpull_dispatch.h index 23c048c..34c9749 100644 --- a/include/fastfields/api/cuda/pushpull_dispatch.h +++ b/include/fastfields/api/cuda/pushpull_dispatch.h @@ -1,5 +1,4 @@ -#ifndef FF_CUDA_PUSHPULL_DISPATCH -#define FF_CUDA_PUSHPULL_DISPATCH +#pragma once /** * Private (not installed) header: the argument-marshalling helpers, the * argument checks and the ndim x order x bound x dtype dispatch matrix @@ -92,5 +91,3 @@ typedef double reduce_t; FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_CUDA_PUSHPULL_DISPATCH diff --git a/include/fastfields/api/cuda/reg_field.h b/include/fastfields/api/cuda/reg_field.h index f797a9b..330351b 100644 --- a/include/fastfields/api/cuda/reg_field.h +++ b/include/fastfields/api/cuda/reg_field.h @@ -1,5 +1,4 @@ -#ifndef FF_CUDA_REG_FIELD -#define FF_CUDA_REG_FIELD +#pragma once #include #include @@ -332,5 +331,3 @@ void field_relax_rls( } // namespace cuda } // namespace ff - -#endif // FF_CUDA_REG_FIELD diff --git a/include/fastfields/api/cuda/reg_flow.h b/include/fastfields/api/cuda/reg_flow.h index 8c7d78f..7d703c6 100644 --- a/include/fastfields/api/cuda/reg_flow.h +++ b/include/fastfields/api/cuda/reg_flow.h @@ -1,5 +1,4 @@ -#ifndef FF_CUDA_REG_FLOW -#define FF_CUDA_REG_FLOW +#pragma once #include #include @@ -359,5 +358,3 @@ void flow_relax_rls( } // namespace cuda } // namespace ff - -#endif // FF_CUDA_REG_FLOW diff --git a/include/fastfields/api/cuda/resize.h b/include/fastfields/api/cuda/resize.h index 119f3bf..90df298 100644 --- a/include/fastfields/api/cuda/resize.h +++ b/include/fastfields/api/cuda/resize.h @@ -1,5 +1,4 @@ -#ifndef FF_CUDA_RESIZE -#define FF_CUDA_RESIZE +#pragma once #include #include @@ -38,5 +37,3 @@ void resample( } // namespace cuda } // namespace ff - -#endif // FF_CUDA_RESIZE diff --git a/include/fastfields/api/cuda/restrict.h b/include/fastfields/api/cuda/restrict.h index d75a99b..ac7c4c3 100644 --- a/include/fastfields/api/cuda/restrict.h +++ b/include/fastfields/api/cuda/restrict.h @@ -1,5 +1,4 @@ -#ifndef FF_CUDA_RESTRICT -#define FF_CUDA_RESTRICT +#pragma once #include #include @@ -40,5 +39,3 @@ void restriction( } // namespace cuda } // namespace ff - -#endif // FF_CUDA_RESTRICT diff --git a/include/fastfields/api/cuda/splinc.h b/include/fastfields/api/cuda/splinc.h index 5cc7c12..f174c9b 100644 --- a/include/fastfields/api/cuda/splinc.h +++ b/include/fastfields/api/cuda/splinc.h @@ -1,5 +1,4 @@ -#ifndef FF_CUDA_SPLINC -#define FF_CUDA_SPLINC +#pragma once #include #include @@ -28,5 +27,3 @@ void spline_coeff( } // namespace cuda } // namespace ff - -#endif // FF_CUDA_SPLINC diff --git a/include/fastfields/api/cuda/stream.h b/include/fastfields/api/cuda/stream.h index 07a6ead..b5745e5 100644 --- a/include/fastfields/api/cuda/stream.h +++ b/include/fastfields/api/cuda/stream.h @@ -1,7 +1,4 @@ #pragma once -#ifndef FF_CUDA_STREAM -#define FF_CUDA_STREAM - /** * The public ABI carries a CUDA stream as an `intptr_t` (no CUDA types leak * into the exported signatures); the cuda-impl launchers take a real @@ -29,5 +26,3 @@ static inline cudaStream_t _reg_stream(intptr_t stream) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_CUDA_STREAM diff --git a/include/fastfields/api/distance.h b/include/fastfields/api/distance.h index 1d9a2db..9c5374e 100644 --- a/include/fastfields/api/distance.h +++ b/include/fastfields/api/distance.h @@ -1,5 +1,4 @@ -#ifndef FF_LIB_DISTANCE -#define FF_LIB_DISTANCE +#pragma once #include #include #include @@ -176,5 +175,3 @@ void dt_mesh( ); FF_NAMESPACE_END(FF_NS) - -#endif // FF_LIB_DISTANCE diff --git a/include/fastfields/api/posdef.h b/include/fastfields/api/posdef.h index 666454a..35d1582 100644 --- a/include/fastfields/api/posdef.h +++ b/include/fastfields/api/posdef.h @@ -1,5 +1,4 @@ -#ifndef FF_LIB_POSDEF -#define FF_LIB_POSDEF +#pragma once #include #include #include @@ -80,5 +79,3 @@ void sym_invert_( ); FF_NAMESPACE_END(FF_NS) - -#endif // FF_LIB_POSDEF diff --git a/include/fastfields/api/pushpull.h b/include/fastfields/api/pushpull.h index f71ebb2..19883b7 100644 --- a/include/fastfields/api/pushpull.h +++ b/include/fastfields/api/pushpull.h @@ -1,5 +1,4 @@ -#ifndef FF_LIB_PUSHPULL -#define FF_LIB_PUSHPULL +#pragma once #include #include #include @@ -228,5 +227,3 @@ void grad_backward( ); FF_NAMESPACE_END(FF_NS) - -#endif // FF_LIB_PUSHPULL diff --git a/include/fastfields/api/reg_field.h b/include/fastfields/api/reg_field.h index 3b43c1b..c8d39f8 100644 --- a/include/fastfields/api/reg_field.h +++ b/include/fastfields/api/reg_field.h @@ -1,5 +1,4 @@ -#ifndef FF_LIB_REG_FIELD -#define FF_LIB_REG_FIELD +#pragma once #include #include #include @@ -376,5 +375,3 @@ void field_relax_rls( ); FF_NAMESPACE_END(FF_NS) - -#endif // FF_LIB_REG_FIELD diff --git a/include/fastfields/api/reg_flow.h b/include/fastfields/api/reg_flow.h index 5b42602..7d185f3 100644 --- a/include/fastfields/api/reg_flow.h +++ b/include/fastfields/api/reg_flow.h @@ -1,5 +1,4 @@ -#ifndef FF_LIB_REG_FLOW -#define FF_LIB_REG_FLOW +#pragma once #include #include #include @@ -397,5 +396,3 @@ void flow_relax_rls( ); FF_NAMESPACE_END(FF_NS) - -#endif // FF_LIB_REG_FLOW diff --git a/include/fastfields/api/resize.h b/include/fastfields/api/resize.h index c8de089..fe75ccd 100644 --- a/include/fastfields/api/resize.h +++ b/include/fastfields/api/resize.h @@ -1,5 +1,4 @@ -#ifndef FF_LIB_RESIZE -#define FF_LIB_RESIZE +#pragma once #include #include #include @@ -68,5 +67,3 @@ void resample( ); FF_NAMESPACE_END(FF_NS) - -#endif // FF_LIB_RESIZE diff --git a/include/fastfields/api/restrict.h b/include/fastfields/api/restrict.h index 7461f71..19d731d 100644 --- a/include/fastfields/api/restrict.h +++ b/include/fastfields/api/restrict.h @@ -1,5 +1,4 @@ -#ifndef FF_LIB_RESTRICT -#define FF_LIB_RESTRICT +#pragma once #include #include #include @@ -67,5 +66,3 @@ void restriction( ); FF_NAMESPACE_END(FF_NS) - -#endif // FF_LIB_RESTRICT diff --git a/include/fastfields/api/solve_field.h b/include/fastfields/api/solve_field.h index 6bc8c21..8b7652c 100644 --- a/include/fastfields/api/solve_field.h +++ b/include/fastfields/api/solve_field.h @@ -1,5 +1,4 @@ -#ifndef FF_LIB_SOLVE_FIELD -#define FF_LIB_SOLVE_FIELD +#pragma once #include #include @@ -93,5 +92,3 @@ void field_cg( ); FF_NAMESPACE_END(FF_NS) - -#endif // FF_LIB_SOLVE_FIELD diff --git a/include/fastfields/api/splinc.h b/include/fastfields/api/splinc.h index 07f32fa..ba00472 100644 --- a/include/fastfields/api/splinc.h +++ b/include/fastfields/api/splinc.h @@ -1,5 +1,4 @@ -#ifndef FF_LIB_SPLINC -#define FF_LIB_SPLINC +#pragma once #include #include #include @@ -114,5 +113,3 @@ void spline_coeff( ); FF_NAMESPACE_END(FF_NS) - -#endif // FF_LIB_SPLINC diff --git a/include/fastfields/core/autocast.h b/include/fastfields/core/autocast.h index e730a66..6886480 100644 --- a/include/fastfields/core/autocast.h +++ b/include/fastfields/core/autocast.h @@ -1,6 +1,4 @@ #pragma once -#ifndef FF_AUTOCAST -#define FF_AUTOCAST #include #include #include @@ -199,5 +197,3 @@ inline void free_if_needed(OutPointer ptr) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_AUTOCAST diff --git a/include/fastfields/core/cuda_switch.h b/include/fastfields/core/cuda_switch.h index e302a00..23ea881 100755 --- a/include/fastfields/core/cuda_switch.h +++ b/include/fastfields/core/cuda_switch.h @@ -1,8 +1,4 @@ #pragma once -#ifndef FF_CUDA_SWITCH -#define FF_CUDA_SWITCH - - #ifndef __CUDACC__ // replace __device__ with empty symbol @@ -50,5 +46,3 @@ #endif #include - -#endif // FF_CUDA_SWITCH diff --git a/include/fastfields/core/defines.h b/include/fastfields/core/defines.h index 3bc5819..d567ce2 100644 --- a/include/fastfields/core/defines.h +++ b/include/fastfields/core/defines.h @@ -1,7 +1,4 @@ #pragma once -#ifndef FF_DEFINES -#define FF_DEFINES - // Merged from fastfields-kernels/defines.h and fastfields-lib/defines.h during // the six-repo consolidation. The first three macros were token-identical in // both; the namespace-device pair came from kernels and the FF_CPU/FF_CUDA pair @@ -34,5 +31,3 @@ #else # define FF_CUDA cuda #endif - -#endif // FF_DEFINES diff --git a/include/fastfields/core/dispatch.h b/include/fastfields/core/dispatch.h index 5862aed..1a0073b 100644 --- a/include/fastfields/core/dispatch.h +++ b/include/fastfields/core/dispatch.h @@ -1,7 +1,4 @@ #pragma once -#ifndef FF_CORE_DISPATCH -#define FF_CORE_DISPATCH - /** * The helpers shared by both dtype-dispatch layers (`src/lib-cpu` and * `src/lib-cuda`): unpack the public pointer ABI's arguments into what the @@ -228,5 +225,3 @@ inline std::vector as_weights(const double * w, int64_t nc) } FF_NAMESPACE_END(FF_NS) - -#endif // FF_CORE_DISPATCH diff --git a/include/fastfields/impl/cpu/distance_euclidean.h b/include/fastfields/impl/cpu/distance_euclidean.h index c55f9f2..e9cf7b5 100755 --- a/include/fastfields/impl/cpu/distance_euclidean.h +++ b/include/fastfields/impl/cpu/distance_euclidean.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_DISTANCE_EUCLIDEAN -#define FF_CPU_DISTANCE_EUCLIDEAN +#pragma once #include #include #include @@ -56,5 +55,3 @@ dt( FF_NAMESPACE_END(distance_e) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_CPU_DISTANCE_EUCLIDEAN diff --git a/include/fastfields/impl/cpu/distance_l1.h b/include/fastfields/impl/cpu/distance_l1.h index 3a5a5b2..ea8b0af 100755 --- a/include/fastfields/impl/cpu/distance_l1.h +++ b/include/fastfields/impl/cpu/distance_l1.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_DISTANCE_L1 -#define FF_CPU_DISTANCE_L1 +#pragma once #include #include #include @@ -35,5 +34,3 @@ dt( FF_NAMESPACE_END(distance_l1) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_CPU_DISTANCE_L1 diff --git a/include/fastfields/impl/cpu/distance_mesh.h b/include/fastfields/impl/cpu/distance_mesh.h index 7484800..53eaf89 100755 --- a/include/fastfields/impl/cpu/distance_mesh.h +++ b/include/fastfields/impl/cpu/distance_mesh.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_DISTANCE_MESH -#define FF_CPU_DISTANCE_MESH +#pragma once #include #include #include @@ -714,6 +713,3 @@ dt( FF_NAMESPACE_END(distance_mesh) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - - -#endif // FF_DISTANCE_MESH diff --git a/include/fastfields/impl/cpu/distance_spline.h b/include/fastfields/impl/cpu/distance_spline.h index a04e340..6d3799a 100755 --- a/include/fastfields/impl/cpu/distance_spline.h +++ b/include/fastfields/impl/cpu/distance_spline.h @@ -1,5 +1,4 @@ -#ifndef FF_CPU_DISTANCE_SPLINE -#define FF_CPU_DISTANCE_SPLINE +#pragma once #include #include #include @@ -182,5 +181,3 @@ mindist_gaussnewton( FF_NAMESPACE_END(distance_spline) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_CPU_DISTANCE_SPLINE diff --git a/include/fastfields/impl/cpu/posdef.h b/include/fastfields/impl/cpu/posdef.h index a467164..9a55849 100755 --- a/include/fastfields/impl/cpu/posdef.h +++ b/include/fastfields/impl/cpu/posdef.h @@ -1,5 +1,4 @@ -#ifndef FF_POSDEF_CPU -#define FF_POSDEF_CPU +#pragma once #include #include #include @@ -466,5 +465,3 @@ void sym_invert_( FF_NAMESPACE_END(posdef) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_POSDEF_CPU diff --git a/include/fastfields/impl/cpu/pushpull.h b/include/fastfields/impl/cpu/pushpull.h index 89bd380..fff4ccb 100755 --- a/include/fastfields/impl/cpu/pushpull.h +++ b/include/fastfields/impl/cpu/pushpull.h @@ -1,5 +1,4 @@ -#ifndef FF_PUSHPULL_CPU -#define FF_PUSHPULL_CPU +#pragma once #include #include #include @@ -772,5 +771,3 @@ void grad_backward( FF_NAMESPACE_END(pushpull) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_PUSHPULL_CPU diff --git a/include/fastfields/impl/cpu/reg_field.h b/include/fastfields/impl/cpu/reg_field.h index 5990f6e..9f838f0 100755 --- a/include/fastfields/impl/cpu/reg_field.h +++ b/include/fastfields/impl/cpu/reg_field.h @@ -1,5 +1,4 @@ -#ifndef FF_REGULARISERS_FIELD_CPU -#define FF_REGULARISERS_FIELD_CPU +#pragma once #include #include #include @@ -1837,5 +1836,3 @@ void relax_bending_jrls_( FF_NAMESPACE_END(reg_field) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_REGULARISERS_FIELD_CPU diff --git a/include/fastfields/impl/cpu/reg_flow.h b/include/fastfields/impl/cpu/reg_flow.h index f29ec0e..a1a71ce 100755 --- a/include/fastfields/impl/cpu/reg_flow.h +++ b/include/fastfields/impl/cpu/reg_flow.h @@ -1,5 +1,4 @@ -#ifndef FF_REGULARISERS_FLOW_CPU -#define FF_REGULARISERS_FLOW_CPU +#pragma once #include #include #include @@ -1495,6 +1494,3 @@ void relax_lame_jrls_( FF_NAMESPACE_END(reg_flow) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - - -#endif // FF_REGULARISERS_FLOW_CPU diff --git a/include/fastfields/impl/cpu/resize.h b/include/fastfields/impl/cpu/resize.h index 4973fc1..d90be66 100755 --- a/include/fastfields/impl/cpu/resize.h +++ b/include/fastfields/impl/cpu/resize.h @@ -1,5 +1,4 @@ -#ifndef FF_RESIZE_LOOP -#define FF_RESIZE_LOOP +#pragma once #include #include #include @@ -96,5 +95,3 @@ void loopnd( FF_NAMESPACE_END(resize) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_RESIZE_LOOP diff --git a/include/fastfields/impl/cpu/restrict.h b/include/fastfields/impl/cpu/restrict.h index a3e9798..9b5b848 100755 --- a/include/fastfields/impl/cpu/restrict.h +++ b/include/fastfields/impl/cpu/restrict.h @@ -1,5 +1,4 @@ -#ifndef FF_RESTRICT_LOOP -#define FF_RESTRICT_LOOP +#pragma once #include #include #include @@ -269,5 +268,3 @@ void loopnd( FF_NAMESPACE_END(restrict) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_RESTRICT_LOOP diff --git a/include/fastfields/impl/cpu/solve_field.h b/include/fastfields/impl/cpu/solve_field.h index 2b06aa0..7c156f8 100644 --- a/include/fastfields/impl/cpu/solve_field.h +++ b/include/fastfields/impl/cpu/solve_field.h @@ -1,5 +1,4 @@ -#ifndef FF_SOLVE_FIELD_CPU -#define FF_SOLVE_FIELD_CPU +#pragma once #include #include #include @@ -144,5 +143,3 @@ void axpby_( FF_NAMESPACE_END(solve_field) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_SOLVE_FIELD_CPU diff --git a/include/fastfields/impl/cpu/splinc.h b/include/fastfields/impl/cpu/splinc.h index 759d525..e9aa227 100755 --- a/include/fastfields/impl/cpu/splinc.h +++ b/include/fastfields/impl/cpu/splinc.h @@ -1,5 +1,4 @@ -#ifndef FF_SPLINC_LOOP -#define FF_SPLINC_LOOP +#pragma once #include #include #include @@ -41,5 +40,3 @@ void loop( FF_NAMESPACE_END(splinc) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_SPLINC_LOOP diff --git a/include/fastfields/impl/cpu/tetrahedron.h b/include/fastfields/impl/cpu/tetrahedron.h index 0454118..d5a7fdf 100755 --- a/include/fastfields/impl/cpu/tetrahedron.h +++ b/include/fastfields/impl/cpu/tetrahedron.h @@ -1,7 +1,4 @@ -#ifndef FF_TETRAHEDRON_LOOP -#define FF_TETRAHEDRON_LOOP - - +#pragma once namespace ff { namespace tetra { @@ -80,5 +77,3 @@ void pull( } // namespace tetra } // namespace ff - -#endif // FF_TETRAHEDRON_LOOP diff --git a/include/fastfields/impl/kernels/atomic.h b/include/fastfields/impl/kernels/atomic.h index 4f9df1e..e184806 100755 --- a/include/fastfields/impl/kernels/atomic.h +++ b/include/fastfields/impl/kernels/atomic.h @@ -1,10 +1,9 @@ +#pragma once /*********************************************************************** * CUDA portion copied from PyTorch/ATen * https://github.com/pytorch/pytorch/blob/master/LICENSE **********************************************************************/ -#ifndef FF_ATOMIC -#define FF_ATOMIC #include /*********************************************************************** @@ -362,5 +361,3 @@ static inline FF_CUDEV void anyAtomicAddNoReturn(T *address, T val) { } // namespace ff #endif // __CUDA__ - -#endif // FF_ATOMIC diff --git a/include/fastfields/impl/kernels/batch.h b/include/fastfields/impl/kernels/batch.h index 8cdceea..0f8523b 100755 --- a/include/fastfields/impl/kernels/batch.h +++ b/include/fastfields/impl/kernels/batch.h @@ -1,3 +1,4 @@ +#pragma once /* Utilities to convert contiguous linear indices to * - sub-indices, and/or * - strided linear indices @@ -19,8 +20,6 @@ * - a dynamically sized version, where `ndim` is a function argument * - a statically sized version, where `ndim` is a template parameter */ -#ifndef FF_BATCH -#define FF_BATCH #include #include "utils.h" @@ -269,5 +268,3 @@ void index2sub( } FF_NAMESPACE_END(FF_NS) - -#endif // FF_BATCH diff --git a/include/fastfields/impl/kernels/bounds.h b/include/fastfields/impl/kernels/bounds.h index 199f285..555685f 100755 --- a/include/fastfields/impl/kernels/bounds.h +++ b/include/fastfields/impl/kernels/bounds.h @@ -1,5 +1,4 @@ -#ifndef FF_BOUNDS -#define FF_BOUNDS +#pragma once #include #include "atomic.h" #include "utils.h" @@ -796,5 +795,3 @@ sign(type bound_type, offset_t coord, size_t size) { FF_NAMESPACE_END(bound) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_BOUNDS diff --git a/include/fastfields/impl/kernels/distance.h b/include/fastfields/impl/kernels/distance.h index 1ff4939..f40a817 100755 --- a/include/fastfields/impl/kernels/distance.h +++ b/include/fastfields/impl/kernels/distance.h @@ -1,4 +1,5 @@ +#pragma once #include "distance/euclidean.h" #include "distance/l1.h" #include "distance/spline.h" -#include "distance/mesh.h" \ No newline at end of file +#include "distance/mesh.h" diff --git a/include/fastfields/impl/kernels/distance/euclidean.h b/include/fastfields/impl/kernels/distance/euclidean.h index b5a6127..8a01135 100755 --- a/include/fastfields/impl/kernels/distance/euclidean.h +++ b/include/fastfields/impl/kernels/distance/euclidean.h @@ -1,3 +1,4 @@ +#pragma once // "Distance Transforms of Sampled Functions" // Pedro F. Felzenszwalb & Daniel P. Huttenlocher // Theory of Computing (2012) @@ -5,8 +6,6 @@ // // This algorithm works by upper-bounding the Euclidean distance with // the lower envelope of a series of parabolas. -#ifndef FF_DISTANCE_E -#define FF_DISTANCE_E #include #include "../utils.h" @@ -120,5 +119,3 @@ void kernel(scalar_t * f, offset_t * v, scalar_t * z, scalar_t * d, scalar_t w2, FF_NAMESPACE_END(distance_e) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_DISTANCE_E diff --git a/include/fastfields/impl/kernels/distance/l1.h b/include/fastfields/impl/kernels/distance/l1.h index f80459d..cfb9529 100755 --- a/include/fastfields/impl/kernels/distance/l1.h +++ b/include/fastfields/impl/kernels/distance/l1.h @@ -1,9 +1,8 @@ +#pragma once // "Distance Transforms of Sampled Functions" // Pedro F. Felzenszwalb & Daniel P. Huttenlocher // Theory of Computing (2012) // https://www.theoryofcomputing.org/articles/v008a019/v008a019.pdf -#ifndef FF_DISTANCE_L1 -#define FF_DISTANCE_L1 #include #include "../utils.h" @@ -45,4 +44,3 @@ void kernel(scalar_t * f, offset_t size, offset_t stride, scalar_t w) FF_NAMESPACE_END(distance_l1) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) -#endif // FF_DISTANCE_L1 diff --git a/include/fastfields/impl/kernels/distance/mesh.h b/include/fastfields/impl/kernels/distance/mesh.h index 0737766..5c771e2 100755 --- a/include/fastfields/impl/kernels/distance/mesh.h +++ b/include/fastfields/impl/kernels/distance/mesh.h @@ -1,9 +1,8 @@ +#pragma once /* * Adapted from * https://github.com/InteractiveComputerGraphics/TriangleMeshDistance */ -#ifndef FF_DISTANCE_MESH_H -#define FF_DISTANCE_MESH_H #include #include "../utils.h" #include "mesh_utils.h" @@ -1477,5 +1476,3 @@ struct MeshDist { FF_NAMESPACE_END(distance_mesh) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_DISTANCE_MESH_H diff --git a/include/fastfields/impl/kernels/distance/mesh_utils.h b/include/fastfields/impl/kernels/distance/mesh_utils.h index c67aaa3..c5735a6 100755 --- a/include/fastfields/impl/kernels/distance/mesh_utils.h +++ b/include/fastfields/impl/kernels/distance/mesh_utils.h @@ -1,5 +1,4 @@ -#ifndef FF_DISTANCE_MESH_UTILS_H -#define FF_DISTANCE_MESH_UTILS_H +#pragma once #include #include "../utils.h" @@ -1154,5 +1153,3 @@ struct ConstStridedPointArray { FF_NAMESPACE_END(distance_mesh) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_DISTANCE_MESH_UTILS_H diff --git a/include/fastfields/impl/kernels/distance/spline.h b/include/fastfields/impl/kernels/distance/spline.h index df9b174..31593a8 100755 --- a/include/fastfields/impl/kernels/distance/spline.h +++ b/include/fastfields/impl/kernels/distance/spline.h @@ -1,5 +1,4 @@ -#ifndef FF_DISTANCE_SPLINE_H -#define FF_DISTANCE_SPLINE_H +#pragma once #include #include "../spline.h" #include "../bounds.h" @@ -469,5 +468,3 @@ class Kernels { FF_NAMESPACE_END(distance_spline) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_DISTANCE_SPLINE_H diff --git a/include/fastfields/impl/kernels/meta.h b/include/fastfields/impl/kernels/meta.h index dcb2705..5ff8741 100644 --- a/include/fastfields/impl/kernels/meta.h +++ b/include/fastfields/impl/kernels/meta.h @@ -1,5 +1,4 @@ -#ifndef FF_META -#define FF_META +#pragma once #include FF_NAMESPACE_BEGIN(FF_NS) @@ -42,6 +41,3 @@ template using Int = Tuple; FF_NAMESPACE_END(meta) FF_NAMESPACE_END(FF_NS) - - -#endif // FF_META diff --git a/include/fastfields/impl/kernels/parallel.h b/include/fastfields/impl/kernels/parallel.h index e91a405..8bf6160 100755 --- a/include/fastfields/impl/kernels/parallel.h +++ b/include/fastfields/impl/kernels/parallel.h @@ -1,9 +1,8 @@ +#pragma once /* LICENSE: * Most of the functions are adapted from PyTorch/ATen's ParallelNative * https://github.com/pytorch/pytorch/blob/master/LICENSE */ -#ifndef FF_PARALLEL_H -#define FF_PARALLEL_H #include #include #include "parallel_impl.h" @@ -51,5 +50,3 @@ inline void parallel_for(int64_t begin, int64_t end, int64_t grain_size, const F } FF_NAMESPACE_END(FF_NS) - -#endif // FF_PARALLEL_H diff --git a/include/fastfields/impl/kernels/parallel_impl.h b/include/fastfields/impl/kernels/parallel_impl.h index 2fcdb78..7b1ef12 100755 --- a/include/fastfields/impl/kernels/parallel_impl.h +++ b/include/fastfields/impl/kernels/parallel_impl.h @@ -1,9 +1,8 @@ +#pragma once /* LICENSE: * Most of the functions are adapted from PyTorch/ATen's ParallelNative * https://github.com/pytorch/pytorch/blob/master/LICENSE */ -#ifndef FF_PARALLEL_IMPL_H -#define FF_PARALLEL_IMPL_H #include #include #include @@ -231,5 +230,3 @@ FF_NAMESPACE_BEGIN(internal) FF_NAMESPACE_END(internal) FF_NAMESPACE_END(FF_NS) - -#endif // FF_PARALLEL_IMPL_H diff --git a/include/fastfields/impl/kernels/posdef.h b/include/fastfields/impl/kernels/posdef.h index ece49aa..d11f9ae 100755 --- a/include/fastfields/impl/kernels/posdef.h +++ b/include/fastfields/impl/kernels/posdef.h @@ -1 +1,2 @@ +#pragma once #include "posdef/posdef.h" diff --git a/include/fastfields/impl/kernels/posdef/cholesky.h b/include/fastfields/impl/kernels/posdef/cholesky.h index f3a7eff..311cedb 100755 --- a/include/fastfields/impl/kernels/posdef/cholesky.h +++ b/include/fastfields/impl/kernels/posdef/cholesky.h @@ -1,5 +1,4 @@ -#ifndef FF_POSDEF_CHOLESKY -#define FF_POSDEF_CHOLESKY +#pragma once #include #include "../utils.h" #include "utils.h" @@ -138,5 +137,3 @@ struct cholesky { FF_NAMESPACE_END(posdef) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_POSDEF_CHOLESKY diff --git a/include/fastfields/impl/kernels/posdef/diag.inl b/include/fastfields/impl/kernels/posdef/diag.inl index 2be755a..797046e 100755 --- a/include/fastfields/impl/kernels/posdef/diag.inl +++ b/include/fastfields/impl/kernels/posdef/diag.inl @@ -1,7 +1,4 @@ -#ifndef FF_POSDEF_DIAG -#define FF_POSDEF_DIAG - - +#pragma once template struct utils: public common_diag { @@ -221,5 +218,3 @@ struct utils: public common_diag internal::div(o[c], 1., h[c]); } }; - -#endif // FF_POSDEF_DIAG diff --git a/include/fastfields/impl/kernels/posdef/estatics.inl b/include/fastfields/impl/kernels/posdef/estatics.inl index 36496ee..64c1ea4 100755 --- a/include/fastfields/impl/kernels/posdef/estatics.inl +++ b/include/fastfields/impl/kernels/posdef/estatics.inl @@ -1,6 +1,4 @@ -#ifndef FF_POSDEF_ESTATICS -#define FF_POSDEF_ESTATICS - +#pragma once template struct utils: public common_estatics { @@ -204,5 +202,3 @@ struct utils: public common_estatics } } }; - -#endif // FF_POSDEF_ESTATICS diff --git a/include/fastfields/impl/kernels/posdef/eye.inl b/include/fastfields/impl/kernels/posdef/eye.inl index 385932a..0710202 100755 --- a/include/fastfields/impl/kernels/posdef/eye.inl +++ b/include/fastfields/impl/kernels/posdef/eye.inl @@ -1,6 +1,4 @@ -#ifndef FF_POSDEF_EYE -#define FF_POSDEF_EYE - +#pragma once template struct utils: public common_eye { @@ -120,5 +118,3 @@ struct utils: public common_eye internal::div(*o, 1., *h); } }; - -#endif // FF_POSDEF_EYE diff --git a/include/fastfields/impl/kernels/posdef/full.inl b/include/fastfields/impl/kernels/posdef/full.inl index fd6f31a..f9df8dd 100755 --- a/include/fastfields/impl/kernels/posdef/full.inl +++ b/include/fastfields/impl/kernels/posdef/full.inl @@ -1,6 +1,4 @@ -#ifndef FF_POSDEF_FULL -#define FF_POSDEF_FULL - +#pragma once template struct utils: public common_sym { @@ -130,5 +128,3 @@ struct utils: public common_sym cholesky::solve_(C, b, v, static_cast(0)); // solve linear system inplace } }; - -#endif // FF_POSDEF_FULL diff --git a/include/fastfields/impl/kernels/posdef/posdef.h b/include/fastfields/impl/kernels/posdef/posdef.h index 62e0dfa..aebde8c 100755 --- a/include/fastfields/impl/kernels/posdef/posdef.h +++ b/include/fastfields/impl/kernels/posdef/posdef.h @@ -1,5 +1,4 @@ -#ifndef FF_POSDEF -#define FF_POSDEF +#pragma once #include #include "../utils.h" #include "utils.h" @@ -1009,5 +1008,3 @@ struct utils: public common_none FF_NAMESPACE_END(posdef) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_POSDEF diff --git a/include/fastfields/impl/kernels/posdef/sym.inl b/include/fastfields/impl/kernels/posdef/sym.inl index f59c02c..13e2c08 100755 --- a/include/fastfields/impl/kernels/posdef/sym.inl +++ b/include/fastfields/impl/kernels/posdef/sym.inl @@ -1,6 +1,4 @@ -#ifndef FF_POSDEF_SYM -#define FF_POSDEF_SYM - +#pragma once // --------------------------------------- // Generic implementation with static size // --------------------------------------- @@ -1089,5 +1087,3 @@ struct utils: public common_sym internal::set(o[0], i[0]); } }; - -#endif // FF_POSDEF_SYM diff --git a/include/fastfields/impl/kernels/posdef/utils.h b/include/fastfields/impl/kernels/posdef/utils.h index 0788372..f0a2a9a 100755 --- a/include/fastfields/impl/kernels/posdef/utils.h +++ b/include/fastfields/impl/kernels/posdef/utils.h @@ -1,5 +1,4 @@ -#ifndef FF_POSDEF_UTILS -#define FF_POSDEF_UTILS +#pragma once #include #include "../utils.h" @@ -445,5 +444,3 @@ FF_NAMESPACE_END(internal) FF_NAMESPACE_END(posdef) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_POSDEF_UTILS diff --git a/include/fastfields/impl/kernels/pushpull.h b/include/fastfields/impl/kernels/pushpull.h index 4f16a5a..9a50422 100755 --- a/include/fastfields/impl/kernels/pushpull.h +++ b/include/fastfields/impl/kernels/pushpull.h @@ -1,3 +1,4 @@ +#pragma once #include "pushpull/1d.h" #include "pushpull/2d.h" #include "pushpull/3d.h" diff --git a/include/fastfields/impl/kernels/pushpull/1d.h b/include/fastfields/impl/kernels/pushpull/1d.h index e4d7e6f..f81b677 100755 --- a/include/fastfields/impl/kernels/pushpull/1d.h +++ b/include/fastfields/impl/kernels/pushpull/1d.h @@ -1,10 +1,9 @@ +#pragma once /*********************************************************************** * * 1D * **********************************************************************/ -#ifndef FF_PUSHPULL_1D -#define FF_PUSHPULL_1D #include #include "../spline.h" #include "../bounds.h" @@ -1578,5 +1577,3 @@ struct Kernels, Bound, ABS>> { FF_NAMESPACE_END(pushpull) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_PUSHPULL_1D diff --git a/include/fastfields/impl/kernels/pushpull/2d.h b/include/fastfields/impl/kernels/pushpull/2d.h index a9e81a7..8310391 100755 --- a/include/fastfields/impl/kernels/pushpull/2d.h +++ b/include/fastfields/impl/kernels/pushpull/2d.h @@ -1,10 +1,9 @@ +#pragma once /*********************************************************************** * * 2D * **********************************************************************/ -#ifndef FF_PUSHPULL_2D -#define FF_PUSHPULL_2D #include #include "../spline.h" #include "../bounds.h" @@ -1252,5 +1251,3 @@ struct Kernels, Bound, ABS>> { FF_NAMESPACE_END(pushpull) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_PUSHPULL_2D diff --git a/include/fastfields/impl/kernels/pushpull/3d.h b/include/fastfields/impl/kernels/pushpull/3d.h index 9b01dfe..9c2624c 100755 --- a/include/fastfields/impl/kernels/pushpull/3d.h +++ b/include/fastfields/impl/kernels/pushpull/3d.h @@ -1,10 +1,9 @@ +#pragma once /*********************************************************************** * * 3D * **********************************************************************/ -#ifndef FF_PUSHPULL_3D -#define FF_PUSHPULL_3D #include #include "../spline.h" #include "../bounds.h" @@ -1848,5 +1847,3 @@ struct Kernels, Bound, ABS>> { FF_NAMESPACE_END(pushpull) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_PUSHPULL_3D diff --git a/include/fastfields/impl/kernels/pushpull/nd.h b/include/fastfields/impl/kernels/pushpull/nd.h index 03df18a..12c2d27 100755 --- a/include/fastfields/impl/kernels/pushpull/nd.h +++ b/include/fastfields/impl/kernels/pushpull/nd.h @@ -1,10 +1,9 @@ +#pragma once /*********************************************************************** * * ND * **********************************************************************/ -#ifndef FF_PUSHPULL_ND -#define FF_PUSHPULL_ND #include #include "../spline.h" #include "../bounds.h" @@ -485,5 +484,3 @@ struct Kernels,Bound<>,ABS>> { FF_NAMESPACE_END(pushpull) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif FF_PUSHPULL_ND diff --git a/include/fastfields/impl/kernels/pushpull/utils.h b/include/fastfields/impl/kernels/pushpull/utils.h index 6d3e67c..94b62a5 100755 --- a/include/fastfields/impl/kernels/pushpull/utils.h +++ b/include/fastfields/impl/kernels/pushpull/utils.h @@ -1,5 +1,4 @@ -#ifndef FF_PUSHPULL_UTILS -#define FF_PUSHPULL_UTILS +#pragma once #include #include "../spline.h" #include "../bounds.h" @@ -1026,5 +1025,3 @@ struct PushPullUtils { FF_NAMESPACE_END(pushpull) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_PUSHPULL_UTILS diff --git a/include/fastfields/impl/kernels/regularisers.h b/include/fastfields/impl/kernels/regularisers.h index 29562ff..9cf2450 100755 --- a/include/fastfields/impl/kernels/regularisers.h +++ b/include/fastfields/impl/kernels/regularisers.h @@ -1,2 +1,3 @@ +#pragma once #include "regularisers/flow.h" #include "regularisers/field.h" diff --git a/include/fastfields/impl/kernels/regularisers/field.h b/include/fastfields/impl/kernels/regularisers/field.h index 6185513..b2a3a42 100755 --- a/include/fastfields/impl/kernels/regularisers/field.h +++ b/include/fastfields/impl/kernels/regularisers/field.h @@ -1,3 +1,4 @@ +#pragma once #include "field/1d.h" #include "field/2d.h" #include "field/3d.h" diff --git a/include/fastfields/impl/kernels/regularisers/field/1d.h b/include/fastfields/impl/kernels/regularisers/field/1d.h index 625e419..2992037 100755 --- a/include/fastfields/impl/kernels/regularisers/field/1d.h +++ b/include/fastfields/impl/kernels/regularisers/field/1d.h @@ -1,5 +1,4 @@ -#ifndef FF_REGULARISERS_FIELD_1D -#define FF_REGULARISERS_FIELD_1D +#pragma once #include #include "../../bounds.h" #include "../../utils.h" @@ -1129,5 +1128,3 @@ struct Kernels> FF_NAMESPACE_END(reg_field) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_REGULARISERS_FIELD_1D diff --git a/include/fastfields/impl/kernels/regularisers/field/2d.h b/include/fastfields/impl/kernels/regularisers/field/2d.h index 1f307ea..060e0b9 100755 --- a/include/fastfields/impl/kernels/regularisers/field/2d.h +++ b/include/fastfields/impl/kernels/regularisers/field/2d.h @@ -1,5 +1,4 @@ -#ifndef FF_REGULARISERS_FIELD_2D -#define FF_REGULARISERS_FIELD_2D +#pragma once #include #include "../../bounds.h" #include "../../utils.h" @@ -1425,6 +1424,3 @@ struct Kernels> FF_NAMESPACE_END(reg_field) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - - -#endif // FF_REGULARISERS_FIELD_2D diff --git a/include/fastfields/impl/kernels/regularisers/field/3d.h b/include/fastfields/impl/kernels/regularisers/field/3d.h index 083a44d..05bf443 100755 --- a/include/fastfields/impl/kernels/regularisers/field/3d.h +++ b/include/fastfields/impl/kernels/regularisers/field/3d.h @@ -1,5 +1,4 @@ -#ifndef FF_REGULARISERS_FIELD_3D -#define FF_REGULARISERS_FIELD_3D +#pragma once #include #include "../../bounds.h" #include "../../utils.h" @@ -1753,5 +1752,3 @@ struct Kernels> FF_NAMESPACE_END(reg_field) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_REGULARISERS_FIELD_3D diff --git a/include/fastfields/impl/kernels/regularisers/field/utils.h b/include/fastfields/impl/kernels/regularisers/field/utils.h index 14e7c2a..f129ec3 100755 --- a/include/fastfields/impl/kernels/regularisers/field/utils.h +++ b/include/fastfields/impl/kernels/regularisers/field/utils.h @@ -1,5 +1,4 @@ -#ifndef FF_REGULARISERS_UTILS -#define FF_REGULARISERS_UTILS +#pragma once #include #include "../../bounds.h" #include "../../utils.h" @@ -156,5 +155,3 @@ bool patch3(const offset_t loc[N], offset_t n) FF_NAMESPACE_END(reg_field) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_REGULARISERS_UTILS diff --git a/include/fastfields/impl/kernels/regularisers/flow.h b/include/fastfields/impl/kernels/regularisers/flow.h index d38918c..e8d0c85 100755 --- a/include/fastfields/impl/kernels/regularisers/flow.h +++ b/include/fastfields/impl/kernels/regularisers/flow.h @@ -1,3 +1,4 @@ +#pragma once #include "flow/1d.h" #include "flow/2d.h" #include "flow/3d.h" diff --git a/include/fastfields/impl/kernels/regularisers/flow/1d.h b/include/fastfields/impl/kernels/regularisers/flow/1d.h index 388b988..bf7db4d 100755 --- a/include/fastfields/impl/kernels/regularisers/flow/1d.h +++ b/include/fastfields/impl/kernels/regularisers/flow/1d.h @@ -1,5 +1,4 @@ -#ifndef FF_REGULARISERS_FLOW_1D -#define FF_REGULARISERS_FLOW_1D +#pragma once #include #include "../../bounds.h" #include "../../utils.h" @@ -847,5 +846,3 @@ struct RegFlow { FF_NAMESPACE_END(reg_flow) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_REGULARISERS_FLOW_1D diff --git a/include/fastfields/impl/kernels/regularisers/flow/2d.h b/include/fastfields/impl/kernels/regularisers/flow/2d.h index 1af7a05..f83e886 100755 --- a/include/fastfields/impl/kernels/regularisers/flow/2d.h +++ b/include/fastfields/impl/kernels/regularisers/flow/2d.h @@ -1,5 +1,4 @@ -#ifndef FF_REGULARISERS_FLOW_2D -#define FF_REGULARISERS_FLOW_2D +#pragma once #include #include "../../bounds.h" #include "../../utils.h" @@ -1647,5 +1646,3 @@ struct RegFlow { FF_NAMESPACE_END(reg_flow) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_REGULARISERS_FLOW_2D diff --git a/include/fastfields/impl/kernels/regularisers/flow/3d.h b/include/fastfields/impl/kernels/regularisers/flow/3d.h index 9fc6159..350d52c 100755 --- a/include/fastfields/impl/kernels/regularisers/flow/3d.h +++ b/include/fastfields/impl/kernels/regularisers/flow/3d.h @@ -1,5 +1,4 @@ -#ifndef FF_REGULARISERS_FLOW_3D -#define FF_REGULARISERS_FLOW_3D +#pragma once #include #include "../../bounds.h" #include "../../utils.h" @@ -2100,5 +2099,3 @@ struct RegFlow { FF_NAMESPACE_END(reg_flow) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_REGULARISERS_FLOW_3D diff --git a/include/fastfields/impl/kernels/regularisers/flow/utils.h b/include/fastfields/impl/kernels/regularisers/flow/utils.h index 394b858..d6fdcaa 100755 --- a/include/fastfields/impl/kernels/regularisers/flow/utils.h +++ b/include/fastfields/impl/kernels/regularisers/flow/utils.h @@ -1,5 +1,4 @@ -#ifndef FF_REGULARISERS_FLOW_UTILS -#define FF_REGULARISERS_FLOW_UTILS +#pragma once #include #include "../../bounds.h" #include "../../utils.h" @@ -126,5 +125,3 @@ bool patch3(const offset_t loc[N], offset_t n) FF_NAMESPACE_END(reg_flow) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_REGULARISERS_FLOW_UTILS diff --git a/include/fastfields/impl/kernels/resize.h b/include/fastfields/impl/kernels/resize.h index 6162df7..6369dc7 100755 --- a/include/fastfields/impl/kernels/resize.h +++ b/include/fastfields/impl/kernels/resize.h @@ -1,5 +1,4 @@ -#ifndef FF_RESIZE -#define FF_RESIZE +#pragma once #include #include "spline.h" #include "bounds.h" @@ -973,5 +972,3 @@ struct Multiscale { FF_NAMESPACE_END(resize) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_RESIZE diff --git a/include/fastfields/impl/kernels/restrict.h b/include/fastfields/impl/kernels/restrict.h index 10d6c49..b743c12 100755 --- a/include/fastfields/impl/kernels/restrict.h +++ b/include/fastfields/impl/kernels/restrict.h @@ -1,5 +1,4 @@ -#ifndef FF_RESTRICT -#define FF_RESTRICT +#pragma once #include #include "spline.h" #include "bounds.h" @@ -452,5 +451,3 @@ struct Multiscale { FF_NAMESPACE_END(restrict) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_RESTRICT diff --git a/include/fastfields/impl/kernels/splinc.h b/include/fastfields/impl/kernels/splinc.h index b65e901..e9c9990 100755 --- a/include/fastfields/impl/kernels/splinc.h +++ b/include/fastfields/impl/kernels/splinc.h @@ -1,3 +1,4 @@ +#pragma once // Compute spline interpolating coefficients // // These functions are ported from the C routines in SPM's bsplines.c @@ -24,8 +25,6 @@ // "Splines: A Perfect Fit for Signal and Image Processing," // IEEE Signal Processing Magazine 16(6):22-38 (1999). -#ifndef FF_SPLINC -#define FF_SPLINC #include #include "spline.h" #include "bounds.h" @@ -335,5 +334,3 @@ inline FF_CUDEV void filter(scalar_t * inp, offset_t size, offset_t stride, FF_NAMESPACE_END(splinc) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_SPLINC diff --git a/include/fastfields/impl/kernels/spline.h b/include/fastfields/impl/kernels/spline.h index 89d7364..6bb0241 100755 --- a/include/fastfields/impl/kernels/spline.h +++ b/include/fastfields/impl/kernels/spline.h @@ -1,3 +1,4 @@ +#pragma once // This file contains static functions for handling (0-7 order) // spline weights. // It also defines an enumerated types that encodes each boundary type. @@ -23,8 +24,6 @@ // TODO? other types of basis functions (gauss, sinc) -#ifndef FF_SPLINE -#define FF_SPLINE #include #include "meta.h" @@ -1443,5 +1442,3 @@ template <> struct dyn FF_NAMESPACE_END(spline) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_SPLINE diff --git a/include/fastfields/impl/kernels/tetrahedron.h b/include/fastfields/impl/kernels/tetrahedron.h index ffd8f12..38375f2 100755 --- a/include/fastfields/impl/kernels/tetrahedron.h +++ b/include/fastfields/impl/kernels/tetrahedron.h @@ -1,5 +1,4 @@ -#ifndef FF_TETRAHEDRON -#define FF_TETRAHEDRON +#pragma once #include #include "utils.h" @@ -238,6 +237,3 @@ void pull1(scalar_t * output, FF_NAMESPACE_END(tetra) FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - - -#endif // FF_TETRAHEDRON diff --git a/include/fastfields/impl/kernels/threadpool.h b/include/fastfields/impl/kernels/threadpool.h index 4948eeb..833b168 100755 --- a/include/fastfields/impl/kernels/threadpool.h +++ b/include/fastfields/impl/kernels/threadpool.h @@ -1,9 +1,8 @@ +#pragma once // Copyright (c) Yasser Asmi // Released under the MIT License (http://opensource.org/licenses/MIT) // https://github.com/YasserAsmi/wstpool -#ifndef FF_THREADPOOL_H -#define FF_THREADPOOL_H #include #include @@ -256,5 +255,3 @@ class ThreadPool FF_NAMESPACE_END(FF_NS) #include "threadpool.inl" - -#endif // FF_THREADPOOL_H diff --git a/include/fastfields/impl/kernels/threadpool.inl b/include/fastfields/impl/kernels/threadpool.inl index 3f3bc4a..8fbf945 100755 --- a/include/fastfields/impl/kernels/threadpool.inl +++ b/include/fastfields/impl/kernels/threadpool.inl @@ -1,5 +1,4 @@ -#ifndef FF_THREADPOOL_INL -#define FF_THREADPOOL_INL +#pragma once #include #include #include @@ -75,4 +74,3 @@ inline std::shared_ptr get_global_pool() { } FF_NAMESPACE_END(FF_NS) -#endif // FF_THREADPOOL_INL diff --git a/include/fastfields/impl/kernels/utils.h b/include/fastfields/impl/kernels/utils.h index ab0cf7c..37394ce 100755 --- a/include/fastfields/impl/kernels/utils.h +++ b/include/fastfields/impl/kernels/utils.h @@ -1,5 +1,4 @@ -#ifndef FF_UTILS -#define FF_UTILS +#pragma once #include #include @@ -697,5 +696,3 @@ FF_CUHOST inline bool canUse32BitIndexMath( FF_NAMESPACE_END(FF_DEVICE) FF_NAMESPACE_END(FF_NS) - -#endif // FF_UTILS diff --git a/include/fastfields/impl/kernels/vector/abstract_ptr.h b/include/fastfields/impl/kernels/vector/abstract_ptr.h index 0fcf3a9..a4c9ce9 100755 --- a/include/fastfields/impl/kernels/vector/abstract_ptr.h +++ b/include/fastfields/impl/kernels/vector/abstract_ptr.h @@ -1,5 +1,4 @@ -#ifndef FF_VECTOR_ABSTRACTPTR_H -#define FF_VECTOR_ABSTRACTPTR_H +#pragma once #include #include "forward.h" #include "traits.h" @@ -438,5 +437,3 @@ using AbstractDynamicPointer = AbstractPointer; } // namespace ff - -#endif // FF_VECTOR_ABSTRACTPTR_H diff --git a/include/fastfields/impl/kernels/vector/abstract_sized.h b/include/fastfields/impl/kernels/vector/abstract_sized.h index e59d08b..2a88cf5 100755 --- a/include/fastfields/impl/kernels/vector/abstract_sized.h +++ b/include/fastfields/impl/kernels/vector/abstract_sized.h @@ -1,5 +1,4 @@ -#ifndef FF_VECTOR_ABSTRACTSIZED_H -#define FF_VECTOR_ABSTRACTSIZED_H +#pragma once #include #include "forward.h" #include "abstract_ptr.h" @@ -257,5 +256,3 @@ using AbstractDynamicSizedPointer = AbstractSizedPointer; } // namespace ff - -#endif // FF_VECTOR_ABSTRACTSIZED_H diff --git a/include/fastfields/impl/kernels/vector/abstract_vector.h b/include/fastfields/impl/kernels/vector/abstract_vector.h index 9e386b4..69b4c72 100755 --- a/include/fastfields/impl/kernels/vector/abstract_vector.h +++ b/include/fastfields/impl/kernels/vector/abstract_vector.h @@ -1,5 +1,4 @@ -#ifndef FF_VECTOR_ABTRACTVECTOR_H -#define FF_VECTOR_ABTRACTVECTOR_H +#pragma once #include "forward.h" #include "traits.h" #include "weak_sized.h" @@ -700,7 +699,3 @@ struct std::tuple_element< I, ff::AbstractVector > { using type = T; }; - - - -#endif // FF_VECTOR_ABTRACTVECTOR_H diff --git a/include/fastfields/impl/kernels/vector/concrete_vector.h b/include/fastfields/impl/kernels/vector/concrete_vector.h index e20824c..0fc8dc7 100755 --- a/include/fastfields/impl/kernels/vector/concrete_vector.h +++ b/include/fastfields/impl/kernels/vector/concrete_vector.h @@ -1,5 +1,4 @@ -#ifndef FF_VECTOR_CONCRETEVECTOR_H -#define FF_VECTOR_CONCRETEVECTOR_H +#pragma once #include #include "forward.h" #include "traits.h" @@ -224,5 +223,3 @@ struct std::tuple_element< I, ff::Vector > { using type = T; }; - -#endif // FF_VECTOR_CONCRETEVECTOR_H diff --git a/include/fastfields/impl/kernels/vector/forward.h b/include/fastfields/impl/kernels/vector/forward.h index 84e5cb4..497883a 100755 --- a/include/fastfields/impl/kernels/vector/forward.h +++ b/include/fastfields/impl/kernels/vector/forward.h @@ -1,5 +1,4 @@ -#ifndef FF_VECTOR_FORWARD_H -#define FF_VECTOR_FORWARD_H +#pragma once #include namespace ff { @@ -29,5 +28,3 @@ template class Vector; } - -#endif // FF_VECTOR_FORWARD_H diff --git a/include/fastfields/impl/kernels/vector/stream.h b/include/fastfields/impl/kernels/vector/stream.h index 5fb185e..f825d10 100755 --- a/include/fastfields/impl/kernels/vector/stream.h +++ b/include/fastfields/impl/kernels/vector/stream.h @@ -1,5 +1,4 @@ -#ifndef FF_VECTOR_STREAM_H -#define FF_VECTOR_STREAM_H +#pragma once #include #include "abstract_ptr.h" #include "abstract_sized.h" @@ -134,5 +133,3 @@ std::ostream& operator <<( { return Vector_print(stream, ptr); } - -#endif // FF_VECTOR_STREAM_H diff --git a/include/fastfields/impl/kernels/vector/traits.h b/include/fastfields/impl/kernels/vector/traits.h index a75d96c..f24f098 100755 --- a/include/fastfields/impl/kernels/vector/traits.h +++ b/include/fastfields/impl/kernels/vector/traits.h @@ -1,6 +1,4 @@ -#ifndef FF_VECTOR_TRAITS_H -#define FF_VECTOR_TRAITS_H - +#pragma once namespace ff { namespace internal { @@ -62,5 +60,3 @@ struct guess_iterator { } // internal } // jf - -#endif // FF_VECTOR_TRAITS_H diff --git a/include/fastfields/impl/kernels/vector/vector.h b/include/fastfields/impl/kernels/vector/vector.h index 211c449..db1591d 100755 --- a/include/fastfields/impl/kernels/vector/vector.h +++ b/include/fastfields/impl/kernels/vector/vector.h @@ -1,6 +1,4 @@ -#ifndef FF_VECTOR_VECTOR_H -#define FF_VECTOR_VECTOR_H - +#pragma once #include "weak_ref.h" #include "weak_sized.h" #include "weak_vector.h" @@ -134,5 +132,3 @@ class Vector: AbstractVector begin(), cbegin(), rbegin(), crbegin(), end(), cend(), rend(), crend() }; */ - -#endif // FF_VECTOR_VECTOR_H diff --git a/include/fastfields/impl/kernels/vector/weak_ref.h b/include/fastfields/impl/kernels/vector/weak_ref.h index 3e2eac4..28d04b6 100755 --- a/include/fastfields/impl/kernels/vector/weak_ref.h +++ b/include/fastfields/impl/kernels/vector/weak_ref.h @@ -1,5 +1,4 @@ -#ifndef FF_VECTOR_WEAKREF_H -#define FF_VECTOR_WEAKREF_H +#pragma once #include "forward.h" #include "traits.h" #include "abstract_ptr.h" @@ -92,5 +91,3 @@ WeakRef weak_ref(const AbstractPointer & ptr) } // namespace ff - -#endif // FF_VECTOR_WEAKREF_H diff --git a/include/fastfields/impl/kernels/vector/weak_sized.h b/include/fastfields/impl/kernels/vector/weak_sized.h index 226c87d..ed3df92 100755 --- a/include/fastfields/impl/kernels/vector/weak_sized.h +++ b/include/fastfields/impl/kernels/vector/weak_sized.h @@ -1,5 +1,4 @@ -#ifndef FF_VECTOR_WEAKSIZEDREF_H -#define FF_VECTOR_WEAKSIZEDREF_H +#pragma once #include "forward.h" #include "abstract_sized.h" #include @@ -135,5 +134,3 @@ WeakSizedRef weak_ref(const AbstractSizedPointer & ptr) } // namespace ff - -#endif // FF_VECTOR_WEAKSIZEDREF_H diff --git a/include/fastfields/impl/kernels/vector/weak_vector.h b/include/fastfields/impl/kernels/vector/weak_vector.h index c8d754b..a55a23a 100755 --- a/include/fastfields/impl/kernels/vector/weak_vector.h +++ b/include/fastfields/impl/kernels/vector/weak_vector.h @@ -1,5 +1,4 @@ -#ifndef FF_VECTOR_WEAKVECTOR_H -#define FF_VECTOR_WEAKVECTOR_H +#pragma once #include "forward.h" #include "traits.h" #include "abstract_vector.h" @@ -138,5 +137,3 @@ struct std::tuple_element< I, ff::WeakVector > { using type = T; }; - -#endif // FF_VECTOR_WEAKVECTOR_H diff --git a/tools/normalise-header-guards.py b/tools/normalise-header-guards.py new file mode 100644 index 0000000..802f6e2 --- /dev/null +++ b/tools/normalise-header-guards.py @@ -0,0 +1,362 @@ +#!/usr/bin/env python3 +""" +normalise-header-guards.py -- `#pragma once` in every header, one convention. + +THE RULE THIS APPLIES +-------------------------------------------------------------------------- +Every header in this repository has `#pragma once` as its first line and +carries no whole-file `#ifndef`/`#define`/`#endif` guard. Line 1, with no +exception for a licence or provenance comment: "is line 1 `#pragma once`" is +a rule that needs no judgement to apply and none to check, and it is what the +headers already using the pragma did. Attribution comments keep their text +and simply sit one line lower. + +The tree had drifted into four conventions at once -- 94 headers with a guard +only, 12 with the pragma only, 5 with both, and 6 with neither -- split by +which of the six pre-consolidation repositories a file came from rather than +by any decision. `#pragma once` is now the single convention. + +`#pragma once` is not ISO C++, but every compiler this project targets or +plans to target supports it: clang, g++, nvcc and MSVC. The historical hazard +here -- that it keys on file identity, which was ambiguous when every +cross-repo dependency was a symlink -- is gone: `main` has no `.gitmodules`, +no gitlinks and no symlinks. + +VENDORED FILES KEEP THEIR UPSTREAM GUARDS +-------------------------------------------------------------------------- +`include/fastfields/core/dlpack.h` is verbatim upstream code and is never +touched. Its `DLPACK_DLPACK_H_` guard is the *upstream* macro, which is what +lets our copy and a system DLPack header with the same guard collapse into a +single inclusion -- something `#pragma once` cannot do for two distinct files. +Replacing it would break that interoperation, so it stays. `--check` treats it +as exempt but still reports it, and fails loudly if the path disappears (e.g. +after a file move) rather than silently dropping the exemption. + +Six other headers carry third-party provenance, and all six are ADAPTATIONS +rather than drop-in vendored copies, so the pragma applies to them: + + impl/kernels/atomic.h "CUDA portion copied from PyTorch/ATen" + impl/kernels/parallel.h "adapted from PyTorch/ATen ParallelNative" + impl/kernels/parallel_impl.h ditto + impl/kernels/threadpool.h YasserAsmi/wstpool (MIT) + impl/kernels/threadpool.inl "some of this is copied from pytorch/aten" + impl/cuda/utils.h two helpers "(Copied from PyTorch)" + impl/kernels/distance/mesh.h InteractiveComputerGraphics/TriangleMeshDistance + +The test that settles it is not how much text came from upstream, it is +whether the file carries an upstream *guard macro* to interoperate with. None +of them does: every one is guarded by a name this project invented (`FF_ATOMIC`, +`FF_PARALLEL_H`, `FF_THREADPOOL_H`, ...), or -- in `impl/cuda/utils.h`'s case -- +by nothing at all, since it already used `#pragma once` before this sweep. They +are also re-namespaced into `ff::` via `FF_NAMESPACE_BEGIN`, use this project's +`FF_CUHOST`/`FF_CUDEV` qualifiers, and include project headers, so no upstream +copy could substitute for them and none is on any include path. There is +nothing for a guard to interoperate with, and `dlpack.h` remains the only +vendored file. (Copyright notices are untouched either way -- this is about +include mechanics, not attribution.) + +REMOVING A GUARD IS NOT AUTOMATICALLY INERT +-------------------------------------------------------------------------- +A guard macro can be *tested* from outside the header that defines it. A +`#ifdef` on a guard name somewhere else in the tree makes that `#define` +load-bearing, and deleting it silently changes what compiles -- the one way +a sweep like this can break something without any diagnostic. So the script +does not assume: before removing anything it greps the whole repository for +every guard macro, and refuses to run at all if one is mentioned in a +compiled source outside its own header. `--check` runs the same audit, so a +future header that starts testing a guard name turns the check red. + +Mentions outside compiled sources cannot affect what compiles, so they are +reported rather than blocking. + +On the tree as of this commit the audit is clean: all 99 guard macros are +referenced exactly once, by their own `#ifndef`, with no `#ifdef` on a guard +name anywhere. The only mentions elsewhere are inert text in the frozen +`tools/consolidate.sh` (which quotes header text it generated), one prose +line in `MIGRATION-PROVENANCE.md`, and this script's own docstring. + +WHAT IS NOT A HEADER GUARD, AND SURVIVES +-------------------------------------------------------------------------- +Only a guard that brackets the *whole file* is removed. `#ifndef` blocks that +guard part of a file, or that exist to make a definition idempotent across +several files, are untouched. Two families matter here: + + * `FF_LIB_BOUND_SPLINE_T` -- eight `api/*.h` headers each wrap the shared + `bound_t`/`spline_t` declarations in it so they can be co-included. This + is exactly the job `#pragma once` cannot do (one macro, eight files), and + it is depended on downstream: `fastfields-dlpack/src/ext.cpp` includes all + eight and says so in a comment. + * `FF_POSDEF_MAX_NBATCH`, `FF_PP_MAX_NBATCH`, `FF_RESIZE_MAX_NBATCH`, + `FF_RESTRICT_MAX_NBATCH`, `FF_SPLINC_MAX_NBATCH`, `FF_AUTOCAST_PINNED_HOST` + -- `#ifndef X / #define X ` overridable build knobs. + +The guard finder only accepts an `#ifndef` that is the file's first directive, +whose `#define` has an empty replacement list, and whose `#endif` is the file's +last directive, so none of the above can be mistaken for a guard. + +USAGE +-------------------------------------------------------------------------- + python3 tools/normalise-header-guards.py # apply + python3 tools/normalise-header-guards.py --check # verify, change nothing + +Idempotent and deterministic: re-running over a normalised tree rewrites +nothing, and running over the pre-sweep tree reproduces the sweep exactly. + +If this lands on a base that has moved, do NOT resolve conflicts by hand: +reset, re-run the script on the new base, and commit that. +""" + +import os +import re +import sys + +ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +SOURCE_DIRS = ("include", "src", "tests") +HEADER_EXTS = (".h", ".hpp", ".inl", ".cuh") +COMPILED_EXTS = HEADER_EXTS + (".cpp", ".cu") + +# Verbatim third-party code: never rewritten, keeps its upstream guard. +VENDORED = {"include/fastfields/core/dlpack.h"} + + +def headers(): + for d in SOURCE_DIRS: + for dirpath, _, filenames in os.walk(os.path.join(ROOT, d)): + for name in sorted(filenames): + if name.endswith(HEADER_EXTS): + yield os.path.relpath(os.path.join(dirpath, name), ROOT) + + +def repo_files(): + for dirpath, dirnames, filenames in os.walk(ROOT): + dirnames[:] = [d for d in dirnames if d not in (".git", "build")] + for name in sorted(filenames): + yield os.path.relpath(os.path.join(dirpath, name), ROOT) + + +def read(rel): + with open(os.path.join(ROOT, rel), encoding="utf-8", errors="ignore") as fh: + return fh.read() + + +def strip_comments(text): + """Blank out comments so directive scanning cannot be fooled by an + `#endif` inside one. Line structure is preserved.""" + out, i, n = [], 0, len(text) + while i < n: + if text.startswith("/*", i): + j = text.find("*/", i + 2) + j = n if j < 0 else j + 2 + out.append("".join(c if c == "\n" else " " for c in text[i:j])) + i = j + elif text.startswith("//", i): + j = text.find("\n", i) + j = n if j < 0 else j + out.append(" " * (j - i)) + i = j + else: + out.append(text[i]) + i += 1 + return "".join(out) + + +def directives(text): + """(line index, directive, rest) for every preprocessor directive, with + line continuations respected and comments already blanked.""" + lines = strip_comments(text).split("\n") + out, i = [], 0 + while i < len(lines): + m = re.match(r"\s*#\s*(\w+)\s*(.*)$", lines[i]) + start = i + while lines[i].rstrip().endswith("\\") and i + 1 < len(lines): + i += 1 + if m: + out.append((start, m.group(1), m.group(2).strip())) + i += 1 + return out + + +def find_guard(text): + """(name, ifndef line, define line, endif line) for a whole-file guard, or + None. + + Requires the first directive to be `#ifndef N`, the second to be + `#define N` with an empty replacement list, and the conditional nesting + that `#ifndef` opens to close only at the file's last directive -- so a + partial-file `#ifndef`, or a `#define N ` build knob, is never + mistaken for a guard. A leading `#pragma once` is stepped over.""" + ds = [d for d in directives(text) if d[1] != "pragma"] + if len(ds) < 3 or ds[0][1] != "ifndef": + return None + name = ds[0][2] + if not re.fullmatch(r"\w+", name or ""): + return None + if ds[1][1] != "define" or ds[1][2] != name: + return None + depth = 0 + for k, (line, d, _rest) in enumerate(ds): + if d in ("if", "ifdef", "ifndef"): + depth += 1 + elif d == "endif": + depth -= 1 + if depth == 0: + if k != len(ds) - 1: + return None + return name, ds[0][0], ds[1][0], line + return None + + +def external_references(names): + """Every mention of a guard macro outside the header that defines it, + split into (blocking, inert). + + Blocking = a mention in a compiled source, where it could be a `#ifdef` + that the guard's `#define` is load-bearing for. Inert = a mention anywhere + else (a script that quotes header text, a prose line in a doc, this + script's own docstring), which cannot affect what compiles but is still + reported so nobody has to wonder.""" + owners = {name: rel for name, (rel, _) in names.items()} + pats = {n: re.compile(r"(?