mirror of
https://github.com/browsermt/bergamot-translator.git
synced 2024-09-11 05:35:33 +03:00
Getting rid of the ifdef from BatchTranslator as well
This commit is contained in:
parent
cd01d7552a
commit
570865e799
@ -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
|
||||
|
@ -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_;
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user