Skip to content

Commit

Permalink
Add examples and make them run
Browse files Browse the repository at this point in the history
  • Loading branch information
chillenzer committed Jan 22, 2025
1 parent bbb8567 commit 7552c80
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 22 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/add_controlled.cmake)
add_controlled("PackageProject.cmake" REQUIRED)
add_controlled("alpaka" REQUIRED)

if(alpaka_ACC_GPU_CUDA_ENABLE)
add_controlled("Gallatin")
endif()

# ---- Create library ----

# Note: for header-only libraries change all PUBLIC flags to INTERFACE and create an interface
add_library(${PROJECT_NAME} INTERFACE)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)

target_link_libraries(${PROJECT_NAME} PRIVATE gallatin)
if(alpaka_ACC_GPU_CUDA_ENABLE)
add_controlled("Gallatin")
target_link_libraries(${PROJECT_NAME} INTERFACE gallatin)
endif()

# being a cross-platform target, we enforce standards conformance on MSVC
target_compile_options(${PROJECT_NAME} INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive->")
Expand Down
7 changes: 4 additions & 3 deletions cmake/package-lock.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ CPMDeclarePackage(Catch2
EXCLUDE_FROM_ALL YES
)
# Gallatin
CPMDeclarePackage(Catch2
CPMDeclarePackage(Gallatin
# There's no release available yet.
GIT_TAG 1aa70ade136c3c2042e2a9c2f25565aa56168a0f
GITHUB_REPOSITORY saltsystemslab/Gallatin
GIT_TAG ac0cb8e380ffcb74156bafb8805fb60412817c5f
# Use our own fork for some patches
GITHUB_REPOSITORY chillenzer/Gallatin
SYSTEM YES
EXCLUDE_FROM_ALL YES
)
26 changes: 20 additions & 6 deletions examples/getAvailableSlots/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,19 @@ struct ExampleKernel
}
};

template<typename T_CreationPolicy>
template<
typename T_CreationPolicy,
typename T_ReservePoolPolicy,
typename T_AlignmentPolicy = mallocMC::AlignmentPolicies::Shrink<AlignmentConfig>>
auto example03() -> int
{
using Allocator = mallocMC::Allocator<
Acc,
T_CreationPolicy,
mallocMC::DistributionPolicies::Noop,
mallocMC::OOMPolicies::ReturnNull,
mallocMC::ReservePoolPolicies::AlpakaBuf<Acc>,
mallocMC::AlignmentPolicies::Shrink<AlignmentConfig>>;
T_ReservePoolPolicy,
T_AlignmentPolicy>;

auto const platform = alpaka::Platform<Acc>{};
auto const dev = alpaka::getDevByIdx(platform, 0);
Expand All @@ -130,8 +133,19 @@ auto example03() -> int

auto main(int /*argc*/, char* /*argv*/[]) -> int
{
example03<FlatterScatter<FlatterScatterHeapConfig>>();
example03<Scatter<FlatterScatterHeapConfig>>();
example03<OldMalloc>();
example03<FlatterScatter<FlatterScatterHeapConfig>, mallocMC::ReservePoolPolicies::AlpakaBuf<Acc>>();
example03<Scatter<FlatterScatterHeapConfig>, mallocMC::ReservePoolPolicies::AlpakaBuf<Acc>>();
#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
example03<
mallocMC::CreationPolicies::GallatinCuda<>,
mallocMC::ReservePoolPolicies::Noop,
mallocMC::AlignmentPolicies::Noop>();
// GallatinCuda already uses cudaSetLimits and we're not allowed to call it a second time.
example03<OldMalloc, mallocMC::ReservePoolPolicies::Noop>();
// This should normally be:
// example01<OldMalloc, mallocMC::ReservePoolPolicies::CudaSetLimits>();
#else
example03<OldMalloc, mallocMC::ReservePoolPolicies::Noop>();
#endif
return 0;
}
29 changes: 20 additions & 9 deletions examples/vectorAdd/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
THE SOFTWARE.
*/

#include "mallocMC/creationPolicies/FlatterScatter.hpp"
#include "mallocMC/creationPolicies/OldMalloc.hpp"

#include <alpaka/alpaka.hpp>
#include <alpaka/example/ExampleDefaultAcc.hpp>

Expand Down Expand Up @@ -80,16 +77,19 @@ ALPAKA_STATIC_ACC_MEM_GLOBAL int** arA;
ALPAKA_STATIC_ACC_MEM_GLOBAL int** arB;
ALPAKA_STATIC_ACC_MEM_GLOBAL int** arC;

template<typename T_CreationPolicy>
template<
typename T_CreationPolicy,
typename T_ReservePoolPolicy,
typename T_AlignmentPolicy = mallocMC::AlignmentPolicies::Shrink<ShrinkConfig>>
auto example01() -> int
{
using Allocator = mallocMC::Allocator<
Acc,
T_CreationPolicy,
mallocMC::DistributionPolicies::Noop,
mallocMC::OOMPolicies::ReturnNull,
mallocMC::ReservePoolPolicies::AlpakaBuf<Acc>,
mallocMC::AlignmentPolicies::Shrink<ShrinkConfig>>;
T_ReservePoolPolicy,
T_AlignmentPolicy>;

constexpr auto length = 100;

Expand Down Expand Up @@ -227,8 +227,19 @@ auto example01() -> int

auto main(int /*argc*/, char* /*argv*/[]) -> int
{
example01<FlatterScatter<FlatterScatterHeapConfig>>();
example01<Scatter<FlatterScatterHeapConfig>>();
example01<OldMalloc>();
example01<FlatterScatter<FlatterScatterHeapConfig>, mallocMC::ReservePoolPolicies::AlpakaBuf<Acc>>();
example01<Scatter<FlatterScatterHeapConfig>, mallocMC::ReservePoolPolicies::AlpakaBuf<Acc>>();
#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
example01<
mallocMC::CreationPolicies::GallatinCuda<>,
mallocMC::ReservePoolPolicies::Noop,
mallocMC::AlignmentPolicies::Noop>();
// GallatinCuda already uses cudaSetLimits and we're not allowed to call it a second time.
example01<OldMalloc, mallocMC::ReservePoolPolicies::Noop>();
// This should normally be:
// example01<OldMalloc, mallocMC::ReservePoolPolicies::CudaSetLimits>();
#else
example01<OldMalloc, mallocMC::ReservePoolPolicies::Noop>();
#endif
return 0;
}

0 comments on commit 7552c80

Please sign in to comment.