MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / has_cupy

Function has_cupy

tests/test_utils.py:361–381  ·  view source on GitHub ↗

Returns True if the user has installed a version of cupy.

()

Source from the content-addressed store, hash-verified

359
360
361def has_cupy():
362 """
363 Returns True if the user has installed a version of cupy.
364 """
365 cp, has_cp = optional_import("cupy")
366 if not is_main_test_process():
367 return has_cp # skip the check if we are running in subprocess
368 if not has_cp:
369 return False
370 try: # test cupy installation with a basic example
371 x = cp.arange(6, dtype="f").reshape(2, 3)
372 y = cp.arange(3, dtype="f")
373 kernel = cp.ElementwiseKernel(
374 "float32 x, float32 y", "float32 z", """ if (x - 2 > y) { z = x * y; } else { z = x + y; } """, "my_kernel"
375 )
376 flag = kernel(x, y)[0, 0] == 0
377 del x, y, kernel
378 cp.get_default_memory_pool().free_all_blocks()
379 return flag
380 except Exception:
381 return False
382
383
384HAS_CUPY = has_cupy()

Callers 1

test_utils.pyFile · 0.85

Calls 2

optional_importFunction · 0.90
is_main_test_processFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…