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

Graph Container Interface #17

Merged
merged 36 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7ee19a1
DeviceTypeUtil: fixing name in string.
massimim Jul 14, 2022
1fe86f4
Adding a mutable version of getBackend in GridBase.
massimim Jul 14, 2022
ef1b18a
WIP: New container interface
massimim Jul 14, 2022
a07f632
Adding some extra information to report for a device report.
massimim Jul 14, 2022
cc64f77
WIP: New container interface
massimim Jul 14, 2022
f03bb2e
Documentation
massimim Jul 18, 2022
f4d851d
Merge remote-tracking branch 'origin/develop' into container
massimim Jul 18, 2022
1d06c32
Fixing merging issues.
massimim Jul 18, 2022
090e57f
Documentation
massimim Jul 18, 2022
182155b
Imposing coding standards on the Container class.
massimim Jul 18, 2022
0a944c3
WIP: new container graph mechanism.
massimim Jul 19, 2022
b2cefa1
Merge remote-tracking branch 'origin/develop' into container
massimim Aug 8, 2022
3c7a25b
WIP
massimim Aug 8, 2022
7942c0a
WIP
massimim Aug 9, 2022
23b2d34
WIP
massimim Aug 10, 2022
87ffb4c
WIP
massimim Aug 12, 2022
7d11d4d
WIP
massimim Aug 12, 2022
c05341e
WIP
massimim Aug 12, 2022
78bb946
WIP
massimim Aug 12, 2022
fe27bd2
WIP
massimim Aug 12, 2022
f709e8b
WIP
massimim Aug 12, 2022
cf2dee4
WIP
massimim Aug 12, 2022
0796ddb
WIP
massimim Aug 22, 2022
16f4e5d
WIP
massimim Aug 22, 2022
1583db7
WIP
massimim Aug 23, 2022
bd57943
WIP
massimim Aug 23, 2022
b62fb87
WIP
massimim Aug 24, 2022
150a045
WIP
massimim Aug 29, 2022
601915f
WIP
massimim Aug 30, 2022
1a67851
WIP
massimim Aug 31, 2022
cc478a8
WIP
massimim Sep 2, 2022
3ca3d30
Merge remote-tracking branch 'origin/develop' into container
massimim Sep 2, 2022
c3383ab
New container graph completed, including unit tests.
massimim Sep 12, 2022
c696b27
Fixing compilation issue on windows.
massimim Sep 18, 2022
b1af036
Merge remote-tracking branch 'origin/develop' into container
massimim Sep 26, 2022
e27de7e
Merge remote-tracking branch 'origin/develop' into container
massimim Oct 4, 2022
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
43 changes: 36 additions & 7 deletions libNeonCore/include/Neon/core/types/digraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ struct Empty

/**
* DiGraph is a directed graph datastructure implemented using an adjacency list.
*
*
* Self loops can be represented.
* Parallel loops cannot be represented.
*
*
* @tparam VertexProp Type representing the properties to be stored per-vertex
* @tparam EdgeProp Type representing the properties to be stored per-edge
*/
Expand Down Expand Up @@ -187,6 +187,18 @@ class DiGraph
}
}

/**
* Run a function on each vertex in the graph
*
* @param fn Function that takes in a vertex and does something
*/
void forEachVertex(std::function<void(size_t)> fn) const
{
for (auto& kv : mAdj) {
fn(kv.first);
}
}

/**
* Returns a copy of incoming edges from a vertex as pairs of vertex ids
*
Expand Down Expand Up @@ -313,6 +325,21 @@ class DiGraph
}
}

/**
* Run a function on each edge
*
* @param fn Function that takes in an edge and does something
*/
void forEachEdge(std::function<void(const Edge&)> fn) const
{
for (auto i : mAdj) {
size_t src = i.first;
for (size_t tgt : i.second) {
fn({src, tgt});
}
}
}

/**
* Get a const-ref to the vertex property
*
Expand All @@ -337,6 +364,7 @@ class DiGraph
return mVprop.at(v);
}


/**
* Set the vertex property
*
Expand Down Expand Up @@ -415,9 +443,9 @@ class DiGraph

/**
* Contract an edge by deleting the source vertex and connecting all its neighbors
* with the target vertex. The edge property of the removed vertex is set to all the
* with the target vertex. The edge property of the removed vertex is set to all the
* new edges.
*
*
* a--->c--->d
* ^
* |
Expand Down Expand Up @@ -449,9 +477,9 @@ class DiGraph

/**
* Contract an edge by deleting the source vertex and connecting all its neighbors
* with the target vertex The edge property of the removed vertex is set to all the
* with the target vertex The edge property of the removed vertex is set to all the
* new edges.
*
*
* a--->c--->d
* ^
* |
Expand Down Expand Up @@ -504,7 +532,8 @@ class DiGraph
* @param v Vertex
* @return Neighboring vertices of v
*/
const std::set<size_t> inNeighbors(size_t v) const
auto inNeighbors(size_t v) const
-> const std::set<size_t>
{
std::set<size_t> in;
forEachInEdge(v, [&](const Edge& e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ auto DataViewUtil::toString(DataView e) -> std::string
}
case DataView::BOUNDARY: {
return "BOUNDARY";
}
}
default: {
NEON_THROW_UNSUPPORTED_OPTION("DataViewUtil");
}
Expand All @@ -40,7 +40,7 @@ auto DataViewUtil::fromInt(int val) -> DataView
}
case static_cast<int>(DataView::BOUNDARY): {
return DataView::BOUNDARY;
}
}
default: {
NEON_THROW_UNSUPPORTED_OPTION("DataViewUtil");
}
Expand All @@ -52,9 +52,9 @@ auto DataViewUtil::toInt(DataView dataView) -> int
return static_cast<int>(dataView);
}

} // namespace Neon

std::ostream& operator<<(std::ostream& os, Neon::DataView const& m)
{
return os << std::string(Neon::DataViewUtil::toString(m));
}

} // namespace Neon
4 changes: 2 additions & 2 deletions libNeonCore/src/core/types/DeviceType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ auto DeviceTypeUtil::Cli::getStringOptions() -> std::string

auto DeviceTypeUtil::Cli::addToReport(Neon::core::Report& report, Neon::core::Report::SubBlock& subBlock) -> void
{
report.addMember("Executor", DeviceTypeUtil::toString(this->getOption()), &subBlock);
report.addMember("DeviceType", DeviceTypeUtil::toString(this->getOption()), &subBlock);
}

auto DeviceTypeUtil::Cli::addToReport(Neon::core::Report& report) -> void
{
report.addMember("Executor", DeviceTypeUtil::toString(this->getOption()));
report.addMember("DeviceType", DeviceTypeUtil::toString(this->getOption()));
}


Expand Down
66 changes: 46 additions & 20 deletions libNeonDomain/include/Neon/domain/interface/GridBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ class GridBase
public:
GridBase();

GridBase(const std::string& gridImplementationName,
const Neon::Backend& backend,
const Neon::index_3d& dim,
const Neon::domain::Stencil& stencil,
const Neon::set::DataSet<size_t>& nPartitionElements /**< Number of element per partition */,
const Neon::index_3d& defaultBlockSize,
const Vec_3d<double>& spacingData = Vec_3d<double>(1, 1, 1) /*! Spacing, i.e. size of a voxel */,
const Vec_3d<double>& origin = Vec_3d<double>(0, 0, 0) /*! Origin */);

/**
* Returns the size of the grid
*/
Expand Down Expand Up @@ -82,7 +73,6 @@ class GridBase

/**
* Creates a DataSet object compatible with the number of GPU used by the grid.
* TODO - refactor into a create method once all grids are ported
*/
template <typename T>
auto newDataSet() const
Expand All @@ -106,6 +96,12 @@ class GridBase
auto getBackend() const
-> const Backend&;

/**
* Returns the backed used to create the grid
*/
auto getBackend()
-> Backend&;

/**
* Returns the DevSet object used to create the grid.
*/
Expand All @@ -118,32 +114,62 @@ class GridBase
auto toString() const
-> std::string;

/**
* Returns an UID for the grid
* @return
*/
auto getGridUID() const
-> size_t;

/**
* Add the grid information in a Report object
*/
virtual auto toReport(Neon::Report& report,
bool addBackendInfo = false) const
-> void;

/**
* Returns the thread block size used by default by the grid
*/
auto getDefaultBlock() const
-> const Neon::index_3d&;



protected:
auto init(const std::string& gridImplementationName,
const Neon::Backend& backend,
const Neon::index_3d& dimension,
const Neon::domain::Stencil& stencil,
const Neon::set::DataSet<size_t>& nPartitionElements,
const Neon::index_3d& defaultBlockSize,
const Vec_3d<double>& spacingData,
const Vec_3d<double>& origin) -> void;
/**
* Protected constructor
*/
GridBase(const std::string& gridImplementationName,
const Neon::Backend& backend,
const Neon::index_3d& dim,
const Neon::domain::Stencil& stencil,
const Neon::set::DataSet<size_t>& nPartitionElements /**< Number of element per partition */,
const Neon::index_3d& defaultBlockSize,
const Vec_3d<double>& spacingData = Vec_3d<double>(1, 1, 1) /*! Spacing, i.e. size of a voxel */,
const Vec_3d<double>& origin = Vec_3d<double>(0, 0, 0) /*! Origin */);

/**
* Protected initialization function used by derived classes to set some parameters.
*/
auto init(const std::string& gridImplementationName /**< Name of the implementation, for example dGrid eGrid etc */,
const Neon::Backend& backend /**< Backend used to create the grid */,
const Neon::index_3d& dimension /**< Dimension of the grid */,
const Neon::domain::Stencil& stencil /**< Union of all the stencil that will be used with the grid */,
const Neon::set::DataSet<size_t>& nPartitionElements /**< Elements associated to each partition */,
const Neon::index_3d& defaultBlockSize /**< Default thread block size */,
const Vec_3d<double>& spacingData /**< Grid spacing */,
const Vec_3d<double>& origin /**< Position in space of the grid's origin */) -> void;

/**
* Protected method to set the default thread blocks size
*/
auto setDefaultBlock(const Neon::index_3d&)
-> void;

/**
* Protected method to set default thread block size by data view.
*/
auto getDefaultLaunchParameters(Neon::DataView)
-> Neon::set::LaunchParameters&;

Expand All @@ -164,8 +190,8 @@ class GridBase
Neon::index_3d dimension /**< Dimension of the grid */;
Neon::domain::Stencil stencil /**< Stencil used for the grid initialization */;
Neon::set::DataSet<size_t> nPartitionElements /**< Number of elements per partition */;
Vec_3d<double> spacing /*! Spacing, i.e. size of a voxel */;
Vec_3d<double> origin /*! Origin */;
Vec_3d<double> spacing /**< Spacing, i.e. size of a voxel */;
Vec_3d<double> origin /**< Position in space of the grid's origin */;
Defaults_t defaults;
std::string gridImplementationName;
};
Expand Down
10 changes: 5 additions & 5 deletions libNeonDomain/include/Neon/domain/tools/IODomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ auto IODomain<ExportType, intType_ta>::resetValuesToMasked(ExportType offset,
template <typename ExportType, typename intType_ta>
auto IODomain<ExportType, intType_ta>::resetValuesToConst(ExportType offset) -> void
{
mField.forEach([&](const Integer_3d<intType_ta>& idx, int c, ExportType& val) {
mField.forEach([&](const Integer_3d<intType_ta>&, int, ExportType& val) {
val = offset;
});
}
Expand Down Expand Up @@ -363,9 +363,9 @@ auto IODomain<ExportType, intType_ta>::maxDiff(const IODomain<ExportType, intTyp
}

a.forEachActive([&](const Integer_3d<intType_ta>& idx,
int c,
const ExportType& valA,
const ExportType& valB) {
int c,
const ExportType& valA,
const ExportType& valB) {
const auto newDiff = std::abs(valA - valB);
const int threadId = omp_get_thread_num();
if (newDiff > std::get<0>(max_diff[threadId])) {
Expand All @@ -375,7 +375,7 @@ auto IODomain<ExportType, intType_ta>::maxDiff(const IODomain<ExportType, intTyp
std::get<2>(md) = c;
}
},
b);
b);

int target = 0;
for (auto i = 1; i < nThreads; i++) {
Expand Down
33 changes: 17 additions & 16 deletions libNeonDomain/include/Neon/domain/tools/TestData.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ template <typename G, typename T, int C>
auto TestData<G, T, C>::axpy(const Type* alpha, IODomain& A, IODomain& B)
-> void
{
this->template forEachActiveIODomain([&](const Neon::index_3d& idx,
int cardinality,
Type& a,
Type& b) {
this->forEachActiveIODomain([&](const Neon::index_3d& /*idx*/,
int /*cardinality*/,
Type& a,
Type& b) {
b += (*alpha) * a;
},
A, B);
A, B);
}

template <typename G, typename T, int C>
Expand All @@ -318,8 +318,8 @@ auto TestData<G, T, C>::laplace(IODomain& A, NEON_IO IODomain& B)
}
this->template forEachActiveIODomain([&](const Neon::index_3d& idx,
int cardinality,
Type& a,
Type& b) {
Type& /*a*/,
Type& b) {
// Laplacian stencil operates on 6 neighbors (assuming 3D)
T res = 0;
bool isValid = false;
Expand All @@ -342,23 +342,24 @@ auto TestData<G, T, C>::laplace(IODomain& A, NEON_IO IODomain& B)
}

template <typename G, typename T, int C>
auto TestData<G, T, C>::compare(FieldNames name, T tollerance) -> bool
auto TestData<G, T, C>::compare(FieldNames name,
[[maybe_unused]] T tollerance) -> bool
{
bool isTheSame = false;
if constexpr (std::is_integral_v<T>) {
bool foundAnIssue = false;
this->compare(name, [&](const Neon::index_3d& idx,
int cardinality,
const T& golden,
const T& computed) {
this->compare(name, [&](const Neon::index_3d& /*idx*/,
int /*cardinality*/,
const T& golden,
const T& computed) {
if (golden != computed) {
{
#pragma omp critical
{
foundAnIssue = true;
//std::stringstream s;
//s << idx.to_string() << " " << golden << " " << computed << std::endl;
//NEON_INFO(s.str());
// std::stringstream s;
// s << idx.to_string() << " " << golden << " " << computed << std::endl;
// NEON_INFO(s.str());
}
}
}
Expand All @@ -375,7 +376,7 @@ auto TestData<G, T, C>::compare(FieldNames name, T tollerance) -> bool
T maxAbs = std::max(goldenABS, computedABS);

auto relativeDiff = (maxAbs == 0.0 ? 0.0 : std::abs(golden - computed) / maxAbs);
foundAnIssue = relativeDiff >= 0.00001;
foundAnIssue = relativeDiff >= tollerance;
});
isTheSame = !foundAnIssue;
}
Expand Down
6 changes: 6 additions & 0 deletions libNeonDomain/src/domain/interface/GridBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ auto GridBase::getBackend() const
return mStorage->backend;
}

auto GridBase::getBackend()
-> Backend&
{
return mStorage->backend;
}

auto GridBase::getDevSet() const
-> const Neon::set::DevSet&
{
Expand Down
2 changes: 1 addition & 1 deletion libNeonDomain/src/domain/internal/dGrid/dGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ auto dGrid::getKernelConfig(int streamIdx,
getDefaultBlock(), 0);

kernelConfig.expertSetLaunchParameters(launchInfoSet);
kernelConfig.expertSetBackend(getBackend());
kernelConfig.expertSetBackend(this->getBackend());

return kernelConfig;
}
Expand Down
4 changes: 2 additions & 2 deletions libNeonDomain/tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ add_subdirectory("gUt_containers")
add_subdirectory("gUt_dataView_patterns")
add_subdirectory("gUt_map")
add_subdirectory("gUt_patterns_container")
#add_subdirectory("gUt_periodic")
add_subdirectory("domainUt_swap")
add_subdirectory("gUt_tools")
add_subdirectory("gUt_vtk")
add_subdirectory("gUt_bGrid")
add_subdirectory("gUt_bGrid")

Loading