Skip to content

Commit cbd4725

Browse files
committed
Remove header-only libraries
1 parent 054a2c8 commit cbd4725

15 files changed

+382
-174
lines changed

CMakeLists.txt

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,18 @@ endif()
123123

124124
## The library itself
125125

126-
add_library(ddc_core INTERFACE)
126+
add_library(ddc_core)
127127
add_library(DDC::core ALIAS ddc_core)
128128
configure_file(cmake/config.hpp.in generated/ddc/config.hpp NO_SOURCE_PERMISSIONS @ONLY)
129-
target_compile_features(ddc_core INTERFACE cxx_std_17)
130-
target_link_libraries(ddc_core INTERFACE Kokkos::kokkos)
129+
target_compile_features(ddc_core PUBLIC cxx_std_17)
130+
target_link_libraries(ddc_core PUBLIC Kokkos::kokkos)
131131
target_sources(
132132
ddc_core
133+
PRIVATE
134+
src/ddc/discrete_space.cpp
135+
src/ddc/discrete_element.cpp
136+
src/ddc/discrete_vector.cpp
137+
src/ddc/print.cpp
133138
INTERFACE
134139
FILE_SET HEADERS
135140
BASE_DIRS src ${CMAKE_CURRENT_BINARY_DIR}/generated
@@ -212,13 +217,22 @@ if("${DDC_BUILD_KERNELS_FFT}")
212217
endif()
213218
endif()
214219

215-
add_library(ddc_fft INTERFACE)
220+
add_library(ddc_fft)
216221
add_library(DDC::fft ALIAS ddc_fft)
217-
target_compile_features(ddc_fft INTERFACE cxx_std_17)
218-
target_link_libraries(ddc_fft INTERFACE DDC::core Kokkos::kokkos KokkosFFT::fft)
219-
target_sources(ddc_fft INTERFACE FILE_SET HEADERS BASE_DIRS src FILES src/ddc/kernels/fft.hpp)
222+
target_compile_features(ddc_fft PUBLIC cxx_std_17)
223+
target_link_libraries(ddc_fft PUBLIC DDC::core Kokkos::kokkos KokkosFFT::fft)
224+
target_sources(
225+
ddc_fft
226+
INTERFACE FILE_SET HEADERS BASE_DIRS src FILES src/ddc/kernels/fft.hpp
227+
PRIVATE src/ddc/kernels/fft.cpp
228+
)
220229

221-
set_target_properties(ddc_fft PROPERTIES EXPORT_NAME fft)
230+
set_target_properties(
231+
ddc_fft
232+
PROPERTIES
233+
EXPORT_NAME fft
234+
INSTALL_RPATH "$<$<PLATFORM_ID:Linux>:$ORIGIN>;$<$<PLATFORM_ID:Darwin>:@loader_path>"
235+
)
222236
install(TARGETS ddc_fft EXPORT DDCFftTargets FILE_SET HEADERS)
223237
install(EXPORT DDCFftTargets NAMESPACE DDC:: DESTINATION ${DDC_INSTALL_CMAKEDIR})
224238
endif()
@@ -258,13 +272,14 @@ if("${DDC_BUILD_KERNELS_SPLINES}")
258272
target_compile_features(ddc_splines INTERFACE cxx_std_17)
259273
target_link_libraries(
260274
ddc_splines
275+
INTERFACE DDC::core
261276
PRIVATE Ginkgo::ginkgo Kokkos::kokkoskernels LAPACKE::LAPACKE
262277
PUBLIC Kokkos::kokkos
263-
INTERFACE DDC::core
264278
)
265279
target_sources(
266280
ddc_splines
267281
PRIVATE
282+
src/ddc/kernels/splines/spline_boundary_conditions.cpp
268283
src/ddc/kernels/splines/splines_linear_problem.cpp
269284
src/ddc/kernels/splines/splines_linear_problem_2x2_blocks.cpp
270285
src/ddc/kernels/splines/splines_linear_problem_3x3_blocks.cpp
@@ -310,7 +325,12 @@ if("${DDC_BUILD_KERNELS_SPLINES}")
310325
)
311326

312327
install(FILES cmake/FindLAPACKE.cmake DESTINATION ${DDC_INSTALL_CMAKEDIR})
313-
set_target_properties(ddc_splines PROPERTIES EXPORT_NAME splines)
328+
set_target_properties(
329+
ddc_splines
330+
PROPERTIES
331+
EXPORT_NAME splines
332+
INSTALL_RPATH "$<$<PLATFORM_ID:Linux>:$ORIGIN>;$<$<PLATFORM_ID:Darwin>:@loader_path>"
333+
)
314334
install(TARGETS ddc_splines EXPORT DDCSplinesTargets FILE_SET HEADERS)
315335
install(EXPORT DDCSplinesTargets NAMESPACE DDC:: DESTINATION ${DDC_INSTALL_CMAKEDIR})
316336
endif()
@@ -320,13 +340,22 @@ endif()
320340
if("${DDC_BUILD_PDI_WRAPPER}")
321341
find_package(PDI 1.10.1...<2 REQUIRED COMPONENTS C)
322342

323-
add_library(ddc_pdi INTERFACE)
343+
add_library(ddc_pdi)
324344
add_library(DDC::pdi ALIAS ddc_pdi)
325-
target_compile_features(ddc_pdi INTERFACE cxx_std_17)
326-
target_link_libraries(ddc_pdi INTERFACE DDC::core PDI::PDI_C)
327-
target_sources(ddc_pdi INTERFACE FILE_SET HEADERS BASE_DIRS src FILES src/ddc/pdi.hpp)
345+
target_compile_features(ddc_pdi PUBLIC cxx_std_17)
346+
target_link_libraries(ddc_pdi PUBLIC DDC::core PDI::PDI_C)
347+
target_sources(
348+
ddc_pdi
349+
INTERFACE FILE_SET HEADERS BASE_DIRS src FILES src/ddc/pdi.hpp
350+
PRIVATE src/ddc/pdi.cpp
351+
)
328352

329-
set_target_properties(ddc_pdi PROPERTIES EXPORT_NAME pdi)
353+
set_target_properties(
354+
ddc_pdi
355+
PROPERTIES
356+
EXPORT_NAME pdi
357+
INSTALL_RPATH "$<$<PLATFORM_ID:Linux>:$ORIGIN>;$<$<PLATFORM_ID:Darwin>:@loader_path>"
358+
)
330359
install(TARGETS ddc_pdi EXPORT DDCPdiTargets FILE_SET HEADERS)
331360
install(EXPORT DDCPdiTargets NAMESPACE DDC:: DESTINATION ${DDC_INSTALL_CMAKEDIR})
332361
endif()

src/ddc/discrete_element.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) The DDC development team, see COPYRIGHT.md file
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <cstddef>
6+
#include <ostream>
7+
8+
#include "discrete_element.hpp"
9+
10+
namespace ddc::detail {
11+
12+
void print_discrete_element(
13+
std::ostream& os,
14+
DiscreteElementType const* const data,
15+
std::size_t const n)
16+
{
17+
os << '(';
18+
if (n > 0) {
19+
os << data[0];
20+
for (std::size_t i = 1; i < n; ++i) {
21+
os << ", " << data[i];
22+
}
23+
}
24+
os << ')';
25+
}
26+
27+
} // namespace ddc::detail

