Support constructing FMBScene with Python data
#34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Part of MET-36
Summary of Changes
While working on the forward kernel, I noticed that currently we don't have a way to create a
FMBScenewith data from Python side. This PR fills in this missing piece by defining a new constructor forFMBScenethat takes in references tostd::vectors and copy the values.Sadly, this copy is needed because
FMBSceneis designed to manage the memory for itself and we want to avoid double-free issue. In addition, since Python list is always on host (CPU) side, if we want the scene to live in GPU memory, then we have to move the data anyways.Aside: Using RAII Containers in
FMBSceneWhile writing the constructor & the unit test, I started to get a bit frustrated by having to write similar code twice to specialize for host/device memory management, so I replaced the underlying containers in
FMBScenewiththrust::device/host_vector:). Another nice side effect of this is that Thrust's device pointer & device reference types handle the moving of data for us automatically when we attempt to read it from host (see the definition ofFMBScene.__getitem__inbindints.cufor example).Test Plans
I added a unit test to verify that we can create
FMBSceneon both device & host and read the values stored in it.pixi run test