MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / worker

Method worker

csrc/adam/cpu_adam_impl.cpp:438–473  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

436
437private:
438 void worker(size_t tid, int core)
439 {
440#if defined(__linux__)
441 if (core >= 0) {
442 cpu_set_t set;
443 CPU_ZERO(&set);
444 CPU_SET(core, &set);
445 pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &set);
446 }
447#endif
448 long seen = 0;
449 while (true) {
450 std::function<void(size_t, size_t)> fn;
451 size_t total = 0;
452 size_t align = 1;
453 {
454 std::unique_lock<std::mutex> lk(m_);
455 cv_start_.wait(lk, [this, seen] { return gen_ != seen; });
456 seen = gen_;
457 if (stop_) return;
458 fn = fn_;
459 total = total_;
460 align = align_;
461 }
462 size_t chunk = (total + n_ - 1) / n_;
463 chunk = ((chunk + align - 1) / align) * align; // round up to SIMD-block alignment
464 size_t begin = std::min(tid * chunk, total);
465 size_t end = std::min(begin + chunk, total);
466 if (end > begin) fn(begin, end);
467 {
468 std::lock_guard<std::mutex> lk(m_);
469 ++done_count_;
470 if (done_count_ == n_) cv_done_.notify_one();
471 }
472 }
473 }
474
475 size_t n_;
476 std::vector<std::thread> threads_;

Callers

nothing calls this directly

Calls 2

fnFunction · 0.50
waitMethod · 0.45

Tested by

no test coverage detected