Skip to content

Commit 147335a

Browse files
committed
Changed definition of Payload to not include ALLOCATION_SIZE
1 parent 8f13f17 commit 147335a

File tree

1 file changed

+7
-5
lines changed
  • examples/multi-size-malloc/source

1 file changed

+7
-5
lines changed

examples/multi-size-malloc/source/main.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static constexpr std::uint32_t ALLOCATION_SIZE = 16U;
6565
// whether the obtained value was actually correct. `notApplicable` means that the checks were
6666
// skipped. `nullpointer` means that a nullpointer was given, so the checks couldn't run at all.
6767
enum class Reason { completed, notApplicable, nullpointer };
68-
using Payload = std::variant<std::span<std::byte, ALLOCATION_SIZE>, std::pair<bool, Reason>>;
68+
using Payload = std::variant<std::span<std::byte>, std::pair<bool, Reason>>;
6969

7070
template <typename TAccTag> struct SimpleSumLogger {
7171
using Clock = DeviceClock<TAccTag>;
@@ -175,13 +175,16 @@ struct IotaReductionChecker {
175175
if (std::get<0>(result) != Actions::MALLOC) {
176176
return std::make_tuple(Actions::CHECK, Payload(std::make_pair(true, Reason::notApplicable)));
177177
}
178-
auto range = std::get<1>(result);
178+
auto range = std::get<0>(std::get<1>(result));
179179
if (range.data() == nullptr) {
180180
return std::make_tuple(Actions::CHECK, Payload(std::make_pair(false, Reason::nullpointer)));
181181
}
182182
auto uintRange = convertDataType<uint32_t>(range);
183+
184+
// TODO: Segmentation fault by std::iota
183185
std::iota(std::begin(uintRange), std::end(uintRange), currentValue);
184186
size_t n = uintRange.size();
187+
185188
// The exact formula is using size_t because n is size_t. Casting it down will oftentimes run
186189
// into an overflow that the reduction encounters, too.
187190
auto expected = static_cast<uint32_t>(n * currentValue + n * (n - 1) / 2) ^ currentValue;
@@ -229,15 +232,14 @@ namespace setups {
229232
std::array<std::byte*, allocations> pointers{{}};
230233
std::uint32_t counter{0U};
231234

232-
233235
ALPAKA_FN_ACC auto next([[maybe_unused]] const auto& acc) {
234236
if (counter >= allocations)
235237
return std::make_tuple(kitgenbench::Actions::STOP,
236-
std::span<std::byte>{static_cast<std::byte*>(nullptr), 0U});
238+
Payload(std::span<std::byte>{static_cast<std::byte*>(nullptr), 0U}));
237239
pointers[counter] = static_cast<std::byte*>(malloc(sizes[counter]));
238240
auto result = std::make_tuple(
239241
+kitgenbench::Actions::MALLOC,
240-
std::span<std::byte>(pointers[counter], sizes[counter]));
242+
Payload(std::span<std::byte>(pointers[counter], sizes[counter])));
241243
counter++;
242244
return result;
243245
}

0 commit comments

Comments
 (0)