Skip to content

Commit

Permalink
Sync DDC
Browse files Browse the repository at this point in the history
  • Loading branch information
tpadioleau committed Oct 27, 2023
1 parent 1380075 commit ddfc169
Show file tree
Hide file tree
Showing 15 changed files with 317 additions and 248 deletions.
18 changes: 9 additions & 9 deletions vendor/ddc/.github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Identify repository
id: identify_repo
run: |
echo "in_base_repo=${{ (github.event_name == 'push' && github.repository == 'Maison-de-la-Simulation/ddc') || github.event.pull_request.head.repo.full_name == 'Maison-de-la-Simulation/ddc' }}" >> "$GITHUB_OUTPUT"
echo "in_base_repo=${{ (github.event_name == 'push' && github.repository == 'CExA-project/ddc') || github.event.pull_request.head.repo.full_name == 'CExA-project/ddc' }}" >> "$GITHUB_OUTPUT"
docker-build:
needs: id_repo
Expand All @@ -25,24 +25,24 @@ jobs:
- name: Build
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin || true
docker pull ghcr.io/maison-de-la-simulation/ddc/doxygen || true
docker pull ghcr.io/cexa-project/ddc/doxygen || true
docker build \
--cache-from ghcr.io/maison-de-la-simulation/ddc/doxygen \
-t ghcr.io/maison-de-la-simulation/ddc/doxygen \
-t ghcr.io/maison-de-la-simulation/ddc/doxygen:${GITHUB_SHA:0:7} \
--cache-from ghcr.io/cexa-project/ddc/doxygen \
-t ghcr.io/cexa-project/ddc/doxygen \
-t ghcr.io/cexa-project/ddc/doxygen:${GITHUB_SHA:0:7} \
docker/doxygen
- name: Publish image for current SHA
if: needs.id_repo.outputs.in_base_repo == 'true'
run: |
docker push ghcr.io/maison-de-la-simulation/ddc/doxygen:${GITHUB_SHA:0:7}
docker push ghcr.io/cexa-project/ddc/doxygen:${GITHUB_SHA:0:7}
- name: Publish latest (default) image
if: github.event_name == 'push' && github.ref_name == 'main' && needs.id_repo.outputs.in_base_repo == 'true'
run: |
docker push ghcr.io/maison-de-la-simulation/ddc/doxygen
docker push ghcr.io/cexa-project/ddc/doxygen
- name: Create image tarball
if: needs.id_repo.outputs.in_base_repo == 'false'
run: |
docker save ghcr.io/maison-de-la-simulation/ddc/doxygen:${GITHUB_SHA:0:7} > doxygen.tar
docker save ghcr.io/cexa-project/ddc/doxygen:${GITHUB_SHA:0:7} > doxygen.tar
- name: Generate docker artifact from image
if: needs.id_repo.outputs.in_base_repo == 'false'
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -90,7 +90,7 @@ jobs:
EOF
mkdir docs_out
chmod a+rwx docs_out
docker run -v ${PWD}:/src ghcr.io/maison-de-la-simulation/ddc/doxygen:${GITHUB_SHA:0:7} bash /src/run.sh
docker run -v ${PWD}:/src ghcr.io/cexa-project/ddc/doxygen:${GITHUB_SHA:0:7} bash /src/run.sh
- name: Publish site
if: ${{ github.event_name == 'push' && github.ref_name == 'main' && needs.id_repo.outputs.in_base_repo == 'true' }}
run: |
Expand Down
20 changes: 10 additions & 10 deletions vendor/ddc/.github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Identify repository
id: identify_repo
run: |
echo "in_base_repo=${{ (github.event_name == 'push' && github.repository == 'Maison-de-la-Simulation/ddc') || github.event.pull_request.head.repo.full_name == 'Maison-de-la-Simulation/ddc' }}" >> "$GITHUB_OUTPUT"
echo "in_base_repo=${{ (github.event_name == 'push' && github.repository == 'CExA-project/ddc') || github.event.pull_request.head.repo.full_name == 'CExA-project/ddc' }}" >> "$GITHUB_OUTPUT"
outputs: { in_base_repo: '${{ steps.identify_repo.outputs.in_base_repo }}' }

