Skip to content

Commit

Permalink
Skeleton refactoring (#28)
Browse files Browse the repository at this point in the history
* New skeleton structure based on the Container graph mechanism. 

* New Containers to abstract data transfers and synchronization.
  • Loading branch information
massimim authored Dec 9, 2022
1 parent 3731270 commit 7a180a4
Show file tree
Hide file tree
Showing 129 changed files with 3,722 additions and 5,027 deletions.
7 changes: 4 additions & 3 deletions cmake/ManageCompilationFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ set(NeonCXXFlags

#Add GCC specific compiler flags here
#-Wno-class-memaccess for "writing to an object of type XXX with no trivial copy-assignment; use copy-assignment or copy-initialization instead"
$<$<CXX_COMPILER_ID:GNU>:-m64 -Wall -Wextra -Werror -Wno-unused-function -Wno-deprecated-declarations -Wno-class-memaccess>
$<$<CXX_COMPILER_ID:GNU>:-m64 -Wall -Wextra -Werror -Wno-unused-function -Wno-deprecated-declarations -Wno-class-memaccess -Wno-deprecated-declarations>

#Add Clang specific compiler flags here
$<$<CXX_COMPILER_ID:Clang>:-m64 -Wall -Wextra -Werror -Wno-unused-function -Wno-deprecated-declarations>
$<$<CXX_COMPILER_ID:Clang>:-m64 -Wall -Wextra -Werror -Wno-unused-function -Wno-deprecated-declarations -Wno-deprecated-copy -Wno-unused-parameter -Wno-unused-private-field -Wno-braced-scalar-init -Wno-unused-variable -Wno-unused-but-set-variable -Wno-deprecated-declarations >
)

set(MSVC_XCOMPILER_FLAGS "/openmp /std:c++17")
set(NeonCUDAFlags
# Optimization flags for Release
$<$<CXX_COMPILER_ID:GNU>: $<$<CONFIG:Release>:-O3> >
Expand All @@ -51,7 +52,7 @@ set(NeonCUDAFlags
# Host compiler
$<$<CXX_COMPILER_ID:GNU>:-Xcompiler -fopenmp -std=c++17 $<$<CONFIG:Release>:-O3> $<$<CONFIG:Debug>:-O0> >
$<$<CXX_COMPILER_ID:Clang>:-Xcompiler -fopenmp -std=c++17 $<$<CONFIG:Release>:-O3> $<$<CONFIG:Debug>:-O0>>
$<$<CXX_COMPILER_ID:MSVC>:-Xcompiler /std:c++17>
$<$<CXX_COMPILER_ID:MSVC>:-Xcompiler ${MSVC_XCOMPILER_FLAGS}>
#Disables warning
#177-D "function XXX was declared but never referenced"
-Xcudafe "--display_error_number --diag_suppress=177"
Expand Down
2 changes: 1 addition & 1 deletion cmake/Nvtx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ if (${NEON_USE_NVTX})
message(STATUS "NVTX Ranges is enabled")
else ()
message(STATUS "NVTX Ranges is disabled")
endif ()
endif ()
5 changes: 5 additions & 0 deletions libNeonCore/include/Neon/core/tools/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ LIBNEONCORE_EXPORT extern Logger LoggerObj;

} // namespace Neon

#if defined( NEON_ACTIVETE_TRACING)
#define NEON_TRACE(...) ::Neon::globalSpace::LoggerObj.getLogger()->trace(__VA_ARGS__)
#else
#define NEON_TRACE(...)
#endif

#define NEON_INFO(...) ::Neon::globalSpace::LoggerObj.getLogger()->info(__VA_ARGS__)
#define NEON_WARNING(...) \
::Neon::globalSpace::LoggerObj.getLogger()->warn("Line {} File {}", __LINE__, __FILE__); \
Expand Down
10 changes: 7 additions & 3 deletions libNeonDomain/include/Neon/domain/interface/FieldBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Neon/core/tools/io/IODense.h"
#include "Neon/core/types/Macros.h"

#include "Neon/set/Containter.h"
#include "Neon/set/DataConfig.h"
#include "Neon/set/DevSet.h"
#include "Neon/set/HuOptions.h"
Expand All @@ -12,7 +13,6 @@
#include "GridBase.h"
#include "Neon/domain/interface/common.h"


namespace Neon::domain::interface {

template <typename T, int C>
Expand All @@ -25,8 +25,8 @@ class FieldBase

FieldBase();

FieldBase(const std::string fieldUserName,
const std::string fieldClassName,
FieldBase(const std::string& fieldUserName,
const std::string& fieldClassName,
const Neon::index_3d& dimension,
int cardinality,
T outsideVal,
Expand Down Expand Up @@ -57,6 +57,10 @@ class FieldBase
virtual auto haloUpdate(Neon::set::HuOptions& opt)
-> void = 0;

virtual auto haloUpdateContainer(Neon::set::TransferMode transferMode,
Neon::set::StencilSemantic stencilSemantic) const
-> Neon::set::Container;

auto getDimension() const
-> const Neon::index_3d&;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "Neon/set/DataConfig.h"
#include "Neon/set/DevSet.h"
#include "Neon/set/MultiDeviceObjectInterface.h"
#include "Neon/set/MultiXpuDataInterface.h"
#include "Neon/set/memory/memSet.h"

#include "Neon/domain/interface/FieldBase.h"
Expand All @@ -21,7 +21,7 @@ template <typename T /** Field's cell metadata type */,
typename P /** Type of a Partition */,
typename S /** Storage type */>
class FieldBaseTemplate : public FieldBase<T, C>,
public Neon::set::interface::MultiDeviceObjectInterface<P, S>
public Neon::set::interface::MultiXpuDataInterface<P, S>
{
public:
using Partition = P;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ auto FieldBaseTemplate<T, C, G, P, S>::swapUIDBeforeFullSwap(FieldBaseTemplate::
NEON_THROW(exp);

}
Neon::set::interface::MultiDeviceObjectInterface<P, S>::swapUIDs(A,B);
Neon::set::interface::MultiXpuDataInterface<P, S>::swapUIDs(A,B);
}


Expand Down
11 changes: 9 additions & 2 deletions libNeonDomain/include/Neon/domain/interface/FieldBase_imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ FieldBase<T, C>::FieldBase()
}

template <typename T, int C>
FieldBase<T, C>::FieldBase(const std::string FieldBaseUserName,
const std::string fieldClassName,
FieldBase<T, C>::FieldBase(const std::string& FieldBaseUserName,
const std::string& fieldClassName,
const Neon::index_3d& dimension,
int cardinality,
T outsideVal,
Expand Down Expand Up @@ -274,6 +274,13 @@ auto FieldBase<T, C>::getClassName() const -> const std::string&
return mStorage->className;
}

template <typename T, int C>
auto FieldBase<T, C>::haloUpdateContainer(Neon::set::TransferMode,
Neon::set::StencilSemantic) const -> Neon::set::Container
{
NEON_THROW_UNSUPPORTED_OPERATION("");
}

template <typename T, int C>
FieldBase<T, C>::Storage::Storage(const std::string FieldBaseUserName,
const std::string fieldClassName,
Expand Down
2 changes: 2 additions & 0 deletions libNeonDomain/include/Neon/domain/internal/bGrid/bGrid_imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ auto bGrid::dot(const std::string& name,
return Neon::set::Container::factoryOldManaged(
name,
Neon::set::internal::ContainerAPI::DataViewSupport::on,
Neon::set::ContainerPatternType::reduction,
*this, [&](Neon::set::Loader& loader) {
loader.load(input1);
if (input1.getUid() != input2.getUid()) {
Expand Down Expand Up @@ -372,6 +373,7 @@ auto bGrid::norm2(const std::string& name,
return Neon::set::Container::factoryOldManaged(
name,
Neon::set::internal::ContainerAPI::DataViewSupport::on,
Neon::set::ContainerPatternType::reduction,
*this, [&](Neon::set::Loader& loader) {
loader.load(input);

Expand Down
12 changes: 9 additions & 3 deletions libNeonDomain/include/Neon/domain/internal/dGrid/dField.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class dField : public Neon::domain::interface::FieldBaseTemplate<T,

dField() = default;

~dField() = default;
virtual ~dField() = default;

auto self() -> Self&;

Expand All @@ -61,14 +61,18 @@ class dField : public Neon::domain::interface::FieldBaseTemplate<T,
auto haloUpdate(Neon::set::HuOptions& opt) const
-> void final;

auto haloUpdateContainer(Neon::set::TransferMode,
Neon::set::StencilSemantic)
const -> Neon::set::Container final;

auto haloUpdate(SetIdx setIdx, Neon::set::HuOptions& opt) const
-> void; //TODO add this function to the API if performance boost is reasonable -> void final;
-> void; // TODO add this function to the API if performance boost is reasonable -> void final;

auto haloUpdate(Neon::set::HuOptions& opt)
-> void final;

auto haloUpdate(SetIdx setIdx, Neon::set::HuOptions& opt)
-> void; //TODO add this function to the API if performance boost is reasonable -> void final;
-> void; // TODO add this function to the API if performance boost is reasonable -> void final;

virtual auto getReference(const Neon::index_3d& idx,
const int& cardinality)
Expand Down Expand Up @@ -188,4 +192,6 @@ class dField : public Neon::domain::interface::FieldBaseTemplate<T,
Neon::MemoryOptions mMemoryOptions;
};



} // namespace Neon::domain::internal::dGrid
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class dFieldDev

~dFieldDev() = default;

auto uid() const -> Neon::set::MultiDeviceObjectUid;
auto uid() const -> Neon::set::dataDependency::MultiXpuDataUid;

auto grid() -> grid_t&;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ auto dFieldDev<T, C>::operator=(dFieldDev&& other) -> dFieldDev&
}

template <typename T, int C>
auto dFieldDev<T, C>::uid() const -> Neon::set::MultiDeviceObjectUid
auto dFieldDev<T, C>::uid() const -> Neon::set::dataDependency::MultiXpuDataUid
{
void* addr = static_cast<void*>(m_data.get());
Neon::set::MultiDeviceObjectUid uidRes = (size_t)addr;
Neon::set::dataDependency::MultiXpuDataUid uidRes = (size_t)addr;
return uidRes;
}

Expand Down
60 changes: 59 additions & 1 deletion libNeonDomain/include/Neon/domain/internal/dGrid/dField_imp.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ auto dField<T, C>::getPartition(Neon::Execution execution,
-> const Partition&
{
const Neon::DataUse dataUse = this->getDataUse();
bool isOk = Neon::ExecutionUtils::checkCompatibility(dataUse, execution);
bool isOk = Neon::ExecutionUtils::checkCompatibility(dataUse, execution);
if (isOk) {
if (execution == Neon::Execution::device) {
return m_gpu.getPartition(Neon::DeviceType::CUDA, setIdx, dataView);
Expand Down Expand Up @@ -438,6 +438,7 @@ template <typename T, int C>
auto dField<T, C>::haloUpdate(Neon::set::HuOptions& opt) const
-> void
{
NEON_TRACE("haloUpdate stream {} transferMode {} ", opt.streamSetIdx(), Neon::set::TransferModeUtils::toString(opt.transferMode()));
auto& bk = self().getBackend();
auto fieldDev = field(bk.devType());
switch (opt.transferMode()) {
Expand All @@ -458,13 +459,19 @@ auto dField<T, C>::haloUpdate(Neon::SetIdx setIdx,
Neon::set::HuOptions& opt) const
-> void
{


auto& bk = self().getBackend();
auto fieldDev = field(bk.devType());
switch (opt.transferMode()) {
case Neon::set::TransferMode::put:
NEON_TRACE("TRACE haloUpdate PUT setIdx {} stream {} transferMode {} ", setIdx.idx(), opt.streamSetIdx(), Neon::set::TransferModeUtils::toString(opt.transferMode()));

fieldDev.template haloUpdate<Neon::set::TransferMode::put>(setIdx, bk, -1, opt.startWithBarrier(), opt.streamSetIdx());
break;
case Neon::set::TransferMode::get:
NEON_TRACE("TRACE haloUpdate GET setIdx {} stream {} transferMode {} ", setIdx.idx(), opt.streamSetIdx(), Neon::set::TransferModeUtils::toString(opt.transferMode()));

fieldDev.template haloUpdate<Neon::set::TransferMode::get>(setIdx, bk, -1, opt.startWithBarrier(), opt.streamSetIdx());
break;
default:
Expand All @@ -477,6 +484,8 @@ template <typename T, int C>
auto dField<T, C>::haloUpdate(Neon::set::HuOptions& opt)
-> void
{
NEON_TRACE("haloUpdate stream {} transferMode {} ", opt.streamSetIdx(), Neon::set::TransferModeUtils::toString(opt.transferMode()));

auto& bk = self().getBackend();
auto fieldDev = field(bk.devType());
switch (opt.transferMode()) {
Expand All @@ -501,9 +510,17 @@ auto dField<T, C>::haloUpdate(Neon::SetIdx setIdx,
auto fieldDev = field(bk.devType());
switch (opt.transferMode()) {
case Neon::set::TransferMode::put:
#pragma omp critical
{
NEON_TRACE("TRACE haloUpdate PUT setIdx {} stream {} transferMode {} ", setIdx.idx(), opt.streamSetIdx(), Neon::set::TransferModeUtils::toString(opt.transferMode()));
}
fieldDev.template haloUpdate<Neon::set::TransferMode::put>(setIdx, bk, -1, opt.startWithBarrier(), opt.streamSetIdx());
break;
case Neon::set::TransferMode::get:
#pragma omp critical
{
NEON_TRACE("TRACE haloUpdate GET setIdx {} stream {} transferMode {} ", setIdx.idx(), opt.streamSetIdx(), Neon::set::TransferModeUtils::toString(opt.transferMode()));
}
fieldDev.template haloUpdate<Neon::set::TransferMode::get>(setIdx, bk, -1, opt.startWithBarrier(), opt.streamSetIdx());
break;
default:
Expand All @@ -512,6 +529,46 @@ auto dField<T, C>::haloUpdate(Neon::SetIdx setIdx,
}
}


template <typename T, int C>
auto dField<T, C>::
haloUpdateContainer(Neon::set::TransferMode transferMode,
Neon::set::StencilSemantic stencilSemantic)
const -> Neon::set::Container
{
Neon::set::Container dataTransferContainer =
Neon::set::Container::factoryDataTransfer(*this,
transferMode,
stencilSemantic);

Neon::set::Container SyncContainer =
Neon::set::Container::factorySynchronization(*this,
Neon::set::SynchronizationContainerType::hostOmpBarrier);
Neon::set::container::Graph graph(this->getBackend());
const auto& dataTransferNode = graph.addNode(dataTransferContainer);
const auto& syncNode = graph.addNode(SyncContainer);

switch (transferMode) {
case Neon::set::TransferMode::put:
graph.addDependency(dataTransferNode, syncNode, Neon::GraphDependencyType::data);
break;
case Neon::set::TransferMode::get:
graph.addDependency(syncNode, dataTransferNode, Neon::GraphDependencyType::data);
break;
default:
NEON_THROW_UNSUPPORTED_OPTION();
break;
}

graph.removeRedundantDependencies();

Neon::set::Container output =
Neon::set::Container::factoryGraph("dGrid-Halo-Update",
graph,
[](Neon::SetIdx, Neon::set::Loader&) {});
return output;
}

template <typename T, int C>
auto dField<T, C>::dot(Neon::set::patterns::BlasSet<T>& blasSet,
const dField<T>& input,
Expand Down Expand Up @@ -584,4 +641,5 @@ auto dField<T, C>::swap(dField::Field& A, dField::Field& B) -> void
std::swap(A, B);
}


} // namespace Neon::domain::internal::dGrid
6 changes: 3 additions & 3 deletions libNeonDomain/include/Neon/domain/internal/dGrid/dGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class dGrid : public Neon::domain::interface::GridBaseTemplate<dGrid, dCell>

dGrid(const dGrid& rhs) = default;

~dGrid() = default;
virtual ~dGrid() = default;

/**
* Constructor compatible with the general grid API
Expand Down Expand Up @@ -88,7 +88,7 @@ class dGrid : public Neon::domain::interface::GridBaseTemplate<dGrid, dCell>
* Creates a new Field
*/
template <typename T, int C = 0>
auto newField(const std::string fieldUserName,
auto newField(const std::string& fieldUserName,
int cardinality,
T inactiveValue,
Neon::DataUse dataUse = Neon::DataUse::IO_COMPUTE,
Expand Down Expand Up @@ -183,7 +183,7 @@ class dGrid : public Neon::domain::interface::GridBaseTemplate<dGrid, dCell>

Neon::index_3d halo;
std::vector<Neon::set::DataSet<PartitionIndexSpace>> partitionIndexSpaceVec;
Neon::sys::patterns::Engine reduceEngine;
Neon::sys::patterns::Engine reduceEngine;
};
std::shared_ptr<data_t> m_data;
};
Expand Down
Loading

0 comments on commit 7a180a4

Please sign in to comment.