Skip to content
Open
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
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Official Tool: clang-format version 16.0.0
BasedOnStyle: google
SortIncludes: false
AlignConsecutiveAssignments: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
Comment on lines +3 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that there is no mandate to adopt the same style as Kokkos Core

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend picking something that minimizes the diff.

15 changes: 15 additions & 0 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: clang-format check

on: [push, pull_request]

permissions: read-all

jobs:
clang-formatting-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Run clang-format style check.
uses: DoozyX/clang-format-lint-action@bcb4eb2cb0d707ee4f3e5cc3b456eb075f12cf73 # v0.20
with:
clangFormatVersion: 16
254 changes: 117 additions & 137 deletions benchmarks/copy/copy_layout_stride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@ MDSPAN_IMPL_INLINE_VARIABLE constexpr auto dyn = Kokkos::dynamic_extent;
template <class MDSpan, class... DynSizes>
void BM_MDSpan_Copy_2D_right(benchmark::State& state, MDSpan, DynSizes... dyn) {
using value_type = typename MDSpan::value_type;
auto buffer = std::make_unique<value_type[]>(
MDSpan{nullptr, dyn...}.mapping().required_span_size()
);
auto buffer = std::make_unique<value_type[]>(
MDSpan{nullptr, dyn...}.mapping().required_span_size());
auto buffer2 = std::make_unique<value_type[]>(
MDSpan{nullptr, dyn...}.mapping().required_span_size()
);
MDSpan{nullptr, dyn...}.mapping().required_span_size());
auto s = MDSpan{buffer.get(), dyn...};
mdspan_benchmark::fill_random(s);
auto dest = MDSpan{buffer2.get(), dyn...};
for (auto _ : state) {
for(index_type i = 0; i < s.extent(0); ++i) {
for (index_type i = 0; i < s.extent(0); ++i) {
for (index_type j = 0; j < s.extent(1); ++j) {
dest(i, j) = s(i, j);
dest(i, j) = s(i, j);
}
}
auto sdata = s.data_handle();
Expand All @@ -50,32 +48,29 @@ void BM_MDSpan_Copy_2D_right(benchmark::State& state, MDSpan, DynSizes... dyn) {
}

BENCHMARK_CAPTURE(
BM_MDSpan_Copy_2D_right, size_100_100, Kokkos::mdspan<int, Kokkos::extents<index_type, 100, 100>>(nullptr)
);
BENCHMARK_CAPTURE(
BM_MDSpan_Copy_2D_right, size_100_dyn, Kokkos::mdspan<int, Kokkos::extents<index_type, 100, dyn>>(), 100
);
BENCHMARK_CAPTURE(
BM_MDSpan_Copy_2D_right, size_dyn_dyn, Kokkos::mdspan<int, Kokkos::dextents<index_type, 2>>(), 100, 100
);
BM_MDSpan_Copy_2D_right, size_100_100,
Kokkos::mdspan<int, Kokkos::extents<index_type, 100, 100>>(nullptr));
BENCHMARK_CAPTURE(BM_MDSpan_Copy_2D_right, size_100_dyn,
Kokkos::mdspan<int, Kokkos::extents<index_type, 100, dyn>>(),
100);
BENCHMARK_CAPTURE(BM_MDSpan_Copy_2D_right, size_dyn_dyn,
Kokkos::mdspan<int, Kokkos::dextents<index_type, 2>>(), 100,
100);

//================================================================================

template <class MDSpan, class LayoutMapping>
void BM_MDSpan_Copy_2D_stride(benchmark::State& state, MDSpan, LayoutMapping map) {
void BM_MDSpan_Copy_2D_stride(benchmark::State& state, MDSpan,
LayoutMapping map) {
benchmark::DoNotOptimize(map);
using value_type = typename MDSpan::value_type;
auto buffer = std::make_unique<value_type[]>(
map.required_span_size()
);
auto buffer2 = std::make_unique<value_type[]>(
map.required_span_size()
);
auto s = MDSpan{buffer.get(), map};
auto buffer = std::make_unique<value_type[]>(map.required_span_size());
auto buffer2 = std::make_unique<value_type[]>(map.required_span_size());
auto s = MDSpan{buffer.get(), map};
mdspan_benchmark::fill_random(s);
auto dest = MDSpan{buffer2.get(), map};
for (auto _ : state) {
for(index_type i = 0; i < s.extent(0); ++i) {
for (index_type i = 0; i < s.extent(0); ++i) {
for (index_type j = 0; j < s.extent(1); ++j) {
dest(i, j) = s(i, j);
}
Expand All @@ -88,64 +83,57 @@ void BM_MDSpan_Copy_2D_stride(benchmark::State& state, MDSpan, LayoutMapping map
state.SetBytesProcessed(s.size() * sizeof(value_type) * state.iterations());
}

BENCHMARK_CAPTURE(
BM_MDSpan_Copy_2D_stride, size_100_100,
Kokkos::mdspan<int, Kokkos::extents<index_type, 100, 100>, Kokkos::layout_stride>(nullptr,
Kokkos::layout_stride::mapping<Kokkos::extents<index_type, 100, 100>>()),
Kokkos::layout_stride::template mapping<Kokkos::extents<index_type, 100, 100>>(
Kokkos::extents<index_type, 100, 100>{},
// layout right
std::array<size_t, 2>{100, 1}
)
);
BENCHMARK_CAPTURE(
BM_MDSpan_Copy_2D_stride, size_100_100d,
Kokkos::mdspan<int, Kokkos::extents<index_type, 100, dyn>, Kokkos::layout_stride>(),
Kokkos::layout_stride::template mapping<Kokkos::extents<index_type, 100, dyn>>(
Kokkos::extents<index_type, 100, dyn>{100},
// layout right
std::array<size_t, 2>{100, 1}
)
);
BENCHMARK_CAPTURE(
BM_MDSpan_Copy_2D_stride, size_100d_100,
Kokkos::mdspan<int, Kokkos::extents<index_type, dyn, 100>, Kokkos::layout_stride>(),
Kokkos::layout_stride::template mapping<Kokkos::extents<index_type, dyn, 100>>(
Kokkos::extents<index_type, dyn, 100>{100},
// layout right
std::array<size_t, 2>{100, 1}
)
);
BENCHMARK_CAPTURE(
BM_MDSpan_Copy_2D_stride, size_100d_100d,
Kokkos::mdspan<int, Kokkos::extents<index_type, dyn, dyn>, Kokkos::layout_stride>(),
Kokkos::layout_stride::template mapping<Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{100, 1}
)
);
BENCHMARK_CAPTURE(BM_MDSpan_Copy_2D_stride, size_100_100,
Kokkos::mdspan<int, Kokkos::extents<index_type, 100, 100>,
Kokkos::layout_stride>(
nullptr, Kokkos::layout_stride::mapping<
Kokkos::extents<index_type, 100, 100>>()),
Kokkos::layout_stride::template mapping<
Kokkos::extents<index_type, 100, 100>>(
Kokkos::extents<index_type, 100, 100>{},
// layout right
std::array<size_t, 2>{100, 1}));
BENCHMARK_CAPTURE(BM_MDSpan_Copy_2D_stride, size_100_100d,
Kokkos::mdspan<int, Kokkos::extents<index_type, 100, dyn>,
Kokkos::layout_stride>(),
Kokkos::layout_stride::template mapping<
Kokkos::extents<index_type, 100, dyn>>(
Kokkos::extents<index_type, 100, dyn>{100},
// layout right
std::array<size_t, 2>{100, 1}));
BENCHMARK_CAPTURE(BM_MDSpan_Copy_2D_stride, size_100d_100,
Kokkos::mdspan<int, Kokkos::extents<index_type, dyn, 100>,
Kokkos::layout_stride>(),
Kokkos::layout_stride::template mapping<
Kokkos::extents<index_type, dyn, 100>>(
Kokkos::extents<index_type, dyn, 100>{100},
// layout right
std::array<size_t, 2>{100, 1}));
BENCHMARK_CAPTURE(BM_MDSpan_Copy_2D_stride, size_100d_100d,
Kokkos::mdspan<int, Kokkos::extents<index_type, dyn, dyn>,
Kokkos::layout_stride>(),
Kokkos::layout_stride::template mapping<
Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{100, 1}));

//================================================================================

template <class T, class Extents, class MapSrc, class MapDst>
void BM_MDSpan_Copy_2D_stride_diff_map(benchmark::State& state,
T, Extents, MapSrc map_src, MapDst map_dest
) {
void BM_MDSpan_Copy_2D_stride_diff_map(benchmark::State& state, T, Extents,
MapSrc map_src, MapDst map_dest) {
using value_type = T;
auto buff_src = std::make_unique<value_type[]>(
map_src.required_span_size()
);
auto buff_dest = std::make_unique<value_type[]>(
map_dest.required_span_size()
);
auto buff_src = std::make_unique<value_type[]>(map_src.required_span_size());
auto buff_dest =
std::make_unique<value_type[]>(map_dest.required_span_size());
using map_stride_dyn = Kokkos::layout_stride;
using mdspan_type = Kokkos::mdspan<T, Extents, map_stride_dyn>;
auto src = mdspan_type{buff_src.get(), map_src};
using mdspan_type = Kokkos::mdspan<T, Extents, map_stride_dyn>;
auto src = mdspan_type{buff_src.get(), map_src};
mdspan_benchmark::fill_random(src);
auto dest = mdspan_type{buff_dest.get(), map_dest};
for (auto _ : state) {
for(index_type i = 0; i < src.extent(0); ++i) {
for (index_type i = 0; i < src.extent(0); ++i) {
for (index_type j = 0; j < src.extent(1); ++j) {
dest(i, j) = src(i, j);
}
Expand All @@ -155,72 +143,67 @@ void BM_MDSpan_Copy_2D_stride_diff_map(benchmark::State& state,
benchmark::DoNotOptimize(sdata);
benchmark::DoNotOptimize(ddata);
}
state.SetBytesProcessed(src.extent(0) * src.extent(1) * sizeof(value_type) * state.iterations());
state.SetBytesProcessed(src.extent(0) * src.extent(1) * sizeof(value_type) *
state.iterations());
}

BENCHMARK_CAPTURE(
BM_MDSpan_Copy_2D_stride_diff_map, size_100d_100d_bcast_0, int(),
Kokkos::extents<index_type, dyn, dyn>{100, 100},
Kokkos::layout_stride::template mapping<Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{0, 1}
),
Kokkos::layout_stride::template mapping<Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{100, 1}
)
);

BENCHMARK_CAPTURE(
BM_MDSpan_Copy_2D_stride_diff_map, size_100d_100d_bcast_1, int(),
Kokkos::extents<index_type, dyn, dyn>{100, 100},
Kokkos::layout_stride::template mapping<Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{1, 0}
),
Kokkos::layout_stride::template mapping<Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{100, 1}
)
);

BENCHMARK_CAPTURE(
BM_MDSpan_Copy_2D_stride_diff_map, size_100d_100d_bcast_both, int(),
Kokkos::extents<index_type, dyn, dyn>{100, 100},
Kokkos::layout_stride::template mapping<Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{0, 0}
),
Kokkos::layout_stride::template mapping<Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{100, 1}
)
);

BENCHMARK_CAPTURE(BM_MDSpan_Copy_2D_stride_diff_map, size_100d_100d_bcast_0,
int(), Kokkos::extents<index_type, dyn, dyn>{100, 100},
Kokkos::layout_stride::template mapping<
Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{0, 1}),
Kokkos::layout_stride::template mapping<
Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{100, 1}));

