Skip to content

[Common] Avoid zero-initialising the NN TPC PID prediction buffer - #17831

Open
ktf wants to merge 1 commit into
AliceO2Group:masterfrom
ktf:tpc-pid-uninit-prediction-buffer
Open

[Common] Avoid zero-initialising the NN TPC PID prediction buffer#17831
ktf wants to merge 1 commit into
AliceO2Group:masterfrom
ktf:tpc-pid-uninit-prediction-buffer

Conversation

@ktf

@ktf ktf commented Sep 8, 2026

Copy link
Copy Markdown
Member

The per-DataFrame NN prediction buffer (masked tracks × output dims × 9 mass hypotheses, ~72 MB for a 1M-track PbPb DataFrame) is a value-initialised std::vector<float>: a full memset touching every page of the allocation, immediately overwritten in full by the per-hypothesis evaluation loop, so every page is paid for twice.

Carry it as an uninitialised unique_ptr<float[]> instead, so each page is touched exactly once, by the write that fills it. makePidTables takes const float* accordingly.

The per-DataFrame prediction buffer (masked tracks x output dims x 9 mass
hypotheses, ~72 MB for a 1M-track PbPb DataFrame) is a value-initialised
std::vector: a full memset touching every page, immediately overwritten in
full by the per-hypothesis evaluation loop. Carry it as an uninitialised
unique_ptr<float[]> instead, so each page is touched once, by the write that
fills it. All consumers only read it under useNetworkCorrection, so the null
buffer with the network disabled is never dereferenced. No change to any
computed value.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DgKXVM9Q9Hcgexfyj7Eqpp
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown

O2 linter results: ❌ 22 errors, ⚠️ 34 warnings, 🔕 0 disabled

@alibuild

alibuild commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Error while checking build/O2Physics/code-check for 6a54a0e at 2026-09-08 14:52:

## sw/BUILD/O2Physics-code-check-latest/log
--
========== List of issues found ==========
++ echo 'Found 4 errors and 42 warnings.'
Found 4 errors and 42 warnings.
++ [[ 4 -gt 0 ]]
++ cat /sw/BUILD/78c24ddd01e8f5911367832c9c156854d58e29a9/O2Physics-code-check/errors.txt
Common/Tools/PID/pidTPCModule.h:187:28: error: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay,-warnings-as-errors]
Common/Tools/PID/pidTPCModule.h:312:45: error: the const qualified parameter 'particle' is copied for each invocation; consider making it a reference [performance-unnecessary-value-param,-warnings-as-errors]
Common/Tools/PID/pidTPCModule.h:816:16: error: variable 'hadronicRate' is not initialized [cppcoreguidelines-init-variables,-warnings-as-errors]
Common/Tools/PID/pidTPCModule.h:817:13: error: variable 'occupancy' is not initialized [cppcoreguidelines-init-variables,-warnings-as-errors]
++ [[ 42 -gt 0 ]]
++ cat /sw/BUILD/78c24ddd01e8f5911367832c9c156854d58e29a9/O2Physics-code-check/warnings.txt
Common/Tools/PID/pidTPCModule.h:59:10: warning: inclusion of deprecated C++ header 'math.h'; consider using 'cmath' instead [modernize-deprecated-headers]
Common/Tools/PID/pidTPCModule.h:61:1: warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
Common/Tools/PID/pidTPCModule.h:100:82: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
Common/Tools/PID/pidTPCModule.h:101:76: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
Common/Tools/PID/pidTPCModule.h:106:94: warning: implicit conversion 'int' -> 'bool' [readability-implicit-bool-conversion]
Common/Tools/PID/pidTPCModule.h:178:5: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
Common/Tools/PID/pidTPCModule.h:224:15: warning: redundant string initialization [readability-redundant-string-init]
Common/Tools/PID/pidTPCModule.h:270:13: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
Common/Tools/PID/pidTPCModule.h:274:17: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
Common/Tools/PID/pidTPCModule.h:287:15: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
Common/Tools/PID/pidTPCModule.h:350:9: warning: the 'empty' method should be used to check for emptiness instead of comparing to an empty object [readability-container-size-empty]
Common/Tools/PID/pidTPCModule.h:408:7: warning: do not use 'else' after 'return' [readability-else-after-return]
Common/Tools/PID/pidTPCModule.h:417:191: warning: use nullptr [modernize-use-nullptr]
Common/Tools/PID/pidTPCModule.h:417:241: warning: use nullptr [modernize-use-nullptr]
Common/Tools/PID/pidTPCModule.h:426:15: warning: the 'empty' method should be used to check for emptiness instead of comparing to an empty object [readability-container-size-empty]
Common/Tools/PID/pidTPCModule.h:446:19: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
Common/Tools/PID/pidTPCModule.h:453:13: warning: the 'empty' method should be used to check for emptiness instead of comparing to an empty object [readability-container-size-empty]
Common/Tools/PID/pidTPCModule.h:489:189: warning: use nullptr [modernize-use-nullptr]
Common/Tools/PID/pidTPCModule.h:489:239: warning: use nullptr [modernize-use-nullptr]
Common/Tools/PID/pidTPCModule.h:508:21: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
Common/Tools/PID/pidTPCModule.h:522:11: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
Common/Tools/PID/pidTPCModule.h:530:9: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
Common/Tools/PID/pidTPCModule.h:633:20: warning: statement should be inside braces [readability-braces-around-statements]
Common/Tools/PID/pidTPCModule.h:635:20: warning: statement should be inside braces [readability-braces-around-statements]
Common/Tools/PID/pidTPCModule.h:641:22: warning: statement should be inside braces [readability-braces-around-statements]
Common/Tools/PID/pidTPCModule.h:643:22: warning: statement should be inside braces [readability-braces-around-statements]
Common/Tools/PID/pidTPCModule.h:651:20: warning: statement should be inside braces [readability-braces-around-statements]
Common/Tools/PID/pidTPCModule.h:653:20: warning: statement should be inside braces [readability-braces-around-statements]
Common/Tools/PID/pidTPCModule.h:685:18: warning: statement should be inside braces [readability-braces-around-statements]
Common/Tools/PID/pidTPCModule.h:687:18: warning: statement should be inside braces [readability-braces-around-statements]
Common/Tools/PID/pidTPCModule.h:753:21: warning: do not declare C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
Common/Tools/PID/pidTPCModule.h:778:13: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
Common/Tools/PID/pidTPCModule.h:786:11: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [readability-string-compare]
Common/Tools/PID/pidTPCModule.h:837:39: warning: statement should be inside braces [readability-braces-around-statements]
Common/Tools/PID/pidTPCModule.h:839:31: warning: statement should be inside braces [readability-braces-around-statements]
Common/Tools/PID/pidTPCModule.h:848:38: warning: statement should be inside braces [readability-braces-around-statements]
[0 more errors; see full log]

Full log here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants