LoadVocabularies inlined in service_base.h

To fix WASM Mac builds on CI. loadVocabularies function is now inlines
and available through service_base.h, from where it seems to propogate
to all places of use.
This commit is contained in:
Jerin Philip 2021-02-26 00:43:36 +00:00
parent dad3a4088c
commit 66e3b4493e
3 changed files with 21 additions and 26 deletions

View File

@ -65,24 +65,5 @@ void Service::stop() {
Service::~Service() { stop(); }
// Internal function nobody used, only within service.
std::vector<Ptr<const Vocab>> loadVocabularies(Ptr<Options> options) {
// @TODO: parallelize vocab loading for faster startup
auto vfiles = options->get<std::vector<std::string>>("vocabs");
// with the current setup, we need at least two vocabs: src and trg
ABORT_IF(vfiles.size() < 2, "Insufficient number of vocabularies.");
std::vector<Ptr<Vocab const>> vocabs(vfiles.size());
std::unordered_map<std::string, Ptr<Vocab>> vmap;
for (size_t i = 0; i < vocabs.size(); ++i) {
auto m = vmap.emplace(std::make_pair(vfiles[i], Ptr<Vocab>()));
if (m.second) { // new: load the vocab
m.first->second = New<Vocab>(options, i);
m.first->second->load(vfiles[i]);
}
vocabs[i] = m.first->second;
}
return vocabs;
}
} // namespace bergamot
} // namespace marian

View File

@ -1,4 +1,3 @@
#ifndef SRC_BERGAMOT_SERVICE_H_
#define SRC_BERGAMOT_SERVICE_H_
@ -44,8 +43,6 @@ private:
std::vector<BatchTranslator> translators_;
};
std::vector<Ptr<const Vocab>> loadVocabularies(Ptr<Options> options);
} // namespace bergamot
} // namespace marian

View File

@ -1,5 +1,5 @@
#ifndef SRC_BERGAMOT_SUBSTANDARD_SERVICE_H_
#define SRC_BERGAMOT_SUBSTANDARD_SERVICE_H_
#ifndef SRC_BERGAMOT_SERVICE_BASE_H_
#define SRC_BERGAMOT_SERVICE_BASE_H_
#include "batch_translator.h"
#include "batcher.h"
#include "data/types.h"
@ -42,9 +42,26 @@ private:
BatchTranslator translator_;
};
std::vector<Ptr<const Vocab>> loadVocabularies(Ptr<Options> options);
// Internal function nobody used, only within service.
inline std::vector<Ptr<const Vocab>> loadVocabularies(Ptr<Options> options) {
// @TODO: parallelize vocab loading for faster startup
auto vfiles = options->get<std::vector<std::string>>("vocabs");
// with the current setup, we need at least two vocabs: src and trg
ABORT_IF(vfiles.size() < 2, "Insufficient number of vocabularies.");
std::vector<Ptr<Vocab const>> vocabs(vfiles.size());
std::unordered_map<std::string, Ptr<Vocab>> vmap;
for (size_t i = 0; i < vocabs.size(); ++i) {
auto m = vmap.emplace(std::make_pair(vfiles[i], Ptr<Vocab>()));
if (m.second) { // new: load the vocab
m.first->second = New<Vocab>(options, i);
m.first->second->load(vfiles[i]);
}
vocabs[i] = m.first->second;
}
return vocabs;
}
} // namespace bergamot
} // namespace marian
#endif // SRC_BERGAMOT_SUBSTANDARD_SERVICE_H_
#endif // SRC_BERGAMOT_SERVICE_BASE_H_