Skip to content

Commit

Permalink
add reload option (non threaded)
Browse files Browse the repository at this point in the history
  • Loading branch information
caillonantoine committed May 24, 2023
1 parent bc2276b commit 8dd747a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/backend/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <iostream>
#include <stdlib.h>


#define CUDA torch::kCUDA
#define CPU torch::kCPU

Expand Down Expand Up @@ -85,20 +86,26 @@ void Backend::perform(std::vector<float *> in_buffer,

int Backend::load(std::string path) {
try {
m_model = torch::jit::load(path);
m_model.eval();
auto model = torch::jit::load(path);
model.eval();
if (m_cuda_available) {
std::cout << "sending model to gpu" << std::endl;
m_model.to(CUDA);
model.to(CUDA);
}
m_model = model;
m_loaded = 1;
m_path = path;
return 0;
} catch (const std::exception &e) {
std::cerr << e.what() << '\n';
return 1;
}
}

int Backend::reload(){
return load(m_path);
}

bool Backend::has_method(std::string method_name) {
for (const auto &m : m_model.get_methods()) {
if (m.name() == method_name)
Expand Down
2 changes: 2 additions & 0 deletions src/backend/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Backend {
private:
torch::jit::script::Module m_model;
int m_loaded;
std::string m_path;

public:
Backend();
Expand All @@ -26,6 +27,7 @@ class Backend {
std::vector<int> get_method_params(std::string method);
int get_higher_ratio();
int load(std::string path);
int reload();
bool is_loaded();
bool m_cuda_available;
torch::jit::script::Module get_model() { return m_model; }
Expand Down

0 comments on commit 8dd747a

Please sign in to comment.