Returns True if the user has installed a version of cupy.
()
| 359 | |
| 360 | |
| 361 | def 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 | |
| 384 | HAS_CUPY = has_cupy() |
no test coverage detected
searching dependent graphs…