diff --git a/include/mallocMC/creationPolicies/FlatterScatter.hpp b/include/mallocMC/creationPolicies/FlatterScatter.hpp index 67fa4d10..d9cefd69 100644 --- a/include/mallocMC/creationPolicies/FlatterScatter.hpp +++ b/include/mallocMC/creationPolicies/FlatterScatter.hpp @@ -411,6 +411,12 @@ namespace mallocMC::CreationPolicies { using MyHeap = FlatterScatterAlloc::Heap; auto numBlocks = MyHeap::numBlocks(memsize); + if(numBlocks == 0U) + { + // This is not just an optimisation. The call to `getValidWorkDiv` below really dislikes the 0 extent + // that we'd give it, so better stop here to not run into division by zero. + return; + } auto numPagesPerBlock = MyHeap::MyAccessBlock::numPages(); alpaka::KernelCfg const kernelCfg diff --git a/test/unit/source/Allocator.cpp b/test/unit/source/Allocator.cpp new file mode 100644 index 00000000..fcfc22f8 --- /dev/null +++ b/test/unit/source/Allocator.cpp @@ -0,0 +1,62 @@ +/* + mallocMC: Memory Allocator for Many Core Architectures. + + Copyright 2025 Helmholtz-Zentrum Dresden - Rossendorf + + Author(s): Julian Johannes Lenz, Rene Widera + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "mallocMC/allocator.hpp" + +#include "mallocMC/alignmentPolicies/Shrink.hpp" +#include "mallocMC/creationPolicies/FlatterScatter.hpp" +#include "mallocMC/distributionPolicies/Noop.hpp" +#include "mallocMC/oOMPolicies/ReturnNull.hpp" +#include "mallocMC/reservePoolPolicies/AlpakaBuf.hpp" + +#include + +#include +#include +using Dim = alpaka::DimInt<1>; +using Idx = std::size_t; + +// Define the device accelerator +using Acc = alpaka::ExampleDefaultAcc; + +TEST_CASE("Allocator") +{ + SECTION("can be initialised with 0 memory.") + { + auto const platform = alpaka::Platform{}; + auto const dev = alpaka::getDevByIdx(platform, 0); + auto queue = alpaka::Queue{dev}; + + mallocMC::Allocator< + Acc, + mallocMC::CreationPolicies::FlatterScatter<>, + mallocMC::DistributionPolicies::Noop, + mallocMC::OOMPolicies::ReturnNull, + mallocMC::ReservePoolPolicies::AlpakaBuf, + mallocMC::AlignmentPolicies::Shrink<>> + allocator{dev, queue, 0}; + } +}