src/ddc/discrete_element.hpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <array>
88
#include <cstddef>
9-
#include <ostream>
9+
#include <iosfwd>
1010
#include <type_traits>
1111
#include <utility>
1212

@@ -317,20 +317,18 @@ class DiscreteElement
317317
}
318318
};
319319

320-
inline std::ostream& operator<<(std::ostream& out, DiscreteElement<> const&)
321-
{
322-
out << "()";
323-
return out;
324-
}
320+
namespace detail {
321+
322+
void print_discrete_element(std::ostream& os, DiscreteElementType const* data, std::size_t n);
325323

326-
template <class Head, class... Tags>
327-
std::ostream& operator<<(std::ostream& out, DiscreteElement<Head, Tags...> const& arr)
324+
} // namespace detail
325+
326+
template <class... Tags>
327+
std::ostream& operator<<(std::ostream& os, DiscreteElement<Tags...> const& arr)
328328
{
329-
out << "(";
330-
out << uid<Head>(arr);
331-
((out << ", " << uid<Tags>(arr)), ...);
332-
out << ")";
333-
return out;
329+
std::array const std_arr = detail::array(arr);
330+
detail::print_discrete_element(os, std_arr.data(), std_arr.size());
331+
return os;
334332
}
335333

336334

src/ddc/discrete_space.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (C) The DDC development team, see COPYRIGHT.md file
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <cassert>
6+
#include <functional>
7+
#include <map>
8+
#include <optional>
9+
#include <ostream>
10+
#include <string>
11+
12+
#include <Kokkos_Core.hpp>
13+
14+
#if defined(KOKKOS_ENABLE_CUDA)
15+
# include <sstream>
16+
17+
# include <cuda.h>
18+
#elif defined(KOKKOS_ENABLE_HIP)
19+
# include <sstream>
20+
21+
# include <hip/hip_runtime.h>
22+
#endif
23+
24+
namespace ddc::detail {
25+
26+
#if defined(KOKKOS_ENABLE_CUDA)
27+
void device_throw_on_error(
28+
cudaError_t const err,
29+
const char* const func,
30+
const char* const file,
31+
const int line)
32+
{
33+
if (err != cudaSuccess) {
34+
std::stringstream ss;
35+
ss << "CUDA Runtime Error at: " << file << ":" << line << "\n";
36+
ss << cudaGetErrorString(err) << " " << func << "\n";
37+
throw std::runtime_error(ss.str());
38+
}
39+
}
40+
#elif defined(KOKKOS_ENABLE_HIP)
41+
void device_throw_on_error(
42+
hipError_t const err,
43+
const char* const func,
44+
const char* const file,
45+
const int line)
46+
{
47+
if (err != hipSuccess) {
48+
std::stringstream ss;
49+
ss << "HIP Runtime Error at: " << file << ":" << line << "\n";
50+
ss << hipGetErrorString(err) << " " << func << "\n";
51+
throw std::runtime_error(ss.str());
52+
}
53+
}
54+
#endif
55+
56+
// Global CPU variable storing resetters. Required to correctly free data.
57+
std::optional<std::map<std::string, std::function<void()>>> g_discretization_store;
58+
59+
void display_discretization_store(std::ostream& os)
60+
{
61+
if (g_discretization_store) {
62+
os << "The host discretization store is initialized:\n";
63+
for (auto const& [key, value] : *g_discretization_store) {
64+
os << " - " << key << "\n";
65+
}
66+
} else {
67+
os << "The host discretization store is not initialized:\n";
68+
}
69+
}
70+
71+
} // namespace ddc::detail

src/ddc/discrete_space.hpp

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#include <cassert>
88
#include <cstddef>
99
#include <functional>
10+
#include <iosfwd>
1011
#include <map>
1112
#include <optional>
12-
#include <ostream>
1313
#include <stdexcept>
1414
#include <string>
1515
#include <tuple>
@@ -23,12 +23,8 @@
2323
#include "detail/macros.hpp"
2424

2525
#if defined(KOKKOS_ENABLE_CUDA)
26-
# include <sstream>
27-
2826
# include <cuda.h>
2927
#elif defined(KOKKOS_ENABLE_HIP)
30-
# include <sstream>
31-
3228
# include <hip/hip_runtime.h>
3329
#endif
3430

@@ -42,33 +38,17 @@ namespace ddc {
4238
namespace detail {
4339

4440
#if defined(KOKKOS_ENABLE_CUDA)
45-
inline void device_throw_on_error(
41+
void device_throw_on_error(
4642
cudaError_t const err,
4743
const char* const func,
4844
const char* const file,
49-
const int line)
50-
{
51-
if (err != cudaSuccess) {
52-
std::stringstream ss;
53-
ss << "CUDA Runtime Error at: " << file << ":" << line << "\n";
54-
ss << cudaGetErrorString(err) << " " << func << "\n";
55-
throw std::runtime_error(ss.str());
56-
}
57-
}
45+
const int line);
5846
#elif defined(KOKKOS_ENABLE_HIP)
59-
inline void device_throw_on_error(
47+
void device_throw_on_error(
6048
hipError_t const err,
6149
const char* const func,
6250
const char* const file,
63-
const int line)
64-
{
65-
if (err != hipSuccess) {
66-
std::stringstream ss;
67-
ss << "HIP Runtime Error at: " << file << ":" << line << "\n";
68-
ss << hipGetErrorString(err) << " " << func << "\n";
69-
throw std::runtime_error(ss.str());
70-
}
71-
}
51+
const int line);
7252
#endif
7353

7454
template <class DDim, class MemorySpace>
@@ -111,7 +91,7 @@ class GpuProxy
11191
};
11292

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

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

137-
inline void display_discretization_store(std::ostream& os)
138-
{
139-
if (g_discretization_store) {
140-
os << "The host discretization store is initialized:\n";
141-
for (auto const& [key, value] : *g_discretization_store) {
142-
os << " - " << key << "\n";
143-
}
144-
} else {
145-
os << "The host discretization store is not initialized:\n";
146-
}
147-
}
117+
void display_discretization_store(std::ostream& os);
148118

149119
template <class Tuple, std::size_t... Ids>
150120
auto extract_after(Tuple&& t, std::index_sequence<Ids...>)

src/ddc/discrete_vector.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) The DDC development team, see COPYRIGHT.md file
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
#include <cstddef>
6+
#include <ostream>
7+
8+
#include "discrete_vector.hpp"
9+
10+
namespace ddc::detail {
11+
12+
void print_discrete_vector(
13+
std::ostream& os,
14+
DiscreteVectorElement const* const data,
15+
std::size_t const n)
16+
{
17+
os << '(';
18+
if (n > 0) {
19+
os << data[0];
20+
for (std::size_t i = 1; i < n; ++i) {
21+
os << ", " << data[i];
22+
}
23+
}
24+
os << ')';
25+
}
26+
27+
} // namespace ddc::detail

0 commit comments

Comments
 (0)