| 7216 | } |
| 7217 | |
| 7218 | void ForesightSwap::fill_loop() { |
| 7219 | strata::platform::name_this_thread("strata-fill"); |
| 7220 | int cur_dev = -1; |
| 7221 | for (;;) { |
| 7222 | int64_t idx; |
| 7223 | { |
| 7224 | std::unique_lock<std::mutex> lk(mu_); |
| 7225 | cv_.wait(lk, [&] { return stop_ || !queue_.empty(); }); |
| 7226 | if (stop_) return; |
| 7227 | idx = queue_.front(); |
| 7228 | queue_.pop_front(); |
| 7229 | } |
| 7230 | Slot& sl = slot[(size_t) idx]; |
| 7231 | const int64_t l = idx / slots; |
| 7232 | const int dev = layer_dev[(size_t) l]; |
| 7233 | if (dev != cur_dev) { cudaSetDevice(dev); cur_dev = dev; } |
| 7234 | cudaStream_t s = (cudaStream_t) card_stream[(size_t) layer_card[(size_t) l]]; |
| 7235 | if (cudaMemcpyAsync((void*) sl.dptr, sl.src, sl.bytes, cudaMemcpyHostToDevice, s) != cudaSuccess || |
| 7236 | cudaEventRecord((cudaEvent_t) sl.ev, s) != cudaSuccess) { |
| 7237 | cudaGetLastError(); |
| 7238 | if (!failed.exchange(true)) std::fprintf(stderr, "strata serve: foresight swap: a copy failed - swap space off\n"); |
| 7239 | continue; // never marked issued: the slot is never used |
| 7240 | } |
| 7241 | sl.issued.store(true, std::memory_order_release); |
| 7242 | } |
| 7243 | } |
| 7244 | |
| 7245 | bool ForesightSwap::take(int64_t layer, int32_t expert, unsigned long long& ptr) { |
| 7246 | std::lock_guard<std::mutex> smu_lk(smu_); |
nothing calls this directly
no test coverage detected