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

Method worker

csrc/adam/cpu_adam_impl.cpp:574–609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

572
573private:
574 void worker(size_t tid, int core)
575 {
576#if defined(__linux__)
577 if (core >= 0) {
578 cpu_set_t set;
579 CPU_ZERO(&set);
580 CPU_SET(core, &set);
581 pthread_setaffinity_np(pthread_self(), sizeof(cpu_set_t), &set);
582 }
583#endif
584 long seen = 0;
585 while (true) {
586 std::function<void(size_t, size_t)> fn;
587 size_t total = 0;
588 size_t align = 1;
589 {
590 std::unique_lock<std::mutex> lk(m_);
591 cv_start_.wait(lk, [this, seen] { return gen_ != seen; });
592 seen = gen_;
593 if (stop_) return;
594 fn = fn_;
595 total = total_;
596 align = align_;
597 }
598 size_t chunk = (total + n_ - 1) / n_;
599 chunk = ((chunk + align - 1) / align) * align; // round up to SIMD-block alignment
600 size_t begin = std::min(tid * chunk, total);
601 size_t end = std::min(begin + chunk, total);
602 if (end > begin) fn(begin, end);
603 {
604 std::lock_guard<std::mutex> lk(m_);
605 ++done_count_;
606 if (done_count_ == n_) cv_done_.notify_one();
607 }
608 }
609 }
610
611 size_t n_;
612 std::vector<std::thread> threads_;

Callers

nothing calls this directly

Calls 2

fnFunction · 0.50
waitMethod · 0.45

Tested by

no test coverage detected