Skip to content

Commit 3a80d12

Browse files
committed
Reassemble society from the rubble
1 parent 4bee3e8 commit 3a80d12

File tree

6 files changed

+42
-8
lines changed

6 files changed

+42
-8
lines changed

CMakeLists.txt

+11-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
3939
if(alpaka_ACC_GPU_CUDA_ENABLE)
4040
add_controlled("Gallatin")
4141

42+
if (TARGET gallatin::gallatin)
43+
set(mallocMC_HAS_Gallatin_AVAILABLE YES)
44+
else()
45+
set(mallocMC_HAS_Gallatin_AVAILABLE NO)
46+
endif()
47+
4248
# Gallatin needs some fairly recent compute capability from CUDA.
4349
# CMake defaults to taking the oldest supported by the device
4450
# (https://cmake.org/cmake/help/latest/variable/CMAKE_CUDA_ARCHITECTURES.html)
@@ -56,9 +62,13 @@ if(alpaka_ACC_GPU_CUDA_ENABLE)
5662
"If the architecture set is too old, this can lead to compilation errors with Gallatin. "
5763
"If Gallatin is needed, please set CMAKE_CUDA_ARCHITECTURES to the correct value >= 70."
5864
)
65+
set(mallocMC_HAS_Gallatin_AVAILABLE NO)
5966
endif()
6067

61-
target_link_libraries(${PROJECT_NAME} INTERFACE gallatin)
68+
if (mallocMC_HAS_Gallatin_AVAILABLE)
69+
target_link_libraries(${PROJECT_NAME} INTERFACE gallatin)
70+
target_compile_definitions(${PROJECT_NAME} INTERFACE mallocMC_HAS_Gallatin_AVAILABLE)
71+
endif()
6272
endif()
6373

6474
# being a cross-platform target, we enforce standards conformance on MSVC

examples/getAvailableSlots/source/main.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,17 @@ auto main(int /*argc*/, char* /*argv*/[]) -> int
136136
example03<FlatterScatter<FlatterScatterHeapConfig>, mallocMC::ReservePoolPolicies::AlpakaBuf<Acc>>();
137137
example03<Scatter<FlatterScatterHeapConfig>, mallocMC::ReservePoolPolicies::AlpakaBuf<Acc>>();
138138
#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
139+
# ifdef mallocMC_HAS_Gallatin_AVAILABLE
139140
example03<
140141
mallocMC::CreationPolicies::GallatinCuda<>,
141142
mallocMC::ReservePoolPolicies::Noop,
142143
mallocMC::AlignmentPolicies::Noop>();
143144
// GallatinCuda already uses cudaSetLimits and we're not allowed to call it a second time.
144145
example03<OldMalloc, mallocMC::ReservePoolPolicies::Noop>();
146+
# else
145147
// This should normally be:
146-
// example01<OldMalloc, mallocMC::ReservePoolPolicies::CudaSetLimits>();
148+
example01<OldMalloc, mallocMC::ReservePoolPolicies::CudaSetLimits>();
149+
# endif
147150
#else
148151
example03<OldMalloc, mallocMC::ReservePoolPolicies::Noop>();
149152
#endif

examples/vectorAdd/source/main.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,19 @@ auto main(int /*argc*/, char* /*argv*/[]) -> int
229229
{
230230
example01<FlatterScatter<FlatterScatterHeapConfig>, mallocMC::ReservePoolPolicies::AlpakaBuf<Acc>>();
231231
example01<Scatter<FlatterScatterHeapConfig>, mallocMC::ReservePoolPolicies::AlpakaBuf<Acc>>();
232+
232233
#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
234+
# ifdef mallocMC_HAS_Gallatin_AVAILABLE
233235
example01<
234236
mallocMC::CreationPolicies::GallatinCuda<>,
235237
mallocMC::ReservePoolPolicies::Noop,
236238
mallocMC::AlignmentPolicies::Noop>();
237239
// GallatinCuda already uses cudaSetLimits and we're not allowed to call it a second time.
238240
example01<OldMalloc, mallocMC::ReservePoolPolicies::Noop>();
241+
# else
239242
// This should normally be:
240-
// example01<OldMalloc, mallocMC::ReservePoolPolicies::CudaSetLimits>();
243+
example01<OldMalloc, mallocMC::ReservePoolPolicies::CudaSetLimits>();
244+
# endif
241245
#else
242246
example01<OldMalloc, mallocMC::ReservePoolPolicies::Noop>();
243247
#endif

include/mallocMC/creationPolicies/GallatinCuda.hpp

+20-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
#include <alpaka/alpaka.hpp>
3232

33-
#ifdef ALPAKA_ACC_GPU_CUDA_ENABLED
33+
#ifdef mallocMC_HAS_Gallatin_AVAILABLE
3434
# include <gallatin/allocators/gallatin.cuh>
3535
#else
3636

@@ -45,6 +45,23 @@ namespace gallatin::allocators
4545
{
4646
return nullptr;
4747
}
48+
49+
template<typename... T>
50+
auto malloc(T... /*unused*/) -> void*
51+
{
52+
// This always triggers but it depends on the template parameter, so it's only instantiated if we actually
53+
// use it.
54+
static_assert(sizeof...(T) < 0, "Attempt to use malloc of unavailable gallatin prototype.");
55+
return nullptr;
56+
}
57+
58+
template<typename... T>
59+
auto free(T... /*unused*/)
60+
{
61+
// This always triggers but it depends on the template parameter, so it's only instantiated if we actually
62+
// use it.
63+
static_assert(sizeof...(T) < 0, "Attempt to use free of unavailable gallatin prototype.");
64+
}
4865
};
4966
} // namespace gallatin::allocators
5067

@@ -89,7 +106,7 @@ namespace mallocMC
89106
static constexpr auto providesAvailableSlots = false;
90107

91108
template<typename AlpakaAcc>
92-
ALPAKA_FN_ACC auto create(AlpakaAcc const& acc, uint32_t bytes) const -> void*
109+
ALPAKA_FN_ACC auto create(AlpakaAcc const& /*acc*/, uint32_t bytes) const -> void*
93110
{
94111
return heap->malloc(static_cast<size_t>(bytes));
95112
}
@@ -107,7 +124,7 @@ namespace mallocMC
107124

108125
template<typename AlpakaAcc, typename AlpakaDevice, typename AlpakaQueue, typename T_DeviceAllocator>
109126
static void initHeap(
110-
AlpakaDevice& dev,
127+
AlpakaDevice& /*dev*/,
111128
AlpakaQueue& queue,
112129
T_DeviceAllocator* devAllocator,
113130
void*,

include/mallocMC/reservePoolPolicies/CudaSetLimits.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace mallocMC
5959
struct CudaSetLimits
6060
{
6161
template<typename AlpakaDev>
62-
auto setMemPool(AlpakaDev const& dev, size_t memsize) -> void*
62+
auto setMemPool(AlpakaDev const& /*dev*/, size_t memsize) -> void*
6363
{
6464
cudaDeviceSetLimit(cudaLimitMallocHeapSize, memsize);
6565
return nullptr;

test/unit/source/Allocator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ TEST_CASE("Allocator")
5151
auto queue = alpaka::Queue<Acc, alpaka::Blocking>{dev};
5252

5353
mallocMC::Allocator<
54-
Acc,
54+
alpaka::AccToTag<Acc>,
5555
mallocMC::CreationPolicies::FlatterScatter<>,
5656
mallocMC::DistributionPolicies::Noop,
5757
mallocMC::OOMPolicies::ReturnNull,

0 commit comments

Comments
 (0)