Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow init with 0 mem size #289

Merged
merged 1 commit into from
Feb 10, 2025
Merged
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 include/mallocMC/creationPolicies/FlatterScatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,12 @@ namespace mallocMC::CreationPolicies
{
using MyHeap = FlatterScatterAlloc::Heap<T_HeapConfig, T_HashConfig, T_AlignmentPolicy>;
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<TAcc> const kernelCfg
Expand Down
62 changes: 62 additions & 0 deletions test/unit/source/Allocator.cpp
Original file line number Diff line number Diff line change
@@ -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 <alpaka/example/ExampleDefaultAcc.hpp>

#include <catch2/catch_test_macros.hpp>
#include <mallocMC/mallocMC.hpp>
using Dim = alpaka::DimInt<1>;
using Idx = std::size_t;

// Define the device accelerator
using Acc = alpaka::ExampleDefaultAcc<Dim, Idx>;

TEST_CASE("Allocator")
{
SECTION("can be initialised with 0 memory.")
{
auto const platform = alpaka::Platform<Acc>{};
auto const dev = alpaka::getDevByIdx(platform, 0);
auto queue = alpaka::Queue<Acc, alpaka::Blocking>{dev};

mallocMC::Allocator<
Acc,
mallocMC::CreationPolicies::FlatterScatter<>,
mallocMC::DistributionPolicies::Noop,
mallocMC::OOMPolicies::ReturnNull,
mallocMC::ReservePoolPolicies::AlpakaBuf<Acc>,
mallocMC::AlignmentPolicies::Shrink<>>
allocator{dev, queue, 0};
}
}
Loading