From e2cb9d785d88077f250baa9f2f2a720782a1bbf3 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 7 Sep 2022 19:15:15 -0500 Subject: [PATCH] Retry clSVMAlloc in SVMAllocation after running GC --- src/wrap_cl.hpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp index 15aa882fc..413b8452b 100644 --- a/src/wrap_cl.hpp +++ b/src/wrap_cl.hpp @@ -3646,10 +3646,19 @@ namespace pyopencl "supplying an out-of-order queue to SVMAllocation is invalid"); } - PYOPENCL_PRINT_CALL_TRACE("clSVMalloc"); - m_allocation = clSVMAlloc( - ctx->data(), - flags, size, alignment); + int try_count = 0; + while (try_count < 2) + { + PYOPENCL_PRINT_CALL_TRACE("clSVMalloc"); + m_allocation = clSVMAlloc( + ctx->data(), + flags, size, alignment); + if (m_allocation) + return; + + ++try_count; + run_python_gc(); + } if (!m_allocation) throw pyopencl::error("clSVMAlloc", CL_OUT_OF_RESOURCES);