Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
59 changes: 44 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,18 @@ endif()

## The library itself

add_library(ddc_core INTERFACE)
add_library(ddc_core)
add_library(DDC::core ALIAS ddc_core)
configure_file(cmake/config.hpp.in generated/ddc/config.hpp NO_SOURCE_PERMISSIONS @ONLY)
target_compile_features(ddc_core INTERFACE cxx_std_17)
target_link_libraries(ddc_core INTERFACE Kokkos::kokkos)
target_compile_features(ddc_core PUBLIC cxx_std_17)
target_link_libraries(ddc_core PUBLIC Kokkos::kokkos)
target_sources(
ddc_core
PRIVATE
src/ddc/discrete_space.cpp
src/ddc/discrete_element.cpp
src/ddc/discrete_vector.cpp
src/ddc/print.cpp
INTERFACE
FILE_SET HEADERS
BASE_DIRS src ${CMAKE_CURRENT_BINARY_DIR}/generated
Expand Down Expand Up @@ -212,13 +217,22 @@ if("${DDC_BUILD_KERNELS_FFT}")
endif()
endif()

add_library(ddc_fft INTERFACE)
add_library(ddc_fft)
add_library(DDC::fft ALIAS ddc_fft)
target_compile_features(ddc_fft INTERFACE cxx_std_17)
target_link_libraries(ddc_fft INTERFACE DDC::core Kokkos::kokkos KokkosFFT::fft)
target_sources(ddc_fft INTERFACE FILE_SET HEADERS BASE_DIRS src FILES src/ddc/kernels/fft.hpp)
target_compile_features(ddc_fft PUBLIC cxx_std_17)
target_link_libraries(ddc_fft PUBLIC DDC::core Kokkos::kokkos KokkosFFT::fft)
target_sources(
ddc_fft
INTERFACE FILE_SET HEADERS BASE_DIRS src FILES src/ddc/kernels/fft.hpp
PRIVATE src/ddc/kernels/fft.cpp
)

set_target_properties(ddc_fft PROPERTIES EXPORT_NAME fft)
set_target_properties(
ddc_fft
PROPERTIES
EXPORT_NAME fft
INSTALL_RPATH "$<$<PLATFORM_ID:Linux>:$ORIGIN>;$<$<PLATFORM_ID:Darwin>:@loader_path>"
)
install(TARGETS ddc_fft EXPORT DDCFftTargets FILE_SET HEADERS)
install(EXPORT DDCFftTargets NAMESPACE DDC:: DESTINATION ${DDC_INSTALL_CMAKEDIR})
endif()
Expand Down Expand Up @@ -258,13 +272,14 @@ if("${DDC_BUILD_KERNELS_SPLINES}")
target_compile_features(ddc_splines INTERFACE cxx_std_17)
target_link_libraries(
ddc_splines
INTERFACE DDC::core
PRIVATE Ginkgo::ginkgo Kokkos::kokkoskernels LAPACKE::LAPACKE
PUBLIC Kokkos::kokkos
INTERFACE DDC::core
)
target_sources(
ddc_splines
PRIVATE
src/ddc/kernels/splines/spline_boundary_conditions.cpp
src/ddc/kernels/splines/splines_linear_problem.cpp
src/ddc/kernels/splines/splines_linear_problem_2x2_blocks.cpp
src/ddc/kernels/splines/splines_linear_problem_3x3_blocks.cpp
Expand Down Expand Up @@ -310,7 +325,12 @@ if("${DDC_BUILD_KERNELS_SPLINES}")
)

install(FILES cmake/FindLAPACKE.cmake DESTINATION ${DDC_INSTALL_CMAKEDIR})
set_target_properties(ddc_splines PROPERTIES EXPORT_NAME splines)
set_target_properties(
ddc_splines
PROPERTIES
EXPORT_NAME splines
INSTALL_RPATH "$<$<PLATFORM_ID:Linux>:$ORIGIN>;$<$<PLATFORM_ID:Darwin>:@loader_path>"
)
install(TARGETS ddc_splines EXPORT DDCSplinesTargets FILE_SET HEADERS)
install(EXPORT DDCSplinesTargets NAMESPACE DDC:: DESTINATION ${DDC_INSTALL_CMAKEDIR})
endif()
Expand All @@ -320,13 +340,22 @@ endif()
if("${DDC_BUILD_PDI_WRAPPER}")
find_package(PDI 1.10.1...<2 REQUIRED COMPONENTS C)

add_library(ddc_pdi INTERFACE)
add_library(ddc_pdi)
add_library(DDC::pdi ALIAS ddc_pdi)
target_compile_features(ddc_pdi INTERFACE cxx_std_17)
target_link_libraries(ddc_pdi INTERFACE DDC::core PDI::PDI_C)
target_sources(ddc_pdi INTERFACE FILE_SET HEADERS BASE_DIRS src FILES src/ddc/pdi.hpp)
target_compile_features(ddc_pdi PUBLIC cxx_std_17)
target_link_libraries(ddc_pdi PUBLIC DDC::core PDI::PDI_C)
target_sources(
ddc_pdi
INTERFACE FILE_SET HEADERS BASE_DIRS src FILES src/ddc/pdi.hpp
PRIVATE src/ddc/pdi.cpp
)

set_target_properties(ddc_pdi PROPERTIES EXPORT_NAME pdi)
set_target_properties(
ddc_pdi
PROPERTIES
EXPORT_NAME pdi
INSTALL_RPATH "$<$<PLATFORM_ID:Linux>:$ORIGIN>;$<$<PLATFORM_ID:Darwin>:@loader_path>"
)
install(TARGETS ddc_pdi EXPORT DDCPdiTargets FILE_SET HEADERS)
install(EXPORT DDCPdiTargets NAMESPACE DDC:: DESTINATION ${DDC_INSTALL_CMAKEDIR})
endif()
Expand Down
27 changes: 27 additions & 0 deletions src/ddc/discrete_element.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) The DDC development team, see COPYRIGHT.md file
//
// SPDX-License-Identifier: MIT

#include <cstddef>
#include <ostream>

#include "discrete_element.hpp"

namespace ddc::detail {

void print_discrete_element(
std::ostream& os,
DiscreteElementType const* const data,
std::size_t const n)
{
os << '(';
if (n > 0) {
os << data[0];
for (std::size_t i = 1; i < n; ++i) {
os << ", " << data[i];
}
}
os << ')';
}

} // namespace ddc::detail
24 changes: 11 additions & 13 deletions src/ddc/discrete_element.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <array>
#include <cstddef>
#include <ostream>
#include <iosfwd>
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -317,20 +317,18 @@ class DiscreteElement
}
};

inline std::ostream& operator<<(std::ostream& out, DiscreteElement<> const&)
{
out << "()";
return out;
}
namespace detail {

void print_discrete_element(std::ostream& os, DiscreteElementType const* data, std::size_t n);

template <class Head, class... Tags>
std::ostream& operator<<(std::ostream& out, DiscreteElement<Head, Tags...> const& arr)
} // namespace detail

template <class... Tags>
std::ostream& operator<<(std::ostream& os, DiscreteElement<Tags...> const& arr)
{
out << "(";
out << uid<Head>(arr);
((out << ", " << uid<Tags>(arr)), ...);
out << ")";
return out;
std::array const std_arr = detail::array(arr);
detail::print_discrete_element(os, std_arr.data(), std_arr.size());
return os;
}


Expand Down
71 changes: 71 additions & 0 deletions src/ddc/discrete_space.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (C) The DDC development team, see COPYRIGHT.md file
//
// SPDX-License-Identifier: MIT

#include <cassert>
#include <functional>
#include <map>
#include <optional>
#include <ostream>
#include <string>

#include <Kokkos_Core.hpp>

#if defined(KOKKOS_ENABLE_CUDA)
# include <sstream>

# include <cuda.h>
#elif defined(KOKKOS_ENABLE_HIP)
# include <sstream>

# include <hip/hip_runtime.h>
#endif

namespace ddc::detail {

#if defined(KOKKOS_ENABLE_CUDA)
void device_throw_on_error(
cudaError_t const err,
const char* const func,
const char* const file,
const int line)
{
if (err != cudaSuccess) {
std::stringstream ss;
ss << "CUDA Runtime Error at: " << file << ":" << line << "\n";
ss << cudaGetErrorString(err) << " " << func << "\n";
throw std::runtime_error(ss.str());
}
}
#elif defined(KOKKOS_ENABLE_HIP)
void device_throw_on_error(
hipError_t const err,
const char* const func,
const char* const file,
const int line)
{
if (err != hipSuccess) {
std::stringstream ss;
ss << "HIP Runtime Error at: " << file << ":" << line << "\n";
ss << hipGetErrorString(err) << " " << func << "\n";
throw std::runtime_error(ss.str());
}
}
#endif

// Global CPU variable storing resetters. Required to correctly free data.
std::optional<std::map<std::string, std::function<void()>>> g_discretization_store;

void display_discretization_store(std::ostream& os)
{
if (g_discretization_store) {
os << "The host discretization store is initialized:\n";
for (auto const& [key, value] : *g_discretization_store) {
os << " - " << key << "\n";
}
} else {
os << "The host discretization store is not initialized:\n";
}
}

} // namespace ddc::detail
44 changes: 7 additions & 37 deletions src/ddc/discrete_space.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#include <cassert>
#include <cstddef>
#include <functional>
#include <iosfwd>
#include <map>
#include <optional>
#include <ostream>
#include <stdexcept>
#include <string>
#include <tuple>
Expand All @@ -23,12 +23,8 @@
#include "detail/macros.hpp"

#if defined(KOKKOS_ENABLE_CUDA)
# include <sstream>

# include <cuda.h>
#elif defined(KOKKOS_ENABLE_HIP)
# include <sstream>

# include <hip/hip_runtime.h>
#endif

Expand All @@ -42,33 +38,17 @@ namespace ddc {
namespace detail {

#if defined(KOKKOS_ENABLE_CUDA)
inline void device_throw_on_error(
void device_throw_on_error(
cudaError_t const err,
const char* const func,
const char* const file,
const int line)
{
if (err != cudaSuccess) {
std::stringstream ss;
ss << "CUDA Runtime Error at: " << file << ":" << line << "\n";
ss << cudaGetErrorString(err) << " " << func << "\n";
throw std::runtime_error(ss.str());
}
}
const int line);
#elif defined(KOKKOS_ENABLE_HIP)
inline void device_throw_on_error(
void device_throw_on_error(
hipError_t const err,
const char* const func,
const char* const file,
const int line)
{
if (err != hipSuccess) {
std::stringstream ss;
ss << "HIP Runtime Error at: " << file << ":" << line << "\n";
ss << hipGetErrorString(err) << " " << func << "\n";
throw std::runtime_error(ss.str());
}
}
const int line);
#endif

template <class DDim, class MemorySpace>
Expand Down Expand Up @@ -111,7 +91,7 @@ class GpuProxy
};

// Global CPU variable storing resetters. Required to correctly free data.
inline std::optional<std::map<std::string, std::function<void()>>> g_discretization_store;
extern std::optional<std::map<std::string, std::function<void()>>> g_discretization_store;

// Global CPU variable owning discrete spaces data for CPU and GPU
template <class DDim>
Expand All @@ -134,17 +114,7 @@ SYCL_EXTERNAL inline sycl::ext::oneapi::experimental::device_global<
g_discrete_space_device;
#endif

inline void display_discretization_store(std::ostream& os)
{
if (g_discretization_store) {
os << "The host discretization store is initialized:\n";
for (auto const& [key, value] : *g_discretization_store) {
os << " - " << key << "\n";
}
} else {
os << "The host discretization store is not initialized:\n";
}
}
void display_discretization_store(std::ostream& os);

template <class Tuple, std::size_t... Ids>
auto extract_after(Tuple&& t, std::index_sequence<Ids...>)
Expand Down
27 changes: 27 additions & 0 deletions src/ddc/discrete_vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (C) The DDC development team, see COPYRIGHT.md file
//
// SPDX-License-Identifier: MIT

#include <cstddef>
#include <ostream>

#include "discrete_vector.hpp"

namespace ddc::detail {

void print_discrete_vector(
std::ostream& os,
DiscreteVectorElement const* const data,
std::size_t const n)
{
os << '(';
if (n > 0) {
os << data[0];
for (std::size_t i = 1; i < n; ++i) {
os << ", " << data[i];
}
}
os << ')';
}

} // namespace ddc::detail
Loading