Skip to content

BUG: Fix Import DREAM3D Memory Usage #1341

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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,11 @@ set(SIMPLNX_HDRS
${SIMPLNX_SOURCE_DIR}/DataStructure/DataStructure.hpp
${SIMPLNX_SOURCE_DIR}/DataStructure/DynamicListArray.hpp
${SIMPLNX_SOURCE_DIR}/DataStructure/EmptyDataStore.hpp
${SIMPLNX_SOURCE_DIR}/DataStructure/EmptyListStore.hpp
${SIMPLNX_SOURCE_DIR}/DataStructure/IArray.hpp
${SIMPLNX_SOURCE_DIR}/DataStructure/IDataArray.hpp
${SIMPLNX_SOURCE_DIR}/DataStructure/IDataStore.hpp
${SIMPLNX_SOURCE_DIR}/DataStructure/IListStore.hpp
${SIMPLNX_SOURCE_DIR}/DataStructure/INeighborList.hpp
${SIMPLNX_SOURCE_DIR}/DataStructure/LinkedPath.hpp
${SIMPLNX_SOURCE_DIR}/DataStructure/Metadata.hpp
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/SimplnxCore/test/DREAM3DFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ TEST_CASE("DREAM3DFileTest:Import/Export DREAM3D Filter Test")
REQUIRE(importDataStructure.getData(DataPath({DataNames::k_Group1Name})) != nullptr);
auto* dataArray = importDataStructure.getDataAs<DataArray<int8>>(DataPath({DataNames::k_ArrayName}));
REQUIRE(dataArray != nullptr);
REQUIRE(dataArray->template getIDataStoreAs<EmptyDataStore<int8>>() != nullptr);
REQUIRE(dataArray->template getIDataStoreAs<EmptyDataStore<int8>>() == nullptr);
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/simplnx/DataStructure/AbstractDataStore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "simplnx/Common/TypesUtility.hpp"
#include "simplnx/DataStructure/DataObject.hpp"
#include "simplnx/DataStructure/IDataStore.hpp"
#include "simplnx/Utilities/Parsing/HDF5/IO/DatasetIO.hpp"

#include <nonstd/span.hpp>

Expand All @@ -18,6 +17,11 @@

namespace nx::core
{
namespace HDF5
{
class DatasetIO;
}

/**
* @class AbstractDataStore
* @brief The AbstractDataStore class serves as an interface class for the
Expand Down
49 changes: 3 additions & 46 deletions src/simplnx/DataStructure/AbstractListStore.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "simplnx/Common/Types.hpp"
#include "simplnx/DataStructure/IListStore.hpp"

#include <memory>
#include <numeric>
Expand All @@ -11,7 +12,7 @@
namespace nx::core
{
template <class T>
class AbstractListStore
class AbstractListStore : public IListStore
{
public:
/////////////////////////////////
Expand Down Expand Up @@ -536,43 +537,17 @@ class AbstractListStore
using reference = value_type&;
using const_reference = const value_type&;

virtual ~AbstractListStore() = default;
~AbstractListStore() override = default;

virtual std::unique_ptr<AbstractListStore> deepCopy() const = 0;

/**
* @brief This method sets the shape of the dimensions to `tupleShape`.
*
* There are 3 possibilities when using this function:
* [1] The number of tuples of the new shape is *LESS* than the original. In this
* case a memory allocation will take place and the first 'N' elements of data
* will be copied into the new array. The remaining data is *LOST*
*
* [2] The number of tuples of the new shape is *EQUAL* to the original. In this
* case the shape is set and the function returns.
*
* [3] The number of tuples of the new shape is *GREATER* than the original. In
* this case a new array is allocated and all the data from the original array
* is copied into the new array and the remaining elements are initialized to
* the default initialization value.
*
* @param tupleShape The new shape of the data where the dimensions are "C" ordered
* from *slowest* to *fastest*.
*/
virtual void resizeTuples(usize tupleCount) = 0;

/**
* @brief addEntry
* @param grainId
* @param value
*/
virtual void addEntry(int32 grainId, value_type value) = 0;

/**
* @brief Clear All Lists
*/
virtual void clearAllLists() = 0;

/**
* @brief setList
* @param grainId
Expand All @@ -594,8 +569,6 @@ class AbstractListStore
*/
virtual vector_type getList(int32 grainId) const = 0;

virtual usize getListSize(usize grainId) const = 0;

/**
* @brief copyOfList
* @param grainId
Expand All @@ -614,17 +587,6 @@ class AbstractListStore

virtual void setValue(int32 grainId, usize index, T value) = 0;

/**
* @brief getNumberOfLists
* @return int32
*/
virtual uint64 getNumberOfLists() const = 0;

uint64 size() const
{
return getNumberOfLists();
}

/**
* @brief operator []
* @param grainId
Expand Down Expand Up @@ -683,11 +645,6 @@ class AbstractListStore
return const_iterator(*this, size());
}

/**
* @brief Clears the array.
*/
virtual void clear() = 0;

virtual void setData(const std::vector<shared_vector_type>& lists) = 0;

virtual void setData(const std::vector<vector_type>& lists) = 0;
Expand Down
1 change: 1 addition & 0 deletions src/simplnx/DataStructure/DataStore.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "simplnx/DataStructure/AbstractDataStore.hpp"
#include "simplnx/Utilities/Parsing/HDF5/IO/DatasetIO.hpp"

#include <fmt/core.h>
#include <nonstd/span.hpp>
Expand Down
213 changes: 213 additions & 0 deletions src/simplnx/DataStructure/EmptyListStore.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
#pragma once

#include "AbstractListStore.hpp"

#include "simplnx/Utilities/Parsing/HDF5/IO/DatasetIO.hpp"

namespace nx::core
{
template <class T>
class EmptyListStore : public AbstractListStore<T>
{
public:
using shape_type = typename std::vector<usize>;
using value_type = T;
using parent_type = AbstractListStore<T>;
using vector_type = typename parent_type::vector_type;
using shared_vector_type = typename parent_type::shared_vector_type;

EmptyListStore() = default;
/**
* @brief Constructs a ListStore using the specified tuple shape and list size.
* @param tupleShape
* @param listSize
*/
EmptyListStore(usize numTuples)
: AbstractListStore<T>()
, m_NumTuples(numTuples)
{
}

EmptyListStore(const EmptyListStore& rhs) = default;
EmptyListStore(EmptyListStore&& rhs) = default;

~EmptyListStore() override = default;

/**
* @brief Returns a copy of the current list store.
* @return std::unique<AbstractListStore<T>>
*/
std::unique_ptr<parent_type> deepCopy() const override
{
return std::make_unique<EmptyListStore>(*this);
}

/**
* @brief addEntry
* @param grainId
* @param value
*/
void addEntry(int32 grainId, value_type value) override
{
throw std::runtime_error("EmptyListStore cannot add values to list");
}

void resizeTuples(usize tupleCount) override
{
m_NumTuples = tupleCount;
}

void clear() override
{
m_NumTuples = 0;
}

/**
* @brief Clear All Lists
*/
void clearAllLists() override
{
m_NumTuples = 0;
}

uint64 getNumberOfLists() const override
{
return m_NumTuples;
}

/**
* @brief getList
* @param grainId
* @return shared_vector_type
*/
vector_type getList(int32 grainId) const override
{
return {};
}

/**
* @brief copyOfList
* @param grainId
* @return vector_type
*/
vector_type copyOfList(int32 grainId) const override
{
return {};
}

/**
* @brief setList
* @param grainId
* @param neighborList
*/
void setList(int32 grainId, const shared_vector_type& neighborList) override
{
throw std::runtime_error("EmptyListStore cannot set list values");
}

/**
* @brief setList
* @param grainId
* @param neighborList
*/
void setList(int32 grainId, const vector_type& neighborList) override
{
throw std::runtime_error("EmptyListStore cannot set list values");
}

usize getListSize(usize grainId) const override
{
return 0;
}

/**
* @brief getValue
* @param grainId
* @param index
* @param ok
* @return T
*/
T getValue(int32 grainId, int32 index, bool& ok) const override
{
throw std::runtime_error("EmptyListStore cannot get list value");
}

void setValue(int32 grainId, usize index, T value) override
{
throw std::runtime_error("EmptyListStore cannot set list value");
}

/**
* @brief operator []
* @param grainId
* @return vector_type&
*/
vector_type operator[](int32 grainId) const override
{
throw std::runtime_error("EmptyListStore cannot get list");
}

/**
* @brief operator []
* @param grainId
* @return vector_type&
*/
vector_type operator[](usize grainId) const override
{
throw std::runtime_error("EmptyListStore cannot get list");
}

/**
* @brief Returns a const reference to the vector_type value found at the specified index. This cannot be used to edit the vector_type value found at the specified index.
* @param grainId
* @return vector_type
*/
vector_type at(int32 grainId) const override
{
throw std::runtime_error("EmptyListStore cannot get list");
}

/**
* @brief Returns a const reference to the vector_type value found at the specified index. This cannot be used to edit the vector_type value found at the specified index.
* @param grainId
* @return vector_type
*/
vector_type at(usize grainId) const override
{
throw std::runtime_error("EmptyListStore cannot get list");
}

void setData(const std::vector<shared_vector_type>& lists) override
{
throw std::runtime_error("EmptyListStore cannot set lists");
}

void setData(const std::vector<vector_type>& lists) override
{
throw std::runtime_error("EmptyListStore cannot set lists");
}

void readHdf5(const HDF5::DatasetIO& datasetReader) override
{
auto tupleDimsResult = datasetReader.readVectorAttribute<uint64>("TupleDimensions");
if(tupleDimsResult.invalid())
{
clear();
}
else
{
std::vector<uint64> tupleDims = tupleDimsResult.value();
uint64 numTuples = std::accumulate(tupleDims.begin(), tupleDims.end(), static_cast<uint64>(1), std::multiplies<>());
resizeTuples(numTuples);
}
}

void writeHdf5(HDF5::DatasetIO& datasetReader) override
{
throw std::runtime_error("EmptyListStore cannot write to HDF5");
}

private:
usize m_NumTuples = 0;
};
} // namespace nx::core
Loading
Loading