| 13 | #include "errors.h" |
| 14 | |
| 15 | bool try_push_context() |
| 16 | { |
| 17 | CUcontext context = nullptr; |
| 18 | |
| 19 | check(cuCtxGetCurrent(&context)); |
| 20 | |
| 21 | if (context == nullptr) |
| 22 | { |
| 23 | const int default_device = 0; |
| 24 | check(cuDevicePrimaryCtxRetain(&context, default_device)); |
| 25 | check(cuCtxPushCurrent(context)); |
| 26 | |
| 27 | return true; |
| 28 | } |
| 29 | |
| 30 | return false; |
| 31 | } |