| 69 | RemoteExperts::~RemoteExperts() { close(); } |
| 70 | |
| 71 | bool RemoteExperts::preflight(int device, double& free_gib, std::string& err) { |
| 72 | int count = 0; |
| 73 | if (!check(cudaGetDeviceCount(&count), "cudaGetDeviceCount", err, device)) return false; |
| 74 | if (device < 0 || device >= count) { |
| 75 | err = "CUDA" + std::to_string(device) + " experts: CUDA device is not visible"; |
| 76 | return false; |
| 77 | } |
| 78 | if (device == primary_device()) { // the primary may be any visible ordinal; the helper cannot be it |
| 79 | err = "CUDA" + std::to_string(device) + " experts: the helper cannot be the primary device " |
| 80 | "(STRATA_PRIMARY_DEVICE)"; |
| 81 | return false; |
| 82 | } |
| 83 | // The layer waits for this GPU on the CPU pool's critical path: spin instead of sleeping, whose wake-up |
| 84 | // costs more than a small expert batch takes (measured: ~0.3 ms per round trip on Windows). Only possible |
| 85 | // before the device's context exists, so first thing; STRATA_REMOTE_SPIN=0 keeps the driver's default. |
| 86 | #if !defined(STRATA_USE_HIP) && !defined(STRATA_GPU_METAL) |
| 87 | const char* spin = std::getenv("STRATA_REMOTE_SPIN"); |
| 88 | if (!(spin && spin[0] == '0')) cudaInitDevice(device, cudaDeviceScheduleSpin | cudaDeviceMapHost, 0); |
| 89 | cudaGetLastError(); |
| 90 | #endif |
| 91 | // HIP has no cudaInitDevice equivalent; retain its default scheduling policy. |
| 92 | DeviceScope scope(device); |
| 93 | if (!scope.ok) { err = scope.error(device); return false; } |
| 94 | size_t free_bytes = 0, total_bytes = 0; |
| 95 | if (!check(cudaMemGetInfo(&free_bytes, &total_bytes), "preflight free memory", err, device)) return false; |
| 96 | free_gib = (double) free_bytes / 1073741824.0; |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | void RemoteExperts::close() { |
| 101 | if (device_ < 0) return; |
nothing calls this directly
no test coverage detected