docker-build:
Expand All @@ -43,25 +43,25 @@ jobs:
- name: Build
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin || true
docker pull ghcr.io/maison-de-la-simulation/ddc/${{matrix.image}}_${{matrix.backend}} || true
docker pull ghcr.io/cexa-project/ddc/${{matrix.image}}_${{matrix.backend}} || true
docker build \
--build-arg BACKEND=${{matrix.backend}} \
--cache-from ghcr.io/maison-de-la-simulation/ddc/${{matrix.image}}_${{matrix.backend}} \
-t ghcr.io/maison-de-la-simulation/ddc/${{matrix.image}}_${{matrix.backend}} \
-t ghcr.io/maison-de-la-simulation/ddc/${{matrix.image}}_${{matrix.backend}}:${GITHUB_SHA:0:7} \
--cache-from ghcr.io/cexa-project/ddc/${{matrix.image}}_${{matrix.backend}} \
-t ghcr.io/cexa-project/ddc/${{matrix.image}}_${{matrix.backend}} \
-t ghcr.io/cexa-project/ddc/${{matrix.image}}_${{matrix.backend}}:${GITHUB_SHA:0:7} \
docker/${{matrix.image}}
- name: Publish image for current SHA
if: needs.id_repo.outputs.in_base_repo == 'true'
run: |
docker push ghcr.io/maison-de-la-simulation/ddc/${{matrix.image}}_${{matrix.backend}}:${GITHUB_SHA:0:7}
docker push ghcr.io/cexa-project/ddc/${{matrix.image}}_${{matrix.backend}}:${GITHUB_SHA:0:7}
- name: Publish latest (default) image
if: github.event_name == 'push' && github.ref_name == 'main' && needs.id_repo.outputs.in_base_repo == 'true'
run: |
docker push ghcr.io/maison-de-la-simulation/ddc/${{matrix.image}}_${{matrix.backend}}
docker push ghcr.io/cexa-project/ddc/${{matrix.image}}_${{matrix.backend}}
- name: Create image tarball
if: needs.id_repo.outputs.in_base_repo == 'false'
run: |
docker save ghcr.io/maison-de-la-simulation/ddc/${{matrix.image}}_${{matrix.backend}}:${GITHUB_SHA:0:7} > ${{matrix.image}}_${{matrix.backend}}.tar
docker save ghcr.io/cexa-project/ddc/${{matrix.image}}_${{matrix.backend}}:${GITHUB_SHA:0:7} > ${{matrix.image}}_${{matrix.backend}}.tar
- name: Generate docker artifact from image
if: needs.id_repo.outputs.in_base_repo == 'false'
uses: actions/upload-artifact@v3
Expand Down Expand Up @@ -169,7 +169,7 @@ jobs:
docker run \
--cidfile='docker.cid' \
-v ${PWD}:/src:ro \
ghcr.io/maison-de-la-simulation/ddc/${{matrix.image}}_${{fromJSON('{"cpu-gcc":"cpu","cpu-clang":"cpu"}')[matrix.backend] || matrix.backend}}:${GITHUB_SHA:0:7} \
ghcr.io/cexa-project/ddc/${{matrix.image}}_${{fromJSON('{"cpu-gcc":"cpu","cpu-clang":"cpu"}')[matrix.backend] || matrix.backend}}:${GITHUB_SHA:0:7} \
bash /src/run.sh
if docker cp "$(cat docker.cid)":/data/tests.xml /home/runner/work/ddc/ddc/tests.xml
then echo "with_report=true" >> "$GITHUB_OUTPUT"
Expand Down Expand Up @@ -221,5 +221,5 @@ jobs:
find /src/benchmarks /src/examples /src/tests -name '*.cpp' -exec clang-tidy-14 -p build -header-filter="(/src/include/ddc/.*|/src/tests/.*)" '{}' '+'
EOF
docker run \
-v ${PWD}:/src:ro ghcr.io/maison-de-la-simulation/ddc/latest_cpu:${GITHUB_SHA:0:7} \
-v ${PWD}:/src:ro ghcr.io/cexa-project/ddc/latest_cpu:${GITHUB_SHA:0:7} \
bash /src/run.sh
7 changes: 2 additions & 5 deletions vendor/ddc/docs/first_steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ As usual, the file starts with a few includes that will be used in the code.

\snippet heat_equation.cpp includes

As you can see, DDC includes all follow the same convention: `<ddc/SYMBOL>` where `SYMBOL` is a
the name of a DDC symbol.
So for example, in order to use a class named `Chunk`, you should include `<ddc/Chunk>` and to use a
free function template named `for_each`, you should include `<ddc/for_each>`.
As you can see, to use DDC, we have to include `<ddc/ddc.hpp>`

Then, we define the value of some parameters that would typically be read from some form of
configuration file in a more realistic code.
Expand Down Expand Up @@ -135,7 +132,7 @@ Then we handle the domains for the simulated time dimension.

# Data allocation

We allocate two 2D Chunks along the X and Y dimensions which will be used to map temperature to the domains' points at t and t+dt.
We allocate two 2D Chunks along the X and Y dimensions which will be used to map temperature to the domains' points at t and t+dt. When constructing the Chunks one can give an optional string to label the memory allocations. This helps debugging and profiling applications using the Kokkos tools, see also [Kokkos Tools](https://github.com/kokkos/kokkos-tools).

\snippet heat_equation.cpp data allocation

Expand Down
18 changes: 12 additions & 6 deletions vendor/ddc/examples/game_of_life.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,18 @@ int main()
ddc::DiscreteElement<DDimX, DDimY>(1, 1),
ddc::DiscreteVector<DDimX, DDimY>(length - 2, height - 2));

ddc::Chunk
cells_in_host_alloc(domain_xy, ddc::HostAllocator<cell>());
ddc::Chunk
cells_in_dev_alloc(domain_xy, ddc::DeviceAllocator<cell>());
ddc::Chunk
cells_out_dev_alloc(domain_xy, ddc::DeviceAllocator<cell>());
ddc::Chunk cells_in_host_alloc(
"cells_in_host",
domain_xy,
ddc::HostAllocator<cell>());
ddc::Chunk cells_in_dev_alloc(
"cells_in_dev",
domain_xy,
ddc::DeviceAllocator<cell>());
ddc::Chunk cells_out_dev_alloc(
"cells_out_dev",
domain_xy,
ddc::DeviceAllocator<cell>());

ddc::ChunkSpan cells_in = cells_in_dev_alloc.span_view();
ddc::ChunkSpan cells_out = cells_out_dev_alloc.span_view();
Expand Down
5 changes: 3 additions & 2 deletions vendor/ddc/examples/heat_equation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#include <numeric>

#include <ddc/ddc.hpp>

#include <Kokkos_Core.hpp>
//! [includes]


Expand Down Expand Up @@ -199,13 +197,15 @@ int main(int argc, char** argv)
// Maps temperature into the full domain (including ghosts) twice:
// - once for the last fully computed time-step
ddc::Chunk ghosted_last_temp(
"ghosted_last_temp",
ddc::DiscreteDomain<
DDimX,
DDimY>(ghosted_x_domain, ghosted_y_domain),
ddc::DeviceAllocator<double>());

// - once for time-step being computed
ddc::Chunk ghosted_next_temp(
"ghosted_next_temp",
ddc::DiscreteDomain<
DDimX,
DDimY>(ghosted_x_domain, ghosted_y_domain),
Expand All @@ -230,6 +230,7 @@ int main(int argc, char** argv)
//! [initial-conditions]

ddc::Chunk ghosted_temp(
"ghost_temp",
ddc::DiscreteDomain<
DDimX,
DDimY>(ghosted_x_domain, ghosted_y_domain),
Expand Down
6 changes: 5 additions & 1 deletion vendor/ddc/examples/heat_equation_spectral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,13 @@ int main(int argc, char** argv)
// Maps temperature into the full domain (including ghosts) twice:
// - once for the last fully computed time-step
ddc::Chunk _last_temp(
"_last_temp",
ddc::DiscreteDomain<DDimX, DDimY>(x_domain, y_domain),
ddc::DeviceAllocator<double>());

// - once for time-step being computed
ddc::Chunk _next_temp(
"_next_temp",
ddc::DiscreteDomain<DDimX, DDimY>(x_domain, y_domain),
ddc::DeviceAllocator<double>());
//! [data allocation]
Expand All @@ -194,6 +196,7 @@ int main(int argc, char** argv)
//! [initial-conditions]

ddc::Chunk _host_temp(
"_host_temp",
ddc::DiscreteDomain<DDimX, DDimY>(x_domain, y_domain),
ddc::HostAllocator<double>());

Expand All @@ -213,7 +216,8 @@ int main(int argc, char** argv)
ddc::PeriodicSampling<ddc::Fourier<Y>>> const k_mesh
= ddc::FourierMesh(initial_temp.domain(), false);
ddc::Chunk Ff_allocation = ddc::
Chunk(k_mesh,
Chunk("Ff_allocation",
k_mesh,
ddc::DeviceAllocator<Kokkos::complex<double>>());
ddc::ChunkSpan Ff = Ff_allocation.span_view();

Expand Down
38 changes: 31 additions & 7 deletions vendor/ddc/include/ddc/chunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#pragma once

#include <memory>
#include <string>

#include "ddc/chunk_common.hpp"
#include "ddc/chunk_span.hpp"
Expand Down Expand Up @@ -76,14 +76,26 @@ class Chunk<ElementType, DiscreteDomain<DDims...>, Allocator>
private:
Allocator m_allocator;

std::string m_label;

public:
/// Empty Chunk
Chunk() = default;

/// Construct a labeled Chunk on a domain with uninitialized values
explicit Chunk(
std::string const& label,
mdomain_type const& domain,
Allocator allocator = Allocator())
: base_type(allocator.allocate(label, domain.size()), domain)
, m_allocator(std::move(allocator))
, m_label(label)
{
}

/// Construct a Chunk on a domain with uninitialized values
explicit Chunk(mdomain_type const& domain, Allocator allocator = Allocator())
: base_type(std::allocator_traits<Allocator>::allocate(m_allocator, domain.size()), domain)
, m_allocator(std::move(allocator))
: Chunk("no-label", domain, std::move(allocator))
{
}

Expand All @@ -106,15 +118,15 @@ class Chunk<ElementType, DiscreteDomain<DDims...>, Allocator>
Chunk(Chunk&& other)
: base_type(std::move(static_cast<base_type&>(other)))
, m_allocator(std::move(other.m_allocator))
, m_label(std::move(other.m_label))
{
other.m_internal_mdspan = internal_mdspan_type(nullptr, other.m_internal_mdspan.mapping());
}

~Chunk()
{
if (this->m_internal_mdspan.data_handle()) {
std::allocator_traits<
Allocator>::deallocate(m_allocator, this->data_handle(), this->size());
m_allocator.deallocate(this->data_handle(), this->size());
}
}

Expand All @@ -131,11 +143,11 @@ class Chunk<ElementType, DiscreteDomain<DDims...>, Allocator>
return *this;
}
if (this->m_internal_mdspan.data_handle()) {
std::allocator_traits<
Allocator>::deallocate(m_allocator, this->data_handle(), this->size());
m_allocator.deallocate(this->data_handle(), this->size());
}
static_cast<base_type&>(*this) = std::move(static_cast<base_type&>(other));
m_allocator = std::move(other.m_allocator);
m_label = std::move(other.m_label);
other.m_internal_mdspan = internal_mdspan_type(nullptr, other.m_internal_mdspan.mapping());

return *this;
Expand Down Expand Up @@ -221,6 +233,14 @@ class Chunk<ElementType, DiscreteDomain<DDims...>, Allocator>
return this->m_internal_mdspan(uid<DDims>(delems)...);
}

/** Returns the label of the Chunk
* @return c-string
*/
char const* label() const
{
return m_label.c_str();
}

/** Access to the underlying allocation pointer
* @return read-only allocation pointer
*/
Expand Down Expand Up @@ -301,6 +321,10 @@ class Chunk<ElementType, DiscreteDomain<DDims...>, Allocator>
}
};