BENCHMARK_CAPTURE(BM_MDSpan_Copy_2D_stride_diff_map, size_100d_100d_bcast_1,
int(), Kokkos::extents<index_type, dyn, dyn>{100, 100},
Kokkos::layout_stride::template mapping<
Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{1, 0}),
Kokkos::layout_stride::template mapping<
Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{100, 1}));

BENCHMARK_CAPTURE(BM_MDSpan_Copy_2D_stride_diff_map, size_100d_100d_bcast_both,
int(), Kokkos::extents<index_type, dyn, dyn>{100, 100},
Kokkos::layout_stride::template mapping<
Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{0, 0}),
Kokkos::layout_stride::template mapping<
Kokkos::extents<index_type, dyn, dyn>>(
Kokkos::extents<index_type, dyn, dyn>{100, 100},
// layout right
std::array<size_t, 2>{100, 1}));

//================================================================================

template <class T>
void BM_Raw_Copy_1D(benchmark::State& state, T, size_t size) {
benchmark::DoNotOptimize(size);
using value_type = T;
auto buffer = std::make_unique<value_type[]>(size);
auto buffer = std::make_unique<value_type[]>(size);
{
// just for setup...
auto wrapped = Kokkos::mdspan<T, Kokkos::dextents<index_type, 1>>{buffer.get(), size};
auto wrapped =
Kokkos::mdspan<T, Kokkos::dextents<index_type, 1>>{buffer.get(), size};
mdspan_benchmark::fill_random(wrapped);
}
value_type* src = buffer.get();
auto buffer2 = std::make_unique<value_type[]>(size);
value_type* src = buffer.get();
auto buffer2 = std::make_unique<value_type[]>(size);
value_type* dest = buffer2.get();
for (auto _ : state) {
for(size_t i = 0; i < size; ++i) {
for (size_t i = 0; i < size; ++i) {
dest[i] = src[i];
}
benchmark::DoNotOptimize(src);
Expand All @@ -229,28 +212,27 @@ void BM_Raw_Copy_1D(benchmark::State& state, T, size_t size) {
state.SetBytesProcessed(size * sizeof(value_type) * state.iterations());
}

BENCHMARK_CAPTURE(
BM_Raw_Copy_1D, size_10000, int(), 10000
);
BENCHMARK_CAPTURE(BM_Raw_Copy_1D, size_10000, int(), 10000);

//================================================================================

template <class T>
void BM_Raw_Copy_2D(benchmark::State& state, T, size_t x, size_t y) {
using value_type = T;
auto buffer = std::make_unique<value_type[]>(x * y);
auto buffer = std::make_unique<value_type[]>(x * y);
{
// just for setup...
auto wrapped = Kokkos::mdspan<T, Kokkos::dextents<index_type, 1>>{buffer.get(), x * y};
auto wrapped =
Kokkos::mdspan<T, Kokkos::dextents<index_type, 1>>{buffer.get(), x * y};
mdspan_benchmark::fill_random(wrapped);
}
value_type* src = buffer.get();
auto buffer2 = std::make_unique<value_type[]>(x * y);
value_type* src = buffer.get();
auto buffer2 = std::make_unique<value_type[]>(x * y);
value_type* dest = buffer2.get();
for (auto _ : state) {
for(size_t i = 0; i < x; ++i) {
for(size_t j = 0; j < y; ++j) {
dest[i*y + j] = src[i*y + j];
for (size_t i = 0; i < x; ++i) {
for (size_t j = 0; j < y; ++j) {
dest[i * y + j] = src[i * y + j];
}
}
benchmark::DoNotOptimize(src);
Expand All @@ -259,9 +241,7 @@ void BM_Raw_Copy_2D(benchmark::State& state, T, size_t x, size_t y) {
state.SetBytesProcessed(x * y * sizeof(value_type) * state.iterations());
}

BENCHMARK_CAPTURE(
BM_Raw_Copy_2D, size_100_100, int(), 100, 100
);
BENCHMARK_CAPTURE(BM_Raw_Copy_2D, size_100_100, int(), 100, 100);

//================================================================================

Expand Down
Loading