Skip to content

Vtkm basic storage ownership controls over memory are more robust

VTK-m StorageBasic is now able to give/take ownership of user allocated memory.

This fixes the three following issues with StorageBasic.

  1. Memory that was allocated by VTK-m and Stolen by the user needed the proper free function called which is generally StorageBasicAllocator::deallocate. But that was hard for the user to hold onto. So now we provide a function pointer to the correct free function.

  2. Memory that was allocated outside of VTK-m was impossible to transfer to VTK-m as we didn't know how to free it. This is now resolved by allowing the user to specify a free function to be called on release. With support for a user defined free function it is now possible to construct an ArrayHandle with user memory that can be re-allocated. This is done with the following code:

      T* buffer = new T[100];
      auto user_free_function = [](void* ptr) { delete[] static_cast<T*>(ptr); };
    
      vtkm::cont::internal::Storage<T, vtkm::cont::StorageTagBasic>
          storage(buffer, 100, user_free_function);
      vtkm::cont::ArrayHandle<T> arrayHandle(std::move(storage));
  3. When the CUDA backend allocates memory for an ArrayHandle that has no control representation, and the location we are running on supports concurrent managed access we want to specify that cuda managed memory as also the host memory. This requires that StorageBasic be able to call an arbitrary new delete function which is chosen at runtime.

Edited by Robert Maynard

Merge request reports

Loading