Files
Filip LeonarskiandClaude Opus 5.5 1178452466 Bulk-solvent mask shrink on the Apple GPU, bit for bit
PutMaskOnGrid() takes a `gpu` flag (default on, as PutModelDensityOnGrid's): on macOS the shrink by
the 0.8 A radius (ShrinkMask) runs on the Apple GPU (ShrinkMaskMetal.mm/.metal), one thread per point
applying the CPU's rule - a masked point becomes solvent where a near offset is solvent, or a far
offset is a solvent point with a masked near offset - read from the mask as it was, with the CPU's
offsets; the mask and its copy handed to the GPU in place where page aligned. The atoms, the
symmetrize and gemmi's island removal stay on the CPU. --no-gpu, no device, or a failure (one
warning) keep the CPU's loop.

ShrinkMaskMetal_BitIdenticalToCPU ([portable][Metal]): clustered atoms, 0.4 A mask grids of a
triclinic P1 and a P212121 cell - every point the same bits.

M6 Mac mini, rugnux --mode refine (open-arm sets' merged MTZ and refined model), on top of the two
previous Metal commits: 9s02 184.2 -> 175.6 s, 9zlo 41.3 -> 39.0 s; the refined models
byte-identical to the build before on both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UqXYdJDrM65gxsCn2PrbfK
2026-11-16 08:23:53 +01:00

21 lines
1.0 KiB
C++

// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute <filip.leonarski@psi.ch>
// SPDX-License-Identifier: GPL-3.0-only
#pragma once
// The bulk-solvent mask's shrink (ModelGrid.cpp, ShrinkMask) on an Apple GPU (macOS only): one thread per point, the
// CPU's rule read from the mask as it was - the same mask, bit for bit. tests/ShrinkMaskMetalTest.cpp holds it to the
// CPU's.
#include <array>
#include <cstddef>
#include <vector>
// `in` shrunk into `out` (nu nv nw floats each, u fastest), with the CPU's offsets: `near`, then `far`, each stored
// wrapped (a positive offset less the grid's size). False where the GPU does not take it - no Metal device the process
// may use (rugnux --no-gpu hides it); `out` is then untouched. Throws JFJochException on a Metal failure.
bool ShrinkMaskMetal(int nu, int nv, int nw, const std::vector<std::array<int, 3>> &near,
const std::vector<std::array<int, 3>> &far, const float *in, float *out);
// How many masks the GPU has shrunk in this process.
size_t ShrinkMaskMetalCalls();