Skip to content

Issue 179 compilation speedup PIMPL#331

Closed
SinYita wants to merge 13 commits into
masterfrom
issue-179=compilation-speedup-PIMPL
Closed

Issue 179 compilation speedup PIMPL#331
SinYita wants to merge 13 commits into
masterfrom
issue-179=compilation-speedup-PIMPL

Conversation

@SinYita

@SinYita SinYita commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

This PR introduces PIMPL as we talked in meetings, reducing the cost of parsing heavy header files like Thrust during compilation of various codeobjects. Specifically: objects_storage.h holds the actual Thrust container. The lean objects.h exposes raw pointers (such as dev_array_* / host_array_*). And the newly generated objects_api.h inside device.py provides resize/clear/copy, eventspace extensions, and wrappers for some algorithms and cuRAND-related code previously scattered across other TUs. Most .cu files access data via raw pointers and the API, concentrating Thrust usage primarily in objects.cu.

Pointers:

sync_all_dev_ptrs() is called once at the end of _init_arrays() for a full refresh. If the container is modified via the API (such as resize_*), only the relevant pointers are synchronized. Therefore, as long as mutates use the API, the global PIMPL pointer can remain consistent with the container. The trade-off is the generation of a large number of API symbols in arrays(which is quite ugly right now). A more general template could be considered later to reduce the amount of generated code. And also I haven't apply PIMPL also for host vector, which will be add soon in following commits.

Outcome

On MushroomBody (N=1000), cold compilation with make -j1 is reduced to approximately ~100s (compared to approximately ~200s on master under the same environment RTX3080Ti 12GB).

@SinYita

SinYita commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

@mstimberg Hi Marcel,I am wondering If Thrust is indeed the main bottleneck—and given that we only use a limited set of its features (mainly host/device vectors and copy_if)—would it make sense to replace these with lightweight custom implementations? That way, we could avoid adding extra architectural complexity and significantly reduce compilation overhead. What do you think?

@SinYita
SinYita requested a review from mstimberg July 22, 2026 14:14
@SinYita SinYita self-assigned this Jul 22, 2026
@mstimberg

Copy link
Copy Markdown
Member

@mstimberg Hi Marcel,I am wondering If Thrust is indeed the main bottleneck—and given that we only use a limited set of its features (mainly host/device vectors and copy_if)—would it make sense to replace these with lightweight custom implementations? That way, we could avoid adding extra architectural complexity and significantly reduce compilation overhead. What do you think?

Maybe! Currently, our DynamicArray and DynamicArray2D implementations are thin wrappers around std::vector, but implementing them without std::vector shouldn't be terribly hard, either.

@SinYita SinYita changed the title Issue 179-compilation speedup pimpl Issue 179 compilation speedup PIMPL Jul 22, 2026
@SinYita
SinYita force-pushed the issue-179=compilation-speedup-PIMPL branch from 905218e to 4af01d3 Compare July 22, 2026 17:58
Also wire host dynamic arrays to host_array_* / _num_host_array_*
(with shadowing-safe aliases) instead of raw_pointer_cast / .size().
@SinYita
SinYita force-pushed the issue-179=compilation-speedup-PIMPL branch from 4af01d3 to 369fd48 Compare July 22, 2026 18:00
Rename leftover objects_thrust.h includes to objects_storage.h, and drop
the duplicate _run_random_number_buffer declaration from objects_api.
@SinYita SinYita closed this Jul 23, 2026
@SinYita
SinYita deleted the issue-179=compilation-speedup-PIMPL branch July 24, 2026 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants