From fd74cc932ae8d734d8830e07eeba39c2d967e72c Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Tue, 7 Feb 2017 16:29:11 +0000 Subject: [PATCH 1/5] make sure it runs on machine with GPU or CUDA --- src/plugin/nmt.cu | 13 ------------- src/plugin/nmt.h | 1 - 2 files changed, 14 deletions(-) diff --git a/src/plugin/nmt.cu b/src/plugin/nmt.cu index 09d11d79..8cab3cb6 100644 --- a/src/plugin/nmt.cu +++ b/src/plugin/nmt.cu @@ -27,19 +27,6 @@ MosesPlugin::~MosesPlugin() { } -size_t MosesPlugin::GetDevices(size_t maxDevices) { - int num_gpus = 0; // number of CUDA GPUs - HANDLE_ERROR( cudaGetDeviceCount(&num_gpus)); - std::cerr << "Number of CUDA devices: " << num_gpus << std::endl; - - for (int i = 0; i < num_gpus; i++) { - cudaDeviceProp dprop; - HANDLE_ERROR( cudaGetDeviceProperties(&dprop, i)); - std::cerr << i << ": " << dprop.name << std::endl; - } - return (size_t)std::min(num_gpus, (int)maxDevices); -} - AmunOutput MosesPlugin::SetSource(const std::vector& words) { AmunOutput ret; diff --git a/src/plugin/nmt.h b/src/plugin/nmt.h index 07aa2105..9bda6768 100644 --- a/src/plugin/nmt.h +++ b/src/plugin/nmt.h @@ -25,7 +25,6 @@ class MosesPlugin { MosesPlugin(); ~MosesPlugin(); - static size_t GetDevices(size_t = 1); void SetDevice(); size_t GetDevice(); const amunmt::God &GetGod() const From 6b7aa7577b71143e9093846f38dc51a183ccb7af Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Tue, 7 Feb 2017 16:54:59 +0000 Subject: [PATCH 2/5] clean up hypo state interface --- src/CMakeLists.txt | 4 ++-- src/plugin/hypo_info.cpp | 2 +- src/plugin/hypo_info.h | 15 ++------------- src/plugin/nmt.cu | 8 ++++---- src/plugin/nmt.h | 4 ++-- 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bdb7c2b7..2ca0155c 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -101,7 +101,7 @@ cuda_add_library(mosesplugin STATIC $ $ ) -set_target_properties("mosesplugin" PROPERTIES EXCLUDE_FROM_ALL 1) +#set_target_properties("mosesplugin" PROPERTIES EXCLUDE_FROM_ALL 1) else(CUDA_FOUND) @@ -124,7 +124,7 @@ add_library(amunmt SHARED $ $ ) -set_target_properties("amunmt" PROPERTIES EXCLUDE_FROM_ALL 1) +#set_target_properties("amunmt" PROPERTIES EXCLUDE_FROM_ALL 1) endif(PYTHONLIBS_FOUND) endif(CUDA_FOUND) diff --git a/src/plugin/hypo_info.cpp b/src/plugin/hypo_info.cpp index 6a3c2608..1141c993 100644 --- a/src/plugin/hypo_info.cpp +++ b/src/plugin/hypo_info.cpp @@ -5,7 +5,7 @@ using namespace std; namespace amunmt { -std::string AmunOutput::Debug() const +std::string HypoState::Debug() const { stringstream strm; /* diff --git a/src/plugin/hypo_info.h b/src/plugin/hypo_info.h index d89def98..30f738c4 100644 --- a/src/plugin/hypo_info.h +++ b/src/plugin/hypo_info.h @@ -10,7 +10,7 @@ namespace amunmt { -struct AmunOutput +struct HypoState { States states; Beam prevHyps; @@ -21,19 +21,8 @@ struct AmunOutput }; -typedef std::vector AmunOutputs; +typedef std::vector HypoStates; -//////////////////////////////////////////////////////////////// -struct AmunInput -{ - States prevStates; - States nextStates; - Beam prevHyps; - - Words phrase; -}; - -typedef std::vector AmunInputs; } diff --git a/src/plugin/nmt.cu b/src/plugin/nmt.cu index 8cab3cb6..8b372b64 100644 --- a/src/plugin/nmt.cu +++ b/src/plugin/nmt.cu @@ -27,8 +27,8 @@ MosesPlugin::~MosesPlugin() { } -AmunOutput MosesPlugin::SetSource(const std::vector& words) { - AmunOutput ret; +HypoState MosesPlugin::SetSource(const std::vector& words) { + HypoState ret; amunmt::Sentences sentences; sentences.push_back(SentencePtr(new Sentence(god_, 0, words))); @@ -55,9 +55,9 @@ AmunOutput MosesPlugin::SetSource(const std::vector& words) { return ret; } -AmunOutputs MosesPlugin::Score(const AmunInputs &inputs) +HypoStates MosesPlugin::Score(const HypoStates &inputs) { - AmunOutputs outputs(inputs.size()); + HypoStates outputs(inputs.size()); // TODO diff --git a/src/plugin/nmt.h b/src/plugin/nmt.h index 9bda6768..5ae39cc6 100644 --- a/src/plugin/nmt.h +++ b/src/plugin/nmt.h @@ -32,9 +32,9 @@ class MosesPlugin { void initGod(const std::string& configPath); - AmunOutput SetSource(const std::vector& words); + HypoState SetSource(const std::vector& words); - AmunOutputs Score(const AmunInputs &inputs); + HypoStates Score(const HypoStates &inputs); private: amunmt::God god_; From a4587cb3f2051e922d55ad1d19ca885a3ade390d Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Tue, 7 Feb 2017 17:12:36 +0000 Subject: [PATCH 3/5] clean up hypo state interface --- src/plugin/hypo_info.h | 12 ++++++++++++ src/plugin/nmt.cu | 2 +- src/plugin/nmt.h | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/plugin/hypo_info.h b/src/plugin/hypo_info.h index 30f738c4..1b33ee00 100644 --- a/src/plugin/hypo_info.h +++ b/src/plugin/hypo_info.h @@ -23,6 +23,18 @@ struct HypoState typedef std::vector HypoStates; +//////////////////////////////////////////////////////////////// +struct AmunInput : public HypoState +{ + AmunInput(const HypoState &hypoState) + :HypoState(hypoState) + { + } + + Words phrase; +}; + +typedef std::vector AmunInputs; } diff --git a/src/plugin/nmt.cu b/src/plugin/nmt.cu index 8b372b64..fc362a1c 100644 --- a/src/plugin/nmt.cu +++ b/src/plugin/nmt.cu @@ -55,7 +55,7 @@ HypoState MosesPlugin::SetSource(const std::vector& words) { return ret; } -HypoStates MosesPlugin::Score(const HypoStates &inputs) +HypoStates MosesPlugin::Score(const AmunInputs &inputs) { HypoStates outputs(inputs.size()); diff --git a/src/plugin/nmt.h b/src/plugin/nmt.h index 5ae39cc6..af8ad6a6 100644 --- a/src/plugin/nmt.h +++ b/src/plugin/nmt.h @@ -34,7 +34,7 @@ class MosesPlugin { HypoState SetSource(const std::vector& words); - HypoStates Score(const HypoStates &inputs); + HypoStates Score(const AmunInputs &inputs); private: amunmt::God god_; From 790abd5f8f50c18594fcec8a46cfe0a3798750e8 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Tue, 7 Feb 2017 17:14:21 +0000 Subject: [PATCH 4/5] re-exclude building libraries --- src/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2ca0155c..bdb7c2b7 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -101,7 +101,7 @@ cuda_add_library(mosesplugin STATIC $ $ ) -#set_target_properties("mosesplugin" PROPERTIES EXCLUDE_FROM_ALL 1) +set_target_properties("mosesplugin" PROPERTIES EXCLUDE_FROM_ALL 1) else(CUDA_FOUND) @@ -124,7 +124,7 @@ add_library(amunmt SHARED $ $ ) -#set_target_properties("amunmt" PROPERTIES EXCLUDE_FROM_ALL 1) +set_target_properties("amunmt" PROPERTIES EXCLUDE_FROM_ALL 1) endif(PYTHONLIBS_FOUND) endif(CUDA_FOUND) From 65d57da0b0c529661d23ca438c82db2da0d1b1ca Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Tue, 7 Feb 2017 17:39:35 +0000 Subject: [PATCH 5/5] stored sentences. Used in decoding --- src/plugin/hypo_info.cpp | 7 +++++++ src/plugin/hypo_info.h | 5 +++++ src/plugin/nmt.cu | 12 ++++++------ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/plugin/hypo_info.cpp b/src/plugin/hypo_info.cpp index 1141c993..7a06950d 100644 --- a/src/plugin/hypo_info.cpp +++ b/src/plugin/hypo_info.cpp @@ -5,6 +5,13 @@ using namespace std; namespace amunmt { +HypoState::HypoState() +{} + +HypoState::~HypoState() +{ +} + std::string HypoState::Debug() const { stringstream strm; diff --git a/src/plugin/hypo_info.h b/src/plugin/hypo_info.h index 1b33ee00..b5344cbe 100644 --- a/src/plugin/hypo_info.h +++ b/src/plugin/hypo_info.h @@ -17,6 +17,11 @@ struct HypoState float score; + std::shared_ptr sentences; + + HypoState(); + ~HypoState(); + std::string Debug() const; }; diff --git a/src/plugin/nmt.cu b/src/plugin/nmt.cu index fc362a1c..80b5ce0d 100644 --- a/src/plugin/nmt.cu +++ b/src/plugin/nmt.cu @@ -30,22 +30,22 @@ MosesPlugin::~MosesPlugin() HypoState MosesPlugin::SetSource(const std::vector& words) { HypoState ret; - amunmt::Sentences sentences; - sentences.push_back(SentencePtr(new Sentence(god_, 0, words))); + ret.sentences.reset(new Sentences()); + ret.sentences->push_back(SentencePtr(new Sentence(god_, 0, words))); // Encode Search &search = god_.GetSearch(); size_t numScorers = search.GetScorers().size(); - std::shared_ptr histories(new Histories(god_, sentences)); + std::shared_ptr histories(new Histories(god_, *ret.sentences)); - size_t batchSize = sentences.size(); + size_t batchSize = ret.sentences->size(); Beam prevHyps(batchSize, HypothesisPtr(new Hypothesis())); States states = search.NewStates(); - search.PreProcess(god_, sentences, histories, prevHyps); - search.Encode(sentences, states); + search.PreProcess(god_, *ret.sentences, histories, prevHyps); + search.Encode(*ret.sentences, states); // fill return info ret.states = states;