diff --git a/image_analysis/scale_merge/RotationScaleMerge.cpp b/image_analysis/scale_merge/RotationScaleMerge.cpp index ab3f9f41e..b969ff62f 100644 --- a/image_analysis/scale_merge/RotationScaleMerge.cpp +++ b/image_analysis/scale_merge/RotationScaleMerge.cpp @@ -701,11 +701,15 @@ size_t RotationScaleMerge::DeviceBytes() const { const size_t bytes = BYTES_PER_OBS * static_cast(n_partials_obs) + BYTES_PER_EVENT * events + BYTES_PER_HKL * rawrun_start.size(); // The resident ingest's own peak comes before any of that, over every reflection read and every run - // before the resolution cut: the observation arrays, the sort key and the integrated delta_phi of - // each (66 bytes) and 24 bytes of the sort's or the cut's working arrays beside them, plus sixty-four - // bytes per run at the cut (IngestSort). - constexpr size_t INGEST_BYTES_PER_REFLECTION = 90, INGEST_BYTES_PER_RUN = 64; - const size_t ingest = INGEST_BYTES_PER_REFLECTION * ingest_reflections + INGEST_BYTES_PER_RUN * ingest_runs; + // before the resolution cut, measured with cudaMemGetInfo. Beside the observation arrays, the sort key + // and the integrated delta_phi of each (66 bytes): the second radix sort holds the frame order, the + // permutation, both keys and cub's alternate key and value buffers, 102.6 bytes per reflection in + // all; the cut (IngestSort) 98 per reflection and 56 per run. The upload before them holds the 66 + // bytes and the two 64 MB staging buffers. + constexpr size_t INGEST_BYTES_PER_REFLECTION = 103, INGEST_BYTES_PER_RUN = 58; + constexpr size_t INGEST_ARRAY_BYTES = 66, INGEST_STAGING_BYTES = size_t(160) << 20; + const size_t ingest = std::max(INGEST_BYTES_PER_REFLECTION * ingest_reflections + INGEST_BYTES_PER_RUN * ingest_runs, + INGEST_ARRAY_BYTES * ingest_reflections + INGEST_STAGING_BYTES); return std::max(bytes + bytes / 5, ingest); }