Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Remove PixelMaps + ModuleMaps from Globals #380

Closed
GNiendorf opened this issue Mar 29, 2024 · 0 comments · Fixed by #401
Closed

Remove PixelMaps + ModuleMaps from Globals #380

GNiendorf opened this issue Mar 29, 2024 · 0 comments · Fixed by #401
Labels
bug Something isn't working code cleanup

Comments

@GNiendorf
Copy link
Member

See this conversation for more details: #374 (comment)
Also discussed in @slava77's recent PR: #377

When the code was moved from CUDA to Alpaka, I had to put the sizes of the maps as constants in Constants.h here:

TrackLooper/SDL/Constants.h

Lines 143 to 148 in ad8ed39

// Temporary fix for endcap buffer allocation.
const unsigned int endcap_size = 9104;
// Temporary fix for module buffer allocation.
const unsigned int modules_size = 26401;
const unsigned int pix_tot = 1794686;

This is because the module and pixel maps are global variables, and I could not find a way to calculate the sizes at runtime and make the relevant arrays on the GPU using Alpaka. CUDA is much more relaxed about this, so this was not an issue before we moved to Alpaka. The downside of having the sizes stored in the Constants.h is that if you change the pixel maps in /data/ and the number of connections changes then it would throw a runtime error. To make this clear and avoid future issues, I put warnings in the code to check that the sizes in Constants.h were the sizes calculated at runtime. See the below

// Temporary check for endcap initialization.
if (phi_size != endcap_size) {
std::cerr << "\nError: phi_size and endcap_size are not equal.\n";
std::cerr << "phi_size: " << phi_size << ", endcap_size: " << endcap_size << "\n";
std::cerr << "Please change endcap_size in Constants.h to make it equal to phi_size.\n";
throw std::runtime_error("Mismatched sizes");
}

// Temporary check for module initialization.
if (pix_tot != connectedPix_size) {
std::cerr << "\nError: pix_tot and connectedPix_size are not equal.\n";
std::cerr << "pix_tot: " << pix_tot << ", connectedPix_size: " << connectedPix_size << "\n";
std::cerr << "Please change pix_tot in Constants.h to make it equal to connectedPix_size.\n";
throw std::runtime_error("Mismatched sizes");
}

The best solution here is to remove these variables as globals (probably initialize them in sdl.cc and pass their pointer to each Event object that is created), calculate their sizes at runtime when they are initialized, and then allocate the relevant arrays with these computed sizes. @slava77's recent PR fixed a lot of the issues I ran into when I attempted to do this when moving the code over to Alpaka, so I think this can be done now.

@GNiendorf GNiendorf added bug Something isn't working code cleanup labels Mar 29, 2024
@GNiendorf GNiendorf linked a pull request May 17, 2024 that will close this issue
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working code cleanup
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant