// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute // SPDX-License-Identifier: GPL-3.0-only #pragma once // The side-chain field's direct sums (SideChainField.cpp, EvaluatorCPU::Contribution) on an Apple GPU (macOS only): // one thread per reflection and state, as SideChainFieldGPU.cu's contribution_kernel does under CUDA, with the CPU's // single-precision arithmetic in its order (SideChainFieldMetal.metal spells it out). tests/SideChainFieldMetalTest.cpp // holds it to the CPU's. #include #include #include #include #include "SideChainField.h" // FieldStates class SideChainFieldMetal { public: // The evaluator's tables, kept on the GPU: per operator and row (k * rows + m) R^T h and h . t, per element and // row the form factor, per row stol2. Null where there is no Metal device the process may use (rugnux --no-gpu // hides it). Throws JFJochException on a Metal failure. static std::unique_ptr Make(size_t rows, size_t n_ops, const std::vector &hx, const std::vector &hy, const std::vector &hz, const std::vector &ht, const std::vector &f0, const std::vector &stol2); ~SideChainFieldMetal(); // The contributions of states first .. first + out.size() - 1, each `rows` values into its vector. void Contributions(const FieldStates &states, int first, std::vector>> &out); // How many states the GPU has summed in this process. static size_t States(); struct Impl; private: explicit SideChainFieldMetal(std::unique_ptr impl); std::unique_ptr impl_; };