Skip to content
Snippets Groups Projects
Commit 789005fe authored by Pavol Margitfalvi's avatar Pavol Margitfalvi
Browse files

clang format

parent 9d211045
No related branches found
No related tags found
5 merge requests!22Basic implementation of Matrix-free BwdTrans and padding feature in Field,!11Implement CUDA BwdTrans sum-factorization kernels,!8BwdTrans operator in CUDA,!3First naive implementation,!2Implements BwdTrans StdMat operator
......@@ -32,7 +32,7 @@ struct BlockAttributes
/**
* @brief Possible states for Field data.
*
*
* These identify the mathematical representation of the field data. The two
* main states are *Phys*, representing the field at the quadrature points,
* and *Coeff*, representing the field in terms of its spectral/hp element
......@@ -51,8 +51,7 @@ static constexpr FieldState DefaultState = FieldState::Phys;
* @tparam TType The floating-point representation used by the field.
* @tparam TState A FieldState value representing the state of the field.
*/
template <typename TType = double, FieldState TState = DefaultState>
class Field
template <typename TType = double, FieldState TState = DefaultState> class Field
{
public:
Field(const Field &) = delete;
......@@ -61,8 +60,8 @@ public:
/**
* @brief Construct a new Field object by moving storage from an existing
* Field object.
*
* @param rhs
*
* @param rhs
*/
Field(Field &&rhs)
: m_storage(std::move(rhs.m_storage)),
......@@ -73,9 +72,9 @@ public:
/**
* @brief Move assignment operator.
*
* @param rhs
* @return Field&
*
* @param rhs
* @return Field&
*/
Field &operator=(Field &&rhs)
{
......@@ -88,11 +87,11 @@ public:
/**
* @brief Static templated creation method.
*
*
* @tparam TMemoryRegion Type of memory region to use
* @param blocks Field data specification.
* @param num_components Number of components for a vector field.
* @return Field<TType, TState>
* @return Field<TType, TState>
*/
template <template <typename> class TMemoryRegion = MemoryRegionCPU>
static Field<TType, TState> create(std::vector<BlockAttributes> &blocks,
......@@ -120,11 +119,11 @@ public:
/**
* @brief Get the underlying storage of the field as the requested type.
* @return MemoryRegion storage converted to the requested type
*
*
* This routine performs MemoryRegion conversions if necessary to enable
* casting of, for example a CUDA memory region to a CPU memory region to
* support the use of a CPU-only operator if necessary.
*
*
* A runtime warning is provided if a transfer of data from device to host
* is required to achieve the conversion.
*/
......@@ -174,8 +173,8 @@ public:
/**
* @brief Gets the number of components for a vector field.
*
* @return size_t
*
* @return size_t
*/
size_t GetNumComponents()
{
......@@ -185,7 +184,7 @@ public:
private:
/**
* @brief Construct a new Field object.
*
*
* @param blocks Field data layout specification
* @param num_components Number of components for a vector field.
*/
......
......@@ -2,10 +2,10 @@
/**
* @brief Stores underlying data for a Field on the CPU.
*
*
* It acts as a holder for a contiguous block of memory, allocated on the
* host system.
*
* host system.
*
* This class also acts as a base class for device-aware builds.
*/
template <typename TData> class MemoryRegionCPU
......@@ -45,7 +45,7 @@ public:
/**
* @brief Get the pointer to the CPU memory.
*
*
* This is a virtual function so that subclasses can move memory to the
* CPU from a device if needed.
*/
......@@ -56,7 +56,7 @@ public:
/**
* @brief Move memory to the CPU.
*
*
* This is a virtual function so that subclasses can move memory to the
* CPU from a device if needed.
*/
......
......@@ -91,7 +91,7 @@ protected:
private:
void initFromSize(size_t n);
TData *m_device = nullptr; ///< Device memory pointer
size_t m_size = 0; ///< Device storage size
bool m_ondevice = false; ///< Flag indicating if data is on device
TData *m_device = nullptr; ///< Device memory pointer
size_t m_size = 0; ///< Device storage size
bool m_ondevice = false; ///< Flag indicating if data is on device
};
#include "BwdTransSumFac.hpp"
#include "BwdTransMatFree.hpp"
#include "BwdTransSumFac.hpp"
namespace Nektar::Operators::detail
{
......@@ -14,7 +14,7 @@ std::string OperatorBwdTransImpl<double, ImplMatFree>::className =
template <>
std::string OperatorBwdTransImpl<double, ImplSumFac>::className =
GetOperatorFactory<double>().RegisterCreatorFunction(
"BwdTransSumFac",
OperatorBwdTransImpl<double, ImplSumFac>::instantiate, "...");
"BwdTransSumFac", OperatorBwdTransImpl<double, ImplSumFac>::instantiate,
"...");
}
\ No newline at end of file
} // namespace Nektar::Operators::detail
namespace Nektar::Operators::detail::matfree {
namespace Nektar::Operators::detail::matfree
{
}
\ No newline at end of file
}
......@@ -2,7 +2,7 @@
namespace Nektar::Operators::detail
{
// sum-factorisation implementation
template <typename TData>
class OperatorBwdTransImpl<TData, ImplSumFac> : public OperatorBwdTrans<TData>
......@@ -22,4 +22,4 @@ public:
static std::string className;
};
}
\ No newline at end of file
} // namespace Nektar::Operators::detail
......@@ -2,9 +2,8 @@
namespace Nektar::Operators
{
template< typename TData>
OperatorFactory<TData> &GetOperatorFactory()
template <typename TData> OperatorFactory<TData> &GetOperatorFactory()
{
static OperatorFactory<TData> instance;
return instance;
......@@ -12,4 +11,4 @@ OperatorFactory<TData> &GetOperatorFactory()
template OperatorFactory<double> &GetOperatorFactory();
}
\ No newline at end of file
} // namespace Nektar::Operators
......@@ -18,34 +18,36 @@ struct ImplMatFree;
struct ImplCUDA;
// Forward-declare the Operator base class so we can define the factory
template< typename TData> class Operator;
template <typename TData> class Operator;
// Typename alias for the factory
template< typename TData>
template <typename TData>
using OperatorFactory =
Nektar::LibUtilities::NekFactory<std::string, Operator<TData>>;
// Operator factory singleton
template< typename TData>
OperatorFactory<TData> &GetOperatorFactory();
template <typename TData> OperatorFactory<TData> &GetOperatorFactory();
template <typename TData>
class Operator
template <typename TData> class Operator
{
public:
template< typename TDescriptor>
static std::unique_ptr<typename TDescriptor::class_name> create(std::string pKey = "")
template <typename TDescriptor>
static std::unique_ptr<typename TDescriptor::class_name> create(
std::string pKey = "")
{
std::string key = TDescriptor::key;
if (pKey.empty()) {
if (pKey.empty())
{
key += TDescriptor::default_impl;
}
else {
else
{
key += pKey;
}
auto x = GetOperatorFactory<TData>().CreateInstance(key);
return std::unique_ptr<typename TDescriptor::class_name>(static_cast<typename TDescriptor::class_name*>(x.release()));
return std::unique_ptr<typename TDescriptor::class_name>(
static_cast<typename TDescriptor::class_name *>(x.release()));
}
};
}
\ No newline at end of file
} // namespace Nektar::Operators
......@@ -2,8 +2,8 @@
namespace Nektar::Operators
{
template<> const std::string BwdTrans<>::key = "BwdTrans";
template<> const std::string BwdTrans<>::default_impl = "MatFree";
}
\ No newline at end of file
template <> const std::string BwdTrans<>::key = "BwdTrans";
template <> const std::string BwdTrans<>::default_impl = "MatFree";
} // namespace Nektar::Operators
......@@ -8,25 +8,24 @@ namespace Nektar::Operators
// BwdTrans base class
// Defines the apply operator to enforce apply parameter types
template <typename TData>
class OperatorBwdTrans : public Operator<TData>
template <typename TData> class OperatorBwdTrans : public Operator<TData>
{
public:
virtual void apply(Field<TData, FieldState::Coeff> &in,
Field<TData, FieldState::Phys> &out) = 0;
virtual void operator()(Field<TData, FieldState::Coeff> &in,
Field<TData, FieldState::Phys> &out)
Field<TData, FieldState::Phys> &out)
{
apply(in, out);
}
};
// Descriptor / traits class for BwdTrans
template<typename TData = default_fp_type>
struct BwdTrans {
template <typename TData = default_fp_type> struct BwdTrans
{
using class_name = OperatorBwdTrans<TData>;
using FieldIn = Field<TData, FieldState::Coeff>;
using FieldOut = Field<TData, FieldState::Phys>;
using FieldIn = Field<TData, FieldState::Coeff>;
using FieldOut = Field<TData, FieldState::Phys>;
static const std::string key;
static const std::string default_impl;
......@@ -36,11 +35,10 @@ struct BwdTrans {
}
};
namespace detail {
namespace detail
{
// Template for BwdTrans implementations
template <typename TData, typename Op>
class OperatorBwdTransImpl;
}
template <typename TData, typename Op> class OperatorBwdTransImpl;
} // namespace detail
}
} // namespace Nektar::Operators
......@@ -4,10 +4,10 @@
* @brief Demonstrator program for the new Field class.
* @version 0.1
* @date 2023-02-13
*
*
* @copyright Copyright (c) 2023 Imperial College London, University of Utah,
* Kings College London
*
*
*/
#include <iostream>
#include <memory>
......@@ -32,7 +32,7 @@ int main()
// Create two Field objects with a MemoryRegionCPU backend by default
auto in = Field<double, FieldState::Coeff>::create(blocks);
auto out = Field<double, FieldState::Phys >::create(blocks);
auto out = Field<double, FieldState::Phys>::create(blocks);
// Populate the field with some data. In this case, we just grab a pointer
// to the memory on the CPU and populate the array with values. Operators,
......@@ -80,7 +80,7 @@ int main()
// Create two Fields with memory on the GPU
in = Field<double, FieldState::Coeff>::create<MemoryRegionCUDA>(blocks);
out = Field<double, FieldState::Phys >::create<MemoryRegionCUDA>(blocks);
out = Field<double, FieldState::Phys>::create<MemoryRegionCUDA>(blocks);
// Perform the BwdTrans on the fields using the CUDA implementation
// Since this is a CUDA operator, acting on CUDA fields, everything happens
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment