Skip to content

Commit d0b588c

Browse files
committed
test: use MemoryPool in testing actx
1 parent d2974b5 commit d0b588c

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

grudge/array_context.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ def __init__(self, queue, allocator=None,
164164
warn("No memory allocator specified, please pass one. "
165165
"(Preferably a pyopencl.tools.MemoryPool in order "
166166
"to reduce device allocations)", stacklevel=2)
167+
167168
super().__init__(queue, allocator,
168169
compile_trace_callback=compile_trace_callback)
169170

@@ -509,11 +510,34 @@ class PytestPyOpenCLArrayContextFactory(
509510
_PytestPyOpenCLArrayContextFactoryWithClass):
510511
actx_class = PyOpenCLArrayContext
511512

513+
def __call__(self):
514+
actx = super().__call__()
515+
if actx.allocator is not None:
516+
return actx
517+
518+
from pyopencl.tools import ImmediateAllocator, MemoryPool
519+
alloc = MemoryPool(ImmediateAllocator(actx.queue))
520+
521+
return self.actx_class(
522+
actx.queue,
523+
allocator=alloc,
524+
force_device_scalars=self.force_device_scalars)
525+
512526

513527
class PytestPytatoPyOpenCLArrayContextFactory(
514528
_PytestPytatoPyOpenCLArrayContextFactory):
515529
actx_class = PytatoPyOpenCLArrayContext
516530

531+
def __call__(self):
532+
actx = super().__call__()
533+
if actx.allocator is not None:
534+
return actx
535+
536+
from pyopencl.tools import ImmediateAllocator, MemoryPool
537+
alloc = MemoryPool(ImmediateAllocator(actx.queue))
538+
539+
return self.actx_class(actx.queue, allocator=alloc)
540+
517541

518542
# deprecated
519543
class PytestPyOpenCLArrayContextFactoryWithHostScalars(

0 commit comments

Comments
 (0)