From 26ce64ed555ef6589bd2dd3b4c54c1a8cd89bb24 Mon Sep 17 00:00:00 2001 From: Kris Rowe Date: Fri, 26 Jul 2024 22:17:33 +0000 Subject: [PATCH 1/3] Test memoryPool reservation with void type. Currently this results in a segfault. --- tests/src/core/memoryPool.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/src/core/memoryPool.cpp b/tests/src/core/memoryPool.cpp index 647613744..09dba123a 100644 --- a/tests/src/core/memoryPool.cpp +++ b/tests/src/core/memoryPool.cpp @@ -2,9 +2,11 @@ #include void testReserve(); +void testVoid(); int main(const int argc, const char **argv) { testReserve(); + testVoid(); return 0; } @@ -165,3 +167,15 @@ void testReserve() { delete[] test; delete[] data; } + +void testVoid() { +#define ASSERT_SAME_SIZE(a, b) \ + ASSERT_EQ((size_t) (a), (size_t) (b)) + + occa::device device({{"mode", "Serial"}}); + occa::memoryPool memory_pool = device.createMemoryPool(); + + const int size = 10; + occa::memory memory = memory_pool.reserve(10); + ASSERT_SAME_SIZE(memory.size(), size); +} From ee42913e371db0aee14b7757c95b6182a5cb7ee9 Mon Sep 17 00:00:00 2001 From: Kris Rowe Date: Fri, 26 Jul 2024 22:18:19 +0000 Subject: [PATCH 2/3] Declare template function specialization so it is available in other translation units. --- include/occa/core/memoryPool.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/occa/core/memoryPool.hpp b/include/occa/core/memoryPool.hpp index a6a9c3d80..3388b4ac1 100644 --- a/include/occa/core/memoryPool.hpp +++ b/include/occa/core/memoryPool.hpp @@ -215,6 +215,12 @@ namespace occa { template occa::memory reserve(const dim_t entries); + + // Need to declare this function template specialization + // in the header so it is available in other translation units. + template <> + occa::memory reserve(const dim_t entries); + /** * @startDoc{reserve[1]} * @@ -233,7 +239,7 @@ namespace occa { * @endDoc */ occa::memory reserve(const dim_t entries, - const dtype_t &dtype);\ + const dtype_t &dtype); /** * @startDoc{setAlignment} From a502fbd326b0f7ae7bb89b56dd971bad6a25f990 Mon Sep 17 00:00:00 2001 From: Kris Rowe Date: Fri, 26 Jul 2024 22:40:11 +0000 Subject: [PATCH 3/3] Move template specialization out of class definition. --- include/occa/core/memoryPool.hpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/include/occa/core/memoryPool.hpp b/include/occa/core/memoryPool.hpp index 3388b4ac1..e2ca1de1a 100644 --- a/include/occa/core/memoryPool.hpp +++ b/include/occa/core/memoryPool.hpp @@ -215,12 +215,6 @@ namespace occa { template occa::memory reserve(const dim_t entries); - - // Need to declare this function template specialization - // in the header so it is available in other translation units. - template <> - occa::memory reserve(const dim_t entries); - /** * @startDoc{reserve[1]} * @@ -257,6 +251,10 @@ namespace occa { void setAlignment(const udim_t alignment); }; + // Need to declare this function template specialization + // in the header so it is available in other translation units. + template <> + occa::memory memoryPool::reserve(const dim_t entries); } #include "memoryPool.tpp"