QuEST-Kit / QuEST

A multithreaded, distributed, GPU-accelerated simulator of quantum computers
https://quest.qtechtheory.org/
MIT License
393 stars 134 forks source link

refactored allocation and gpu-sync checks #474

Closed TysonRayJones closed 3 weeks ago

TysonRayJones commented 3 weeks ago

All allocation checks have been moved to memory.cpp so that nullptr comparisons aren't littering the code, and to make explicit when nested data-structures are being thoroughly checked (i.e. that all nested pointers are non-NULL, vs just the outer). Also tidied/combined validation related to memory allocation.

Structures with persistent GPU memory now have a wasGpuSynced field to indicate whether their memory has ever been copied to the GPU since creation. This replaces the previously hacky design which kept the first GPU element as a special default value until being overwritten. That design necessitated wastefully copying (a single amplitude) from device to host at every invocation of "has synched" validation, which forces kernel synchronisation and precludes efficient streaming. Further, it persuaded lots of validation boilerplate to check a user wasn't unknowingly passing in that special default value (a rare but technically possible scenario).