Example for use of BlockData on host/device
Closed this issue · 3 comments
I've been trying to put together a simple example of use of BlockData
on host/device. Nothing fancy, just to demo construction/destruction and adding/removing data. However, I'm confused about a couple of things and also getting some errors. First is simple construction/destruction, where the following code will give a double free error:
// this is a .cu file, so compiled with nvcc
struct Track_t {
size_t eventID{0};
size_t trackID{0};
};
int main()
{
using TrackBlock_t = adept::BlockData<Track_t>;
constexpr size_t blocksize = 1024;
// Default construction (on host?)
auto *tb = TrackBlock_t::MakeInstance(blocksize);
// Clean up
TrackBlock_t::ReleaseInstance(tb);
return 0;
}
The current tests don't call the ReleaseInstance
static member function, but the documentation for VariableSizeObj/Interface
in VecGeom seems to indicate it's required. I'm certainly missing something basic, at the moment the host/device separation and who owns the memory managed is a bit unclear to me.
This first implementation is certainly incomplete as I was not paying a lot of attention to anything else than allocation in a buffer. Thanks for pointing this out, it shows that the scope verified currently by the unit test is quite reduced. I'll have a look and fix this.
This is now fixed by PR #21 - it required introducing in the base class in VecGeom support for composition of VariableSizeObj, which is merged now in VecGeom master. I extended the unit test to more use cases, including allocation/deallocation/copying on host. People will need to fetch the master of VecGeom to compile this. I will improve the documentation for VariableSizeObjectInterface when moving to the new apt-sim/CopCore (?) library, as mentioned in #14
Looks fixed for me. Closing the issues.