Skip to content

Commit

Permalink
Use Kokkos 4.4.01 with mdspan coming from Kokkos (#651)
Browse files Browse the repository at this point in the history
* Use Kokkos 4.4.01 with mdspan coming from Kokkos

* Review from Yuuichi
  • Loading branch information
tpadioleau authored Oct 2, 2024
1 parent 88375b9 commit 2e8e3ed
Show file tree
Hide file tree
Showing 26 changed files with 163 additions and 233 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ jobs:
export GTest_ROOT=$PWD/opt/gtest
export Kokkos_ROOT=$PWD/opt/kokkos
export KokkosKernels_ROOT=$PWD/opt/kokkos-kernels
export mdspan_ROOT=$PWD/opt/mdspan
cmake \
-DCMAKE_BUILD_TYPE=${{matrix.cmake_build_type}} \
Expand Down Expand Up @@ -214,16 +213,6 @@ jobs:
cmake --install build --prefix $KokkosKernels_ROOT
rm -rf build
cmake \
-DCMAKE_BUILD_TYPE=${{matrix.cmake_build_type}} \
-DCMAKE_CXX_STANDARD=${{matrix.cxx_version}} \
-DMDSPAN_CXX_STANDARD=${{matrix.cxx_version}} \
-B build \
-S /src/vendor/mdspan
cmake --build build --parallel 2
cmake --install build --prefix $mdspan_ROOT
rm -rf build
cmake \
-DCMAKE_BUILD_TYPE=${{matrix.cmake_build_type}} \
-DCMAKE_CXX_FLAGS="\
Expand All @@ -234,7 +223,6 @@ jobs:
-DDDC_benchmark_DEPENDENCY_POLICY=INSTALLED \
-DDDC_GTest_DEPENDENCY_POLICY=INSTALLED \
-DDDC_Kokkos_DEPENDENCY_POLICY=INSTALLED \
-DDDC_mdspan_DEPENDENCY_POLICY=INSTALLED \
-B build \
-S /src
cmake --build build --parallel 2
Expand Down Expand Up @@ -301,7 +289,6 @@ jobs:
-DDDC_BUILD_BENCHMARKS=ON \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_STANDARD=17 \
-DMDSPAN_CXX_STANDARD=17 \
-DKokkos_ENABLE_DEPRECATED_CODE_3=OFF \
-DKokkos_ENABLE_DEPRECATED_CODE_4=OFF \
-DKokkos_ENABLE_DEPRECATION_WARNINGS=OFF \
Expand Down Expand Up @@ -364,7 +351,6 @@ jobs:
-DBUILD_TESTING=ON \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=17 \
-DMDSPAN_CXX_STANDARD=17 \
-DKokkos_ENABLE_DEPRECATED_CODE_4=OFF \
-DKokkos_ENABLE_DEPRECATION_WARNINGS=OFF \
-B build \
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#
# SPDX-License-Identifier: MIT

[submodule "vendor/mdspan"]
path = vendor/mdspan
url = https://github.com/kokkos/mdspan.git
[submodule "vendor/googletest"]
path = vendor/googletest
url = https://github.com/google/googletest.git
Expand Down
23 changes: 3 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,13 @@ include(CMakePackageConfigHelpers)
include(CTest)


## mdspan

set(DDC_mdspan_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `mdspan` package. Options: ${DDC_DEPENDENCY_POLICIES}")
set_property(CACHE DDC_mdspan_DEPENDENCY_POLICY PROPERTY STRINGS "${DDC_DEPENDENCY_POLICIES}")
if("${DDC_mdspan_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET std::mdspan)
find_package(mdspan 0.6.0 EXACT CONFIG QUIET)
if(NOT mdspan_FOUND)
add_subdirectory(vendor/mdspan)
endif()
endif()
elseif("${DDC_mdspan_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
add_subdirectory(vendor/mdspan)
elseif("${DDC_mdspan_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(mdspan 0.6.0 EXACT CONFIG REQUIRED)
endif()

## kokkos

set(DDC_Kokkos_DEPENDENCY_POLICY "AUTO" CACHE STRING "Policy to find the `Kokkos` package. Options: ${DDC_DEPENDENCY_POLICIES}")
set_property(CACHE DDC_Kokkos_DEPENDENCY_POLICY PROPERTY STRINGS "${DDC_DEPENDENCY_POLICIES}")
if("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "AUTO")
if(NOT TARGET Kokkos::kokkos)
find_package(Kokkos CONFIG QUIET)
find_package(Kokkos 4.4...4.5 CONFIG QUIET)
if(NOT Kokkos_FOUND)
if("${Kokkos_ENABLE_CUDA}")
option(Kokkos_ENABLE_CUDA_CONSTEXPR "Whether to activate experimental relaxed constexpr functions" ON)
Expand All @@ -72,7 +55,7 @@ elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "EMBEDDED")
endif()
add_subdirectory(vendor/kokkos)
elseif("${DDC_Kokkos_DEPENDENCY_POLICY}" STREQUAL "INSTALLED")
find_package(Kokkos CONFIG REQUIRED)
find_package(Kokkos 4.4...4.5 CONFIG REQUIRED)
endif()

# Custom cmake modules
Expand Down Expand Up @@ -179,7 +162,7 @@ target_include_directories(DDC
"$<INSTALL_INTERFACE:include>"
)
target_link_libraries(DDC
INTERFACE std::mdspan Kokkos::kokkos
INTERFACE Kokkos::kokkos
)
target_compile_definitions(DDC
INTERFACE
Expand Down
1 change: 0 additions & 1 deletion cmake/DDCConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

include(CMakeFindDependencyMacro)

find_dependency(mdspan)
if(@DDC_BUILD_PDI_WRAPPER@)
find_dependency(PDI COMPONENTS C)
endif()
Expand Down
4 changes: 1 addition & 3 deletions examples/game_of_life.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include <iostream>
#include <string>

#include <experimental/mdspan>

#include <ddc/ddc.hpp>

#include <Kokkos_Core.hpp>
Expand All @@ -31,7 +29,7 @@ void blinker_init(
ddc::ChunkSpan<
cell,
ddc::DiscreteDomain<DDimX, DDimY>,
std::experimental::layout_right,
Kokkos::layout_right,
Kokkos::DefaultExecutionSpace::memory_space> cells)
{
ddc::parallel_for_each(
Expand Down
11 changes: 4 additions & 7 deletions include/ddc/chunk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <string>
#include <utility>

#include <experimental/mdspan>

#include <Kokkos_Core.hpp>

#include "ddc/chunk_common.hpp"
Expand All @@ -27,11 +25,10 @@ inline constexpr bool enable_chunk<Chunk<ElementType, SupportType, Allocator>> =

template <class ElementType, class... DDims, class Allocator>
class Chunk<ElementType, DiscreteDomain<DDims...>, Allocator>
: public ChunkCommon<ElementType, DiscreteDomain<DDims...>, std::experimental::layout_right>
: public ChunkCommon<ElementType, DiscreteDomain<DDims...>, Kokkos::layout_right>
{
protected:
using base_type
= ChunkCommon<ElementType, DiscreteDomain<DDims...>, std::experimental::layout_right>;
using base_type = ChunkCommon<ElementType, DiscreteDomain<DDims...>, Kokkos::layout_right>;

/// ND memory view
using internal_mdspan_type = typename base_type::internal_mdspan_type;
Expand All @@ -41,14 +38,14 @@ class Chunk<ElementType, DiscreteDomain<DDims...>, Allocator>
using span_type = ChunkSpan<
ElementType,
DiscreteDomain<DDims...>,
std::experimental::layout_right,
Kokkos::layout_right,
typename Allocator::memory_space>;

/// type of a view of this full chunk
using view_type = ChunkSpan<
ElementType const,
DiscreteDomain<DDims...>,
std::experimental::layout_right,
Kokkos::layout_right,
typename Allocator::memory_space>;

/// The dereferenceable part of the co-domain but with indexing starting at 0
Expand Down
27 changes: 11 additions & 16 deletions include/ddc/chunk_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#include <type_traits>
#include <utility>

#include <experimental/mdspan>

#include <Kokkos_Macros.hpp>
#include <Kokkos_Core.hpp>

#include "ddc/chunk_traits.hpp"
#include "ddc/detail/macros.hpp"
Expand All @@ -39,10 +37,10 @@ class ChunkCommon<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy>
{
protected:
/// the raw mdspan underlying this, with the same indexing (0 might no be dereferenceable)
using internal_mdspan_type = std::experimental::mdspan<
using internal_mdspan_type = Kokkos::mdspan<
ElementType,
std::experimental::dextents<std::size_t, sizeof...(DDims)>,
std::experimental::layout_stride>;
Kokkos::dextents<std::size_t, sizeof...(DDims)>,
Kokkos::layout_stride>;

public:
using discrete_domain_type = DiscreteDomain<DDims...>;
Expand All @@ -51,14 +49,14 @@ class ChunkCommon<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy>
= DiscreteDomain<DDims...>;

/// The dereferenceable part of the co-domain but with a different domain, starting at 0
using allocation_mdspan_type = std::experimental::mdspan<
using allocation_mdspan_type = Kokkos::mdspan<
ElementType,
std::experimental::dextents<std::size_t, sizeof...(DDims)>,
Kokkos::dextents<std::size_t, sizeof...(DDims)>,
LayoutStridedPolicy>;

using const_allocation_mdspan_type = std::experimental::mdspan<
using const_allocation_mdspan_type = Kokkos::mdspan<
const ElementType,
std::experimental::dextents<std::size_t, sizeof...(DDims)>,
Kokkos::dextents<std::size_t, sizeof...(DDims)>,
LayoutStridedPolicy>;

using discrete_element_type = typename discrete_domain_type::discrete_element_type;
Expand Down Expand Up @@ -138,18 +136,15 @@ class ChunkCommon<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy>
make_internal_mdspan(ElementType* ptr, discrete_domain_type const& domain)
{
if (domain.empty()) {
return internal_mdspan_type(
ptr,
std::experimental::layout_stride::mapping<extents_type>());
return internal_mdspan_type(ptr, Kokkos::layout_stride::mapping<extents_type>());
}
extents_type const extents_r(::ddc::extents<DDims>(domain).value()...);
mapping_type const mapping_r(extents_r);

extents_type const extents_s((front<DDims>(domain) + ddc::extents<DDims>(domain)).uid()...);
std::array<std::size_t, sizeof...(DDims)> const strides_s {
mapping_r.stride(type_seq_rank_v<DDims, detail::TypeSeq<DDims...>>)...};
std::experimental::layout_stride::mapping<extents_type> const
mapping_s(extents_s, strides_s);
Kokkos::layout_stride::mapping<extents_type> const mapping_s(extents_s, strides_s);
return internal_mdspan_type(ptr - mapping_s(front<DDims>(domain).uid()...), mapping_s);
}

Expand Down Expand Up @@ -300,7 +295,7 @@ class ChunkCommon<ElementType, DiscreteDomain<DDims...>, LayoutStridedPolicy>
{
DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
extents_type const extents_s(::ddc::extents<DDims>(m_domain).value()...);
if constexpr (std::is_same_v<LayoutStridedPolicy, std::experimental::layout_stride>) {
if constexpr (std::is_same_v<LayoutStridedPolicy, Kokkos::layout_stride>) {
mapping_type const map(extents_s, m_internal_mdspan.mapping().strides());
return allocation_mdspan_type(data_handle(), map);
} else {
Expand Down
Loading

0 comments on commit 2e8e3ed

Please sign in to comment.