Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sidre dest memory space when importing from Conduit #1460

Merged
merged 9 commits into from
Nov 5, 2024
4 changes: 4 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ The Axom project release numbers follow [Semantic Versioning](http://semver.org/
### Added

### Changed
- Importing Conduit array data into `sidre::View` now allocates destination
data using the `View`'s parent's allocator ID, insteading of always using
host memory. This is consistent with the behavior of deep-copying data
from Sidre.

### Deprecated

Expand Down
7 changes: 4 additions & 3 deletions src/axom/sidre/core/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ void View::importFrom(conduit::Node& data_holder,
*
*************************************************************************
*/
View* View::importArrayNode(const Node& array)
View* View::importArrayNode(const Node& array, int allocID)
{
conduit::DataType array_dtype = array.dtype();

Expand All @@ -1511,14 +1511,15 @@ View* View::importArrayNode(const Node& array)
conduit::index_t num_ele = array_dtype.number_of_elements();
conduit::index_t ele_bytes = DataType::default_bytes(array_dtype.id());

buff->allocate((TypeID)array_dtype.id(), num_ele);
allocID = getValidAllocatorID(allocID);
buff->allocate((TypeID)array_dtype.id(), num_ele, allocID);

// copy the data in a way that matches
// to compact representation of the buffer
conduit::uint8* data_ptr = (conduit::uint8*)buff->getVoidPtr();
for(conduit::index_t i = 0; i < num_ele; i++)
{
memcpy(data_ptr, array.element_ptr(i), ele_bytes);
axom::copy(data_ptr, array.element_ptr(i), ele_bytes);
data_ptr += ele_bytes;
}

Expand Down
3 changes: 2 additions & 1 deletion src/axom/sidre/core/View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ class View

/*
* \brief set the View to hold an array in a Buffer
* \param allocID Allocator id for array data allocation.
*
* This takes a Node that holds an array of data and sets up the View to
* hold a copy of that data in an attached Buffer.
Expand All @@ -692,7 +693,7 @@ class View
*
* \return pointer to this View object
*/
View* importArrayNode(const Node& array);
View* importArrayNode(const Node& array, int allocID = INVALID_ALLOCATOR_ID);

//
// RDH -- Add an overload of the following that takes a const char *.
Expand Down