Getting rid of the ifdef from BatchTranslator as well

This commit is contained in:
Jerin Philip 2021-02-25 23:50:57 +00:00
parent cd01d7552a
commit 570865e799
4 changed files with 16 additions and 24 deletions

View File

@ -96,22 +96,5 @@ void BatchTranslator::translate(Batch &batch) {
batch.completeBatch(histories);
}
#ifdef WITH_PTHREADS
void BatchTranslator::consumeFrom(PCQueue<Batch> &pcqueue) {
Batch batch;
Histories histories;
while (true) {
pcqueue.ConsumeSwap(batch);
if (batch.isPoison()) {
return;
} else {
translate(batch);
}
}
}
#endif
} // namespace bergamot
} // namespace marian

View File

@ -34,10 +34,6 @@ public:
void translate(Batch &batch);
void initialize();
#ifdef WITH_PTHREADS
void consumeFrom(PCQueue<Batch> &pcqueue);
#endif
private:
Ptr<Options> options_;
DeviceId device_;

View File

@ -21,11 +21,22 @@ Service::Service(Ptr<Options> options)
for (size_t cpuId = 0; cpuId < numWorkers_; cpuId++) {
marian::DeviceId deviceId(cpuId, DeviceType::cpu);
translators_.emplace_back(deviceId, vocabs_, options);
auto &translator = translators_.back();
workers_.emplace_back([&translator, this] {
translator.initialize();
translator.consumeFrom(pcqueue_);
// Run thread mainloop
Batch batch;
Histories histories;
while (true) {
pcqueue_.ConsumeSwap(batch);
if (batch.isPoison()) {
return;
} else {
translator.translate(batch);
}
}
});
}
}

View File

@ -26,7 +26,9 @@ std::future<Response> ServiceBase::translate(std::string &&input) {
NonThreadedService::NonThreadedService(Ptr<Options> options)
: ServiceBase(options),
translator_(DeviceId(0, DeviceType::cpu), vocabs_, options) {}
translator_(DeviceId(0, DeviceType::cpu), vocabs_, options) {
translator_.initialize();
}
void NonThreadedService::enqueue() {
// Queue single-threaded