Skip to content

Commit

Permalink
Compile defs: __EMSCRIPTEN__ -> WASM
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerin Philip committed Mar 23, 2021
1 parent 8c89581 commit 258f23e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/translator/batch_translator.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "translator/history.h"
#include "translator/scorers.h"

#ifndef __EMSCRIPTEN__
#ifndef WASM
#include "pcqueue.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/translator/batcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "definitions.h"
#include "request.h"

#ifndef __EMSCRIPTEN__
#ifndef WASM
#include "pcqueue.h"
#endif

Expand Down
10 changes: 5 additions & 5 deletions src/translator/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Service::Service(Ptr<Options> options, const void *model_memory)
: requestId_(0), vocabs_(std::move(loadVocabularies(options))),
text_processor_(vocabs_, options), batcher_(options),
numWorkers_(options->get<int>("cpu-threads")), model_memory_(model_memory)
#ifndef __EMSCRIPTEN__
#ifndef WASM
// 0 elements in PCQueue is illegal and can lead to failures. Adding a
// guard to have at least one entry allocated. In the single-threaded
// case, while initialized pcqueue_ remains unused.
Expand Down Expand Up @@ -70,7 +70,7 @@ void Service::blocking_translate() {
}
}

#ifndef __EMSCRIPTEN__
#ifndef WASM
void Service::initialize_async_translators() {
workers_.reserve(numWorkers_);

Expand Down Expand Up @@ -100,15 +100,15 @@ void Service::async_translate() {
pcqueue_.ProduceSwap(batch);
}
}
#else // __EMSCRIPTEN__
#else // WASM
void Service::initialize_async_translators() {
ABORT("Cannot run in async mode without multithreading.");
}

void Service::async_translate() {
ABORT("Cannot run in async mode without multithreading.");
}
#endif // __EMSCRIPTEN__
#endif // WASM

std::future<Response> Service::translate(std::string &&input) {
Segments segments;
Expand All @@ -132,7 +132,7 @@ std::future<Response> Service::translate(std::string &&input) {
}

Service::~Service() {
#ifndef __EMSCRIPTEN__
#ifndef WASM
for (size_t workerId = 0; workerId < numWorkers_; workerId++) {

Batch poison = Batch::poison();
Expand Down
6 changes: 3 additions & 3 deletions src/translator/service.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "text_processor.h"
#include "translator/parser.h"

#ifndef __EMSCRIPTEN__
#ifndef WASM
#include "pcqueue.h"
#endif

Expand Down Expand Up @@ -111,10 +111,10 @@ class Service {

// The following constructs are available providing full capabilities on a non
// WASM platform, where one does not have to hide threads.
#ifndef __EMSCRIPTEN__
#ifndef WASM
PCQueue<Batch> pcqueue_; // ORDER DEPENDENCY (numWorkers_)
std::vector<std::thread> workers_;
#endif // __EMSCRIPTEN__
#endif // WASM
};

} // namespace bergamot
Expand Down

0 comments on commit 258f23e

Please sign in to comment.