template <class... DDims, class Allocator>
Chunk(std::string const&, DiscreteDomain<DDims...> const&, Allocator)
-> Chunk<typename Allocator::value_type, DiscreteDomain<DDims...>, Allocator>;

template <class... DDims, class Allocator>
Chunk(DiscreteDomain<DDims...> const&, Allocator)
-> Chunk<typename Allocator::value_type, DiscreteDomain<DDims...>, Allocator>;
Expand Down
21 changes: 7 additions & 14 deletions vendor/ddc/include/ddc/detail/tagged_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,30 +187,23 @@ KOKKOS_FUNCTION constexpr detail::TaggedVector<ElementType, QueryTags...> select
namespace detail {

template <class QueryTag, class ElementType, class HeadTag, class... TailTags>
KOKKOS_FUNCTION constexpr detail::TaggedVector<ElementType, QueryTag> const& take_impl(
KOKKOS_FUNCTION constexpr detail::TaggedVector<ElementType, QueryTag> const& take(
detail::TaggedVector<ElementType, HeadTag> const& head,
detail::TaggedVector<ElementType, TailTags> const&... tags)
{
DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
static_assert(
!type_seq_contains_v<detail::TypeSeq<HeadTag>, detail::TypeSeq<TailTags...>>,
"ERROR: tag redundant");
if constexpr (std::is_same_v<QueryTag, HeadTag>) {
static_assert(
!type_seq_contains_v<detail::TypeSeq<QueryTag>, detail::TypeSeq<TailTags...>>,
"ERROR: tag redundant");
return head;
} else {
static_assert(sizeof...(TailTags) > 0, "ERROR: tag not found");
return take_impl<QueryTag>(tags...);
return take<QueryTag>(tags...);
}
DDC_IF_NVCC_THEN_POP
}

template <class QueryTag, class ElementType, class... Tags>
KOKKOS_FUNCTION constexpr detail::TaggedVector<ElementType, QueryTag> const& take(
detail::TaggedVector<ElementType, Tags> const&... tags)
{
return take_impl<QueryTag>(tags...);
}


template <class T>
class ConversionOperators
Expand Down Expand Up @@ -291,15 +284,15 @@ class TaggedVector : public ConversionOperators<TaggedVector<ElementType, Tags..
KOKKOS_FUNCTION constexpr TaggedVector& operator=(
TaggedVector<ElementType, OTags...> const& other) noexcept
{
m_values = other.m_values;
((this->get<Tags>() = other.template get<Tags>()), ...);
return *this;
}

template <class... OTags>
KOKKOS_FUNCTION constexpr TaggedVector& operator=(
TaggedVector<ElementType, OTags...>&& other) noexcept
{
m_values = std::move(other.m_values);
((this->get<Tags>() = std::move(other.template get<Tags>())), ...);
return *this;
}

Expand Down
6 changes: 3 additions & 3 deletions vendor/ddc/include/ddc/discrete_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ KOKKOS_FUNCTION constexpr DiscreteElement<QueryTag> const& take(
DiscreteElement<TailTags> const&... tags)
{
DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
static_assert(
!type_seq_contains_v<detail::TypeSeq<HeadTag>, detail::TypeSeq<TailTags...>>,
"ERROR: tag redundant");
if constexpr (std::is_same_v<QueryTag, HeadTag>) {
static_assert(
!type_seq_contains_v<detail::TypeSeq<QueryTag>, detail::TypeSeq<TailTags...>>,
"ERROR: tag redundant");
return head;
} else {
static_assert(sizeof...(TailTags) > 0, "ERROR: tag not found");
Expand Down
Loading

0 comments on commit ddfc169

Please sign in to comment.